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

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