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

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