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

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