Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestJobSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.ingest;
20 
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
26 import java.util.ArrayList;
27 import java.util.List;
28 import javax.swing.JTable;
29 import javax.swing.ListSelectionModel;
30 import javax.swing.event.ListSelectionEvent;
31 import javax.swing.event.ListSelectionListener;
32 import javax.swing.table.AbstractTableModel;
33 import javax.swing.table.DefaultTableCellRenderer;
34 import javax.swing.table.TableColumn;
36 
40 public final class IngestJobSettingsPanel extends javax.swing.JPanel {
41 
42  private final IngestJobSettings settings;
43  private final List<IngestModuleModel> modules;
45 
53  this.settings = settings;
54  this.modules = new ArrayList<>();
55  for (IngestModuleTemplate moduleTemplate : settings.getIngestModuleTemplates()) {
56  this.modules.add(new IngestModuleModel(moduleTemplate));
57  }
60  }
61 
68  List<IngestModuleTemplate> moduleTemplates = new ArrayList<>();
69  for (IngestModuleModel module : modules) {
70  IngestModuleTemplate moduleTemplate = module.getIngestModuleTemplate();
71  if (module.hasModuleSettingsPanel()) {
72  IngestModuleIngestJobSettings moduleSettings = module.getModuleSettingsPanel().getSettings();
73  moduleTemplate.setModuleSettings(moduleSettings);
74  }
75  moduleTemplates.add(moduleTemplate);
76  }
77  this.settings.setIngestModuleTemplates(moduleTemplates);
78  return this.settings;
79  }
80 
81  private void customizeComponents() {
82  modulesTable.setModel(new IngestModulesTableModel());
83  modulesTable.setTableHeader(null);
84  modulesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
85 
86  // Set the column widths in the table model and add a custom cell
87  // renderer that will display module descriptions from the module models
88  // as tooltips.
90  int width = modulesScrollPane.getPreferredSize().width;
91  for (int i = 0; i < modulesTable.getColumnCount(); ++i) {
92  TableColumn column = modulesTable.getColumnModel().getColumn(i);
93  if (0 == i) {
94  column.setPreferredWidth(((int) (width * 0.15)));
95  } else {
96  column.setCellRenderer(renderer);
97  column.setPreferredWidth(((int) (width * 0.84)));
98  }
99  }
100 
101  // Add a selection listener to the table model that will display the
102  // ingest job options panel of the currently selected module model and
103  // enable or disable the resources configuration panel invocation button.
104  modulesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
105  @Override
106  public void valueChanged(ListSelectionEvent e) {
107  ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
108  if (!listSelectionModel.isSelectionEmpty()) {
109  int index = listSelectionModel.getMinSelectionIndex();
110  selectedModule = modules.get(index);
111  simplePanel.removeAll();
112  if (null != selectedModule.getModuleSettingsPanel()) {
113  simplePanel.add(selectedModule.getModuleSettingsPanel());
114  }
115  simplePanel.revalidate();
116  simplePanel.repaint();
117  advancedButton.setEnabled(null != selectedModule.getGlobalSettingsPanel());
118  descriptionLabel.setText(selectedModule.getDescription());
119  descriptionLabel.setToolTipText(selectedModule.getDescription());
120  }
121  }
122  });
123 
124  processUnallocCheckbox.setSelected(this.settings.getProcessUnallocatedSpace());
125  }
126 
132  @SuppressWarnings("unchecked")
133  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
134  private void initComponents() {
135 
136  timeGroup = new javax.swing.ButtonGroup();
137  modulesScrollPane = new javax.swing.JScrollPane();
138  modulesTable = new javax.swing.JTable();
139  jPanel1 = new javax.swing.JPanel();
140  advancedButton = new javax.swing.JButton();
141  jSeparator2 = new javax.swing.JSeparator();
142  descriptionLabel = new javax.swing.JLabel();
143  jScrollPane1 = new javax.swing.JScrollPane();
144  simplePanel = new javax.swing.JPanel();
145  jButtonSelectAll = new javax.swing.JButton();
146  jButtonDeselectAll = new javax.swing.JButton();
147  processUnallocCheckbox = new javax.swing.JCheckBox();
148 
149  setMaximumSize(new java.awt.Dimension(5750, 3000));
150  setMinimumSize(new java.awt.Dimension(522, 257));
151  setPreferredSize(new java.awt.Dimension(575, 300));
152 
153  modulesScrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 160, 160)));
154  modulesScrollPane.setPreferredSize(new java.awt.Dimension(160, 160));
155 
156  modulesTable.setBackground(new java.awt.Color(240, 240, 240));
157  modulesTable.setModel(new javax.swing.table.DefaultTableModel(
158  new Object [][] {
159 
160  },
161  new String [] {
162 
163  }
164  ));
165  modulesTable.setShowHorizontalLines(false);
166  modulesTable.setShowVerticalLines(false);
167  modulesScrollPane.setViewportView(modulesTable);
168 
169  jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 160, 160)));
170  jPanel1.setPreferredSize(new java.awt.Dimension(338, 257));
171 
172  advancedButton.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.advancedButton.text")); // NOI18N
173  advancedButton.setActionCommand(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.advancedButton.actionCommand")); // NOI18N
174  advancedButton.setEnabled(false);
175  advancedButton.addActionListener(new java.awt.event.ActionListener() {
176  public void actionPerformed(java.awt.event.ActionEvent evt) {
178  }
179  });
180 
181  descriptionLabel.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.descriptionLabel.text")); // NOI18N
182 
183  jScrollPane1.setBorder(null);
184  jScrollPane1.setPreferredSize(new java.awt.Dimension(250, 180));
185 
186  simplePanel.setLayout(new javax.swing.BoxLayout(simplePanel, javax.swing.BoxLayout.PAGE_AXIS));
187  jScrollPane1.setViewportView(simplePanel);
188 
189  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
190  jPanel1.setLayout(jPanel1Layout);
191  jPanel1Layout.setHorizontalGroup(
192  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193  .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING)
194  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
195  .addContainerGap()
196  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
197  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
198  .addGroup(jPanel1Layout.createSequentialGroup()
199  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
200  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
201  .addComponent(advancedButton)))
202  .addContainerGap())
203  );
204  jPanel1Layout.setVerticalGroup(
205  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
207  .addContainerGap()
208  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
209  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
210  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
211  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
212  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
214  .addComponent(advancedButton))
215  .addContainerGap())
216  );
217 
218  jButtonSelectAll.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.jButtonSelectAll.text")); // NOI18N
219  jButtonSelectAll.addActionListener(new java.awt.event.ActionListener() {
220  public void actionPerformed(java.awt.event.ActionEvent evt) {
222  }
223  });
224 
225  jButtonDeselectAll.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.jButtonDeselectAll.text")); // NOI18N
226  jButtonDeselectAll.addActionListener(new java.awt.event.ActionListener() {
227  public void actionPerformed(java.awt.event.ActionEvent evt) {
229  }
230  });
231 
232  processUnallocCheckbox.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.processUnallocCheckbox.text")); // NOI18N
233  processUnallocCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.processUnallocCheckbox.toolTipText")); // NOI18N
234  processUnallocCheckbox.addActionListener(new java.awt.event.ActionListener() {
235  public void actionPerformed(java.awt.event.ActionEvent evt) {
237  }
238  });
239 
240  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
241  this.setLayout(layout);
242  layout.setHorizontalGroup(
243  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244  .addGroup(layout.createSequentialGroup()
245  .addContainerGap()
246  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
248  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
249  .addGap(10, 10, 10))
250  .addGroup(layout.createSequentialGroup()
251  .addGap(24, 24, 24)
252  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253  .addComponent(processUnallocCheckbox)
254  .addGroup(layout.createSequentialGroup()
255  .addComponent(jButtonSelectAll, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
256  .addGap(18, 18, 18)
257  .addComponent(jButtonDeselectAll)))
258  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)))
259  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
260  .addContainerGap())
261  );
262  layout.setVerticalGroup(
263  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264  .addGroup(layout.createSequentialGroup()
265  .addContainerGap()
266  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
267  .addGroup(layout.createSequentialGroup()
268  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
269  .addContainerGap())
270  .addGroup(layout.createSequentialGroup()
271  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
272  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
273  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
274  .addComponent(jButtonDeselectAll)
275  .addComponent(jButtonSelectAll))
276  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
277  .addComponent(processUnallocCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
278  );
279  }// </editor-fold>//GEN-END:initComponents
280 
281  private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
283 
284  dialog.addApplyButtonListener(new ActionListener() {
285  @Override
286  public void actionPerformed(ActionEvent e) {
287  if (selectedModule.hasGlobalSettingsPanel()) {
288  selectedModule.saveResourcesConfig();
289  }
290  dialog.close();
291  }
292  });
293 
294  dialog.addWindowListener(new WindowAdapter() {
295  @Override
296  public void windowClosing(WindowEvent e) {
297  dialog.close();
298  }
299  });
300 
301  dialog.display(selectedModule.getGlobalSettingsPanel());
302  }//GEN-LAST:event_advancedButtonActionPerformed
303 
304  private void jButtonSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectAllActionPerformed
305  SelectAllModules(true);
306  }//GEN-LAST:event_jButtonSelectAllActionPerformed
307 
308  private void jButtonDeselectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeselectAllActionPerformed
309  SelectAllModules(false);
310  }//GEN-LAST:event_jButtonDeselectAllActionPerformed
311 
312  private void processUnallocCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processUnallocCheckboxActionPerformed
313  this.settings.setProcessUnallocatedSpace(processUnallocCheckbox.isSelected());
314  }//GEN-LAST:event_processUnallocCheckboxActionPerformed
315 
316  private void SelectAllModules(boolean set) {
317  for (IngestModuleModel module : modules) {
318  module.setEnabled(set);
319  }
320  modulesTable.repaint();
321  }
322 
323  // Variables declaration - do not modify//GEN-BEGIN:variables
324  private javax.swing.JButton advancedButton;
325  private javax.swing.JLabel descriptionLabel;
326  private javax.swing.JButton jButtonDeselectAll;
327  private javax.swing.JButton jButtonSelectAll;
328  private javax.swing.JPanel jPanel1;
329  private javax.swing.JScrollPane jScrollPane1;
330  private javax.swing.JSeparator jSeparator2;
331  private javax.swing.JScrollPane modulesScrollPane;
332  private javax.swing.JTable modulesTable;
333  private javax.swing.JCheckBox processUnallocCheckbox;
334  private javax.swing.JPanel simplePanel;
335  private javax.swing.ButtonGroup timeGroup;
336  // End of variables declaration//GEN-END:variables
337 
343  static private class IngestModuleModel {
344 
345  private final IngestModuleTemplate moduleTemplate;
348 
349  IngestModuleModel(IngestModuleTemplate moduleTemplate) {
350  this.moduleTemplate = moduleTemplate;
351  if (moduleTemplate.hasModuleSettingsPanel()) {
352  moduleSettingsPanel = moduleTemplate.getModuleSettingsPanel();
353  }
354  if (moduleTemplate.hasGlobalSettingsPanel()) {
355  globalSettingsPanel = moduleTemplate.getGlobalSettingsPanel();
356  }
357  }
358 
359  IngestModuleTemplate getIngestModuleTemplate() {
360  return moduleTemplate;
361  }
362 
363  String getName() {
364  return moduleTemplate.getModuleName();
365  }
366 
367  String getDescription() {
368  return moduleTemplate.getModuleDescription();
369  }
370 
371  void setEnabled(boolean enabled) {
372  moduleTemplate.setEnabled(enabled);
373  }
374 
375  boolean isEnabled() {
376  return moduleTemplate.isEnabled();
377  }
378 
379  boolean hasModuleSettingsPanel() {
380  return moduleTemplate.hasModuleSettingsPanel();
381  }
382 
383  IngestModuleIngestJobSettingsPanel getModuleSettingsPanel() {
384  return moduleSettingsPanel;
385  }
386 
387  boolean hasGlobalSettingsPanel() {
388  return moduleTemplate.hasGlobalSettingsPanel();
389  }
390 
391  IngestModuleGlobalSettingsPanel getGlobalSettingsPanel() {
392  return globalSettingsPanel;
393  }
394 
395  void saveResourcesConfig() {
396  globalSettingsPanel.saveSettings();
397  }
398  }
399 
404  private class IngestModulesTableModel extends AbstractTableModel {
405 
406  @Override
407  public int getRowCount() {
408  return modules.size();
409  }
410 
411  @Override
412  public int getColumnCount() {
413  return 2;
414  }
415 
416  @Override
417  public Object getValueAt(int rowIndex, int columnIndex) {
418  IngestModuleModel module = modules.get(rowIndex);
419  if (columnIndex == 0) {
420  return module.isEnabled();
421  } else {
422  return module.getName();
423  }
424  }
425 
426  @Override
427  public boolean isCellEditable(int rowIndex, int columnIndex) {
428  return columnIndex == 0;
429  }
430 
431  @Override
432  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
433  if (columnIndex == 0) {
434  modules.get(rowIndex).setEnabled((boolean) aValue);
435  }
436  }
437 
438  @Override
439  public Class<?> getColumnClass(int c) {
440  return getValueAt(0, c).getClass();
441  }
442  }
443 
448  private class IngestModulesTableRenderer extends DefaultTableCellRenderer {
449 
450  List<String> tooltips = new ArrayList<>();
451 
453  for (IngestModuleModel moduleTemplate : modules) {
454  tooltips.add(moduleTemplate.getDescription());
455  }
456  }
457 
458  @Override
459  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
460  super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
461  if (1 == column) {
462  setToolTipText(tooltips.get(row));
463  }
464  return this;
465  }
466  }
467 }
void advancedButtonActionPerformed(java.awt.event.ActionEvent evt)
void processUnallocCheckboxActionPerformed(java.awt.event.ActionEvent evt)
void jButtonSelectAllActionPerformed(java.awt.event.ActionEvent evt)
void jButtonDeselectAllActionPerformed(java.awt.event.ActionEvent evt)
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.