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

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