Autopsy  4.18.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-2021 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  contentViewer.setNode(null);
103  if (info != null) {
104  try {
105  relationshipSources = info.getRelationshipSources();
106 
107  relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
108  artifactList.add((BlackboardArtifact) content);
109  });
110 
111  } catch (TskCoreException ex) {
112  logger.log(Level.WARNING, "Unable to update selection.", ex);
113  }
114  }
115  thumbnailViewer.resetComponent();
116 
117  thumbnailViewer.setNode(new TableFilterNode(new DataResultFilterNode(new AbstractNode(new AttachmentThumbnailsChildren(artifactList)), tableEM), true, this.getClass().getName()));
118  }
119 
120  @Override
121  public ExplorerManager getExplorerManager() {
122  return tableEM;
123  }
124 
125  @Override
126  public Lookup getLookup() {
127  return proxyLookup;
128  }
129 
130  @Override
131  public void addNotify() {
132  super.addNotify();
133 
134  if (focusPropertyListener == null) {
135  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
136  // explaination of focusPropertyListener
137  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
138  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
139  handleFocusChange((Component) focusEvent.getNewValue());
140  }
141  };
142 
143  }
144  //add listener that maintains correct selection in the Global Actions Context
145  KeyboardFocusManager.getCurrentKeyboardFocusManager()
146  .addPropertyChangeListener("focusOwner", focusPropertyListener);
147  }
148 
154  private void handleFocusChange(Component newFocusOwner) {
155  if (newFocusOwner == null) {
156  return;
157  }
158  if (isDescendingFrom(newFocusOwner, contentViewer)) {
159  //if the focus owner is within the MessageContentViewer (the attachments table)
160  proxyLookup.setNewLookups(createLookup(contentViewer.getExplorerManager(), getActionMap()));
161  } else if (isDescendingFrom(newFocusOwner, this)) {
162  //... or if it is within the Results table.
163  proxyLookup.setNewLookups(createLookup(tableEM, getActionMap()));
164 
165  }
166  }
167 
168  @Override
169  public void removeNotify() {
170  super.removeNotify();
171 
172  if (focusPropertyListener != null) {
173  KeyboardFocusManager.getCurrentKeyboardFocusManager()
174  .removePropertyChangeListener("focusOwner", focusPropertyListener);
175  }
176  }
177 
181  private void handleNodeSelectionChange() {
182  final Node[] nodes = tableEM.getSelectedNodes();
183 
184  if (nodes != null && nodes.length == 1) {
185  AbstractContent thumbnail = nodes[0].getLookup().lookup(AbstractContent.class);
186  if (thumbnail != null) {
187  try {
188  Content parentContent = thumbnail.getParent();
189  if (parentContent != null && parentContent instanceof BlackboardArtifact) {
190  contentViewer.setNode(new BlackboardArtifactNode((BlackboardArtifact) parentContent));
191  }
192  } catch (TskCoreException ex) {
193  logger.log(Level.WARNING, "Unable to get parent Content from AbstraceContent instance.", ex); //NON-NLS
194  }
195  }
196  } else {
197  contentViewer.setNode(null);
198  }
199  }
200 
206  @SuppressWarnings("unchecked")
207  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
208  private void initComponents() {
209  java.awt.GridBagConstraints gridBagConstraints;
210 
211  splitPane = new javax.swing.JSplitPane();
212  thumbnailViewer = new org.sleuthkit.autopsy.corecomponents.DataResultViewerThumbnail(tableEM);
213 
214  setLayout(new java.awt.GridBagLayout());
215 
216  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
217 
218  thumbnailViewer.setMinimumSize(new java.awt.Dimension(350, 102));
219  thumbnailViewer.setPreferredSize(new java.awt.Dimension(450, 400));
220  splitPane.setLeftComponent(thumbnailViewer);
221 
222  gridBagConstraints = new java.awt.GridBagConstraints();
223  gridBagConstraints.gridx = 0;
224  gridBagConstraints.gridy = 0;
225  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
226  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
227  gridBagConstraints.weightx = 1.0;
228  gridBagConstraints.weighty = 1.0;
229  add(splitPane, gridBagConstraints);
230  }// </editor-fold>//GEN-END:initComponents
231 
232 
233  // Variables declaration - do not modify//GEN-BEGIN:variables
234  private javax.swing.JSplitPane splitPane;
236  // End of variables declaration//GEN-END:variables
237 
238 }

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