Autopsy  4.13.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportVisualPanel1.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2019 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.report.infrastructure;
20 
26 import java.awt.BorderLayout;
27 import java.awt.Component;
28 import java.util.ArrayList;
29 import static java.util.Collections.swap;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.logging.Level;
34 import javax.swing.JList;
35 import javax.swing.JPanel;
36 import javax.swing.JRadioButton;
37 import javax.swing.ListCellRenderer;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.event.ListSelectionEvent;
40 import javax.swing.event.ListSelectionListener;
41 import org.openide.DialogDisplayer;
42 import org.openide.NotifyDescriptor;
43 import org.openide.util.NbBundle;
45 
49 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
50 final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
51 
52  private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
53  private final ReportWizardPanel1 wizPanel;
54  private final List<ReportModule> modules = new ArrayList<>();
55  private List<GeneralReportModule> generalModules = new ArrayList<>();
56  private List<TableReportModule> tableModules = new ArrayList<>();
57  private List<FileReportModule> fileModules = new ArrayList<>();
58  private PortableCaseReportModule portableCaseModule;
59  private Map<String, ReportModuleConfig> moduleConfigs;
60  private Integer selectedIndex;
61 
65  public ReportVisualPanel1(ReportWizardPanel1 wizPanel, Map<String, ReportModuleConfig> moduleConfigs) {
66  this.wizPanel = wizPanel;
67  this.moduleConfigs = moduleConfigs;
68  initComponents();
69  configurationPanel.setLayout(new BorderLayout());
70  descriptionTextPane.setEditable(false);
71  initModules();
72  }
73 
74  // Initialize the list of ReportModules
75  private void initModules() {
76 
77  tableModules = ReportModuleLoader.getTableReportModules();
78  generalModules = ReportModuleLoader.getGeneralReportModules();
79  fileModules = ReportModuleLoader.getFileReportModules();
80 
81  for (TableReportModule module : tableModules) {
82  if (!moduleIsValid(module)) {
83  popupWarning(module);
84  tableModules.remove(module);
85  }
86  }
87 
88  for (GeneralReportModule module : generalModules) {
89  if (!moduleIsValid(module)) {
90  popupWarning(module);
91  generalModules.remove(module);
92  }
93  }
94 
95  for (FileReportModule module : fileModules) {
96  if (!moduleIsValid(module)) {
97  popupWarning(module);
98  fileModules.remove(module);
99  }
100  }
101 
102  // our theory is that the report table modules are more common, so they go on top
103  modules.addAll(tableModules);
104  modules.addAll(fileModules);
105  modules.addAll(generalModules);
106 
107  portableCaseModule = new PortableCaseReportModule();
108  if (moduleIsValid(portableCaseModule)) {
109  modules.add(portableCaseModule);
110  } else {
111  popupWarning(portableCaseModule);
112  }
113 
114  // Results-HTML should always be first in the list of Report Modules.
115  int indexOfHTMLReportModule = 0;
116  for (ReportModule module : modules) {
117  if (module instanceof HTMLReport) {
118  break;
119  }
120  indexOfHTMLReportModule++;
121  }
122  swap(modules, indexOfHTMLReportModule, 0);
123 
124  // set module configurations
125  selectedIndex = 0;
126  int indx = 0;
127  for (ReportModule module : modules) {
128  ReportModuleSettings settings = null;
129  if (moduleConfigs != null) {
130  // get configuration for this module
131  ReportModuleConfig config = moduleConfigs.get(module.getClass().getCanonicalName());
132  if (config != null) {
133  // there is an existing configuration for this module
134  settings = config.getModuleSettings();
135 
136  // check if this module is enabled
137  if (config.isEnabled()) {
138  // make sure this module is the selected module in the UI panel
139  selectedIndex = indx;
140  }
141  }
142  }
143  if (settings == null) {
144  // get default module configuration
145  settings = module.getDefaultConfiguration();
146  }
147  // set module configuration
148  module.setConfiguration(settings);
149  indx++;
150  }
151 
152  modulesJList.getSelectionModel().addListSelectionListener(this);
153  modulesJList.setCellRenderer(new ModuleCellRenderer());
154  modulesJList.setListData(modules.toArray(new ReportModule[modules.size()]));
155  modulesJList.setSelectedIndex(selectedIndex);
156  }
157 
158  // Make sure that the report module has a valid non-null name.
159  private boolean moduleIsValid(ReportModule module) {
160  return module.getName() != null && !module.getName().isEmpty();
161  }
162 
163  private void popupWarning(ReportModule module) {
164  String moduleClassName = module.getClass().getSimpleName();
165  logger.log(Level.WARNING, "Invalid ReportModule: {0}", moduleClassName); // NON_NLS NON-NLS
166  DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
167  NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.invalidModuleWarning", moduleClassName),
168  NotifyDescriptor.ERROR_MESSAGE));
169  }
170 
171  @Override
172  public String getName() {
173  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel1.getName.text");
174  }
175 
176  public ReportModule getSelectedModule() {
177  return modules.get(selectedIndex);
178  }
179 
185  TableReportModule getTableModule() {
186  ReportModule mod = getSelectedModule();
187  if (tableModules.contains(mod)) {
188  return (TableReportModule) mod;
189  }
190  return null;
191  }
192 
198  GeneralReportModule getGeneralModule() {
199  ReportModule mod = getSelectedModule();
200  if (generalModules.contains(mod)) {
201  return (GeneralReportModule) mod;
202  }
203  return null;
204  }
205 
211  FileReportModule getFileModule() {
212  ReportModule mod = getSelectedModule();
213  if (fileModules.contains(mod)) {
214  return (FileReportModule) mod;
215  }
216  return null;
217  }
218 
224  PortableCaseReportModule getPortableCaseModule() {
225  ReportModule mod = getSelectedModule();
226  if (portableCaseModule.equals(mod)) {
227  return (PortableCaseReportModule) mod;
228  }
229  return null;
230  }
231 
237  Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
238  moduleConfigs = new HashMap<>();
239  for (ReportModule module : modules) {
240  // get updated module configuration
241  ReportModuleSettings settings = module.getConfiguration();
242  moduleConfigs.put(module.getClass().getCanonicalName(), new ReportModuleConfig(module, false, settings));
243  }
244 
245  // set "enabled" flag for the selected module
246  ReportModule mod = getSelectedModule();
247  ReportModuleConfig config = moduleConfigs.get(mod.getClass().getCanonicalName());
248  config.setEnabled(true);
249 
250  return moduleConfigs;
251  }
252 
258  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
259  private void initComponents() {
260 
261  reportModulesLabel = new javax.swing.JLabel();
262  configurationPanel = new javax.swing.JPanel();
263  descriptionScrollPane = new javax.swing.JScrollPane();
264  descriptionTextPane = new javax.swing.JTextPane();
265  modulesScrollPane = new javax.swing.JScrollPane();
266  modulesJList = new javax.swing.JList<>();
267 
268  setPreferredSize(new java.awt.Dimension(650, 250));
269 
270  org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.reportModulesLabel.text")); // NOI18N
271 
272  configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(125, 125, 125)));
273  configurationPanel.setOpaque(false);
274 
275  javax.swing.GroupLayout configurationPanelLayout = new javax.swing.GroupLayout(configurationPanel);
276  configurationPanel.setLayout(configurationPanelLayout);
277  configurationPanelLayout.setHorizontalGroup(
278  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279  .addGap(0, 432, Short.MAX_VALUE)
280  );
281  configurationPanelLayout.setVerticalGroup(
282  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283  .addGap(0, 168, Short.MAX_VALUE)
284  );
285 
286  descriptionScrollPane.setBorder(null);
287 
288  descriptionTextPane.setBackground(new java.awt.Color(240, 240, 240));
289  descriptionTextPane.setBorder(null);
290  descriptionTextPane.setOpaque(false);
291  descriptionScrollPane.setViewportView(descriptionTextPane);
292 
293  modulesJList.setBackground(new java.awt.Color(240, 240, 240));
294  modulesJList.setModel(new javax.swing.AbstractListModel<ReportModule>() {
295  ReportModule[] modules = {};
296  public int getSize() { return modules.length; }
297  public ReportModule getElementAt(int i) { return modules[i]; }
298  });
299  modulesJList.setOpaque(false);
300  modulesScrollPane.setViewportView(modulesJList);
301 
302  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
303  this.setLayout(layout);
304  layout.setHorizontalGroup(
305  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306  .addGroup(layout.createSequentialGroup()
307  .addContainerGap()
308  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
309  .addComponent(reportModulesLabel)
310  .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
311  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
312  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
314  .addComponent(descriptionScrollPane))
315  .addContainerGap())
316  );
317  layout.setVerticalGroup(
318  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
319  .addGroup(layout.createSequentialGroup()
320  .addContainerGap()
321  .addComponent(reportModulesLabel)
322  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
323  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324  .addGroup(layout.createSequentialGroup()
325  .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
326  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
327  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
328  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
329  .addContainerGap())
330  );
331  }// </editor-fold>//GEN-END:initComponents
332  // Variables declaration - do not modify//GEN-BEGIN:variables
333  private javax.swing.JPanel configurationPanel;
334  private javax.swing.JScrollPane descriptionScrollPane;
335  private javax.swing.JTextPane descriptionTextPane;
336  private javax.swing.JList<ReportModule> modulesJList;
337  private javax.swing.JScrollPane modulesScrollPane;
338  private javax.swing.JLabel reportModulesLabel;
339  // End of variables declaration//GEN-END:variables
340 
341  @Override
342  public void valueChanged(ListSelectionEvent e) {
343  if (e.getValueIsAdjusting()) {
344  return;
345  }
346  configurationPanel.removeAll();
347  ListSelectionModel m = (ListSelectionModel) e.getSource();
348  // single selection, so max selection index is the only one selected.
349  selectedIndex = m.getMaxSelectionIndex();
350 
351  ReportModule module = modules.get(selectedIndex);
352  JPanel panel = module.getConfigurationPanel();
353  if (panel == null) {
354  panel = new JPanel();
355  }
356 
357  descriptionTextPane.setText(module.getDescription());
358  configurationPanel.add(panel, BorderLayout.CENTER);
359  configurationPanel.revalidate();
360  configurationPanel.repaint();
361 
362  boolean generalModuleSelected = (module instanceof GeneralReportModule);
363 
364  wizPanel.setNext(!generalModuleSelected);
365  wizPanel.setFinish(generalModuleSelected);
366  }
367 
368  private class ModuleCellRenderer extends JRadioButton implements ListCellRenderer<ReportModule> {
369 
370  @Override
371  public Component getListCellRendererComponent(JList<? extends ReportModule> list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus) {
372  this.setText(value.getName());
373  this.setEnabled(true);
374  this.setSelected(isSelected);
375  return this;
376  }
377 
378  }
379 }
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.