19 package org.sleuthkit.autopsy.report.infrastructure;
26 import java.awt.BorderLayout;
27 import java.awt.Component;
28 import java.util.ArrayList;
29 import static java.util.Collections.swap;
30 import java.util.HashMap;
31 import java.util.List;
33 import java.util.logging.Level;
34 import javax.swing.JList;
35 import javax.swing.JPanel;
36 import javax.swing.JRadioButton;
37 import javax.swing.ListCellRenderer;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.border.Border;
40 import javax.swing.event.ListSelectionEvent;
41 import javax.swing.event.ListSelectionListener;
42 import org.openide.DialogDisplayer;
43 import org.openide.NotifyDescriptor;
44 import org.openide.util.NbBundle;
51 @SuppressWarnings(
"PMD.SingularField")
52 final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
54 private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
55 private final ReportWizardPanel1 wizPanel;
56 private final List<ReportModule> modules =
new ArrayList<>();
57 private List<GeneralReportModule> generalModules =
new ArrayList<>();
58 private List<TableReportModule> tableModules =
new ArrayList<>();
59 private List<FileReportModule> fileModules =
new ArrayList<>();
60 private PortableCaseReportModule portableCaseModule;
61 private Map<String, ReportModuleConfig> moduleConfigs;
62 private Integer selectedIndex;
63 private final boolean displayCaseSpecificData;
68 ReportVisualPanel1(ReportWizardPanel1 wizPanel, Map<String, ReportModuleConfig> moduleConfigs,
boolean displayCaseSpecificData) {
69 this.displayCaseSpecificData = displayCaseSpecificData;
70 this.wizPanel = wizPanel;
71 this.moduleConfigs = moduleConfigs;
73 configurationPanel.setLayout(
new BorderLayout());
74 descriptionTextPane.setEditable(
false);
79 private void initModules() {
81 tableModules = ReportModuleLoader.getTableReportModules();
82 generalModules = ReportModuleLoader.getGeneralReportModules();
83 fileModules = ReportModuleLoader.getFileReportModules();
85 for (TableReportModule module : tableModules) {
86 if (!moduleIsValid(module)) {
88 tableModules.remove(module);
92 for (GeneralReportModule module : generalModules) {
93 if (!moduleIsValid(module)) {
95 generalModules.remove(module);
99 for (FileReportModule module : fileModules) {
100 if (!moduleIsValid(module)) {
101 popupWarning(module);
102 fileModules.remove(module);
107 modules.addAll(tableModules);
108 modules.addAll(fileModules);
109 modules.addAll(generalModules);
111 portableCaseModule =
new PortableCaseReportModule();
112 if (moduleIsValid(portableCaseModule)) {
113 modules.add(portableCaseModule);
115 popupWarning(portableCaseModule);
119 int indexOfHTMLReportModule = 0;
120 for (ReportModule module : modules) {
121 if (module instanceof HTMLReport) {
124 indexOfHTMLReportModule++;
126 swap(modules, indexOfHTMLReportModule, 0);
131 for (ReportModule module : modules) {
132 ReportModuleSettings settings = null;
133 if (moduleConfigs != null) {
135 ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()));
136 if (config != null) {
138 settings = config.getModuleSettings();
141 if (config.isEnabled()) {
143 selectedIndex = indx;
147 if (settings == null) {
149 settings = module.getDefaultConfiguration();
152 module.setConfiguration(settings);
156 modulesJList.getSelectionModel().addListSelectionListener(
this);
157 modulesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
158 modulesJList.setCellRenderer(
new ModuleCellRenderer());
159 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
160 modulesJList.setSelectedIndex(selectedIndex);
164 private boolean moduleIsValid(ReportModule module) {
165 return module.getName() != null && !module.getName().isEmpty();
168 private void popupWarning(ReportModule module) {
169 String moduleClassName = module.getClass().getSimpleName();
170 logger.log(Level.WARNING,
"Invalid ReportModule: {0}", moduleClassName);
171 DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
172 NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.invalidModuleWarning", moduleClassName),
173 NotifyDescriptor.ERROR_MESSAGE));
177 public String getName() {
178 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
181 public ReportModule getSelectedModule() {
182 return modules.get(selectedIndex);
190 TableReportModule getTableModule() {
191 ReportModule mod = getSelectedModule();
192 if (tableModules.contains(mod)) {
193 return (TableReportModule) mod;
203 GeneralReportModule getGeneralModule() {
204 ReportModule mod = getSelectedModule();
205 if (generalModules.contains(mod)) {
206 return (GeneralReportModule) mod;
216 FileReportModule getFileModule() {
217 ReportModule mod = getSelectedModule();
218 if (fileModules.contains(mod)) {
219 return (FileReportModule) mod;
229 PortableCaseReportModule getPortableCaseModule() {
230 ReportModule mod = getSelectedModule();
231 if (portableCaseModule.equals(mod)) {
232 return (PortableCaseReportModule) mod;
242 Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
243 moduleConfigs =
new HashMap<>();
244 for (ReportModule module : modules) {
246 ReportModuleSettings settings = module.getConfiguration();
247 moduleConfigs.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()),
new ReportModuleConfig(module,
false, settings));
251 ReportModule mod = getSelectedModule();
252 ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(mod.getClass().getCanonicalName()));
253 config.setEnabled(
true);
255 return moduleConfigs;
258 Map<String, ReportModule> getReportModules() {
259 Map<String, ReportModule> modulesMap =
new HashMap<>();
260 for (ReportModule module : modules) {
261 modulesMap.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
272 private void initComponents() {
274 reportModulesLabel =
new javax.swing.JLabel();
275 javax.swing.JSplitPane modulesSplitPane =
new javax.swing.JSplitPane();
276 javax.swing.JPanel detailsPanel =
new javax.swing.JPanel();
277 configurationPanel =
new javax.swing.JPanel();
278 descriptionScrollPane =
new javax.swing.JScrollPane();
279 descriptionTextPane =
new javax.swing.JTextPane();
280 modulesScrollPane =
new javax.swing.JScrollPane();
281 modulesJList =
new javax.swing.JList<>();
283 setPreferredSize(
new java.awt.Dimension(834, 374));
285 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
288 modulesSplitPane.setUI(
new javax.swing.plaf.basic.BasicSplitPaneUI() {
290 public javax.swing.plaf.basic.BasicSplitPaneDivider createDefaultDivider() {
291 javax.swing.plaf.basic.BasicSplitPaneDivider divider =
new javax.swing.plaf.basic.BasicSplitPaneDivider(
this) {
293 public void setBorder(Border border){
300 modulesSplitPane.setBorder(null);
301 modulesSplitPane.setDividerSize(8);
302 modulesSplitPane.setResizeWeight(0.5);
304 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
305 configurationPanel.setOpaque(
false);
307 javax.swing.GroupLayout configurationPanelLayout =
new javax.swing.GroupLayout(configurationPanel);
308 configurationPanel.setLayout(configurationPanelLayout);
309 configurationPanelLayout.setHorizontalGroup(
310 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311 .addGap(0, 546, Short.MAX_VALUE)
313 configurationPanelLayout.setVerticalGroup(
314 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315 .addGap(0, 290, Short.MAX_VALUE)
318 descriptionScrollPane.setBorder(null);
320 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
321 descriptionTextPane.setBorder(null);
322 descriptionTextPane.setOpaque(
false);
323 descriptionScrollPane.setViewportView(descriptionTextPane);
325 javax.swing.GroupLayout detailsPanelLayout =
new javax.swing.GroupLayout(detailsPanel);
326 detailsPanel.setLayout(detailsPanelLayout);
327 detailsPanelLayout.setHorizontalGroup(
328 detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
329 .addGroup(detailsPanelLayout.createSequentialGroup()
331 .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
332 .addComponent(descriptionScrollPane)
333 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
336 detailsPanelLayout.setVerticalGroup(
337 detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338 .addGroup(detailsPanelLayout.createSequentialGroup()
340 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
341 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
346 modulesSplitPane.setRightComponent(detailsPanel);
348 modulesJList.setBackground(
new java.awt.Color(240, 240, 240));
349 modulesJList.setModel(
new javax.swing.AbstractListModel<ReportModule>() {
350 ReportModule[] modules = {};
351 public int getSize() {
return modules.length; }
352 public ReportModule getElementAt(
int i) {
return modules[i]; }
354 modulesJList.setOpaque(
false);
355 modulesScrollPane.setViewportView(modulesJList);
357 modulesSplitPane.setLeftComponent(modulesScrollPane);
359 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
360 this.setLayout(layout);
361 layout.setHorizontalGroup(
362 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
363 .addGroup(layout.createSequentialGroup()
365 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
366 .addGroup(layout.createSequentialGroup()
367 .addComponent(reportModulesLabel)
368 .addGap(0, 0, Short.MAX_VALUE))
369 .addComponent(modulesSplitPane))
372 layout.setVerticalGroup(
373 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
374 .addGroup(layout.createSequentialGroup()
376 .addComponent(reportModulesLabel)
377 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
378 .addComponent(modulesSplitPane)
383 private javax.swing.JPanel configurationPanel;
384 private javax.swing.JScrollPane descriptionScrollPane;
385 private javax.swing.JTextPane descriptionTextPane;
386 private javax.swing.JList<ReportModule> modulesJList;
387 private javax.swing.JScrollPane modulesScrollPane;
388 private javax.swing.JLabel reportModulesLabel;
392 public void valueChanged(ListSelectionEvent e) {
393 if (e.getValueIsAdjusting()) {
396 configurationPanel.removeAll();
397 ListSelectionModel m = (ListSelectionModel) e.getSource();
399 selectedIndex = m.getMaxSelectionIndex();
401 ReportModule module = modules.get(selectedIndex);
402 JPanel panel = module.getConfigurationPanel();
404 panel =
new JPanel();
407 descriptionTextPane.setText(module.getDescription());
408 configurationPanel.add(panel, BorderLayout.CENTER);
409 configurationPanel.revalidate();
410 configurationPanel.repaint();
414 boolean generalModuleSelected = (module instanceof GeneralReportModule) && (!((GeneralReportModule)module).supportsDataSourceSelection() || !displayCaseSpecificData);
416 wizPanel.setNext(!generalModuleSelected);
417 wizPanel.setFinish(generalModuleSelected);
425 this.setEnabled(
true);
426 this.setSelected(isSelected);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)