Autopsy  3.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 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 javax.swing.JList;
31 import javax.swing.JPanel;
32 import javax.swing.JRadioButton;
33 import javax.swing.ListCellRenderer;
34 import javax.swing.ListSelectionModel;
35 import javax.swing.event.ListSelectionEvent;
36 import javax.swing.event.ListSelectionListener;
37 import org.openide.util.Lookup;
38 import org.openide.util.NbBundle;
42 
43  final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
44  private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
45  private ReportWizardPanel1 wizPanel;
46  private List<ReportModule> modules = new ArrayList<>();
47  private List<GeneralReportModule> generalModules = new ArrayList<>();
48  private List<TableReportModule> tableModules = new ArrayList<>();
49  private List<FileReportModule> fileModules = new ArrayList<>();
50  private Integer selectedIndex;
51 
55  public ReportVisualPanel1(ReportWizardPanel1 wizPanel) {
56  this.wizPanel = wizPanel;
57  initComponents();
58  configurationPanel.setLayout(new BorderLayout());
59  descriptionTextPane.setEditable(false);
60  initModules();
61  }
62 
63  // Initialize the list of ReportModules
64  private void initModules() {
65  for (TableReportModule module : Lookup.getDefault().lookupAll(TableReportModule.class)) {
66  tableModules.add(module);
67  modules.add(module);
68  }
69 
70  for (GeneralReportModule module : Lookup.getDefault().lookupAll(GeneralReportModule.class)) {
71  generalModules.add(module);
72  modules.add(module);
73  }
74 
75  for (GeneralReportModule module : JythonModuleLoader.getGeneralReportModules()) {
76  generalModules.add(module);
77  modules.add(module);
78  }
79 
80  for (FileReportModule module : Lookup.getDefault().lookupAll(FileReportModule.class)) {
81  fileModules.add(module);
82  modules.add(module);
83  }
84 
85  Collections.sort(modules, new Comparator<ReportModule>() {
86  @Override
87  public int compare(ReportModule rm1, ReportModule rm2) {
88  // our theory is that the report table modules are more common, so they go on top
89  boolean rm1isTable = (rm1 instanceof TableReportModule);
90  boolean rm2isTable = (rm2 instanceof TableReportModule);
91  if (rm1isTable && !rm2isTable) {
92  return -1;
93  }
94  if (!rm1isTable && rm2isTable) {
95  return 1;
96  }
97 
98  return rm1.getName().compareTo(rm2.getName());
99  }
100  });
101 
102  // Results-HTML should always be first in the list of Report Modules.
103  int indexOfHTMLReportModule = 0;
104  for(ReportModule module : modules) {
105  if(module instanceof ReportHTML)
106  break;
107  indexOfHTMLReportModule++;
108  }
109  swap(modules, indexOfHTMLReportModule, 0);
110 
111  modulesJList.getSelectionModel().addListSelectionListener(this);
112  modulesJList.setCellRenderer(new ModuleCellRenderer());
113  modulesJList.setListData(modules.toArray(new ReportModule[modules.size()]));
114  selectedIndex = 0;
115  modulesJList.setSelectedIndex(selectedIndex);
116  }
117 
118  @Override
119  public String getName() {
120  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel1.getName.text");
121  }
122 
123  public ReportModule getSelectedModule() {
124  return modules.get(selectedIndex);
125  }
126 
132  Map<TableReportModule, Boolean> getTableModuleStates() {
133  Map<TableReportModule, Boolean> reportModuleStates = new LinkedHashMap<>();
134  ReportModule mod = getSelectedModule();
135  if (tableModules.contains(mod)) {
136  reportModuleStates.put((TableReportModule) mod, Boolean.TRUE);
137  }
138  return reportModuleStates;
139  }
140 
146  Map<GeneralReportModule, Boolean> getGeneralModuleStates() {
147  Map<GeneralReportModule, Boolean> reportModuleStates = new LinkedHashMap<>();
148  ReportModule mod = getSelectedModule();
149  if (generalModules.contains(mod)) {
150  reportModuleStates.put((GeneralReportModule) mod, Boolean.TRUE);
151  }
152  return reportModuleStates;
153  }
154 
160  Map<FileReportModule, Boolean> getFileModuleStates() {
161  Map<FileReportModule, Boolean> reportModuleStates = new LinkedHashMap<>();
162  ReportModule mod = getSelectedModule();
163  if (fileModules.contains(mod)) {
164  reportModuleStates.put((FileReportModule) mod, Boolean.TRUE);
165  }
166  return reportModuleStates;
167  }
168 
174  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
175  private void initComponents() {
176 
177  reportModulesLabel = new javax.swing.JLabel();
178  configurationPanel = new javax.swing.JPanel();
179  descriptionScrollPane = new javax.swing.JScrollPane();
180  descriptionTextPane = new javax.swing.JTextPane();
181  modulesScrollPane = new javax.swing.JScrollPane();
182  modulesJList = new javax.swing.JList<>();
183 
184  setPreferredSize(new java.awt.Dimension(650, 250));
185 
186  org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class, "ReportVisualPanel1.reportModulesLabel.text")); // NOI18N
187 
188  configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(125, 125, 125)));
189 
190  javax.swing.GroupLayout configurationPanelLayout = new javax.swing.GroupLayout(configurationPanel);
191  configurationPanel.setLayout(configurationPanelLayout);
192  configurationPanelLayout.setHorizontalGroup(
193  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194  .addGap(0, 432, Short.MAX_VALUE)
195  );
196  configurationPanelLayout.setVerticalGroup(
197  configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198  .addGap(0, 168, Short.MAX_VALUE)
199  );
200 
201  descriptionScrollPane.setBorder(null);
202 
203  descriptionTextPane.setBackground(new java.awt.Color(240, 240, 240));
204  descriptionTextPane.setBorder(null);
205  descriptionScrollPane.setViewportView(descriptionTextPane);
206 
207  modulesJList.setBackground(new java.awt.Color(240, 240, 240));
208  modulesJList.setModel(new javax.swing.AbstractListModel<ReportModule>() {
209  ReportModule[] modules = {};
210  public int getSize() { return modules.length; }
211  public ReportModule getElementAt(int i) { return modules[i]; }
212  });
213  modulesScrollPane.setViewportView(modulesJList);
214 
215  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
216  this.setLayout(layout);
217  layout.setHorizontalGroup(
218  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219  .addGroup(layout.createSequentialGroup()
220  .addContainerGap()
221  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
222  .addComponent(reportModulesLabel)
223  .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
224  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
227  .addComponent(descriptionScrollPane))
228  .addContainerGap())
229  );
230  layout.setVerticalGroup(
231  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232  .addGroup(layout.createSequentialGroup()
233  .addContainerGap()
234  .addComponent(reportModulesLabel)
235  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
236  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237  .addGroup(layout.createSequentialGroup()
238  .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
239  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
240  .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
241  .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
242  .addContainerGap())
243  );
244  }// </editor-fold>//GEN-END:initComponents
245  // Variables declaration - do not modify//GEN-BEGIN:variables
246  private javax.swing.JPanel configurationPanel;
247  private javax.swing.JScrollPane descriptionScrollPane;
248  private javax.swing.JTextPane descriptionTextPane;
249  private javax.swing.JList<ReportModule> modulesJList;
250  private javax.swing.JScrollPane modulesScrollPane;
251  private javax.swing.JLabel reportModulesLabel;
252  // End of variables declaration//GEN-END:variables
253 
254  @Override
255  public void valueChanged(ListSelectionEvent e) {
256  if (e.getValueIsAdjusting()) {
257  return;
258  }
259  configurationPanel.removeAll();
260  ListSelectionModel m = (ListSelectionModel) e.getSource();
261  // single selection, so max selection index is the only one selected.
262  selectedIndex = m.getMaxSelectionIndex();
263 
264  JPanel panel = new DefaultReportConfigurationPanel();
265  ReportModule module = modules.get(selectedIndex);
266  boolean generalModuleSelected = false;
267  if (module instanceof GeneralReportModule) {
268  JPanel generalPanel = ((GeneralReportModule) module).getConfigurationPanel();
269  panel = (generalPanel == null) ? new JPanel() : generalPanel;
270  generalModuleSelected = true;
271  }
272 
273  descriptionTextPane.setText(module.getDescription());
274  configurationPanel.add(panel, BorderLayout.CENTER);
275  configurationPanel.revalidate();
276 
277  wizPanel.setNext(!generalModuleSelected);
278  wizPanel.setFinish(generalModuleSelected);
279  }
280 
281  private class ModuleCellRenderer extends JRadioButton implements ListCellRenderer<ReportModule> {
282 
283  @Override
284  public Component getListCellRendererComponent(JList<? extends ReportModule> list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus) {
285  this.setText(value.getName());
286  this.setEnabled(true);
287  this.setSelected(isSelected);
288  return this;
289  }
290 
291  }
292 }
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.