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.event.ListSelectionEvent;
40 import javax.swing.event.ListSelectionListener;
41 import org.openide.DialogDisplayer;
42 import org.openide.NotifyDescriptor;
43 import org.openide.util.NbBundle;
50 @SuppressWarnings(
"PMD.SingularField")
51 final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
53 private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
54 private final ReportWizardPanel1 wizPanel;
55 private final List<ReportModule> modules =
new ArrayList<>();
56 private List<GeneralReportModule> generalModules =
new ArrayList<>();
57 private List<TableReportModule> tableModules =
new ArrayList<>();
58 private List<FileReportModule> fileModules =
new ArrayList<>();
59 private PortableCaseReportModule portableCaseModule;
60 private Map<String, ReportModuleConfig> moduleConfigs;
61 private Integer selectedIndex;
62 private final boolean displayCaseSpecificData;
67 ReportVisualPanel1(ReportWizardPanel1 wizPanel, Map<String, ReportModuleConfig> moduleConfigs,
boolean displayCaseSpecificData) {
68 this.displayCaseSpecificData = displayCaseSpecificData;
69 this.wizPanel = wizPanel;
70 this.moduleConfigs = moduleConfigs;
72 configurationPanel.setLayout(
new BorderLayout());
73 descriptionTextPane.setEditable(
false);
78 private void initModules() {
80 tableModules = ReportModuleLoader.getTableReportModules();
81 generalModules = ReportModuleLoader.getGeneralReportModules();
82 fileModules = ReportModuleLoader.getFileReportModules();
84 for (TableReportModule module : tableModules) {
85 if (!moduleIsValid(module)) {
87 tableModules.remove(module);
91 for (GeneralReportModule module : generalModules) {
92 if (!moduleIsValid(module)) {
94 generalModules.remove(module);
98 for (FileReportModule module : fileModules) {
99 if (!moduleIsValid(module)) {
100 popupWarning(module);
101 fileModules.remove(module);
106 modules.addAll(tableModules);
107 modules.addAll(fileModules);
108 modules.addAll(generalModules);
110 portableCaseModule =
new PortableCaseReportModule();
111 if (moduleIsValid(portableCaseModule)) {
112 modules.add(portableCaseModule);
114 popupWarning(portableCaseModule);
118 int indexOfHTMLReportModule = 0;
119 for (ReportModule module : modules) {
120 if (module instanceof HTMLReport) {
123 indexOfHTMLReportModule++;
125 swap(modules, indexOfHTMLReportModule, 0);
130 for (ReportModule module : modules) {
131 ReportModuleSettings settings = null;
132 if (moduleConfigs != null) {
134 ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()));
135 if (config != null) {
137 settings = config.getModuleSettings();
140 if (config.isEnabled()) {
142 selectedIndex = indx;
146 if (settings == null) {
148 settings = module.getDefaultConfiguration();
151 module.setConfiguration(settings);
155 modulesJList.getSelectionModel().addListSelectionListener(
this);
156 modulesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
157 modulesJList.setCellRenderer(
new ModuleCellRenderer());
158 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
159 modulesJList.setSelectedIndex(selectedIndex);
163 private boolean moduleIsValid(ReportModule module) {
164 return module.getName() != null && !module.getName().isEmpty();
167 private void popupWarning(ReportModule module) {
168 String moduleClassName = module.getClass().getSimpleName();
169 logger.log(Level.WARNING,
"Invalid ReportModule: {0}", moduleClassName);
170 DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
171 NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.invalidModuleWarning", moduleClassName),
172 NotifyDescriptor.ERROR_MESSAGE));
176 public String getName() {
177 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
180 public ReportModule getSelectedModule() {
181 return modules.get(selectedIndex);
189 TableReportModule getTableModule() {
190 ReportModule mod = getSelectedModule();
191 if (tableModules.contains(mod)) {
192 return (TableReportModule) mod;
202 GeneralReportModule getGeneralModule() {
203 ReportModule mod = getSelectedModule();
204 if (generalModules.contains(mod)) {
205 return (GeneralReportModule) mod;
215 FileReportModule getFileModule() {
216 ReportModule mod = getSelectedModule();
217 if (fileModules.contains(mod)) {
218 return (FileReportModule) mod;
228 PortableCaseReportModule getPortableCaseModule() {
229 ReportModule mod = getSelectedModule();
230 if (portableCaseModule.equals(mod)) {
231 return (PortableCaseReportModule) mod;
241 Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
242 moduleConfigs =
new HashMap<>();
243 for (ReportModule module : modules) {
245 ReportModuleSettings settings = module.getConfiguration();
246 moduleConfigs.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()),
new ReportModuleConfig(module,
false, settings));
250 ReportModule mod = getSelectedModule();
251 ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(mod.getClass().getCanonicalName()));
252 config.setEnabled(
true);
254 return moduleConfigs;
257 Map<String, ReportModule> getReportModules() {
258 Map<String, ReportModule> modulesMap =
new HashMap<>();
259 for (ReportModule module : modules) {
260 modulesMap.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
271 private void initComponents() {
273 reportModulesLabel =
new javax.swing.JLabel();
274 configurationPanel =
new javax.swing.JPanel();
275 descriptionScrollPane =
new javax.swing.JScrollPane();
276 descriptionTextPane =
new javax.swing.JTextPane();
277 modulesScrollPane =
new javax.swing.JScrollPane();
278 modulesJList =
new javax.swing.JList<>();
280 setPreferredSize(
new java.awt.Dimension(650, 250));
282 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
284 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
285 configurationPanel.setOpaque(
false);
287 javax.swing.GroupLayout configurationPanelLayout =
new javax.swing.GroupLayout(configurationPanel);
288 configurationPanel.setLayout(configurationPanelLayout);
289 configurationPanelLayout.setHorizontalGroup(
290 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
291 .addGap(0, 432, Short.MAX_VALUE)
293 configurationPanelLayout.setVerticalGroup(
294 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
295 .addGap(0, 168, Short.MAX_VALUE)
298 descriptionScrollPane.setBorder(null);
300 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
301 descriptionTextPane.setBorder(null);
302 descriptionTextPane.setOpaque(
false);
303 descriptionScrollPane.setViewportView(descriptionTextPane);
305 modulesJList.setBackground(
new java.awt.Color(240, 240, 240));
306 modulesJList.setModel(
new javax.swing.AbstractListModel<ReportModule>() {
307 ReportModule[] modules = {};
308 public int getSize() {
return modules.length; }
309 public ReportModule getElementAt(
int i) {
return modules[i]; }
311 modulesJList.setOpaque(
false);
312 modulesScrollPane.setViewportView(modulesJList);
314 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
315 this.setLayout(layout);
316 layout.setHorizontalGroup(
317 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318 .addGroup(layout.createSequentialGroup()
320 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
321 .addComponent(reportModulesLabel)
322 .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
323 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
324 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
325 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
326 .addComponent(descriptionScrollPane))
329 layout.setVerticalGroup(
330 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331 .addGroup(layout.createSequentialGroup()
333 .addComponent(reportModulesLabel)
334 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
335 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336 .addGroup(layout.createSequentialGroup()
337 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
338 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
340 .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
345 private javax.swing.JPanel configurationPanel;
346 private javax.swing.JScrollPane descriptionScrollPane;
347 private javax.swing.JTextPane descriptionTextPane;
348 private javax.swing.JList<ReportModule> modulesJList;
349 private javax.swing.JScrollPane modulesScrollPane;
350 private javax.swing.JLabel reportModulesLabel;
354 public void valueChanged(ListSelectionEvent e) {
355 if (e.getValueIsAdjusting()) {
358 configurationPanel.removeAll();
359 ListSelectionModel m = (ListSelectionModel) e.getSource();
361 selectedIndex = m.getMaxSelectionIndex();
363 ReportModule module = modules.get(selectedIndex);
364 JPanel panel = module.getConfigurationPanel();
366 panel =
new JPanel();
369 descriptionTextPane.setText(module.getDescription());
370 configurationPanel.add(panel, BorderLayout.CENTER);
371 configurationPanel.revalidate();
372 configurationPanel.repaint();
376 boolean generalModuleSelected = (module instanceof GeneralReportModule) && (!((GeneralReportModule)module).supportsDataSourceSelection() || !displayCaseSpecificData);
378 wizPanel.setNext(!generalModuleSelected);
379 wizPanel.setFinish(generalModuleSelected);
387 this.setEnabled(
true);
388 this.setSelected(isSelected);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)