Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactMenuMouseAdapter.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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.discovery.ui;
20 
21 import java.awt.Color;
22 import java.awt.event.ActionEvent;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.AbstractAction;
28 import javax.swing.Action;
29 import javax.swing.JMenuItem;
30 import javax.swing.JPopupMenu;
31 import javax.swing.JSeparator;
32 import javax.swing.SwingUtilities;
33 import org.openide.util.NbBundle;
47 import org.sleuthkit.datamodel.AbstractFile;
48 import org.sleuthkit.datamodel.BlackboardArtifact;
49 import org.sleuthkit.datamodel.BlackboardAttribute;
50 import org.sleuthkit.datamodel.Content;
51 import org.sleuthkit.datamodel.TskCoreException;
52 
57 class ArtifactMenuMouseAdapter extends java.awt.event.MouseAdapter {
58 
59  private final AbstractArtifactListPanel listPanel;
60  private static final Logger logger = Logger.getLogger(ArtifactMenuMouseAdapter.class.getName());
61 
67  ArtifactMenuMouseAdapter(AbstractArtifactListPanel listPanel) {
68  this.listPanel = listPanel;
69  }
70 
71  @Override
72  public void mouseClicked(java.awt.event.MouseEvent evt) {
73  if (!evt.isPopupTrigger() && SwingUtilities.isRightMouseButton(evt) && listPanel != null && !listPanel.isEmpty()) {
74  if (listPanel.selectAtPoint(evt.getPoint())) {
75  showPopupMenu(evt);
76  }
77  }
78  }
79 
86  private void showPopupMenu(java.awt.event.MouseEvent event) {
87  BlackboardArtifact artifact = listPanel.getSelectedArtifact();
88  if (artifact == null) {
89  return;
90  }
91  try {
92  JMenuItem[] items = getMenuItems(artifact);
93  JPopupMenu popupMenu = new JPopupMenu();
94  for (JMenuItem menu : items) {
95  if (menu != null) {
96  popupMenu.add(menu);
97  } else {
98  popupMenu.add(new JSeparator());
99  }
100  }
101  listPanel.showPopupMenu(popupMenu, event.getPoint());
102  } catch (TskCoreException ex) {
103  logger.log(Level.WARNING, "Unable to get source content of artifact with ID: " + artifact.getArtifactID(), ex);
104  }
105  }
106 
117  @NbBundle.Messages({"ArtifactMenuMouseAdapter.noFile.text=File does not exist."})
118  private JMenuItem[] getMenuItems(BlackboardArtifact artifact) throws TskCoreException {
119  List<JMenuItem> menuItems = new ArrayList<>();
120  BlackboardAttribute pathIdAttr = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID));
121  Long contentId;
122  if (pathIdAttr != null) {
123  contentId = pathIdAttr.getValueLong();
124  } else if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() && artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID()) {
125  contentId = artifact.getObjectID();
126  } else {
127  contentId = null;
128  JMenuItem noFile = new JMenuItem();
129  noFile.setText(Bundle.ArtifactMenuMouseAdapter_noFile_text());
130  noFile.setEnabled(false);
131  noFile.setForeground(Color.RED);
132  menuItems.add(noFile);
133  }
134  menuItems.addAll(getTimelineMenuItems(artifact));
135  if (contentId != null) {
136  Content content = artifact.getSleuthkitCase().getContentById(contentId);
137  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
138  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
139  } else {
140  menuItems.add(AddBlackboardArtifactTagAction.getInstance().getMenuForContent(Arrays.asList(artifact)));
141  }
142  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
143  return menuItems.toArray(new JMenuItem[0]);
144  }
145 
153  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
154  List<JMenuItem> menuItems = new ArrayList<>();
155  //if this artifact has a time stamp add the action to view it in the timeline
156  try {
157  if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
158  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
159  }
160  } catch (TskCoreException ex) {
161  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
162  }
163 
164  return menuItems;
165  }
166 
177  @NbBundle.Messages({
178  "ArtifactMenuMouseAdapter_ExternalViewer_label=Open in external viewer"
179  })
180  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
181  List<JMenuItem> menuItems = new ArrayList<>();
182  List<Action> actions = DataModelActionsFactory.getActions(content, true);
183  for (Action action : actions) {
184  if (action == null) {
185  menuItems.add(null);
186  } else if (action instanceof ExportCSVAction) {
187  // Do nothing we don't need this menu item.
188  } else if (action instanceof AddContentTagAction) {
189  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
190  } else if (action instanceof AddBlackboardArtifactTagAction) {
191  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
192  } else if (action instanceof ExternalViewerShortcutAction) {
193  // Replace with an ExternalViewerAction
194  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.ArtifactMenuMouseAdapter_ExternalViewer_label(), new FileNode((AbstractFile) content));
195  menuItems.add(new JMenuItem(newAction));
196  } else if (action instanceof ExtractAction) {
197  menuItems.add(new JMenuItem(new ExtractFileAction((AbstractFile) content)));
198  } else {
199  menuItems.add(new JMenuItem(action));
200  }
201  }
202  return menuItems;
203  }
204 
208  @NbBundle.Messages({
209  "ArtifactMenuMouseAdapter_label=Extract Files"
210  })
211  private final class ExtractFileAction extends AbstractAction {
212 
213  private static final long serialVersionUID = 1L;
214  final private AbstractFile file;
215 
221  private ExtractFileAction(AbstractFile file) {
222  super(Bundle.ArtifactMenuMouseAdapter_label());
223  this.file = file;
224  }
225 
226  @Override
227  public void actionPerformed(ActionEvent e) {
229  helper.extract(e, Arrays.asList(file));
230  }
231  }
232 }
void extract(ActionEvent event, Collection<?extends AbstractFile > selectedFiles)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.