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

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