Autopsy  4.12.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;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import static java.util.Collections.swap;
26 import java.util.Comparator;
27 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.JList;
30 import javax.swing.JPanel;
31 import javax.swing.JRadioButton;
32 import javax.swing.ListCellRenderer;
33 import javax.swing.ListSelectionModel;
34 import javax.swing.event.ListSelectionEvent;
35 import javax.swing.event.ListSelectionListener;
36 import org.openide.DialogDisplayer;
37 import org.openide.NotifyDescriptor;
38 import org.openide.util.Lookup;
39 import org.openide.util.NbBundle;
42 
46 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
47 final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
48 
49  private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
50  private final ReportWizardPanel1 wizPanel;
51  private final List<ReportModule> modules = new ArrayList<>();
52  private final List<GeneralReportModule> generalModules = new ArrayList<>();
53  private final List<TableReportModule> tableModules = new ArrayList<>();
54  private final List<FileReportModule> fileModules = new ArrayList<>();
55  private PortableCaseReportModule portableCaseModule;
56  private Integer selectedIndex;
57 
61  public ReportVisualPanel1(ReportWizardPanel1 wizPanel) {
62  this.wizPanel = wizPanel;
63  initComponents();
64  configurationPanel.setLayout(new BorderLayout());
65  descriptionTextPane.setEditable(false);
66  initModules();
67  }
68 
69  // Initialize the list of ReportModules
70  private void initModules() {
71  for (TableReportModule module : Lookup.getDefault().lookupAll(TableReportModule.class)) {
72  if (moduleIsValid(module)) {
73  tableModules.add(module);
74  modules.add(module);
75  } else {
76  popupWarning(module);
77  }
78  }
79 
80  for (GeneralReportModule module : Lookup.getDefault().lookupAll(GeneralReportModule.class)) {
81  if (moduleIsValid(module)) {
82  generalModules.add(module);
83  modules.add(module);
84  } else {
85  popupWarning(module);
86  }
87  }
88 
89  for (GeneralReportModule module : JythonModuleLoader.getGeneralReportModules()) {
90  if (moduleIsValid(module)) {
91  generalModules.add(module);
92  modules.add(module);
93  } else {
94  popupWarning(module);
95  }
96  }
97 
98  for (FileReportModule module : Lookup.getDefault().lookupAll(FileReportModule.class)) {
99  if (moduleIsValid(module)) {
100  fileModules.add(module);
101  modules.add(module);
102  } else {
103  popupWarning(module);
104  }
105  }
106 
107  portableCaseModule = new PortableCaseReportModule();
108  if (moduleIsValid(portableCaseModule)) {
109  modules.add(portableCaseModule);
110  } else {
111  popupWarning(portableCaseModule);
112  }
113 
114  Collections.sort(modules, new Comparator<ReportModule>() {
115  @Override
116  public int compare(ReportModule rm1, ReportModule rm2) {
117  // our theory is that the report table modules are more common, so they go on top
118  boolean rm1isTable = (rm1 instanceof TableReportModule);
119  boolean rm2isTable = (rm2 instanceof TableReportModule);
120  if (rm1isTable && !rm2isTable) {
121  return -1;
122  }
123  if (!rm1isTable && rm2isTable) {
124  return 1;
125  }
126 
127  return rm1.getName().compareTo(rm2.getName());
128  }
129  });
130 
131  // Results-HTML should always be first in the list of Report Modules.
132  int indexOfHTMLReportModule = 0;
133  for (ReportModule module : modules) {
134  if (module instanceof ReportHTML) {
135  break;
136  }
137  indexOfHTMLReportModule++;
138  }
139  swap(modules, indexOfHTMLReportModule, 0);
140 
141  modulesJList.getSelectionModel().addListSelectionListener(this);
142  modulesJList.setCellRenderer(new ModuleCellRenderer());
143  modulesJList.setListData(modules.toArray(new ReportModule[modules.size()]));
144  selectedIndex = 0;
145  modulesJList.setSelectedIndex(selectedIndex);
146  }
147 
148  // Make sure that the report module has a valid non-null name.
149  private boolean moduleIsValid(ReportModule module) {
150  return module.getName() != null && !module.getName().isEmpty();
151  }
152 
153  private void popupWarning(ReportModule module) {
154  String moduleClassName = module.getClass().getSimpleName();
155  logger.log(Level.WARNING, "Invalid ReportModule: {0}", moduleClassName); // NON_NLS NON-NLS
156  DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
157  NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.invalidModuleWarning", moduleClassName),
158  NotifyDescriptor.ERROR_MESSAGE));
159  }
160 
161  @Override
162  public String getName() {
163  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel1.getName.text");
164  }
165 
166  public ReportModule getSelectedModule() {
167  return modules.get(selectedIndex);
168  }
169 
175  TableReportModule getTableModule() {
176  ReportModule mod = getSelectedModule();
177  if (tableModules.contains(mod)) {
178  return (TableReportModule) mod;
179  }
180  return null;
181  }
182 
188  GeneralReportModule getGeneralModule() {
189  ReportModule mod = getSelectedModule();
190  if (generalModules.contains(mod)) {
191  return (GeneralReportModule) mod;
192  }
193  return null;
194  }
195 
201  FileReportModule getFileModule() {
202  ReportModule mod = getSelectedModule();
203  if (fileModules.contains(mod)) {
204  return (FileReportModule) mod;
205  }
206  return null;
207  }
208 
214  PortableCaseReportModule getPortableCaseModule() {
215  ReportModule mod = getSelectedModule();
216  if (portableCaseModule.equals(mod)) {
217  return (PortableCaseReportModule) mod;
218  }
219  return null;
220  }
221 
227  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
228  private void initComponents() {
229 
230  reportModulesLabel = new javax.swing.JLabel();
231  configurationPanel = new javax.swing.JPanel();
232  descriptionScrollPane = new javax.swing.JScrollPane();
233  descriptionTextPane = new javax.swing.JTextPane();
234  modulesScrollPane = new javax.swing.JScrollPane();
235  modulesJList = new javax.swing.JList<>();
236 
237  setPreferredSize(new java.awt.Dimension(650, 250));
238 
239  org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.reportModulesLabel.text")); // NOI18N
240 
241  configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(125, 125, 125)));
242  configurationPanel.setOpaque(false);
243 
244  javax.swing.GroupLayout configurationPanelLayout = new javax.swing.GroupLayout(configurationPanel);
245  configurationPanel.setLayout(configurationPanelLayout);
246  configurationPanelLayout.setHorizontalGroup(
247  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248  .addGap(0, 432, Short.MAX_VALUE)
249  );
250  configurationPanelLayout.setVerticalGroup(
251  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252  .addGap(0, 168, Short.MAX_VALUE)
253  );
254 
255  descriptionScrollPane.setBorder(null);
256 
257  descriptionTextPane.setBackground(new java.awt.Color(240, 240, 240));
258  descriptionTextPane.setBorder(null);
259  descriptionTextPane.setOpaque(false);
260  descriptionScrollPane.setViewportView(descriptionTextPane);
261 
262  modulesJList.setBackground(new java.awt.Color(240, 240, 240));
263  modulesJList.setModel(new javax.swing.AbstractListModel<ReportModule>() {
264  ReportModule[] modules = {};
265  public int getSize() { return modules.length; }
266  public ReportModule getElementAt(int i) { return modules[i]; }
267  });
268  modulesJList.setOpaque(false);
269  modulesScrollPane.setViewportView(modulesJList);
270 
271  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
272  this.setLayout(layout);
273  layout.setHorizontalGroup(
274  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275  .addGroup(layout.createSequentialGroup()
276  .addContainerGap()
277  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278  .addComponent(reportModulesLabel)
279  .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
280  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
281  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
282  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
283  .addComponent(descriptionScrollPane))
284  .addContainerGap())
285  );
286  layout.setVerticalGroup(
287  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288  .addGroup(layout.createSequentialGroup()
289  .addContainerGap()
290  .addComponent(reportModulesLabel)
291  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
292  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293  .addGroup(layout.createSequentialGroup()
294  .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
295  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
296  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
297  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
298  .addContainerGap())
299  );
300  }// </editor-fold>//GEN-END:initComponents
301  // Variables declaration - do not modify//GEN-BEGIN:variables
302  private javax.swing.JPanel configurationPanel;
303  private javax.swing.JScrollPane descriptionScrollPane;
304  private javax.swing.JTextPane descriptionTextPane;
305  private javax.swing.JList<ReportModule> modulesJList;
306  private javax.swing.JScrollPane modulesScrollPane;
307  private javax.swing.JLabel reportModulesLabel;
308  // End of variables declaration//GEN-END:variables
309 
310  @Override
311  public void valueChanged(ListSelectionEvent e) {
312  if (e.getValueIsAdjusting()) {
313  return;
314  }
315  configurationPanel.removeAll();
316  ListSelectionModel m = (ListSelectionModel) e.getSource();
317  // single selection, so max selection index is the only one selected.
318  selectedIndex = m.getMaxSelectionIndex();
319 
320  ReportModule module = modules.get(selectedIndex);
321  JPanel panel = module.getConfigurationPanel();
322  if (panel == null) {
323  panel = new JPanel();
324  }
325 
326  descriptionTextPane.setText(module.getDescription());
327  configurationPanel.add(panel, BorderLayout.CENTER);
328  configurationPanel.revalidate();
329  configurationPanel.repaint();
330 
331  boolean generalModuleSelected = (module instanceof GeneralReportModule);
332 
333  wizPanel.setNext(!generalModuleSelected);
334  wizPanel.setFinish(generalModuleSelected);
335  }
336 
337  private class ModuleCellRenderer extends JRadioButton implements ListCellRenderer<ReportModule> {
338 
339  @Override
340  public Component getListCellRendererComponent(JList<? extends ReportModule> list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus) {
341  this.setText(value.getName());
342  this.setEnabled(true);
343  this.setSelected(isSelected);
344  return this;
345  }
346 
347  }
348 }
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.