Autopsy  4.15.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;
41 import org.sleuthkit.datamodel.AbstractContent;
42 import org.sleuthkit.datamodel.BlackboardArtifact;
43 import org.sleuthkit.datamodel.Content;
44 import org.sleuthkit.datamodel.TskCoreException;
45 
49 final class MediaViewer extends JPanel implements RelationshipsViewer, ExplorerManager.Provider, Lookup.Provider {
50 
51  private static final Logger logger = Logger.getLogger(MediaViewer.class.getName());
52  private static final long serialVersionUID = 1L;
53 
54  private final ExplorerManager tableEM = new ExplorerManager();
55  private PropertyChangeListener focusPropertyListener;
56 
57  private final ModifiableProxyLookup proxyLookup;
58 
59  private final MessageDataContent contentViewer;
60 
61  @Messages({
62  "MediaViewer_Name=Media Attachments"
63  })
67  MediaViewer() {
68  initComponents();
69 
70  splitPane.setResizeWeight(0.5);
71  splitPane.setDividerLocation(0.5);
72 
73  contentViewer = new MessageDataContent();
74  contentViewer.setPreferredSize(new java.awt.Dimension(450, 400));
75  splitPane.setRightComponent(contentViewer);
76 
77  proxyLookup = new ModifiableProxyLookup(createLookup(tableEM, getActionMap()));
78 
79  tableEM.addPropertyChangeListener((PropertyChangeEvent evt) -> {
80  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
81  handleNodeSelectionChange();
82  }
83  });
84 
85  thumbnailViewer.resetComponent();
86  }
87 
88  @Override
89  public String getDisplayName() {
90  return Bundle.MediaViewer_Name();
91  }
92 
93  @Override
94  public JPanel getPanel() {
95  return this;
96  }
97 
98  @Override
99  public void setSelectionInfo(SelectionInfo info) {
100  Set<Content> relationshipSources;
101  Set<BlackboardArtifact> artifactList = new HashSet<>();
102 
103  try {
104  relationshipSources = info.getRelationshipSources();
105 
106  relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
107  artifactList.add((BlackboardArtifact) content);
108  });
109 
110  } catch (TskCoreException ex) {
111  logger.log(Level.WARNING, "Unable to update selection.", ex);
112  }
113 
114  thumbnailViewer.resetComponent();
115 
116  thumbnailViewer.setNode(new TableFilterNode(new DataResultFilterNode(new AbstractNode(new AttachmentThumbnailsChildren(artifactList)), tableEM), true, this.getClass().getName()));
117  }
118 
119  @Override
120  public ExplorerManager getExplorerManager() {
121  return tableEM;
122  }
123 
124  @Override
125  public Lookup getLookup() {
126  return proxyLookup;
127  }
128 
129  @Override
130  public void addNotify() {
131  super.addNotify();
132 
133  if (focusPropertyListener == null) {
134  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
135  // explaination of focusPropertyListener
136  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
137  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
138  handleFocusChange((Component) focusEvent.getNewValue());
139  }
140  };
141 
142  }
143  //add listener that maintains correct selection in the Global Actions Context
144  KeyboardFocusManager.getCurrentKeyboardFocusManager()
145  .addPropertyChangeListener("focusOwner", focusPropertyListener);
146  }
147 
153  private void handleFocusChange(Component newFocusOwner) {
154  if (newFocusOwner == null) {
155  return;
156  }
157  if (isDescendingFrom(newFocusOwner, contentViewer)) {
158  //if the focus owner is within the MessageContentViewer (the attachments table)
159  proxyLookup.setNewLookups(createLookup(contentViewer.getExplorerManager(), getActionMap()));
160  } else if (isDescendingFrom(newFocusOwner, this)) {
161  //... or if it is within the Results table.
162  proxyLookup.setNewLookups(createLookup(tableEM, getActionMap()));
163 
164  }
165  }
166 
167  @Override
168  public void removeNotify() {
169  super.removeNotify();
170 
171  if (focusPropertyListener != null) {
172  KeyboardFocusManager.getCurrentKeyboardFocusManager()
173  .removePropertyChangeListener("focusOwner", focusPropertyListener);
174  }
175  }
176 
180  private void handleNodeSelectionChange() {
181  final Node[] nodes = tableEM.getSelectedNodes();
182 
183  if (nodes != null && nodes.length == 1) {
184  AbstractContent thumbnail = nodes[0].getLookup().lookup(AbstractContent.class);
185  if (thumbnail != null) {
186  try {
187  Content parentContent = thumbnail.getParent();
188  if (parentContent != null && parentContent instanceof BlackboardArtifact) {
189  contentViewer.setNode(new BlackboardArtifactNode((BlackboardArtifact) parentContent));
190  }
191  } catch (TskCoreException ex) {
192  logger.log(Level.WARNING, "Unable to get parent Content from AbstraceContent instance.", ex); //NON-NLS
193  }
194  }
195  } else {
196  contentViewer.setNode(null);
197  }
198  }
199 
205  @SuppressWarnings("unchecked")
206  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
207  private void initComponents() {
208  java.awt.GridBagConstraints gridBagConstraints;
209 
210  splitPane = new javax.swing.JSplitPane();
211  thumbnailViewer = new org.sleuthkit.autopsy.corecomponents.DataResultViewerThumbnail(tableEM);
212 
213  setLayout(new java.awt.GridBagLayout());
214 
215  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
216 
217  thumbnailViewer.setMinimumSize(new java.awt.Dimension(350, 102));
218  thumbnailViewer.setPreferredSize(new java.awt.Dimension(450, 400));
219  splitPane.setLeftComponent(thumbnailViewer);
220 
221  gridBagConstraints = new java.awt.GridBagConstraints();
222  gridBagConstraints.gridx = 0;
223  gridBagConstraints.gridy = 0;
224  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
225  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
226  gridBagConstraints.weightx = 1.0;
227  gridBagConstraints.weighty = 1.0;
228  add(splitPane, gridBagConstraints);
229  }// </editor-fold>//GEN-END:initComponents
230 
231 
232  // Variables declaration - do not modify//GEN-BEGIN:variables
233  private javax.swing.JSplitPane splitPane;
235  // End of variables declaration//GEN-END:variables
236 
237 }

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