19 package org.sleuthkit.autopsy.actions;
21 import java.awt.Window;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.KeyEvent;
24 import java.util.ArrayList;
25 import java.util.List;
27 import java.util.TreeMap;
28 import java.util.logging.Level;
29 import javax.swing.AbstractAction;
30 import javax.swing.ActionMap;
31 import javax.swing.InputMap;
32 import javax.swing.JComponent;
33 import javax.swing.JDialog;
34 import javax.swing.JOptionPane;
35 import javax.swing.KeyStroke;
36 import javax.swing.table.AbstractTableModel;
37 import org.openide.util.ImageUtilities;
38 import org.openide.util.NbBundle;
39 import org.openide.util.NbBundle.Messages;
40 import org.openide.windows.WindowManager;
48 @Messages({
"GetTagNameDialog.descriptionLabel.text=Description:",
49 "GetTagNameDialog.notableCheckbox.text=Tag indicates item is notable."})
52 private static final long serialVersionUID = 1L;
53 private static final String TAG_ICON_PATH =
"org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png";
54 private final Map<String, TagName> tagNamesMap =
new TreeMap<>();
55 private TagName tagName = null;
66 return doDialog(WindowManager.getDefault().getMainWindow());
88 ModalityType.APPLICATION_MODAL);
92 setIconImage(ImageUtilities.loadImage(TAG_ICON_PATH));
96 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameDialog.cancelName");
97 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
98 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
99 ActionMap actionMap = getRootPane().getActionMap();
100 actionMap.put(cancelName,
new AbstractAction() {
101 private static final long serialVersionUID = 1L;
104 public void actionPerformed(ActionEvent e) {
105 cancelButtonActionPerformed(e);
114 }
catch (TskCoreException ex) {
119 tagsTable.setModel(
new TagsTableModel(
new ArrayList<>(tagNamesMap.keySet())));
120 tagsTable.setTableHeader(null);
121 tagsTable.setCellSelectionEnabled(
false);
122 tagsTable.setFocusable(
false);
123 tagsTable.setRowHeight(tagsTable.getRowHeight() + 5);
126 this.setLocationRelativeTo(this.getOwner());
132 private static final long serialVersionUID = 1L;
133 private final ArrayList<String> tagDisplayNames =
new ArrayList<>();
136 for (String tagDisplayName : tagDisplayNames) {
137 this.tagDisplayNames.add(tagDisplayName);
143 return tagDisplayNames.size();
158 return tagDisplayNames.get(rowIndex);
167 @SuppressWarnings(
"unchecked")
169 private
void initComponents() {
171 cancelButton =
new javax.swing.JButton();
172 okButton =
new javax.swing.JButton();
173 jScrollPane1 =
new javax.swing.JScrollPane();
174 tagsTable =
new javax.swing.JTable();
175 preexistingLabel =
new javax.swing.JLabel();
176 newTagPanel =
new javax.swing.JPanel();
177 tagNameLabel =
new javax.swing.JLabel();
178 tagNameField =
new javax.swing.JTextField();
179 descriptionLabel =
new javax.swing.JLabel();
180 descriptionScrollPane =
new javax.swing.JScrollPane();
181 descriptionTextArea =
new javax.swing.JTextArea();
182 notableCheckbox =
new javax.swing.JCheckBox();
184 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
185 addKeyListener(
new java.awt.event.KeyAdapter() {
186 public void keyReleased(java.awt.event.KeyEvent evt) {
187 formKeyReleased(evt);
191 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.cancelButton.text"));
192 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
193 public void actionPerformed(java.awt.event.ActionEvent evt) {
194 cancelButtonActionPerformed(evt);
198 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.okButton.text"));
199 okButton.addActionListener(
new java.awt.event.ActionListener() {
200 public void actionPerformed(java.awt.event.ActionEvent evt) {
201 okButtonActionPerformed(evt);
205 jScrollPane1.setBackground(
new java.awt.Color(255, 255, 255));
207 tagsTable.setBackground(
new java.awt.Color(240, 240, 240));
208 tagsTable.setModel(
new javax.swing.table.DefaultTableModel(
216 tagsTable.setShowHorizontalLines(
false);
217 tagsTable.setShowVerticalLines(
false);
218 tagsTable.setTableHeader(null);
219 jScrollPane1.setViewportView(tagsTable);
221 org.openide.awt.Mnemonics.setLocalizedText(preexistingLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.preexistingLabel.text"));
223 newTagPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.newTagPanel.border.title")));
225 org.openide.awt.Mnemonics.setLocalizedText(tagNameLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameLabel.text"));
227 tagNameField.setText(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameField.text"));
228 tagNameField.addKeyListener(
new java.awt.event.KeyAdapter() {
229 public void keyReleased(java.awt.event.KeyEvent evt) {
230 tagNameFieldKeyReleased(evt);
234 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.descriptionLabel.text"));
236 descriptionTextArea.setColumns(20);
237 descriptionTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
238 descriptionTextArea.setRows(3);
239 descriptionScrollPane.setViewportView(descriptionTextArea);
241 org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.notableCheckbox.text"));
243 javax.swing.GroupLayout newTagPanelLayout =
new javax.swing.GroupLayout(newTagPanel);
244 newTagPanel.setLayout(newTagPanelLayout);
245 newTagPanelLayout.setHorizontalGroup(
246 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247 .addGroup(newTagPanelLayout.createSequentialGroup()
249 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
251 .addComponent(tagNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
252 .addGroup(newTagPanelLayout.createSequentialGroup()
253 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
254 .addComponent(notableCheckbox)
255 .addComponent(descriptionLabel)
256 .addComponent(tagNameLabel))
257 .addGap(0, 0, Short.MAX_VALUE)))
260 newTagPanelLayout.setVerticalGroup(
261 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
262 .addGroup(newTagPanelLayout.createSequentialGroup()
264 .addComponent(tagNameLabel)
265 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
266 .addComponent(tagNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
267 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
268 .addComponent(descriptionLabel)
269 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
270 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
272 .addComponent(notableCheckbox)
273 .addContainerGap(31, Short.MAX_VALUE))
276 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
277 getContentPane().setLayout(layout);
278 layout.setHorizontalGroup(
279 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
280 .addGroup(layout.createSequentialGroup()
282 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
284 .addComponent(preexistingLabel))
285 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
286 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287 .addGroup(layout.createSequentialGroup()
288 .addGap(0, 233, Short.MAX_VALUE)
289 .addComponent(okButton)
290 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
291 .addComponent(cancelButton))
292 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
295 layout.setVerticalGroup(
296 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297 .addGroup(layout.createSequentialGroup()
299 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
300 .addGroup(layout.createSequentialGroup()
301 .addComponent(preexistingLabel)
302 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
303 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
304 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
305 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
306 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
307 .addComponent(cancelButton)
308 .addComponent(okButton))
320 @NbBundle.Messages({
"GetTagNameDialog.tagNameAlreadyExists.message=Tag name must be unique. A tag with this name already exists.",
321 "GetTagNameDialog.tagNameAlreadyExists.title=Duplicate Tag Name",
322 "GetTagNameDialog.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
323 "GetTagNameDialog.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
325 String tagDisplayName = tagNameField.getText();
326 String userTagDescription = descriptionTextArea.getText();
327 TskData.FileKnown status = notableCheckbox.isSelected() ? TskData.FileKnown.BAD : TskData.FileKnown.UNKNOWN;
328 if (tagDisplayName.isEmpty()) {
329 JOptionPane.showMessageDialog(null,
330 NbBundle.getMessage(
this.getClass(),
331 "GetTagNameDialog.mustSupplyTtagName.msg"),
332 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameErr"),
333 JOptionPane.ERROR_MESSAGE);
335 JOptionPane.showMessageDialog(null,
336 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalChars.msg"),
337 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalCharsErr"),
338 JOptionPane.ERROR_MESSAGE);
339 }
else if (userTagDescription.contains(
",")
340 || userTagDescription.contains(
";")) {
341 JOptionPane.showMessageDialog(null,
342 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.message"),
343 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.title"),
344 JOptionPane.ERROR_MESSAGE);
346 tagName = tagNamesMap.get(tagDisplayName);
348 if (tagName == null) {
352 }
catch (TskCoreException ex) {
353 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
354 JOptionPane.showMessageDialog(null,
355 NbBundle.getMessage(
this.getClass(),
356 "GetTagNameDialog.unableToAddTagNameToCase.msg",
358 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.taggingErr"),
359 JOptionPane.ERROR_MESSAGE);
364 }
catch (TskCoreException ex1) {
365 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" exists in database but an error occurred in retrieving it.", ex1);
366 JOptionPane.showMessageDialog(null,
367 NbBundle.getMessage(
this.getClass(),
368 "GetTagNameDialog.tagNameExistsTskCore.msg",
370 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.dupTagErr"),
371 JOptionPane.ERROR_MESSAGE);
376 JOptionPane.showMessageDialog(null,
377 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.message"),
378 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.title"),
379 JOptionPane.INFORMATION_MESSAGE);
385 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
386 okButtonActionPerformed(null);
391 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
392 okButtonActionPerformed(null);
javax.swing.JLabel preexistingLabel
void tagNameFieldKeyReleased(java.awt.event.KeyEvent evt)
javax.swing.JButton cancelButton
javax.swing.JScrollPane jScrollPane1
javax.swing.JTable tagsTable
void okButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JScrollPane descriptionScrollPane
javax.swing.JTextArea descriptionTextArea
javax.swing.JPanel newTagPanel
static TagName doDialog(Window owner)
TagsManager getTagsManager()
javax.swing.JLabel tagNameLabel
void formKeyReleased(java.awt.event.KeyEvent evt)
javax.swing.JButton okButton
javax.swing.JLabel descriptionLabel
javax.swing.JTextField tagNameField
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static TagName doDialog()
GetTagNameDialog(Window owner)
javax.swing.JCheckBox notableCheckbox
void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)