Autopsy  4.0
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-15 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.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.AbstractAction;
26 import javax.swing.JMenu;
27 import javax.swing.JMenuItem;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.Presenter;
33 import org.sleuthkit.datamodel.TagName;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
40 abstract class AddTagAction extends AbstractAction implements Presenter.Popup {
41 
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 
59  @Override
60  @SuppressWarnings("NoopMethodInAbstractClass")
61  public void actionPerformed(ActionEvent event) {
62  }
63 
68  abstract protected String getActionDisplayName();
69 
74  abstract protected void addTag(TagName tagName, String comment);
75 
81  // @@@ This user interface has some significant usability issues and needs
82  // to be reworked.
83  private class TagMenu extends JMenu {
84 
85  TagMenu() {
86  super(getActionDisplayName());
87 
88  // Get the current set of tag names.
90  List<TagName> tagNames = null;
91  try {
92  tagNames = tagsManager.getAllTagNames();
93  Collections.sort(tagNames);
94  } catch (TskCoreException ex) {
95  Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
96  }
97 
98  // Create a "Quick Tag" sub-menu.
99  JMenu quickTagMenu = new JMenu(NbBundle.getMessage(this.getClass(), "AddTagAction.quickTag"));
100  add(quickTagMenu);
101 
102  // Each tag name in the current set of tags gets its own menu item in
103  // the "Quick Tags" sub-menu. Selecting one of these menu items adds
104  // a tag with the associated tag name.
105  if (null != tagNames && !tagNames.isEmpty()) {
106  for (final TagName tagName : tagNames) {
107  JMenuItem tagNameItem = new JMenuItem(tagName.getDisplayName());
108  tagNameItem.addActionListener((ActionEvent e) -> {
109  addTag(tagName, NO_COMMENT);
110  });
111  quickTagMenu.add(tagNameItem);
112  }
113  } else {
114  JMenuItem empty = new JMenuItem(NbBundle.getMessage(this.getClass(), "AddTagAction.noTags"));
115  empty.setEnabled(false);
116  quickTagMenu.add(empty);
117  }
118 
119  quickTagMenu.addSeparator();
120 
121  // The "Quick Tag" menu also gets an "Choose Tag..." menu item.
122  // Selecting this item initiates a dialog that can be used to create
123  // or select a tag name and adds a tag with the resulting name.
124  JMenuItem newTagMenuItem = new JMenuItem(NbBundle.getMessage(this.getClass(), "AddTagAction.newTag"));
125  newTagMenuItem.addActionListener((ActionEvent e) -> {
126  TagName tagName = GetTagNameDialog.doDialog();
127  if (null != tagName) {
128  addTag(tagName, NO_COMMENT);
129  }
130  });
131  quickTagMenu.add(newTagMenuItem);
132 
133  // Create a "Choose Tag and Comment..." menu item. Selecting this item initiates
134  // a dialog that can be used to create or select a tag name with an
135  // optional comment and adds a tag with the resulting name.
136  JMenuItem tagAndCommentItem = new JMenuItem(
137  NbBundle.getMessage(this.getClass(), "AddTagAction.tagAndComment"));
138  tagAndCommentItem.addActionListener((ActionEvent e) -> {
140  if (null != tagNameAndComment) {
141  addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
142  }
143  });
144  add(tagAndCommentItem);
145  }
146  }
147 }
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.