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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.