Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddTagAction.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.ActionListener;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JMenu;
27 import javax.swing.JMenuItem;
28 
29 import org.openide.util.NbBundle;
30 import org.openide.util.actions.Presenter;
36 
41 abstract class AddTagAction extends TagAction implements Presenter.Popup {
42  private static final String NO_COMMENT = "";
43 
44  AddTagAction(String menuText) {
45  super(menuText);
46  }
47 
48  @Override
49  public JMenuItem getPopupPresenter() {
50  return new TagMenu();
51  }
52 
53  @Override
54  protected void doAction(ActionEvent event) {
55  }
56 
61  abstract protected String getActionDisplayName();
62 
67  abstract protected void addTag(TagName tagName, String comment);
68 
74  // @@@ This user interface has some significant usability issues and needs
75  // to be reworked.
76  private class TagMenu extends JMenu {
77  TagMenu() {
78  super(getActionDisplayName());
79 
80  // Get the current set of tag names.
82  List<TagName> tagNames = null;
83  try {
84  tagNames = tagsManager.getAllTagNames();
85  Collections.sort(tagNames);
86  }
87  catch (TskCoreException ex) {
88  Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
89  }
90 
91  // Create a "Quick Tag" sub-menu.
92  JMenu quickTagMenu = new JMenu(NbBundle.getMessage(this.getClass(), "AddTagAction.quickTag"));
93  add(quickTagMenu);
94 
95  // Each tag name in the current set of tags gets its own menu item in
96  // the "Quick Tags" sub-menu. Selecting one of these menu items adds
97  // a tag with the associated tag name.
98  if (null != tagNames && !tagNames.isEmpty()) {
99  for (final TagName tagName : tagNames) {
100  JMenuItem tagNameItem = new JMenuItem(tagName.getDisplayName());
101  tagNameItem.addActionListener(new ActionListener() {
102  @Override
103  public void actionPerformed(ActionEvent e) {
104  addTag(tagName, NO_COMMENT);
105  refreshDirectoryTree();
106  }
107  });
108  quickTagMenu.add(tagNameItem);
109  }
110  }
111  else {
112  JMenuItem empty = new JMenuItem(NbBundle.getMessage(this.getClass(), "AddTagAction.noTags"));
113  empty.setEnabled(false);
114  quickTagMenu.add(empty);
115  }
116 
117  quickTagMenu.addSeparator();
118 
119  // The "Quick Tag" menu also gets an "Choose Tag..." menu item.
120  // Selecting this item initiates a dialog that can be used to create
121  // or select a tag name and adds a tag with the resulting name.
122  JMenuItem newTagMenuItem = new JMenuItem(NbBundle.getMessage(this.getClass(), "AddTagAction.newTag"));
123  newTagMenuItem.addActionListener(new ActionListener() {
124  @Override
125  public void actionPerformed(ActionEvent e) {
126  TagName tagName = GetTagNameDialog.doDialog();
127  if (tagName != null) {
128  addTag(tagName, NO_COMMENT);
129  refreshDirectoryTree();
130  }
131  }
132  });
133  quickTagMenu.add(newTagMenuItem);
134 
135  // Create a "Choose Tag and Comment..." menu item. Selecting this item initiates
136  // a dialog that can be used to create or select a tag name with an
137  // optional comment and adds a tag with the resulting name.
138  JMenuItem tagAndCommentItem = new JMenuItem(
139  NbBundle.getMessage(this.getClass(), "AddTagAction.tagAndComment"));
140  tagAndCommentItem.addActionListener(new ActionListener() {
141  @Override
142  public void actionPerformed(ActionEvent e) {
144  if (null != tagNameAndComment) {
145  addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
146  refreshDirectoryTree();
147  }
148  }
149  });
150  add(tagAndCommentItem);
151  }
152  }
153 }
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.