Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MessagesPanel.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 obtain 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 static javax.swing.SwingUtilities.isDescendingFrom;
26 import org.netbeans.swing.outline.DefaultOutlineModel;
27 import org.netbeans.swing.outline.Outline;
28 import org.openide.explorer.ExplorerManager;
29 import static org.openide.explorer.ExplorerUtils.createLookup;
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.ChildFactory;
32 import org.openide.nodes.Children;
33 import org.openide.nodes.Node;
34 import org.openide.util.Lookup;
38 
44 class MessagesPanel extends javax.swing.JPanel implements Lookup.Provider {
45 
46  private static final long serialVersionUID = 1L;
47 
48  private final Outline outline;
49  private final ModifiableProxyLookup proxyLookup;
50  private PropertyChangeListener focusPropertyListener;
51 
52  private final MessageDataContent messageContentViewer;
53 
57  MessagesPanel() {
58  initComponents();
59 
60  messageContentViewer = new MessageDataContent();
61  splitPane.setRightComponent(messageContentViewer);
62 
63  proxyLookup = new ModifiableProxyLookup(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
64 
65  outline = outlineViewPanel.getOutlineView().getOutline();
66  outlineViewPanel.getOutlineView().setPropertyColumns(
67  "From", Bundle.MessageViewer_columnHeader_From(),
68  "To", Bundle.MessageViewer_columnHeader_To(),
69  "Date", Bundle.MessageViewer_columnHeader_Date(),
70  "Subject", Bundle.MessageViewer_columnHeader_Subject(),
71  "Attms", Bundle.MessageViewer_columnHeader_Attms()
72  );
73  outline.setRootVisible(false);
74  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel("Type");
75 
76  outlineViewPanel.getExplorerManager().addPropertyChangeListener((PropertyChangeEvent evt) -> {
77  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
78  final Node[] nodes = outlineViewPanel.getExplorerManager().getSelectedNodes();
79 
80  if (nodes != null && nodes.length == 1) {
81  messageContentViewer.setNode(nodes[0]);
82  } else {
83  messageContentViewer.setNode(null);
84  }
85  }
86  });
87 
88  splitPane.setResizeWeight(0.5);
89  splitPane.setDividerLocation(0.5);
90  outlineViewPanel.setTableColumnsWidth(5, 10, 10, 15, 50, 10);
91  }
92 
93  public MessagesPanel(ChildFactory<?> nodeFactory) {
94  this();
95  setChildFactory(nodeFactory);
96  }
97 
98  @Override
99  public Lookup getLookup() {
100  return proxyLookup;
101  }
102 
103  @Override
104  public void addNotify() {
105  super.addNotify();
106 
107  if (focusPropertyListener == null) {
108  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
109  // explaination of focusPropertyListener
110  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
111  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
112  handleFocusChange((Component) focusEvent.getNewValue());
113 
114  }
115  };
116 
117  }
118 
119  //add listener that maintains correct selection in the Global Actions Context
120  KeyboardFocusManager.getCurrentKeyboardFocusManager()
121  .addPropertyChangeListener("focusOwner", focusPropertyListener);
122  }
123 
124  private void handleFocusChange(Component newFocusOwner) {
125  if (newFocusOwner == null) {
126  return;
127  }
128  if (isDescendingFrom(newFocusOwner, messageContentViewer)) {
129  //if the focus owner is within the MessageContentViewer (the attachments table)
130  proxyLookup.setNewLookups(createLookup((messageContentViewer).getExplorerManager(), getActionMap()));
131  } else if (isDescendingFrom(newFocusOwner, MessagesPanel.this)) {
132  //... or if it is within the Results table.
133  proxyLookup.setNewLookups(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
134 
135  }
136  }
137 
138  @Override
139  public void removeNotify() {
140  super.removeNotify();
141  KeyboardFocusManager.getCurrentKeyboardFocusManager()
142  .removePropertyChangeListener("focusOwner", focusPropertyListener);
143  }
144 
145  final void setChildFactory(ChildFactory<?> nodeFactory) {
146  outlineViewPanel.getExplorerManager().setRootContext(
147  new TableFilterNode(
148  new DataResultFilterNode(
149  new AbstractNode(
150  Children.create(nodeFactory, true)),
151  outlineViewPanel.getExplorerManager()), true));
152  }
153 
159  @SuppressWarnings("unchecked")
160  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
161  private void initComponents() {
162 
163  splitPane = new javax.swing.JSplitPane();
165 
166  setLayout(new java.awt.BorderLayout());
167 
168  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
169  splitPane.setLeftComponent(outlineViewPanel);
170 
171  add(splitPane, java.awt.BorderLayout.CENTER);
172  }// </editor-fold>//GEN-END:initComponents
173 
174 
175  // Variables declaration - do not modify//GEN-BEGIN:variables
177  private javax.swing.JSplitPane splitPane;
178  // End of variables declaration//GEN-END:variables
179 }

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.