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

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