Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonaMetadataDialog.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 javax.swing.JDialog;
22 import javax.swing.JOptionPane;
23 import javax.swing.SwingUtilities;
24 import org.openide.util.NbBundle.Messages;
25 import org.openide.windows.WindowManager;
27 
31 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
32 public class PersonaMetadataDialog extends JDialog {
33 
34  private static final long serialVersionUID = 1L;
35 
36  private final PersonaDetailsPanel pdp;
37 
39 
43  @Messages({"AddMetadataDialog.title.text=Add Metadata",})
45  super(SwingUtilities.windowForComponent(pdp),
46  Bundle.AddMetadataDialog_title_text(),
47  ModalityType.APPLICATION_MODAL);
48  this.pdp = pdp;
49 
50  initComponents();
51  display();
52  }
53 
55  super(SwingUtilities.windowForComponent(pdp),
56  Bundle.AddMetadataDialog_title_text(),
57  ModalityType.APPLICATION_MODAL);
58  this.pdp = pdp;
59 
60  initComponents();
61  currentMetadata = md;
62  confidenceComboBox.setSelectedItem(md.confidence);
63  justificationTextField.setText(md.justification);
64  nameTextField.setText(md.name);
65  valueTextField.setText(md.value);
66 
67  nameTextField.setEnabled(false);
68  valueTextField.setEnabled(false);
69 
70  display();
71  }
72 
78  @SuppressWarnings("unchecked")
79  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
80  private void initComponents() {
81 
82  settingsPanel = new javax.swing.JPanel();
83  nameLbl = new javax.swing.JLabel();
84  nameTextField = new javax.swing.JTextField();
85  valueLbl = new javax.swing.JLabel();
86  valueTextField = new javax.swing.JTextField();
87  confidenceLbl = new javax.swing.JLabel();
88  confidenceComboBox = new javax.swing.JComboBox<>();
89  justificationLbl = new javax.swing.JLabel();
90  justificationTextField = new javax.swing.JTextField();
91  cancelBtn = new javax.swing.JButton();
92  okBtn = new javax.swing.JButton();
93 
94  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
95  setResizable(false);
96 
97  settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
98 
99  org.openide.awt.Mnemonics.setLocalizedText(nameLbl, org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.nameLbl.text")); // NOI18N
100 
101  nameTextField.setText(org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.nameTextField.text")); // NOI18N
102 
103  org.openide.awt.Mnemonics.setLocalizedText(valueLbl, org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.valueLbl.text")); // NOI18N
104 
105  valueTextField.setText(org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.valueTextField.text")); // NOI18N
106 
107  org.openide.awt.Mnemonics.setLocalizedText(confidenceLbl, org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.confidenceLbl.text")); // NOI18N
108 
109  confidenceComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence.values()));
110 
111  org.openide.awt.Mnemonics.setLocalizedText(justificationLbl, org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.justificationLbl.text")); // NOI18N
112 
113  justificationTextField.setText(org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.justificationTextField.text")); // NOI18N
114 
115  javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
116  settingsPanel.setLayout(settingsPanelLayout);
117  settingsPanelLayout.setHorizontalGroup(
118  settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
119  .addGroup(settingsPanelLayout.createSequentialGroup()
120  .addContainerGap()
121  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122  .addGroup(settingsPanelLayout.createSequentialGroup()
123  .addComponent(nameLbl)
124  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
125  .addComponent(nameTextField))
126  .addGroup(settingsPanelLayout.createSequentialGroup()
127  .addComponent(valueLbl)
128  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
129  .addComponent(valueTextField))
130  .addGroup(settingsPanelLayout.createSequentialGroup()
131  .addComponent(justificationLbl)
132  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
133  .addComponent(justificationTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE))
134  .addGroup(settingsPanelLayout.createSequentialGroup()
135  .addComponent(confidenceLbl)
136  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
137  .addComponent(confidenceComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
138  .addContainerGap())
139  );
140  settingsPanelLayout.setVerticalGroup(
141  settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
142  .addGroup(settingsPanelLayout.createSequentialGroup()
143  .addContainerGap()
144  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
145  .addComponent(nameLbl)
146  .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
147  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
148  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
149  .addComponent(valueLbl)
150  .addComponent(valueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
151  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
152  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
153  .addComponent(confidenceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
154  .addComponent(confidenceLbl))
155  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
156  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
157  .addComponent(justificationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
158  .addComponent(justificationLbl))
159  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
160  );
161 
162  org.openide.awt.Mnemonics.setLocalizedText(cancelBtn, org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.cancelBtn.text")); // NOI18N
163  cancelBtn.setMaximumSize(new java.awt.Dimension(79, 23));
164  cancelBtn.setMinimumSize(new java.awt.Dimension(79, 23));
165  cancelBtn.setPreferredSize(new java.awt.Dimension(79, 23));
166  cancelBtn.addActionListener(new java.awt.event.ActionListener() {
167  public void actionPerformed(java.awt.event.ActionEvent evt) {
168  cancelBtnActionPerformed(evt);
169  }
170  });
171 
172  org.openide.awt.Mnemonics.setLocalizedText(okBtn, org.openide.util.NbBundle.getMessage(PersonaMetadataDialog.class, "PersonaMetadataDialog.okBtn.text")); // NOI18N
173  okBtn.addActionListener(new java.awt.event.ActionListener() {
174  public void actionPerformed(java.awt.event.ActionEvent evt) {
175  okBtnActionPerformed(evt);
176  }
177  });
178 
179  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
180  getContentPane().setLayout(layout);
181  layout.setHorizontalGroup(
182  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
183  .addGroup(layout.createSequentialGroup()
184  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
185  .addComponent(okBtn)
186  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
187  .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
188  .addContainerGap())
189  .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
190  );
191 
192  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelBtn, okBtn});
193 
194  layout.setVerticalGroup(
195  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196  .addGroup(layout.createSequentialGroup()
197  .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
198  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
199  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
200  .addComponent(okBtn)
201  .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
202  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
203  );
204 
205  pack();
206  }// </editor-fold>//GEN-END:initComponents
207 
208  private void display() {
209  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
210  setVisible(true);
211  }
212 
213  @Messages({
214  "AddMetadataDialog_dup_Title=Metadata add failure",
215  "AddMetadataDialog_dup_msg=A metadata entry with this name has already been added to this persona.",
216  "AddMetadataDialog_empty_name_Title=Missing field(s)",
217  "AddMetadataDialog_empty_name_msg=A metadata entry cannot have an empty name or value.",})
218  private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
219  if (nameTextField.getText().isEmpty() || valueTextField.getText().isEmpty()) {
220  JOptionPane.showMessageDialog(this,
221  Bundle.AddMetadataDialog_empty_name_msg(),
222  Bundle.AddMetadataDialog_empty_name_Title(),
223  JOptionPane.ERROR_MESSAGE);
224  return;
225  }
226  if (justificationTextField.getText().isEmpty()) {
227  JOptionPane.showMessageDialog(this,
228  Bundle.PersonaDetailsPanel_empty_justification_msg(),
229  Bundle.PersonaDetailsPanel_empty_justification_Title(),
230  JOptionPane.ERROR_MESSAGE);
231  return;
232  }
233 
234  Persona.Confidence confidence = (Persona.Confidence) confidenceComboBox.getSelectedItem();
235  String justification = justificationTextField.getText();
236 
237  if (currentMetadata != null) {
238  currentMetadata.confidence = confidence;
239  currentMetadata.justification = justification;
240  dispose();
241  } else {
242  if (pdp.addMetadata(nameTextField.getText(), valueTextField.getText(), justification, confidence)) {
243  dispose();
244  } else {
245  JOptionPane.showMessageDialog(this,
246  Bundle.AddMetadataDialog_dup_msg(),
247  Bundle.AddMetadataDialog_dup_Title(),
248  JOptionPane.ERROR_MESSAGE);
249  }
250  }
251  }//GEN-LAST:event_okBtnActionPerformed
252 
253  private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
254  dispose();
255  }//GEN-LAST:event_cancelBtnActionPerformed
256 
257  // Variables declaration - do not modify//GEN-BEGIN:variables
258  private javax.swing.JButton cancelBtn;
260  private javax.swing.JLabel confidenceLbl;
261  private javax.swing.JLabel justificationLbl;
262  private javax.swing.JTextField justificationTextField;
263  private javax.swing.JLabel nameLbl;
264  private javax.swing.JTextField nameTextField;
265  private javax.swing.JButton okBtn;
266  private javax.swing.JPanel settingsPanel;
267  private javax.swing.JLabel valueLbl;
268  private javax.swing.JTextField valueTextField;
269  // End of variables declaration//GEN-END:variables
270 }
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence > confidenceComboBox

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.