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;
49 final class MediaViewer
extends JPanel implements RelationshipsViewer, ExplorerManager.Provider, Lookup.Provider {
51 private static final Logger logger = Logger.getLogger(MediaViewer.class.getName());
52 private static final long serialVersionUID = 1L;
54 private final ExplorerManager tableEM =
new ExplorerManager();
55 private PropertyChangeListener focusPropertyListener;
57 private final ModifiableProxyLookup proxyLookup;
59 private final MessageDataContent contentViewer;
62 "MediaViewer_Name=Media Attachments"
70 splitPane.setResizeWeight(0.5);
71 splitPane.setDividerLocation(0.5);
73 contentViewer =
new MessageDataContent();
74 contentViewer.setPreferredSize(
new java.awt.Dimension(450, 400));
75 splitPane.setRightComponent(contentViewer);
77 proxyLookup =
new ModifiableProxyLookup(createLookup(tableEM, getActionMap()));
79 tableEM.addPropertyChangeListener((PropertyChangeEvent evt) -> {
80 if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
81 handleNodeSelectionChange();
85 thumbnailViewer.resetComponent();
89 public String getDisplayName() {
90 return Bundle.MediaViewer_Name();
94 public JPanel getPanel() {
99 public void setSelectionInfo(SelectionInfo info) {
100 Set<Content> relationshipSources;
101 Set<BlackboardArtifact> artifactList =
new HashSet<>();
104 relationshipSources = info.getRelationshipSources();
106 relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
107 artifactList.add((BlackboardArtifact) content);
110 }
catch (TskCoreException ex) {
111 logger.log(Level.WARNING,
"Unable to update selection.", ex);
114 thumbnailViewer.resetComponent();
116 thumbnailViewer.setNode(
new TableFilterNode(
new DataResultFilterNode(
new AbstractNode(
new AttachmentThumbnailsChildren(artifactList)), tableEM),
true, this.getClass().getName()));
120 public ExplorerManager getExplorerManager() {
125 public Lookup getLookup() {
130 public void addNotify() {
133 if (focusPropertyListener == null) {
136 focusPropertyListener = (
final PropertyChangeEvent focusEvent) -> {
137 if (focusEvent.getPropertyName().equalsIgnoreCase(
"focusOwner")) {
138 handleFocusChange((Component) focusEvent.getNewValue());
144 KeyboardFocusManager.getCurrentKeyboardFocusManager()
145 .addPropertyChangeListener(
"focusOwner", focusPropertyListener);
153 private void handleFocusChange(Component newFocusOwner) {
154 if (newFocusOwner == null) {
157 if (isDescendingFrom(newFocusOwner, contentViewer)) {
159 proxyLookup.setNewLookups(createLookup(contentViewer.getExplorerManager(), getActionMap()));
160 }
else if (isDescendingFrom(newFocusOwner,
this)) {
162 proxyLookup.setNewLookups(createLookup(tableEM, getActionMap()));
168 public void removeNotify() {
169 super.removeNotify();
171 if (focusPropertyListener != null) {
172 KeyboardFocusManager.getCurrentKeyboardFocusManager()
173 .removePropertyChangeListener(
"focusOwner", focusPropertyListener);
180 private void handleNodeSelectionChange() {
181 final Node[] nodes = tableEM.getSelectedNodes();
183 if (nodes != null && nodes.length == 1) {
184 AbstractContent thumbnail = nodes[0].getLookup().lookup(AbstractContent.class);
185 if (thumbnail != null) {
187 Content parentContent = thumbnail.getParent();
188 if (parentContent != null && parentContent instanceof BlackboardArtifact) {
189 contentViewer.setNode(
new BlackboardArtifactNode((BlackboardArtifact) parentContent));
191 }
catch (TskCoreException ex) {
192 logger.log(Level.WARNING,
"Unable to get parent Content from AbstraceContent instance.", ex);
196 contentViewer.setNode(null);
205 @SuppressWarnings(
"unchecked")
207 private
void initComponents() {
208 java.awt.GridBagConstraints gridBagConstraints;
210 splitPane =
new javax.swing.JSplitPane();
213 setLayout(
new java.awt.GridBagLayout());
215 splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
217 thumbnailViewer.setMinimumSize(
new java.awt.Dimension(350, 102));
218 thumbnailViewer.setPreferredSize(
new java.awt.Dimension(450, 400));
219 splitPane.setLeftComponent(thumbnailViewer);
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);
233 private javax.swing.JSplitPane splitPane;