Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
GetTagNameAndCommentDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.actions;
20 
21 import java.awt.Window;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.KeyEvent;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.AbstractAction;
28 import javax.swing.ActionMap;
29 import javax.swing.InputMap;
30 import javax.swing.JComponent;
31 import javax.swing.JDialog;
32 import javax.swing.KeyStroke;
33 import org.openide.util.NbBundle;
34 import org.openide.windows.WindowManager;
38 import org.sleuthkit.datamodel.TagName;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
41 public class GetTagNameAndCommentDialog extends JDialog {
42 
43  private static final long serialVersionUID = 1L;
44  private static final String NO_TAG_NAMES_MESSAGE = NbBundle.getMessage(GetTagNameAndCommentDialog.class,
45  "GetTagNameAndCommentDialog.noTags");
46  private final HashMap<String, TagName> tagNames = new HashMap<>();
48 
49  public static class TagNameAndComment {
50 
51  private final TagName tagName;
52  private final String comment;
53 
54  private TagNameAndComment(TagName tagName, String comment) {
55  this.tagName = tagName;
56  this.comment = comment;
57  }
58 
59  public TagName getTagName() {
60  return tagName;
61  }
62 
63  public String getComment() {
64  return comment;
65  }
66  }
67 
77  public static TagNameAndComment doDialog() {
78  return doDialog(WindowManager.getDefault().getMainWindow());
79  }
80 
93  public static TagNameAndComment doDialog(Window owner) {
94  return new GetTagNameAndCommentDialog(owner).tagNameAndComment;
95  }
96 
97  private GetTagNameAndCommentDialog(Window owner) {
98  super(owner,
99  NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.createTag"),
100  ModalityType.APPLICATION_MODAL);
101  initComponents();
102 
103  // Set up the dialog to close when Esc is pressed.
104  String cancelName = NbBundle.getMessage(this.getClass(), "GetTagNameAndCommentDialog.cancelName");
105  InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
106  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
107  ActionMap actionMap = getRootPane().getActionMap();
108  actionMap.put(cancelName, new AbstractAction() {
109  @Override
110  public void actionPerformed(ActionEvent e) {
111  dispose();
112  }
113  });
114 
115  // Populate the combo box with the available tag names and save the
116  // tag name DTOs to be enable to return the one the user selects.
118  List<TagName> currentTagNames = null;
119  try {
120  currentTagNames = tagsManager.getAllTagNames();
121  } catch (TskCoreException ex) {
122  Logger.getLogger(GetTagNameAndCommentDialog.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
123  }
124  if (null != currentTagNames && currentTagNames.isEmpty()) {
125  tagCombo.addItem(NO_TAG_NAMES_MESSAGE);
126  } else {
127  for (TagName tagName : currentTagNames) {
128  tagNames.put(tagName.getDisplayName(), tagName);
129  tagCombo.addItem(tagName.getDisplayName());
130  }
131  }
132 
133  // Center and show the dialog box.
134  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
135  setVisible(true);
136  }
137 
143  @SuppressWarnings("unchecked")
144  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
145  private void initComponents() {
146 
147  okButton = new javax.swing.JButton();
148  cancelButton = new javax.swing.JButton();
149  tagCombo = new javax.swing.JComboBox<String>();
150  tagLabel = new javax.swing.JLabel();
151  commentLabel = new javax.swing.JLabel();
152  commentText = new javax.swing.JTextField();
153  newTagButton = new javax.swing.JButton();
154 
155  addWindowListener(new java.awt.event.WindowAdapter() {
156  public void windowClosing(java.awt.event.WindowEvent evt) {
157  closeDialog(evt);
158  }
159  });
160 
161  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.okButton.text")); // NOI18N
162  okButton.addActionListener(new java.awt.event.ActionListener() {
163  public void actionPerformed(java.awt.event.ActionEvent evt) {
165  }
166  });
167 
168  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.cancelButton.text")); // NOI18N
169  cancelButton.addActionListener(new java.awt.event.ActionListener() {
170  public void actionPerformed(java.awt.event.ActionEvent evt) {
172  }
173  });
174 
175  tagCombo.setToolTipText(org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.tagCombo.toolTipText")); // NOI18N
176 
177  org.openide.awt.Mnemonics.setLocalizedText(tagLabel, org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.tagLabel.text")); // NOI18N
178 
179  org.openide.awt.Mnemonics.setLocalizedText(commentLabel, org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.commentLabel.text")); // NOI18N
180 
181  commentText.setText(org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.commentText.text")); // NOI18N
182  commentText.setToolTipText(org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.commentText.toolTipText")); // NOI18N
183 
184  org.openide.awt.Mnemonics.setLocalizedText(newTagButton, org.openide.util.NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.newTagButton.text")); // NOI18N
185  newTagButton.addActionListener(new java.awt.event.ActionListener() {
186  public void actionPerformed(java.awt.event.ActionEvent evt) {
188  }
189  });
190 
191  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
192  getContentPane().setLayout(layout);
193  layout.setHorizontalGroup(
194  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195  .addGroup(layout.createSequentialGroup()
196  .addContainerGap()
197  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
199  .addComponent(newTagButton)
200  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
201  .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
202  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
203  .addComponent(cancelButton))
204  .addGroup(layout.createSequentialGroup()
205  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206  .addComponent(commentLabel)
207  .addComponent(tagLabel))
208  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
209  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
210  .addComponent(commentText)
211  .addComponent(tagCombo, 0, 214, Short.MAX_VALUE))
212  .addGap(0, 0, Short.MAX_VALUE)))
213  .addContainerGap())
214  );
215 
216  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
217 
218  layout.setVerticalGroup(
219  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
221  .addGap(24, 24, 24)
222  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
223  .addComponent(tagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224  .addComponent(tagLabel))
225  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
227  .addComponent(commentLabel)
228  .addComponent(commentText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
229  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
230  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
231  .addComponent(cancelButton)
232  .addComponent(okButton)
233  .addComponent(newTagButton))
234  .addContainerGap())
235  );
236 
237  getRootPane().setDefaultButton(okButton);
238 
239  pack();
240  }// </editor-fold>//GEN-END:initComponents
241 
242  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
243  tagNameAndComment = new TagNameAndComment(tagNames.get((String) tagCombo.getSelectedItem()), commentText.getText());
244  dispose();
245  }//GEN-LAST:event_okButtonActionPerformed
246 
247  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
248  tagNameAndComment = null;
249  dispose();
250  }//GEN-LAST:event_cancelButtonActionPerformed
251 
252  private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
253  tagNameAndComment = null;
254  dispose();
255  }//GEN-LAST:event_closeDialog
256 
257  private void newTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTagButtonActionPerformed
258  TagName newTagName = GetTagNameDialog.doDialog(this);
259  if (newTagName != null) {
260  tagNames.put(newTagName.getDisplayName(), newTagName);
261  tagCombo.addItem(newTagName.getDisplayName());
262  tagCombo.setSelectedItem(newTagName.getDisplayName());
263  }
264  }//GEN-LAST:event_newTagButtonActionPerformed
265 
266  // Variables declaration - do not modify//GEN-BEGIN:variables
267  private javax.swing.JButton cancelButton;
268  private javax.swing.JLabel commentLabel;
269  private javax.swing.JTextField commentText;
270  private javax.swing.JButton newTagButton;
271  private javax.swing.JButton okButton;
272  private javax.swing.JComboBox<String> tagCombo;
273  private javax.swing.JLabel tagLabel;
274  // End of variables declaration//GEN-END:variables
275 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.