Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TagNameDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.casemodule.services;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.Toolkit;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
26 import javax.swing.JFrame;
27 import javax.swing.JOptionPane;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.windows.WindowManager;
33 import org.sleuthkit.datamodel.TskData;
34 
35 @Messages({"TagNameDialog.descriptionLabel.text=Description:",
36  "TagNameDialog.notableCheckbox.text=Tag indicates item is notable."})
37 final class TagNameDialog extends javax.swing.JDialog {
38 
39  private static final long serialVersionUID = 1L;
40  private String userTagDisplayName;
41  private String userTagDescription;
42  private boolean userTagIsNotable;
43  private BUTTON_PRESSED result;
44 
45  enum BUTTON_PRESSED {
46  OK, CANCEL;
47  }
48 
52  TagNameDialog() {
53  super(new JFrame(NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.title.text")),
54  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.title.text"), true);
55  initComponents();
56  this.display();
57  }
58 
59  @Messages({"TagNameDialog.editTitle.text=Edit Tag"})
60  TagNameDialog(TagNameDefinition tagNameToEdit) {
61  super(new JFrame(NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.editTitle.text")),
62  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.editTitle.text"), true);
63  initComponents();
64  tagNameTextField.setText(tagNameToEdit.getDisplayName());
65  descriptionTextArea.setText(tagNameToEdit.getDescription());
66  notableCheckbox.setSelected(tagNameToEdit.getKnownStatus() == TskData.FileKnown.BAD);
67  tagNameTextField.setEnabled(false);
68  this.display();
69  }
70 
74  private void display() {
75  setLayout(new BorderLayout());
76 
77  /*
78  * Center the dialog
79  */
80  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
81 
82  /*
83  * Add a handler for when the dialog window is closed directly.
84  */
85  this.addWindowListener(new WindowAdapter() {
86  @Override
87  public void windowClosing(WindowEvent e) {
88  doButtonAction(false);
89  }
90  });
91 
92  /*
93  * Add a listener to enable the OK button when the text field changes.
94  */
95  tagNameTextField.getDocument().addDocumentListener(new DocumentListener() {
96  @Override
97  public void changedUpdate(DocumentEvent e) {
98  fire();
99  }
100 
101  @Override
102  public void removeUpdate(DocumentEvent e) {
103  fire();
104  }
105 
106  @Override
107  public void insertUpdate(DocumentEvent e) {
108  fire();
109  }
110 
111  private void fire() {
112  enableOkButton();
113  }
114  });
115 
116  enableOkButton();
117 
118  /*
119  * Used to show the dialog.
120  */
121  setResizable(false);
122  setVisible(true);
123  }
124 
130  @Messages({"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
131  "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
132  private void doButtonAction(boolean okPressed) {
133  if (okPressed) {
134  String newTagDisplayName = tagNameTextField.getText().trim();
135  String descriptionText = descriptionTextArea.getText();
136  if (newTagDisplayName.isEmpty()) {
137  JOptionPane.showMessageDialog(this,
138  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.JOptionPane.tagNameEmpty.message"),
139  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.JOptionPane.tagNameEmpty.title"),
140  JOptionPane.ERROR_MESSAGE);
141  return;
142  }
143  //if a tag name contains illegal characters and is not the name of one of the standard tags
144  if (TagsManager.containsIllegalCharacters(newTagDisplayName) && !TagNameDefinition.getStandardTagNames().contains(newTagDisplayName)) {
145  JOptionPane.showMessageDialog(this,
146  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message"),
147  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title"),
148  JOptionPane.ERROR_MESSAGE);
149  return;
150  } else if (descriptionText.contains(",")
151  || descriptionText.contains(";")) {
152  JOptionPane.showMessageDialog(this,
153  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message"),
154  NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title"),
155  JOptionPane.ERROR_MESSAGE);
156  return;
157  }
158 
159  userTagDescription = descriptionTextArea.getText();
160  userTagDisplayName = newTagDisplayName;
161  userTagIsNotable = notableCheckbox.isSelected();
162  result = BUTTON_PRESSED.OK;
163  } else {
164  result = BUTTON_PRESSED.CANCEL;
165  }
166  setVisible(false);
167  }
168 
174  String getTagName() {
175  return userTagDisplayName;
176  }
177 
178  String getTagDesciption() {
179  return userTagDescription;
180  }
181 
182  boolean isTagNotable() {
183  return userTagIsNotable;
184  }
185 
191  BUTTON_PRESSED getResult() {
192  return result;
193  }
194 
200  private void enableOkButton() {
201  okButton.setEnabled(!tagNameTextField.getText().isEmpty());
202  getRootPane().setDefaultButton(okButton);
203  }
204 
210  @SuppressWarnings("unchecked")
211  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
212  private void initComponents() {
213 
214  newTagNameLabel = new javax.swing.JLabel();
215  tagNameTextField = new javax.swing.JTextField();
216  cancelButton = new javax.swing.JButton();
217  okButton = new javax.swing.JButton();
218  descriptionScrollPane = new javax.swing.JScrollPane();
219  descriptionTextArea = new javax.swing.JTextArea();
220  descriptionLabel = new javax.swing.JLabel();
221  notableCheckbox = new javax.swing.JCheckBox();
222 
223  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
224 
225  org.openide.awt.Mnemonics.setLocalizedText(newTagNameLabel, org.openide.util.NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.newTagNameLabel.text")); // NOI18N
226 
227  tagNameTextField.setText(org.openide.util.NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.tagNameTextField.text")); // NOI18N
228 
229  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.cancelButton.text")); // NOI18N
230  cancelButton.addActionListener(new java.awt.event.ActionListener() {
231  public void actionPerformed(java.awt.event.ActionEvent evt) {
232  cancelButtonActionPerformed(evt);
233  }
234  });
235 
236  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.okButton.text")); // NOI18N
237  okButton.addActionListener(new java.awt.event.ActionListener() {
238  public void actionPerformed(java.awt.event.ActionEvent evt) {
239  okButtonActionPerformed(evt);
240  }
241  });
242 
243  descriptionTextArea.setColumns(20);
244  descriptionTextArea.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
245  descriptionTextArea.setRows(3);
246  descriptionScrollPane.setViewportView(descriptionTextArea);
247 
248  org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.descriptionLabel.text")); // NOI18N
249 
250  org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox, org.openide.util.NbBundle.getMessage(TagNameDialog.class, "TagNameDialog.notableCheckbox.text")); // NOI18N
251 
252  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
253  getContentPane().setLayout(layout);
254  layout.setHorizontalGroup(
255  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256  .addGroup(layout.createSequentialGroup()
257  .addContainerGap()
258  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addComponent(tagNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
260  .addGroup(layout.createSequentialGroup()
261  .addGap(0, 0, Short.MAX_VALUE)
262  .addComponent(okButton)
263  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
264  .addComponent(cancelButton))
265  .addComponent(newTagNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
266  .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
267  .addGroup(layout.createSequentialGroup()
268  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269  .addComponent(notableCheckbox)
270  .addComponent(descriptionLabel))
271  .addGap(0, 0, Short.MAX_VALUE)))
272  .addContainerGap())
273  );
274  layout.setVerticalGroup(
275  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276  .addGroup(layout.createSequentialGroup()
277  .addContainerGap()
278  .addComponent(newTagNameLabel)
279  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
280  .addComponent(tagNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
281  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
282  .addComponent(descriptionLabel)
283  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
284  .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
285  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
286  .addComponent(notableCheckbox)
287  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
288  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
289  .addComponent(cancelButton)
290  .addComponent(okButton)))
291  );
292 
293  pack();
294  }// </editor-fold>//GEN-END:initComponents
295 
296  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
297  doButtonAction(true);
298  }//GEN-LAST:event_okButtonActionPerformed
299 
300  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
301  doButtonAction(false);
302  }//GEN-LAST:event_cancelButtonActionPerformed
303 
304 
305  // Variables declaration - do not modify//GEN-BEGIN:variables
306  private javax.swing.JButton cancelButton;
307  private javax.swing.JLabel descriptionLabel;
308  private javax.swing.JScrollPane descriptionScrollPane;
309  private javax.swing.JTextArea descriptionTextArea;
310  private javax.swing.JLabel newTagNameLabel;
311  private javax.swing.JCheckBox notableCheckbox;
312  private javax.swing.JButton okButton;
313  private javax.swing.JTextField tagNameTextField;
314  // End of variables declaration//GEN-END:variables
315 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.