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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.