Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonaDetailsDialog.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.centralrepository.persona;
20 
21 import java.awt.Component;
22 import java.util.logging.Level;
23 import javax.swing.JDialog;
24 import javax.swing.JFrame;
25 import javax.swing.JOptionPane;
26 import org.openide.util.NbBundle;
27 import org.openide.windows.WindowManager;
30 
34 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
35 public class PersonaDetailsDialog extends JDialog {
36 
37  private static final long serialVersionUID = 1L;
38 
39  private static final Logger logger = Logger.getLogger(PersonaDetailsDialog.class.getName());
40 
42 
43  private String popupMessageOnStartup = "";
44 
45  @NbBundle.Messages({
46  "PersonaDetailsDialogCreateTitle=Create Persona",
47  "PersonaDetailsDialogEditTitle=Edit Persona",
48  "PersonaDetailsDialogViewTitle=View Persona",})
49  public PersonaDetailsDialog(Component parent, PersonaDetailsMode mode, Persona persona, PersonaDetailsDialogCallback callback) {
50  // by default, display the dialog right away
51  this(parent, mode, persona, callback, true);
52  }
53  public PersonaDetailsDialog(Component parent, PersonaDetailsMode mode, Persona persona, PersonaDetailsDialogCallback callback, boolean displayDialog) {
54  super((JFrame) WindowManager.getDefault().getMainWindow(),
55  getTitle(mode),
56  true);
57  this.callback = callback;
58 
59  initComponents();
60 
61  pdp.setMode(parent, mode, persona);
62 
63  if (displayDialog) {
64  display();
65  }
66  }
67 
68  private static String getTitle(PersonaDetailsMode mode) {
69  switch (mode) {
70  case CREATE:
71  return Bundle.PersonaDetailsDialogCreateTitle();
72  case EDIT:
73  return Bundle.PersonaDetailsDialogEditTitle();
74  case VIEW:
75  return Bundle.PersonaDetailsDialogViewTitle();
76  default:
77  logger.log(Level.WARNING, "Unsupported mode: {0}", mode);
78  return Bundle.PersonaDetailsDialogViewTitle();
79  }
80  }
81 
87  @SuppressWarnings("unchecked")
88  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
89  private void initComponents() {
90 
91  cancelBtn = new javax.swing.JButton();
92  okBtn = new javax.swing.JButton();
93  jScrollPane1 = new javax.swing.JScrollPane();
95 
96  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
97  addWindowListener(new java.awt.event.WindowAdapter() {
98  public void windowOpened(java.awt.event.WindowEvent evt) {
99  formWindowOpened(evt);
100  }
101  });
102 
103  org.openide.awt.Mnemonics.setLocalizedText(cancelBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsDialog.class, "PersonaDetailsDialog.cancelBtn.text")); // NOI18N
104  cancelBtn.setMaximumSize(new java.awt.Dimension(79, 23));
105  cancelBtn.setMinimumSize(new java.awt.Dimension(79, 23));
106  cancelBtn.setPreferredSize(new java.awt.Dimension(79, 23));
107  cancelBtn.addActionListener(new java.awt.event.ActionListener() {
108  public void actionPerformed(java.awt.event.ActionEvent evt) {
109  cancelBtnActionPerformed(evt);
110  }
111  });
112 
113  org.openide.awt.Mnemonics.setLocalizedText(okBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsDialog.class, "PersonaDetailsDialog.okBtn.text")); // NOI18N
114  okBtn.addActionListener(new java.awt.event.ActionListener() {
115  public void actionPerformed(java.awt.event.ActionEvent evt) {
116  okBtnActionPerformed(evt);
117  }
118  });
119 
120  jScrollPane1.setBorder(null);
121  jScrollPane1.setViewportView(pdp);
122 
123  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
124  getContentPane().setLayout(layout);
125  layout.setHorizontalGroup(
126  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127  .addGroup(layout.createSequentialGroup()
128  .addContainerGap(470, Short.MAX_VALUE)
129  .addComponent(okBtn)
130  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
131  .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
132  .addContainerGap())
133  .addComponent(jScrollPane1)
134  );
135 
136  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelBtn, okBtn});
137 
138  layout.setVerticalGroup(
139  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140  .addGroup(layout.createSequentialGroup()
141  .addContainerGap()
142  .addComponent(jScrollPane1)
143  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
144  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
145  .addComponent(okBtn)
146  .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
147  .addContainerGap())
148  );
149 
150  pack();
151  }// </editor-fold>//GEN-END:initComponents
152 
153  public final void display() {
154  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
155  setVisible(true);
156  }
157 
158  private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
159  Persona ret = pdp.okHandler();
160  if (ret != null) {
161  callback.callback(ret);
162  dispose();
163  }
164  }//GEN-LAST:event_okBtnActionPerformed
165 
166  private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
167  dispose();
168  }//GEN-LAST:event_cancelBtnActionPerformed
169 
170  private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
171  if(!popupMessageOnStartup.isEmpty()) {
172  JOptionPane.showMessageDialog(this, popupMessageOnStartup, "Persona Details", JOptionPane.INFORMATION_MESSAGE);
173  }
174  }//GEN-LAST:event_formWindowOpened
175 
177  return this.pdp;
178  }
179 
180  public void setStartupPopupMessage(String message) {
181  popupMessageOnStartup = message;
182  }
183 
184  // Variables declaration - do not modify//GEN-BEGIN:variables
185  private javax.swing.JButton cancelBtn;
186  private javax.swing.JScrollPane jScrollPane1;
187  private javax.swing.JButton okBtn;
189  // End of variables declaration//GEN-END:variables
190 }
PersonaDetailsDialog(Component parent, PersonaDetailsMode mode, Persona persona, PersonaDetailsDialogCallback callback, boolean displayDialog)
PersonaDetailsDialog(Component parent, PersonaDetailsMode mode, Persona persona, PersonaDetailsDialogCallback callback)
org.sleuthkit.autopsy.centralrepository.persona.PersonaDetailsPanel pdp
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.