Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilesIdentifierIngestJobSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 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.modules.interestingitems;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Observable;
24 import java.util.Observer;
25 import java.util.TreeMap;
26 import javax.swing.JTable;
27 import javax.swing.table.AbstractTableModel;
28 import javax.swing.table.TableColumn;
31 
35 final class FilesIdentifierIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements Observer {
36 
37  private final FilesSetsTableModel tableModel;
38 
39  // This map of interesting interesting files set names to files sets is used
40  // both to sort interesting files sets by name and to detect when a new
41  // files set is defined, so that the new set can be enabled by default.
42  private TreeMap<String, FilesSet> filesSetSnapshot;
43 
51  static FilesIdentifierIngestJobSettingsPanel makePanel(FilesIdentifierIngestJobSettings settings) {
52  FilesIdentifierIngestJobSettingsPanel panel = new FilesIdentifierIngestJobSettingsPanel(settings);
53 
54  // Observe the interesting item definitions manager for changes to the
55  // interesting file set definitions. This is used to keep this panel in
56  // synch with changes made using the global settings/option panel for
57  // this module.
58  InterestingItemDefsManager.getInstance().addObserver(panel);
59 
60  return panel;
61  }
62 
67  private FilesIdentifierIngestJobSettingsPanel(FilesIdentifierIngestJobSettings settings) {
68  initComponents();
69 
70  /* Make a table row object for each interesting files set, bundling the
71  * set with an enabled flag. The files sets are loaded into a tree map
72  * so they are sorted by name. The keys set also serves as a cache of
73  * set names so that new sets can be easily detected in the override of
74  * Observer.update().
75  */
76  List<FilesSetRow> filesSetRows = new ArrayList<>();
77  this.filesSetSnapshot = new TreeMap<>(InterestingItemDefsManager.getInstance().getInterestingFilesSets());
78  for (FilesSet set : this.filesSetSnapshot.values()) {
79  filesSetRows.add(new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
80  }
81 
82  // Make a table model to manage the row objects.
83  this.tableModel = new FilesSetsTableModel(filesSetRows);
84 
85  // Set up the table component that presents the table model that allows
86  // users to enable and disable interesting files set definitions for an
87  // ingest job.
88  this.filesSetTable.setModel(tableModel);
89  this.filesSetTable.setTableHeader(null);
90  this.filesSetTable.setRowSelectionAllowed(false);
91  final int width = this.filesSetScrollPane.getPreferredSize().width;
92  this.filesSetTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
93  TableColumn column;
94  for (int i = 0; i < this.filesSetTable.getColumnCount(); i++) {
95  column = this.filesSetTable.getColumnModel().getColumn(i);
96  if (i == 0) {
97  column.setPreferredWidth(((int) (width * 0.07)));
98  } else {
99  column.setPreferredWidth(((int) (width * 0.92)));
100  }
101  }
102  }
103 
107  @Override
108  public IngestModuleIngestJobSettings getSettings() {
109  List<String> enabledInterestingFilesSets = new ArrayList<>();
110  List<String> disabledInterestingFilesSets = new ArrayList<>();
111  for (FilesSetRow rowModel : this.tableModel.filesSetRows) {
112  if (rowModel.isEnabled()) {
113  enabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
114  } else {
115  disabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
116  }
117  }
118  return new FilesIdentifierIngestJobSettings(enabledInterestingFilesSets, disabledInterestingFilesSets);
119  }
120 
124  @Override
125  public void update(Observable o, Object arg
126  ) {
127  // Get the user's current enabled/disabled settings.
128  FilesIdentifierIngestJobSettings settings = (FilesIdentifierIngestJobSettings) this.getSettings();
129 
130  // Refresh the view of the interesting files set definitions.
131  List<FilesSetRow> rowModels = new ArrayList<>();
132  TreeMap<String, FilesSet> newFilesSetSnapshot = new TreeMap<>(InterestingItemDefsManager.getInstance().getInterestingFilesSets());
133  for (FilesSet set : newFilesSetSnapshot.values()) {
134  if (this.filesSetSnapshot.keySet().contains(set.getName())) {
135  // Preserve the current enabled/diabled state of the set.
136  rowModels.add(new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
137  } else {
138  // New sets are enabled by default.
139  rowModels.add(new FilesSetRow(set, true));
140  }
141  }
142  this.tableModel.resetTableData(rowModels);
143 
144  // Cache the snapshot so it will be avaialble for the next update.
145  this.filesSetSnapshot = newFilesSetSnapshot;
146  }
147 
152  private final static class FilesSetsTableModel extends AbstractTableModel {
153 
154  private List<FilesSetRow> filesSetRows;
155 
164  FilesSetsTableModel(List<FilesSetRow> filesSetRows) {
165  this.filesSetRows = filesSetRows;
166  }
167 
174  void resetTableData(List<FilesSetRow> filesSetRows) {
175  this.filesSetRows = filesSetRows;
176  this.fireTableDataChanged();
177  }
178 
182  @Override
183  public int getRowCount() {
184  return this.filesSetRows.size();
185  }
186 
190  @Override
191  public int getColumnCount() {
192  return 2;
193  }
194 
198  @Override
199  public Object getValueAt(int rowIndex, int columnIndex) {
200  if (columnIndex == 0) {
201  return this.filesSetRows.get(rowIndex).isEnabled();
202  } else {
203  return this.filesSetRows.get(rowIndex).getFilesSet().getName();
204  }
205  }
206 
210  @Override
211  public boolean isCellEditable(int rowIndex, int columnIndex) {
212  return (columnIndex == 0);
213  }
214 
218  @Override
219  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
220  if (columnIndex == 0) {
221  this.filesSetRows.get(rowIndex).setEnabled((Boolean) aValue);
222  }
223  }
224 
228  @Override
229  public Class<?> getColumnClass(int c) {
230  return getValueAt(0, c).getClass();
231  }
232  }
233 
237  private final static class FilesSetRow {
238 
239  private final FilesSet set;
240  private boolean enabled;
241 
242  FilesSetRow(FilesSet set, boolean enabled) {
243  this.set = set;
244  this.enabled = enabled;
245  }
246 
247  FilesSet getFilesSet() {
248  return this.set;
249  }
250 
251  boolean isEnabled() {
252  return this.enabled;
253  }
254 
255  void setEnabled(boolean enabled) {
256  this.enabled = enabled;
257  }
258  }
259 
265  @SuppressWarnings("unchecked")
266  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
267  private void initComponents() {
268 
269  filesSetScrollPane = new javax.swing.JScrollPane();
270  filesSetTable = new javax.swing.JTable();
271 
272  setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(FilesIdentifierIngestJobSettingsPanel.class, "FilesIdentifierIngestJobSettingsPanel.border.title"))); // NOI18N
273 
274  filesSetTable.setBackground(new java.awt.Color(240, 240, 240));
275  filesSetTable.setModel(new javax.swing.table.DefaultTableModel(
276  new Object [][] {
277 
278  },
279  new String [] {
280 
281  }
282  ));
283  filesSetTable.setShowHorizontalLines(false);
284  filesSetTable.setShowVerticalLines(false);
285  filesSetScrollPane.setViewportView(filesSetTable);
286 
287  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
288  this.setLayout(layout);
289  layout.setHorizontalGroup(
290  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
291  .addGroup(layout.createSequentialGroup()
292  .addContainerGap()
293  .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
294  .addContainerGap())
295  );
296  layout.setVerticalGroup(
297  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
298  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
299  .addContainerGap()
300  .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
301  .addContainerGap())
302  );
303  }// </editor-fold>//GEN-END:initComponents
304 
305 
306  // Variables declaration - do not modify//GEN-BEGIN:variables
307  private javax.swing.JScrollPane filesSetScrollPane;
308  private javax.swing.JTable filesSetTable;
309  // End of variables declaration//GEN-END:variables
310 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.