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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.