Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MediaViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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 obt ain 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.communications.relationships;
20 
21 import java.awt.Component;
22 import java.awt.KeyboardFocusManager;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.util.HashSet;
26 import java.util.Set;
27 import java.util.logging.Level;
28 import javax.swing.JPanel;
29 import static javax.swing.SwingUtilities.isDescendingFrom;
30 import org.openide.explorer.ExplorerManager;
31 import static org.openide.explorer.ExplorerUtils.createLookup;
32 import org.openide.nodes.AbstractNode;
33 import org.openide.nodes.Node;
34 import org.openide.util.Lookup;
35 import org.openide.util.NbBundle.Messages;
43 import org.sleuthkit.datamodel.AbstractContent;
44 import org.sleuthkit.datamodel.BlackboardArtifact;
45 import org.sleuthkit.datamodel.CommunicationsManager;
46 import org.sleuthkit.datamodel.Content;
47 import org.sleuthkit.datamodel.TskCoreException;
48 
52 final class MediaViewer extends JPanel implements RelationshipsViewer, ExplorerManager.Provider, Lookup.Provider {
53 
54  private static final Logger logger = Logger.getLogger(MediaViewer.class.getName());
55 
56  private final ExplorerManager tableEM = new ExplorerManager();
57  private final PropertyChangeListener focusPropertyListener;
58 
59  private final ModifiableProxyLookup proxyLookup;
60 
61  @Messages({
62  "MediaViewer_Name=Media"
63  })
67  public MediaViewer() {
68  initComponents();
69 
70  splitPane.setResizeWeight(0.5);
71  splitPane.setDividerLocation(0.5);
72 
73  proxyLookup = new ModifiableProxyLookup(createLookup(tableEM, getActionMap()));
74 
75  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
76  // explaination of focusPropertyListener
77  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
78  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
79  final Component newFocusOwner = (Component) focusEvent.getNewValue();
80 
81  if (newFocusOwner == null) {
82  return;
83  }
84  if (isDescendingFrom(newFocusOwner, contentViewer)) {
85  //if the focus owner is within the MessageContentViewer (the attachments table)
86  proxyLookup.setNewLookups(createLookup(((MessageDataContent) contentViewer).getExplorerManager(), getActionMap()));
87  } else if (isDescendingFrom(newFocusOwner, MediaViewer.this)) {
88  //... or if it is within the Results table.
89  proxyLookup.setNewLookups(createLookup(tableEM, getActionMap()));
90 
91  }
92  }
93  };
94 
95  tableEM.addPropertyChangeListener((PropertyChangeEvent evt) -> {
96  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
97  handleNodeSelectionChange();
98  }
99  });
100 
101  thumbnailViewer.resetComponent();
102  }
103 
104  @Override
105  public String getDisplayName() {
106  return Bundle.MediaViewer_Name();
107  }
108 
109  @Override
110  public JPanel getPanel() {
111  return this;
112  }
113 
114  @Override
115  public void setSelectionInfo(SelectionInfo info) {
116  final Set<Content> relationshipSources;
117 
118  CommunicationsManager communicationManager;
119  Set<BlackboardArtifact> artifactList = new HashSet<>();
120 
121  try {
122  communicationManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
123  relationshipSources = communicationManager.getRelationshipSources(info.getAccountDevicesInstances(), info.getCommunicationsFilter());
124 
125  relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
126  artifactList.add((BlackboardArtifact) content);
127  });
128 
129  } catch (TskCoreException | NoCurrentCaseException ex) {
130  logger.log(Level.WARNING, "Unable to update selection." , ex);
131  }
132 
133  thumbnailViewer.resetComponent();
134 
135  thumbnailViewer.setNode(new TableFilterNode(new DataResultFilterNode(new AbstractNode(new AttachmentsChildren(artifactList)), tableEM), true, this.getClass().getName()));
136  }
137 
138  @Override
139  public ExplorerManager getExplorerManager() {
140  return tableEM;
141  }
142 
143  @Override
144  public Lookup getLookup() {
145  return proxyLookup;
146  }
147 
148  @Override
149  public void addNotify() {
150  super.addNotify();
151  //add listener that maintains correct selection in the Global Actions Context
152  KeyboardFocusManager.getCurrentKeyboardFocusManager()
153  .addPropertyChangeListener("focusOwner", focusPropertyListener);
154  }
155 
156  @Override
157  public void removeNotify() {
158  super.removeNotify();
159  KeyboardFocusManager.getCurrentKeyboardFocusManager()
160  .removePropertyChangeListener("focusOwner", focusPropertyListener);
161  }
162 
166  private void handleNodeSelectionChange() {
167  final Node[] nodes = tableEM.getSelectedNodes();
168 
169  if (nodes != null && nodes.length == 1) {
170  AbstractContent thumbnail = nodes[0].getLookup().lookup(AbstractContent.class);
171  if (thumbnail != null) {
172  try {
173  Content parentContent = thumbnail.getParent();
174  if (parentContent != null && parentContent instanceof BlackboardArtifact) {
175  contentViewer.setNode(new BlackboardArtifactNode((BlackboardArtifact) parentContent));
176  }
177  } catch (TskCoreException ex) {
178  logger.log(Level.WARNING, "Unable to get parent Content from AbstraceContent instance.", ex); //NON-NLS
179  }
180  }
181  } else {
182  contentViewer.setNode(null);
183  }
184  }
185 
191  @SuppressWarnings("unchecked")
192  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
193  private void initComponents() {
194  java.awt.GridBagConstraints gridBagConstraints;
195 
196  splitPane = new javax.swing.JSplitPane();
197  thumbnailViewer = new org.sleuthkit.autopsy.corecomponents.DataResultViewerThumbnail(tableEM);
198  contentViewer = new MessageDataContent();
199 
200  setLayout(new java.awt.GridBagLayout());
201 
202  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
203 
204  thumbnailViewer.setMinimumSize(new java.awt.Dimension(350, 102));
205  thumbnailViewer.setPreferredSize(new java.awt.Dimension(450, 400));
206  splitPane.setLeftComponent(thumbnailViewer);
207 
208  contentViewer.setPreferredSize(new java.awt.Dimension(450, 400));
209  splitPane.setRightComponent(contentViewer);
210 
211  gridBagConstraints = new java.awt.GridBagConstraints();
212  gridBagConstraints.gridx = 0;
213  gridBagConstraints.gridy = 0;
214  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
215  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
216  gridBagConstraints.weightx = 1.0;
217  gridBagConstraints.weighty = 1.0;
218  add(splitPane, gridBagConstraints);
219  }// </editor-fold>//GEN-END:initComponents
220 
221 
222  // Variables declaration - do not modify//GEN-BEGIN:variables
224  private javax.swing.JSplitPane splitPane;
226  // End of variables declaration//GEN-END:variables
227 
228 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.