19 package org.sleuthkit.autopsy.communications.relationships;
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;
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;
52 final class MediaViewer
extends JPanel implements RelationshipsViewer, ExplorerManager.Provider, Lookup.Provider {
54 private static final Logger logger = Logger.getLogger(MediaViewer.class.getName());
56 private final ExplorerManager tableEM =
new ExplorerManager();
57 private final PropertyChangeListener focusPropertyListener;
59 private final ModifiableProxyLookup proxyLookup;
62 "MediaViewer_Name=Media Attachments"
67 public MediaViewer() {
70 splitPane.setResizeWeight(0.5);
71 splitPane.setDividerLocation(0.5);
73 proxyLookup =
new ModifiableProxyLookup(createLookup(tableEM, getActionMap()));
77 focusPropertyListener = (
final PropertyChangeEvent focusEvent) -> {
78 if (focusEvent.getPropertyName().equalsIgnoreCase(
"focusOwner")) {
79 final Component newFocusOwner = (Component) focusEvent.getNewValue();
81 if (newFocusOwner == null) {
84 if (isDescendingFrom(newFocusOwner, contentViewer)) {
86 proxyLookup.setNewLookups(createLookup(((MessageDataContent) contentViewer).getExplorerManager(), getActionMap()));
87 }
else if (isDescendingFrom(newFocusOwner, MediaViewer.this)) {
89 proxyLookup.setNewLookups(createLookup(tableEM, getActionMap()));
95 tableEM.addPropertyChangeListener((PropertyChangeEvent evt) -> {
96 if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
97 handleNodeSelectionChange();
101 thumbnailViewer.resetComponent();
105 public String getDisplayName() {
106 return Bundle.MediaViewer_Name();
110 public JPanel getPanel() {
115 public void setSelectionInfo(SelectionInfo info) {
116 Set<Content> relationshipSources;
117 Set<BlackboardArtifact> artifactList =
new HashSet<>();
120 relationshipSources = info.getRelationshipSources();
122 relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
123 artifactList.add((BlackboardArtifact) content);
126 }
catch (TskCoreException ex) {
127 logger.log(Level.WARNING,
"Unable to update selection." , ex);
130 thumbnailViewer.resetComponent();
132 thumbnailViewer.setNode(
new TableFilterNode(
new DataResultFilterNode(
new AbstractNode(
new AttachmentThumbnailsChildren(artifactList)), tableEM),
true, this.getClass().getName()));
136 public ExplorerManager getExplorerManager() {
141 public Lookup getLookup() {
146 public void addNotify() {
149 KeyboardFocusManager.getCurrentKeyboardFocusManager()
150 .addPropertyChangeListener(
"focusOwner", focusPropertyListener);
154 public void removeNotify() {
155 super.removeNotify();
156 KeyboardFocusManager.getCurrentKeyboardFocusManager()
157 .removePropertyChangeListener(
"focusOwner", focusPropertyListener);
163 private void handleNodeSelectionChange() {
164 final Node[] nodes = tableEM.getSelectedNodes();
166 if (nodes != null && nodes.length == 1) {
167 AbstractContent thumbnail = nodes[0].getLookup().lookup(AbstractContent.class);
168 if (thumbnail != null) {
170 Content parentContent = thumbnail.getParent();
171 if (parentContent != null && parentContent instanceof BlackboardArtifact) {
172 contentViewer.setNode(
new BlackboardArtifactNode((BlackboardArtifact) parentContent));
174 }
catch (TskCoreException ex) {
175 logger.log(Level.WARNING,
"Unable to get parent Content from AbstraceContent instance.", ex);
179 contentViewer.setNode(null);
188 @SuppressWarnings(
"unchecked")
190 private
void initComponents() {
191 java.awt.GridBagConstraints gridBagConstraints;
193 splitPane =
new javax.swing.JSplitPane();
195 contentViewer =
new MessageDataContent();
197 setLayout(
new java.awt.GridBagLayout());
199 splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
201 thumbnailViewer.setMinimumSize(
new java.awt.Dimension(350, 102));
202 thumbnailViewer.setPreferredSize(
new java.awt.Dimension(450, 400));
203 splitPane.setLeftComponent(thumbnailViewer);
205 contentViewer.setPreferredSize(
new java.awt.Dimension(450, 400));
206 splitPane.setRightComponent(contentViewer);
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);
221 private javax.swing.JSplitPane splitPane;