Autopsy  4.9.1
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.logging.Level;
24 import javax.swing.JPanel;
25 import javax.swing.ListSelectionModel;
26 import javax.swing.SwingUtilities;
27 import javax.swing.table.TableCellRenderer;
28 import org.netbeans.swing.outline.DefaultOutlineModel;
29 import org.netbeans.swing.outline.Outline;
30 import org.openide.explorer.ExplorerManager;
31 import org.openide.explorer.ExplorerUtils;
32 import org.openide.nodes.AbstractNode;
33 import org.openide.nodes.Children;
34 import org.openide.util.Lookup;
35 import org.openide.util.lookup.ProxyLookup;
39 import org.sleuthkit.datamodel.CommunicationsManager;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
51 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
52 public final class AccountsBrowser extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
53 
54  private static final long serialVersionUID = 1L;
55  private static final Logger logger = Logger.getLogger(AccountsBrowser.class.getName());
56 
57  private final Outline outline;
58 
59  private final ExplorerManager messageBrowserEM = new ExplorerManager();
60  private final ExplorerManager accountsTableEM = new ExplorerManager();
61 
62  /*
63  * This lookup proxies the selection lookup of both he accounts table and
64  * the messages table.
65  */
66  private final ProxyLookup proxyLookup;
67 
68  public AccountsBrowser() {
69  initComponents();
70  outline = outlineView.getOutline();
71  outlineView.setPropertyColumns(
72  "device", Bundle.AccountNode_device(),
73  "type", Bundle.AccountNode_accountType(),
74  "count", Bundle.AccountNode_messageCount()
75  );
76 
77  outline.setRootVisible(false);
78  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.AccountNode_accountName());
79  outline.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
80  outline.setColumnSorted(3, false, 1); //it would be nice if the column index wasn't hardcoded
81 
82  accountsTableEM.addPropertyChangeListener(evt -> {
83  if (ExplorerManager.PROP_ROOT_CONTEXT.equals(evt.getPropertyName())) {
84  SwingUtilities.invokeLater(this::setColumnWidths);
85  } else if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
86  SwingUtilities.invokeLater(this::setColumnWidths);
87  }
88  });
89  final MessageBrowser messageBrowser = new MessageBrowser(accountsTableEM, messageBrowserEM);
90 
91  jSplitPane1.setRightComponent(messageBrowser);
92 
93  proxyLookup = new ProxyLookup(
94  messageBrowser.getLookup(),
95  ExplorerUtils.createLookup(accountsTableEM, getActionMap()));
96  }
97 
98  private void setColumnWidths() {
99  int margin = 4;
100  int padding = 8;
101 
102  final int rows = Math.min(100, outline.getRowCount());
103 
104  for (int column = 0; column < outline.getModel().getColumnCount(); column++) {
105  int columnWidthLimit = 500;
106  int columnWidth = 0;
107 
108  // find the maximum width needed to fit the values for the first 100 rows, at most
109  for (int row = 0; row < rows; row++) {
110  TableCellRenderer renderer = outline.getCellRenderer(row, column);
111  Component comp = outline.prepareRenderer(renderer, row, column);
112  columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
113  }
114 
115  columnWidth += 2 * margin + padding; // add margin and regular padding
116  columnWidth = Math.min(columnWidth, columnWidthLimit);
117 
118  outline.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
119  }
120  }
121 
122  @Subscribe
123  public void handleFilterEvent(CVTEvents.FilterChangeEvent filterChangeEvent) {
124  try {
125  final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
126  accountsTableEM.setRootContext(new AbstractNode(Children.create(new AccountDeviceInstanceNodeFactory(commsManager, filterChangeEvent.getNewFilter()), true)));
127  } catch (TskCoreException ex) {
128  logger.log(Level.SEVERE, "There was an error getting the CommunicationsManager for the current case.", ex);
129  } catch (NoCurrentCaseException ex) { //NOPMD empty catch clause
130  //Case is closed, do nothig.
131  }
132  }
133 
139  @SuppressWarnings("unchecked")
140  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
141  private void initComponents() {
142 
143  jSplitPane1 = new javax.swing.JSplitPane();
144  outlineView = new org.openide.explorer.view.OutlineView();
145 
146  setLayout(new java.awt.BorderLayout());
147 
148  jSplitPane1.setDividerLocation(500);
149  jSplitPane1.setLeftComponent(outlineView);
150 
151  add(jSplitPane1, java.awt.BorderLayout.CENTER);
152  }// </editor-fold>//GEN-END:initComponents
153 
154 
155  // Variables declaration - do not modify//GEN-BEGIN:variables
156  private javax.swing.JSplitPane jSplitPane1;
157  private org.openide.explorer.view.OutlineView outlineView;
158  // End of variables declaration//GEN-END:variables
159 
160  @Override
161  public ExplorerManager getExplorerManager() {
162  return accountsTableEM;
163  }
164 
165  @Override
166  public Lookup getLookup() {
167  return proxyLookup;
168  }
169 }
org.openide.explorer.view.OutlineView outlineView
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
void handleFilterEvent(CVTEvents.FilterChangeEvent filterChangeEvent)

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