Autopsy  4.5.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 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 java.awt.Component;
22 import javax.swing.JPanel;
23 import javax.swing.ListSelectionModel;
24 import javax.swing.SwingUtilities;
25 import javax.swing.table.TableCellRenderer;
26 import org.netbeans.swing.outline.DefaultOutlineModel;
27 import org.netbeans.swing.outline.Outline;
28 import org.openide.explorer.ExplorerManager;
29 
34 public class AccountsBrowser extends JPanel {
35 
36  private static final long serialVersionUID = 1L;
37 
38  private final Outline outline;
39  private ExplorerManager em;
40 
44  public AccountsBrowser() {
46  outline = outlineView.getOutline();
47  outlineView.setPropertyColumns(
48  "device", Bundle.AccountNode_device(),
49  "type", Bundle.AccountNode_accountType(),
50  "count", Bundle.AccountNode_messageCount()
51  );
52 
53  outline.setRootVisible(false);
54  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.AccountNode_accountName());
55  outline.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
56  outline.setColumnSorted(3, false, 1); //it would be nice if the column index wasn't hardcoded
57  }
58 
59  @Override
60  public void addNotify() {
61  super.addNotify();
62  em = ExplorerManager.find(this);
63  em.addPropertyChangeListener(evt -> {
64  if (ExplorerManager.PROP_ROOT_CONTEXT.equals(evt.getPropertyName())) {
65  SwingUtilities.invokeLater(this::setColumnWidths);
66  } else if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
67  SwingUtilities.invokeLater(this::setColumnWidths);
68  }
69  });
70  }
71 
72  private void setColumnWidths() {
73  int margin = 4;
74  int padding = 8;
75 
76  final int rows = Math.min(100, outline.getRowCount());
77 
78  for (int column = 0; column < outline.getModel().getColumnCount(); column++) {
79  int columnWidthLimit = 500;
80  int columnWidth = 0;
81 
82  // find the maximum width needed to fit the values for the first 100 rows, at most
83  for (int row = 0; row < rows; row++) {
84  TableCellRenderer renderer = outline.getCellRenderer(row, column);
85  Component comp = outline.prepareRenderer(renderer, row, column);
86  columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
87  }
88 
89  columnWidth += 2 * margin + padding; // add margin and regular padding
90  columnWidth = Math.min(columnWidth, columnWidthLimit);
91 
92  outline.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
93  }
94  }
95 
101  @SuppressWarnings("unchecked")
102  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
103  private void initComponents() {
104 
105  outlineView = new org.openide.explorer.view.OutlineView();
106 
107  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
108  this.setLayout(layout);
109  layout.setHorizontalGroup(
110  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
112  .addGap(0, 0, 0)
113  .addComponent(outlineView, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
114  .addGap(0, 0, 0))
115  );
116  layout.setVerticalGroup(
117  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
119  .addGap(0, 0, 0)
120  .addComponent(outlineView, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
121  .addGap(0, 0, 0))
122  );
123  }// </editor-fold>//GEN-END:initComponents
124 
125 
126  // Variables declaration - do not modify//GEN-BEGIN:variables
127  private org.openide.explorer.view.OutlineView outlineView;
128  // End of variables declaration//GEN-END:variables
129 }
org.openide.explorer.view.OutlineView outlineView

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