Autopsy  4.14.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 Attachments"
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  Set<Content> relationshipSources;
117  Set<BlackboardArtifact> artifactList = new HashSet<>();
118 
119  try {
120  relationshipSources = info.getRelationshipSources();
121 
122  relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
123  artifactList.add((BlackboardArtifact) content);
124  });
125 
126  } catch (TskCoreException ex) {
127  logger.log(Level.WARNING, "Unable to update selection." , ex);
128  }
129 
130  thumbnailViewer.resetComponent();
131 
132  thumbnailViewer.setNode(new TableFilterNode(new DataResultFilterNode(new AbstractNode(new AttachmentThumbnailsChildren(artifactList)), tableEM), true, this.getClass().getName()));
133  }
134 
135  @Override
136  public ExplorerManager getExplorerManager() {
137  return tableEM;
138  }
139 
140  @Override
141  public Lookup getLookup() {
142  return proxyLookup;
143  }
144 
145  @Override
146  public void addNotify() {
147  super.addNotify();
148  //add listener that maintains correct selection in the Global Actions Context
149  KeyboardFocusManager.getCurrentKeyboardFocusManager()
150  .addPropertyChangeListener("focusOwner", focusPropertyListener);
151  }
152 
153  @Override
154  public void removeNotify() {
155  super.removeNotify();
156  KeyboardFocusManager.getCurrentKeyboardFocusManager()
157  .removePropertyChangeListener("focusOwner", focusPropertyListener);
158  }
159 
163  private void handleNodeSelectionChange() {
164  final Node[] nodes = tableEM.getSelectedNodes();
165 
166  if (nodes != null && nodes.length == 1) {
167  AbstractContent thumbnail = nodes[0].getLookup().lookup(AbstractContent.class);
168  if (thumbnail != null) {
169  try {
170  Content parentContent = thumbnail.getParent();
171  if (parentContent != null && parentContent instanceof BlackboardArtifact) {
172  contentViewer.setNode(new BlackboardArtifactNode((BlackboardArtifact) parentContent));
173  }
174  } catch (TskCoreException ex) {
175  logger.log(Level.WARNING, "Unable to get parent Content from AbstraceContent instance.", ex); //NON-NLS
176  }
177  }
178  } else {
179  contentViewer.setNode(null);
180  }
181  }
182 
188  @SuppressWarnings("unchecked")
189  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
190  private void initComponents() {
191  java.awt.GridBagConstraints gridBagConstraints;
192 
193  splitPane = new javax.swing.JSplitPane();
194  thumbnailViewer = new org.sleuthkit.autopsy.corecomponents.DataResultViewerThumbnail(tableEM);
195  contentViewer = new MessageDataContent();
196 
197  setLayout(new java.awt.GridBagLayout());
198 
199  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
200 
201  thumbnailViewer.setMinimumSize(new java.awt.Dimension(350, 102));
202  thumbnailViewer.setPreferredSize(new java.awt.Dimension(450, 400));
203  splitPane.setLeftComponent(thumbnailViewer);
204 
205  contentViewer.setPreferredSize(new java.awt.Dimension(450, 400));
206  splitPane.setRightComponent(contentViewer);
207 
208  gridBagConstraints = new java.awt.GridBagConstraints();
209  gridBagConstraints.gridx = 0;
210  gridBagConstraints.gridy = 0;
211  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
212  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
213  gridBagConstraints.weightx = 1.0;
214  gridBagConstraints.weighty = 1.0;
215  add(splitPane, gridBagConstraints);
216  }// </editor-fold>//GEN-END:initComponents
217 
218 
219  // Variables declaration - do not modify//GEN-BEGIN:variables
221  private javax.swing.JSplitPane splitPane;
223  // End of variables declaration//GEN-END:variables
224 
225 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.