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