Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MessageViewer.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.CardLayout;
22 import java.awt.Component;
23 import java.awt.Graphics2D;
24 import java.awt.Image;
25 import java.awt.KeyboardFocusManager;
26 import java.awt.RenderingHints;
27 import java.awt.event.ActionEvent;
28 import java.awt.image.BufferedImage;
29 import java.beans.PropertyChangeEvent;
30 import java.beans.PropertyChangeListener;
31 import java.beans.PropertyVetoException;
32 import java.lang.reflect.InvocationTargetException;
33 import java.util.ArrayList;
34 import java.util.logging.Level;
35 import javax.swing.AbstractAction;
36 import javax.swing.ImageIcon;
37 import javax.swing.JPanel;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.SwingUtilities;
40 import static javax.swing.SwingUtilities.isDescendingFrom;
41 import org.netbeans.swing.outline.DefaultOutlineModel;
42 import org.netbeans.swing.outline.Outline;
43 import org.openide.explorer.ExplorerManager;
44 import static org.openide.explorer.ExplorerUtils.createLookup;
45 import org.openide.nodes.AbstractNode;
46 import org.openide.nodes.Children;
47 import org.openide.nodes.Node;
48 import org.openide.nodes.Node.Property;
49 import org.openide.nodes.Node.PropertySet;
50 import org.openide.util.Lookup;
51 import org.openide.util.NbBundle.Messages;
54 
59 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
60 public class MessageViewer extends JPanel implements RelationshipsViewer {
61 
62  private static final Logger logger = Logger.getLogger(MessageViewer.class.getName());
63 
65  private final PropertyChangeListener focusPropertyListener;
66  private final ThreadChildNodeFactory rootMessageFactory;
68 
69  private SelectionInfo currentSelectionInfo = null;
70 
71  OutlineViewPanel currentPanel;
72 
73  @Messages({
74  "MessageViewer_tabTitle=Messages",
75  "MessageViewer_columnHeader_From=From",
76  "MessageViewer_columnHeader_Date=Date",
77  "MessageViewer_columnHeader_To=To",
78  "MessageViewer_columnHeader_EarlyDate=Earliest Message",
79  "MessageViewer_columnHeader_Subject=Subject",
80  "MessageViewer_columnHeader_Attms=Attachments",
81  "MessageViewer_no_messages=<No messages found for selected account>",
82  "MessageViewer_viewMessage_all=All",
83  "MessageViewer_viewMessage_selected=Selected",
84  "MessageViewer_viewMessage_unthreaded=Unthreaded",
85  "MessageViewer_viewMessage_calllogs=Call Logs"})
86 
90  public MessageViewer() {
91 
92  initComponents();
93  currentPanel = rootTablePane;
94  proxyLookup = new ModifiableProxyLookup(createLookup(rootTablePane.getExplorerManager(), getActionMap()));
95  rootMessageFactory = new ThreadChildNodeFactory(new ShowThreadMessagesAction());
96  threadMessageNodeFactory = new MessagesChildNodeFactory();
97 
98  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
99  // explaination of focusPropertyListener
100  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
101  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
102  final Component newFocusOwner = (Component) focusEvent.getNewValue();
103 
104  if (newFocusOwner == null) {
105  return;
106  }
107  if (isDescendingFrom(newFocusOwner, rootTablePane)) {
108  proxyLookup.setNewLookups(createLookup(rootTablePane.getExplorerManager(), getActionMap()));
109  } else if (isDescendingFrom(newFocusOwner, MessageViewer.this)) {
110  proxyLookup.setNewLookups(createLookup(currentPanel.getExplorerManager(), getActionMap()));
111  }
112  }
113  };
114 
115  rootTablePane.getExplorerManager().setRootContext(
116  new AbstractNode(Children.create(rootMessageFactory, true)));
117 
118  rootTablePane.getOutlineView().setPopupAllowed(false);
119 
120  Outline outline = rootTablePane.getOutlineView().getOutline();
121  rootTablePane.getOutlineView().setPropertyColumns(
122  "Date", Bundle.MessageViewer_columnHeader_EarlyDate(),
123  "Subject", Bundle.MessageViewer_columnHeader_Subject()
124  );
125  outline.setRootVisible(false);
126  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel("Type");
127  outline.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
128 
129  rootTablePane.getExplorerManager().addPropertyChangeListener((PropertyChangeEvent evt) -> {
130  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
131  showSelectedThread();
132  }
133  });
134 
135  threadMessagesPanel.setChildFactory(threadMessageNodeFactory);
136 
137  rootTablePane.setTableColumnsWidth(10, 20, 70);
138 
139  Image image = getScaledImage((new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/timeline/images/arrow-180.png"))).getImage(), 16, 16);
140  backButton.setIcon(new ImageIcon(image) );
141  }
142 
143  @Override
144  public String getDisplayName() {
145  return Bundle.MessageViewer_tabTitle();
146  }
147 
148  @Override
149  public JPanel getPanel() {
150  return this;
151  }
152 
153  @Override
154  public void setSelectionInfo(SelectionInfo info) {
155  currentSelectionInfo = info;
156 
157  currentPanel = rootTablePane;
158 
159  CardLayout layout = (CardLayout) this.getLayout();
160  layout.show(this, "threads");
161 
162  rootMessageFactory.refresh(info);
163  }
164 
165  @Override
166  public Lookup getLookup() {
167  return proxyLookup;
168  }
169 
170  @Override
171  public void addNotify() {
172  super.addNotify();
173  //add listener that maintains correct selection in the Global Actions Context
174  KeyboardFocusManager.getCurrentKeyboardFocusManager()
175  .addPropertyChangeListener("focusOwner", focusPropertyListener);
176  }
177 
178  @Override
179  public void removeNotify() {
180  super.removeNotify();
181  KeyboardFocusManager.getCurrentKeyboardFocusManager()
182  .removePropertyChangeListener("focusOwner", focusPropertyListener);
183  }
184 
185  @SuppressWarnings("rawtypes")
186  private void showSelectedThread() {
187  final Node[] nodes = rootTablePane.getExplorerManager().getSelectedNodes();
188 
189  if (nodes == null) {
190  return;
191  }
192 
193  if (nodes.length == 0 || nodes.length > 1) {
194  return;
195  }
196 
197  ArrayList<String> threadIDList = new ArrayList<>();
198  String subject = "";
199 
200  PropertySet[] propertySets = nodes[0].getPropertySets();
201  for (PropertySet pset : propertySets) {
202  Property[] properties = pset.getProperties();
203  for (Property prop : properties) {
204  if (prop.getName().equalsIgnoreCase("threadid")) {
205  try {
206  String threadID = prop.getValue().toString();
207  if (!threadIDList.contains(threadID)) {
208  threadIDList.add(threadID);
209  }
210  } catch (IllegalAccessException | InvocationTargetException ex) {
211  logger.log(Level.WARNING, String.format("Unable to get threadid for node: %s", nodes[0].getDisplayName()), ex);
212  }
213  } else if (prop.getName().equalsIgnoreCase("subject")) {
214  try {
215  subject = prop.getValue().toString();
216  } catch (IllegalAccessException | InvocationTargetException ex) {
217  logger.log(Level.WARNING, String.format("Unable to get subject for node: %s", nodes[0].getDisplayName()), ex);
218  subject = "<unavailable>";
219  }
220  }
221  }
222 
223  }
224 
225  if (!threadIDList.isEmpty()) {
226  threadMessageNodeFactory.refresh(currentSelectionInfo, threadIDList);
227 
228  if (!subject.isEmpty()) {
229  threadNameLabel.setText(subject);
230  } else {
231  threadNameLabel.setText(Bundle.MessageViewer_viewMessage_unthreaded());
232  }
233 
234  showMessagesPane();
235  }
236  }
237 
241  private void showThreadsPane() {
242  switchCard("threads");
243  }
244 
248  private void showMessagesPane() {
249  switchCard("messages");
250  }
251 
257  private void switchCard(String cardName) {
258  SwingUtilities.invokeLater(new Runnable() {
259  @Override
260  public void run() {
261  CardLayout layout = (CardLayout)getLayout();
262  layout.show(MessageViewer.this, cardName);
263  }
264  });
265  }
266 
276  private Image getScaledImage(Image srcImg, int w, int h){
277  BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
278  Graphics2D g2 = resizedImg.createGraphics();
279 
280  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
281  g2.drawImage(srcImg, 0, 0, w, h, null);
282  g2.dispose();
283 
284  return resizedImg;
285  }
286 
292  @SuppressWarnings("unchecked")
293  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
294  private void initComponents() {
295  java.awt.GridBagConstraints gridBagConstraints;
296 
297  rootMessagesPane = new javax.swing.JPanel();
298  threadsLabel = new javax.swing.JLabel();
299  showAllButton = new javax.swing.JButton();
301  messagePanel = new javax.swing.JPanel();
302  threadMessagesPanel = new MessagesPanel();
303  backButton = new javax.swing.JButton();
304  showingMessagesLabel = new javax.swing.JLabel();
305  threadNameLabel = new javax.swing.JLabel();
306 
307  setLayout(new java.awt.CardLayout());
308 
309  rootMessagesPane.setOpaque(false);
310  rootMessagesPane.setLayout(new java.awt.GridBagLayout());
311 
312  org.openide.awt.Mnemonics.setLocalizedText(threadsLabel, org.openide.util.NbBundle.getMessage(MessageViewer.class, "MessageViewer.threadsLabel.text")); // NOI18N
313  gridBagConstraints = new java.awt.GridBagConstraints();
314  gridBagConstraints.gridx = 0;
315  gridBagConstraints.gridy = 0;
316  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
317  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
318  gridBagConstraints.weightx = 1.0;
319  gridBagConstraints.insets = new java.awt.Insets(15, 15, 9, 0);
320  rootMessagesPane.add(threadsLabel, gridBagConstraints);
321 
322  org.openide.awt.Mnemonics.setLocalizedText(showAllButton, org.openide.util.NbBundle.getMessage(MessageViewer.class, "MessageViewer.showAllButton.text")); // NOI18N
323  showAllButton.addActionListener(new java.awt.event.ActionListener() {
324  public void actionPerformed(java.awt.event.ActionEvent evt) {
325  showAllButtonActionPerformed(evt);
326  }
327  });
328  gridBagConstraints = new java.awt.GridBagConstraints();
329  gridBagConstraints.gridx = 0;
330  gridBagConstraints.gridy = 2;
331  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
332  gridBagConstraints.insets = new java.awt.Insets(0, 15, 15, 0);
333  rootMessagesPane.add(showAllButton, gridBagConstraints);
334 
335  rootTablePane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
336  gridBagConstraints = new java.awt.GridBagConstraints();
337  gridBagConstraints.gridx = 0;
338  gridBagConstraints.gridy = 1;
339  gridBagConstraints.gridwidth = 2;
340  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
341  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
342  gridBagConstraints.weightx = 1.0;
343  gridBagConstraints.weighty = 1.0;
344  gridBagConstraints.insets = new java.awt.Insets(0, 15, 9, 15);
345  rootMessagesPane.add(rootTablePane, gridBagConstraints);
346 
347  add(rootMessagesPane, "threads");
348 
349  messagePanel.setLayout(new java.awt.GridBagLayout());
350  gridBagConstraints = new java.awt.GridBagConstraints();
351  gridBagConstraints.gridx = 0;
352  gridBagConstraints.gridy = 3;
353  gridBagConstraints.gridwidth = 3;
354  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
355  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
356  gridBagConstraints.weightx = 1.0;
357  gridBagConstraints.weighty = 1.0;
358  gridBagConstraints.insets = new java.awt.Insets(0, 15, 0, 15);
359  messagePanel.add(threadMessagesPanel, gridBagConstraints);
360 
361  org.openide.awt.Mnemonics.setLocalizedText(backButton, org.openide.util.NbBundle.getMessage(MessageViewer.class, "MessageViewer.backButton.text")); // NOI18N
362  backButton.addActionListener(new java.awt.event.ActionListener() {
363  public void actionPerformed(java.awt.event.ActionEvent evt) {
364  backButtonActionPerformed(evt);
365  }
366  });
367  gridBagConstraints = new java.awt.GridBagConstraints();
368  gridBagConstraints.gridx = 2;
369  gridBagConstraints.gridy = 0;
370  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
371  gridBagConstraints.weightx = 1.0;
372  gridBagConstraints.insets = new java.awt.Insets(9, 0, 9, 15);
373  messagePanel.add(backButton, gridBagConstraints);
374  backButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MessageViewer.class, "MessageViewer.backButton.AccessibleContext.accessibleDescription")); // NOI18N
375 
376  org.openide.awt.Mnemonics.setLocalizedText(showingMessagesLabel, org.openide.util.NbBundle.getMessage(MessageViewer.class, "MessageViewer.showingMessagesLabel.text")); // NOI18N
377  gridBagConstraints = new java.awt.GridBagConstraints();
378  gridBagConstraints.gridx = 0;
379  gridBagConstraints.gridy = 0;
380  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
381  gridBagConstraints.insets = new java.awt.Insets(9, 15, 5, 0);
382  messagePanel.add(showingMessagesLabel, gridBagConstraints);
383 
384  org.openide.awt.Mnemonics.setLocalizedText(threadNameLabel, org.openide.util.NbBundle.getMessage(MessageViewer.class, "MessageViewer.threadNameLabel.text")); // NOI18N
385  gridBagConstraints = new java.awt.GridBagConstraints();
386  gridBagConstraints.gridx = 1;
387  gridBagConstraints.gridy = 0;
388  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
389  gridBagConstraints.insets = new java.awt.Insets(9, 5, 5, 15);
390  messagePanel.add(threadNameLabel, gridBagConstraints);
391 
392  add(messagePanel, "messages");
393  }// </editor-fold>//GEN-END:initComponents
394 
395  private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
396  try {
397  rootTablePane.getExplorerManager().setSelectedNodes(new Node[0]);
398  } catch (PropertyVetoException ex) {
399  logger.log(Level.WARNING, "Error setting selected nodes", ex);
400  }
401  showThreadsPane();
402  }//GEN-LAST:event_backButtonActionPerformed
403 
404  private void showAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllButtonActionPerformed
405  threadMessageNodeFactory.refresh(currentSelectionInfo, null);
406  threadNameLabel.setText("All Messages");
407 
408  showMessagesPane();
409  }//GEN-LAST:event_showAllButtonActionPerformed
410 
411  // Variables declaration - do not modify//GEN-BEGIN:variables
412  private javax.swing.JButton backButton;
413  private javax.swing.JPanel messagePanel;
414  private javax.swing.JPanel rootMessagesPane;
416  private javax.swing.JButton showAllButton;
417  private javax.swing.JLabel showingMessagesLabel;
419  private javax.swing.JLabel threadNameLabel;
420  private javax.swing.JLabel threadsLabel;
421  // End of variables declaration//GEN-END:variables
422 
426  class ShowThreadMessagesAction extends AbstractAction {
427 
428  @Override
429  public void actionPerformed(ActionEvent e) {
430 
431  SwingUtilities.invokeLater(new Runnable() {
432  @Override
433  public void run() {
434  showSelectedThread();
435  }
436  });
437  }
438  }
439 }
void showAllButtonActionPerformed(java.awt.event.ActionEvent evt)
void refresh(SelectionInfo selectionInfo, List< String > threadIDs)
org.sleuthkit.autopsy.communications.relationships.OutlineViewPanel rootTablePane
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
org.sleuthkit.autopsy.communications.relationships.MessagesPanel threadMessagesPanel

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.