Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AccountsBrowser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2018 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;
20 
21 import com.google.common.eventbus.Subscribe;
22 import java.awt.Component;
23 import java.util.HashSet;
24 import java.util.Set;
25 import java.util.logging.Level;
26 import javax.swing.JPanel;
27 import javax.swing.ListSelectionModel;
28 import javax.swing.SwingUtilities;
29 import javax.swing.table.TableCellRenderer;
30 import org.netbeans.swing.outline.DefaultOutlineModel;
31 import org.netbeans.swing.outline.Outline;
32 import org.openide.explorer.ExplorerManager;
33 import org.openide.explorer.ExplorerUtils;
34 import org.openide.nodes.AbstractNode;
35 import org.openide.nodes.Children;
36 import org.openide.nodes.Node;
37 import org.openide.util.Lookup;
38 import org.openide.util.lookup.ProxyLookup;
44 import org.sleuthkit.datamodel.AccountDeviceInstance;
45 import org.sleuthkit.datamodel.CommunicationsFilter;
46 import org.sleuthkit.datamodel.CommunicationsManager;
47 import org.sleuthkit.datamodel.TskCoreException;
48 
58 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
59 public final class AccountsBrowser extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
60 
61  private static final long serialVersionUID = 1L;
62  private static final Logger logger = Logger.getLogger(AccountsBrowser.class.getName());
63 
64  private final Outline outline;
65 
66  private final ExplorerManager accountsTableEM = new ExplorerManager();
67 
68  final RelationshipBrowser relationshipBrowser;
69 
70  /*
71  * This lookup proxies the selection lookup of both he accounts table and
72  * the messages table.
73  */
74  private final ProxyLookup proxyLookup;
75 
76  public AccountsBrowser() {
77  initComponents();
78 
79  jSplitPane1.setResizeWeight(0.5);
80  jSplitPane1.setDividerLocation(0.75);
81 
82  outline = outlineView.getOutline();
83  outlineView.setPropertyColumns(
84  "device", Bundle.AccountNode_device(),
85  "type", Bundle.AccountNode_accountType(),
86  "count", Bundle.AccountNode_messageCount()
87  );
88 
89  outline.setRootVisible(false);
90  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.AccountNode_accountName());
91  outline.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
92  outline.setColumnSorted(3, false, 1); //it would be nice if the column index wasn't hardcoded
93 
94  relationshipBrowser = new RelationshipBrowser();
95  jSplitPane1.setRightComponent(relationshipBrowser);
96 
97  accountsTableEM.addPropertyChangeListener(evt -> {
98  if (ExplorerManager.PROP_ROOT_CONTEXT.equals(evt.getPropertyName())) {
99  SwingUtilities.invokeLater(this::setColumnWidths);
100  } else if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
101  SwingUtilities.invokeLater(this::setColumnWidths);
102  } else if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
103  final Node[] selectedNodes = accountsTableEM.getSelectedNodes();
104  final Set<AccountDeviceInstance> accountDeviceInstances = new HashSet<>();
105 
106  CommunicationsFilter filter = null;
107  for (final Node node : selectedNodes) {
108  accountDeviceInstances.add(((AccountDeviceInstanceNode) node).getAccountDeviceInstance());
109  filter = ((AccountDeviceInstanceNode)node).getFilter();
110  }
111  relationshipBrowser.setSelectionInfo(new SelectionInfo(accountDeviceInstances, new HashSet<>(), filter));
112  }
113  });
114 
115  proxyLookup = new ProxyLookup(relationshipBrowser.getLookup(),
116  ExplorerUtils.createLookup(accountsTableEM, getActionMap()));
117  }
118 
119  private void setColumnWidths() {
120  int margin = 4;
121  int padding = 8;
122 
123  final int rows = Math.min(100, outline.getRowCount());
124 
125  for (int column = 0; column < outline.getColumnCount(); column++) {
126  int columnWidthLimit = 500;
127  int columnWidth = 0;
128 
129  // find the maximum width needed to fit the values for the first 100 rows, at most
130  for (int row = 0; row < rows; row++) {
131  TableCellRenderer renderer = outline.getCellRenderer(row, column);
132  Component comp = outline.prepareRenderer(renderer, row, column);
133  columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
134  }
135 
136  columnWidth += 2 * margin + padding; // add margin and regular padding
137  columnWidth = Math.min(columnWidth, columnWidthLimit);
138 
139  outline.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
140  }
141  }
142 
143  @Subscribe
144  void handleFilterEvent(CVTEvents.FilterChangeEvent filterChangeEvent) {
145  try {
146  final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
147  accountsTableEM.setRootContext(new AbstractNode(Children.create(new AccountDeviceInstanceNodeFactory(commsManager, filterChangeEvent.getNewFilter()), true)));
148  } catch (TskCoreException ex) {
149  logger.log(Level.SEVERE, "There was an error getting the CommunicationsManager for the current case.", ex);
150  } catch (NoCurrentCaseException ex) { //NOPMD empty catch clause
151  //Case is closed, do nothig.
152  }
153  }
154 
155  @Subscribe
156  void historyChange(CVTEvents.StateChangeEvent event) {
157  try {
158  final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
159  accountsTableEM.setRootContext(new AbstractNode(Children.create(new AccountDeviceInstanceNodeFactory(commsManager, event.getCommunicationsState().getCommunicationsFilter()), true)));
160  } catch (TskCoreException ex) {
161  logger.log(Level.SEVERE, "There was an error getting the CommunicationsManager for the current case.", ex);
162  } catch (NoCurrentCaseException ex) { //NOPMD empty catch clause
163  //Case is closed, do nothig.
164  }
165 
166  }
167 
173  @SuppressWarnings("unchecked")
174  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
175  private void initComponents() {
176 
177  jSplitPane1 = new javax.swing.JSplitPane();
178  outlineView = new org.openide.explorer.view.OutlineView();
179 
180  setLayout(new java.awt.BorderLayout());
181 
182  jSplitPane1.setDividerLocation(500);
183  jSplitPane1.setLeftComponent(outlineView);
184 
185  add(jSplitPane1, java.awt.BorderLayout.CENTER);
186  }// </editor-fold>//GEN-END:initComponents
187 
188 
189  // Variables declaration - do not modify//GEN-BEGIN:variables
190  private javax.swing.JSplitPane jSplitPane1;
191  private org.openide.explorer.view.OutlineView outlineView;
192  // End of variables declaration//GEN-END:variables
193 
194  @Override
195  public ExplorerManager getExplorerManager() {
196  return accountsTableEM;
197  }
198 
199  @Override
200  public Lookup getLookup() {
201  return proxyLookup;
202  }
203 }
org.openide.explorer.view.OutlineView outlineView
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.