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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.