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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.