Autopsy  4.11.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-2018 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  && module.getRelativeFilePath() != null;
152  }
153 
154  private void popupWarning(ReportModule module) {
155  String moduleClassName = module.getClass().getSimpleName();
156  logger.log(Level.WARNING, "Invalid ReportModule: {0}", moduleClassName); // NON_NLS NON-NLS
157  DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
158  NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.invalidModuleWarning", moduleClassName),
159  NotifyDescriptor.ERROR_MESSAGE));
160  }
161 
162  @Override
163  public String getName() {
164  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel1.getName.text");
165  }
166 
167  public ReportModule getSelectedModule() {
168  return modules.get(selectedIndex);
169  }
170 
176  TableReportModule getTableModule() {
177  ReportModule mod = getSelectedModule();
178  if (tableModules.contains(mod)) {
179  return (TableReportModule) mod;
180  }
181  return null;
182  }
183 
189  GeneralReportModule getGeneralModule() {
190  ReportModule mod = getSelectedModule();
191  if (generalModules.contains(mod)) {
192  return (GeneralReportModule) mod;
193  }
194  return null;
195  }
196 
202  FileReportModule getFileModule() {
203  ReportModule mod = getSelectedModule();
204  if (fileModules.contains(mod)) {
205  return (FileReportModule) mod;
206  }
207  return null;
208  }
209 
215  PortableCaseReportModule getPortableCaseModule() {
216  ReportModule mod = getSelectedModule();
217  if (portableCaseModule.equals(mod)) {
218  return (PortableCaseReportModule) mod;
219  }
220  return null;
221  }
222 
228  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
229  private void initComponents() {
230 
231  reportModulesLabel = new javax.swing.JLabel();
232  configurationPanel = new javax.swing.JPanel();
233  descriptionScrollPane = new javax.swing.JScrollPane();
234  descriptionTextPane = new javax.swing.JTextPane();
235  modulesScrollPane = new javax.swing.JScrollPane();
236  modulesJList = new javax.swing.JList<>();
237 
238  setPreferredSize(new java.awt.Dimension(650, 250));
239 
240  org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.reportModulesLabel.text")); // NOI18N
241 
242  configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(125, 125, 125)));
243  configurationPanel.setOpaque(false);
244 
245  javax.swing.GroupLayout configurationPanelLayout = new javax.swing.GroupLayout(configurationPanel);
246  configurationPanel.setLayout(configurationPanelLayout);
247  configurationPanelLayout.setHorizontalGroup(
248  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249  .addGap(0, 432, Short.MAX_VALUE)
250  );
251  configurationPanelLayout.setVerticalGroup(
252  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253  .addGap(0, 168, Short.MAX_VALUE)
254  );
255 
256  descriptionScrollPane.setBorder(null);
257 
258  descriptionTextPane.setBackground(new java.awt.Color(240, 240, 240));
259  descriptionTextPane.setBorder(null);
260  descriptionTextPane.setOpaque(false);
261  descriptionScrollPane.setViewportView(descriptionTextPane);
262 
263  modulesJList.setBackground(new java.awt.Color(240, 240, 240));
264  modulesJList.setModel(new javax.swing.AbstractListModel<ReportModule>() {
265  ReportModule[] modules = {};
266  public int getSize() { return modules.length; }
267  public ReportModule getElementAt(int i) { return modules[i]; }
268  });
269  modulesJList.setOpaque(false);
270  modulesScrollPane.setViewportView(modulesJList);
271 
272  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
273  this.setLayout(layout);
274  layout.setHorizontalGroup(
275  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276  .addGroup(layout.createSequentialGroup()
277  .addContainerGap()
278  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279  .addComponent(reportModulesLabel)
280  .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
281  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
282  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
284  .addComponent(descriptionScrollPane))
285  .addContainerGap())
286  );
287  layout.setVerticalGroup(
288  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289  .addGroup(layout.createSequentialGroup()
290  .addContainerGap()
291  .addComponent(reportModulesLabel)
292  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294  .addGroup(layout.createSequentialGroup()
295  .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
296  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
297  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
298  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
299  .addContainerGap())
300  );
301  }// </editor-fold>//GEN-END:initComponents
302  // Variables declaration - do not modify//GEN-BEGIN:variables
303  private javax.swing.JPanel configurationPanel;
304  private javax.swing.JScrollPane descriptionScrollPane;
305  private javax.swing.JTextPane descriptionTextPane;
306  private javax.swing.JList<ReportModule> modulesJList;
307  private javax.swing.JScrollPane modulesScrollPane;
308  private javax.swing.JLabel reportModulesLabel;
309  // End of variables declaration//GEN-END:variables
310 
311  @Override
312  public void valueChanged(ListSelectionEvent e) {
313  if (e.getValueIsAdjusting()) {
314  return;
315  }
316  configurationPanel.removeAll();
317  ListSelectionModel m = (ListSelectionModel) e.getSource();
318  // single selection, so max selection index is the only one selected.
319  selectedIndex = m.getMaxSelectionIndex();
320 
321  ReportModule module = modules.get(selectedIndex);
322  JPanel panel = module.getConfigurationPanel();
323  if (panel == null) {
324  panel = new JPanel();
325  }
326 
327  descriptionTextPane.setText(module.getDescription());
328  configurationPanel.add(panel, BorderLayout.CENTER);
329  configurationPanel.revalidate();
330  configurationPanel.repaint();
331 
332  boolean generalModuleSelected = (module instanceof GeneralReportModule);
333 
334  wizPanel.setNext(!generalModuleSelected);
335  wizPanel.setFinish(generalModuleSelected);
336  }
337 
338  private class ModuleCellRenderer extends JRadioButton implements ListCellRenderer<ReportModule> {
339 
340  @Override
341  public Component getListCellRendererComponent(JList<? extends ReportModule> list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus) {
342  this.setText(value.getName());
343  this.setEnabled(true);
344  this.setSelected(isSelected);
345  return this;
346  }
347 
348  }
349 }
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)

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