Autopsy  3.1
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  processUnallocPanel = new javax.swing.JPanel();
146  processUnallocCheckbox = new javax.swing.JCheckBox();
147 
148  setMaximumSize(new java.awt.Dimension(5750, 3000));
149  setMinimumSize(new java.awt.Dimension(522, 257));
150  setPreferredSize(new java.awt.Dimension(575, 300));
151 
152  modulesScrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 160, 160)));
153  modulesScrollPane.setPreferredSize(new java.awt.Dimension(160, 160));
154 
155  modulesTable.setBackground(new java.awt.Color(240, 240, 240));
156  modulesTable.setModel(new javax.swing.table.DefaultTableModel(
157  new Object [][] {
158 
159  },
160  new String [] {
161 
162  }
163  ));
164  modulesTable.setShowHorizontalLines(false);
165  modulesTable.setShowVerticalLines(false);
166  modulesScrollPane.setViewportView(modulesTable);
167 
168  jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 160, 160)));
169  jPanel1.setPreferredSize(new java.awt.Dimension(338, 257));
170 
171  advancedButton.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.advancedButton.text")); // NOI18N
172  advancedButton.setActionCommand(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.advancedButton.actionCommand")); // NOI18N
173  advancedButton.setEnabled(false);
174  advancedButton.addActionListener(new java.awt.event.ActionListener() {
175  public void actionPerformed(java.awt.event.ActionEvent evt) {
177  }
178  });
179 
180  descriptionLabel.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.descriptionLabel.text")); // NOI18N
181 
182  jScrollPane1.setBorder(null);
183  jScrollPane1.setPreferredSize(new java.awt.Dimension(250, 180));
184 
185  simplePanel.setLayout(new javax.swing.BoxLayout(simplePanel, javax.swing.BoxLayout.PAGE_AXIS));
186  jScrollPane1.setViewportView(simplePanel);
187 
188  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
189  jPanel1.setLayout(jPanel1Layout);
190  jPanel1Layout.setHorizontalGroup(
191  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192  .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING)
193  .addGroup(jPanel1Layout.createSequentialGroup()
194  .addContainerGap()
195  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
197  .addGroup(jPanel1Layout.createSequentialGroup()
198  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
199  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
200  .addComponent(advancedButton)))
201  .addContainerGap())
202  );
203  jPanel1Layout.setVerticalGroup(
204  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
206  .addContainerGap()
207  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
208  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
209  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
210  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
211  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
213  .addComponent(advancedButton))
214  .addContainerGap())
215  );
216 
217  processUnallocPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 160, 160)));
218 
219  processUnallocCheckbox.setText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.processUnallocCheckbox.text")); // NOI18N
220  processUnallocCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(IngestJobSettingsPanel.class, "IngestJobSettingsPanel.processUnallocCheckbox.toolTipText")); // NOI18N
221  processUnallocCheckbox.addActionListener(new java.awt.event.ActionListener() {
222  public void actionPerformed(java.awt.event.ActionEvent evt) {
224  }
225  });
226 
227  javax.swing.GroupLayout processUnallocPanelLayout = new javax.swing.GroupLayout(processUnallocPanel);
228  processUnallocPanel.setLayout(processUnallocPanelLayout);
229  processUnallocPanelLayout.setHorizontalGroup(
230  processUnallocPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231  .addGroup(processUnallocPanelLayout.createSequentialGroup()
232  .addContainerGap()
233  .addComponent(processUnallocCheckbox)
234  .addContainerGap(60, Short.MAX_VALUE))
235  );
236  processUnallocPanelLayout.setVerticalGroup(
237  processUnallocPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
238  .addGroup(processUnallocPanelLayout.createSequentialGroup()
239  .addContainerGap()
240  .addComponent(processUnallocCheckbox)
241  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
242  );
243 
244  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
245  this.setLayout(layout);
246  layout.setHorizontalGroup(
247  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248  .addGroup(layout.createSequentialGroup()
249  .addContainerGap()
250  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251  .addComponent(processUnallocPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
252  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
253  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
254  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE)
255  .addContainerGap())
256  );
257  layout.setVerticalGroup(
258  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addGroup(layout.createSequentialGroup()
260  .addContainerGap()
261  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
262  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
263  .addGroup(layout.createSequentialGroup()
264  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
265  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
266  .addComponent(processUnallocPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
267  .addContainerGap())
268  );
269  }// </editor-fold>//GEN-END:initComponents
270 
271  private void processUnallocCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processUnallocCheckboxActionPerformed
272  this.settings.setProcessUnallocatedSpace(processUnallocCheckbox.isSelected());
273  }//GEN-LAST:event_processUnallocCheckboxActionPerformed
274 
275  private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
277 
278  dialog.addApplyButtonListener(new ActionListener() {
279  @Override
280  public void actionPerformed(ActionEvent e) {
281  if (selectedModule.hasGlobalSettingsPanel()) {
282  selectedModule.saveResourcesConfig();
283  }
284  dialog.close();
285  }
286  });
287 
288  dialog.addWindowListener(new WindowAdapter() {
289  @Override
290  public void windowClosing(WindowEvent e) {
291  dialog.close();
292  }
293  });
294 
295  dialog.display(selectedModule.getGlobalSettingsPanel());
296  }//GEN-LAST:event_advancedButtonActionPerformed
297 
298  // Variables declaration - do not modify//GEN-BEGIN:variables
299  private javax.swing.JButton advancedButton;
300  private javax.swing.JLabel descriptionLabel;
301  private javax.swing.JPanel jPanel1;
302  private javax.swing.JScrollPane jScrollPane1;
303  private javax.swing.JSeparator jSeparator2;
304  private javax.swing.JScrollPane modulesScrollPane;
305  private javax.swing.JTable modulesTable;
306  private javax.swing.JCheckBox processUnallocCheckbox;
307  private javax.swing.JPanel processUnallocPanel;
308  private javax.swing.JPanel simplePanel;
309  private javax.swing.ButtonGroup timeGroup;
310  // End of variables declaration//GEN-END:variables
311 
317  static private class IngestModuleModel {
318 
319  private final IngestModuleTemplate moduleTemplate;
322 
323  IngestModuleModel(IngestModuleTemplate moduleTemplate) {
324  this.moduleTemplate = moduleTemplate;
325  if (moduleTemplate.hasModuleSettingsPanel()) {
326  moduleSettingsPanel = moduleTemplate.getModuleSettingsPanel();
327  }
328  if (moduleTemplate.hasGlobalSettingsPanel()) {
329  globalSettingsPanel = moduleTemplate.getGlobalSettingsPanel();
330  }
331  }
332 
333  IngestModuleTemplate getIngestModuleTemplate() {
334  return moduleTemplate;
335  }
336 
337  String getName() {
338  return moduleTemplate.getModuleName();
339  }
340 
341  String getDescription() {
342  return moduleTemplate.getModuleDescription();
343  }
344 
345  void setEnabled(boolean enabled) {
346  moduleTemplate.setEnabled(enabled);
347  }
348 
349  boolean isEnabled() {
350  return moduleTemplate.isEnabled();
351  }
352 
353  boolean hasModuleSettingsPanel() {
354  return moduleTemplate.hasModuleSettingsPanel();
355  }
356 
357  IngestModuleIngestJobSettingsPanel getModuleSettingsPanel() {
358  return moduleSettingsPanel;
359  }
360 
361  boolean hasGlobalSettingsPanel() {
362  return moduleTemplate.hasGlobalSettingsPanel();
363  }
364 
365  IngestModuleGlobalSettingsPanel getGlobalSettingsPanel() {
366  return globalSettingsPanel;
367  }
368 
369  void saveResourcesConfig() {
370  globalSettingsPanel.saveSettings();
371  }
372  }
373 
378  private class IngestModulesTableModel extends AbstractTableModel {
379 
380  @Override
381  public int getRowCount() {
382  return modules.size();
383  }
384 
385  @Override
386  public int getColumnCount() {
387  return 2;
388  }
389 
390  @Override
391  public Object getValueAt(int rowIndex, int columnIndex) {
392  IngestModuleModel module = modules.get(rowIndex);
393  if (columnIndex == 0) {
394  return module.isEnabled();
395  } else {
396  return module.getName();
397  }
398  }
399 
400  @Override
401  public boolean isCellEditable(int rowIndex, int columnIndex) {
402  return columnIndex == 0;
403  }
404 
405  @Override
406  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
407  if (columnIndex == 0) {
408  modules.get(rowIndex).setEnabled((boolean) aValue);
409  }
410  }
411 
412  @Override
413  public Class<?> getColumnClass(int c) {
414  return getValueAt(0, c).getClass();
415  }
416  }
417 
422  private class IngestModulesTableRenderer extends DefaultTableCellRenderer {
423 
424  List<String> tooltips = new ArrayList<>();
425 
427  for (IngestModuleModel moduleTemplate : modules) {
428  tooltips.add(moduleTemplate.getDescription());
429  }
430  }
431 
432  @Override
433  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
434  super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
435  if (1 == column) {
436  setToolTipText(tooltips.get(row));
437  }
438  return this;
439  }
440  }
441 }
void advancedButtonActionPerformed(java.awt.event.ActionEvent evt)
void processUnallocCheckboxActionPerformed(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: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.