19 package org.sleuthkit.autopsy.report;
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;
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;
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;
55 public ReportVisualPanel1(ReportWizardPanel1 wizPanel) {
56 this.wizPanel = wizPanel;
58 configurationPanel.setLayout(
new BorderLayout());
59 descriptionTextPane.setEditable(
false);
64 private void initModules() {
65 for (TableReportModule module : Lookup.getDefault().lookupAll(TableReportModule.class)) {
66 tableModules.add(module);
70 for (GeneralReportModule module : Lookup.getDefault().lookupAll(GeneralReportModule.class)) {
71 generalModules.add(module);
75 for (GeneralReportModule module : JythonModuleLoader.getGeneralReportModules()) {
76 generalModules.add(module);
80 for (FileReportModule module : Lookup.getDefault().lookupAll(FileReportModule.class)) {
81 fileModules.add(module);
85 Collections.sort(modules,
new Comparator<ReportModule>() {
87 public int compare(ReportModule rm1, ReportModule rm2) {
89 boolean rm1isTable = (rm1 instanceof TableReportModule);
90 boolean rm2isTable = (rm2 instanceof TableReportModule);
91 if (rm1isTable && !rm2isTable) {
94 if (!rm1isTable && rm2isTable) {
98 return rm1.getName().compareTo(rm2.getName());
103 int indexOfHTMLReportModule = 0;
104 for(ReportModule module : modules) {
105 if(module instanceof ReportHTML)
107 indexOfHTMLReportModule++;
109 swap(modules, indexOfHTMLReportModule, 0);
111 modulesJList.getSelectionModel().addListSelectionListener(
this);
112 modulesJList.setCellRenderer(
new ModuleCellRenderer());
113 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
115 modulesJList.setSelectedIndex(selectedIndex);
119 public String getName() {
120 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
123 public ReportModule getSelectedModule() {
124 return modules.get(selectedIndex);
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);
138 return reportModuleStates;
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);
152 return reportModuleStates;
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);
166 return reportModuleStates;
175 private void initComponents() {
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<>();
184 setPreferredSize(
new java.awt.Dimension(650, 250));
186 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
188 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
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)
196 configurationPanelLayout.setVerticalGroup(
197 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198 .addGap(0, 168, Short.MAX_VALUE)
201 descriptionScrollPane.setBorder(null);
203 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
204 descriptionTextPane.setBorder(null);
205 descriptionScrollPane.setViewportView(descriptionTextPane);
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]; }
213 modulesScrollPane.setViewportView(modulesJList);
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()
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))
230 layout.setVerticalGroup(
231 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addGroup(layout.createSequentialGroup()
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))
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;
255 public void valueChanged(ListSelectionEvent e) {
256 if (e.getValueIsAdjusting()) {
259 configurationPanel.removeAll();
260 ListSelectionModel m = (ListSelectionModel) e.getSource();
262 selectedIndex = m.getMaxSelectionIndex();
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;
273 descriptionTextPane.setText(module.getDescription());
274 configurationPanel.add(panel, BorderLayout.CENTER);
275 configurationPanel.revalidate();
277 wizPanel.setNext(!generalModuleSelected);
278 wizPanel.setFinish(generalModuleSelected);
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);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)