Autopsy  4.19.3
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  /*
69  * This lookup proxies the selection lookup of both he accounts table and
70  * the messages table.
71  */
72  private final ProxyLookup proxyLookup;
73 
74  public AccountsBrowser(RelationshipBrowser relationshipBrowser) {
75  initComponents();
76 
77  outline = outlineView.getOutline();
78  outlineView.setPropertyColumns(
79  "device", Bundle.AccountNode_device(),
80  "type", Bundle.AccountNode_accountType(),
81  "count", Bundle.AccountNode_messageCount()
82  );
83 
84  outline.setRootVisible(false);
85  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.AccountNode_accountName());
86  outline.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
87  outline.setColumnSorted(3, false, 1); //it would be nice if the column index wasn't hardcoded
88 
89  accountsTableEM.addPropertyChangeListener(evt -> {
90  if (ExplorerManager.PROP_ROOT_CONTEXT.equals(evt.getPropertyName())) {
91  SwingUtilities.invokeLater(this::setColumnWidths);
92  } else if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
93  SwingUtilities.invokeLater(this::setColumnWidths);
94  } else if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
95  final Node[] selectedNodes = accountsTableEM.getSelectedNodes();
96  final Set<AccountDeviceInstance> accountDeviceInstances = new HashSet<>();
97 
98  CommunicationsFilter filter = null;
99  for (final Node node : selectedNodes) {
100  accountDeviceInstances.add(((AccountDeviceInstanceNode) node).getAccountDeviceInstance());
101  filter = ((AccountDeviceInstanceNode)node).getFilter();
102  }
103  relationshipBrowser.setSelectionInfo(new SelectionInfo(accountDeviceInstances, new HashSet<>(), filter));
104  }
105  });
106 
107  proxyLookup = new ProxyLookup(relationshipBrowser.getLookup(),
108  ExplorerUtils.createLookup(accountsTableEM, getActionMap()));
109  }
110 
111  private void setColumnWidths() {
112  int margin = 4;
113  int padding = 8;
114 
115  final int rows = Math.min(100, outline.getRowCount());
116 
117  for (int column = 0; column < outline.getColumnCount(); column++) {
118  int columnWidthLimit = 500;
119  int columnWidth = 0;
120 
121  // find the maximum width needed to fit the values for the first 100 rows, at most
122  for (int row = 0; row < rows; row++) {
123  TableCellRenderer renderer = outline.getCellRenderer(row, column);
124  Component comp = outline.prepareRenderer(renderer, row, column);
125  columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
126  }
127 
128  columnWidth += 2 * margin + padding; // add margin and regular padding
129  columnWidth = Math.min(columnWidth, columnWidthLimit);
130 
131  outline.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
132  }
133  }
134 
135  @Subscribe
136  void handleFilterEvent(CVTEvents.FilterChangeEvent filterChangeEvent) {
137  try {
138  final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
139  accountsTableEM.setRootContext(new AbstractNode(Children.create(new AccountDeviceInstanceNodeFactory(commsManager, filterChangeEvent.getNewFilter()), true)));
140  } catch (TskCoreException ex) {
141  logger.log(Level.SEVERE, "There was an error getting the CommunicationsManager for the current case.", ex);
142  } catch (NoCurrentCaseException ex) { //NOPMD empty catch clause
143  //Case is closed, do nothig.
144  }
145  }
146 
147  @Subscribe
148  void historyChange(CVTEvents.StateChangeEvent event) {
149  try {
150  final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
151  accountsTableEM.setRootContext(new AbstractNode(Children.create(new AccountDeviceInstanceNodeFactory(commsManager, event.getCommunicationsState().getCommunicationsFilter()), true)));
152  } catch (TskCoreException ex) {
153  logger.log(Level.SEVERE, "There was an error getting the CommunicationsManager for the current case.", ex);
154  } catch (NoCurrentCaseException ex) { //NOPMD empty catch clause
155  //Case is closed, do nothig.
156  }
157 
158  }
159 
165  @SuppressWarnings("unchecked")
166  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
167  private void initComponents() {
168 
169  outlineView = new org.openide.explorer.view.OutlineView();
170 
171  setLayout(new java.awt.BorderLayout());
172  add(outlineView, java.awt.BorderLayout.CENTER);
173  }// </editor-fold>//GEN-END:initComponents
174 
175 
176  // Variables declaration - do not modify//GEN-BEGIN:variables
177  private org.openide.explorer.view.OutlineView outlineView;
178  // End of variables declaration//GEN-END:variables
179 
180  @Override
181  public ExplorerManager getExplorerManager() {
182  return accountsTableEM;
183  }
184 
185  @Override
186  public Lookup getLookup() {
187  return proxyLookup;
188  }
189 }
org.openide.explorer.view.OutlineView outlineView
AccountsBrowser(RelationshipBrowser relationshipBrowser)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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