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;
66 public ReportVisualPanel1(ReportWizardPanel1 wizPanel, Map<String, ReportModuleConfig> moduleConfigs) {
67 this.wizPanel = wizPanel;
68 this.moduleConfigs = moduleConfigs;
70 configurationPanel.setLayout(
new BorderLayout());
71 descriptionTextPane.setEditable(
false);
76 private void initModules() {
78 tableModules = ReportModuleLoader.getTableReportModules();
79 generalModules = ReportModuleLoader.getGeneralReportModules();
80 fileModules = ReportModuleLoader.getFileReportModules();
82 for (TableReportModule module : tableModules) {
83 if (!moduleIsValid(module)) {
85 tableModules.remove(module);
89 for (GeneralReportModule module : generalModules) {
90 if (!moduleIsValid(module)) {
92 generalModules.remove(module);
96 for (FileReportModule module : fileModules) {
97 if (!moduleIsValid(module)) {
99 fileModules.remove(module);
104 modules.addAll(tableModules);
105 modules.addAll(fileModules);
106 modules.addAll(generalModules);
108 portableCaseModule =
new PortableCaseReportModule();
109 if (moduleIsValid(portableCaseModule)) {
110 modules.add(portableCaseModule);
112 popupWarning(portableCaseModule);
116 int indexOfHTMLReportModule = 0;
117 for (ReportModule module : modules) {
118 if (module instanceof HTMLReport) {
121 indexOfHTMLReportModule++;
123 swap(modules, indexOfHTMLReportModule, 0);
128 for (ReportModule module : modules) {
129 ReportModuleSettings settings = null;
130 if (moduleConfigs != null) {
132 ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()));
133 if (config != null) {
135 settings = config.getModuleSettings();
138 if (config.isEnabled()) {
140 selectedIndex = indx;
144 if (settings == null) {
146 settings = module.getDefaultConfiguration();
149 module.setConfiguration(settings);
153 modulesJList.getSelectionModel().addListSelectionListener(
this);
154 modulesJList.setCellRenderer(
new ModuleCellRenderer());
155 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
156 modulesJList.setSelectedIndex(selectedIndex);
160 private boolean moduleIsValid(ReportModule module) {
161 return module.getName() != null && !module.getName().isEmpty();
164 private void popupWarning(ReportModule module) {
165 String moduleClassName = module.getClass().getSimpleName();
166 logger.log(Level.WARNING,
"Invalid ReportModule: {0}", moduleClassName);
167 DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
168 NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.invalidModuleWarning", moduleClassName),
169 NotifyDescriptor.ERROR_MESSAGE));
173 public String getName() {
174 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
177 public ReportModule getSelectedModule() {
178 return modules.get(selectedIndex);
186 TableReportModule getTableModule() {
187 ReportModule mod = getSelectedModule();
188 if (tableModules.contains(mod)) {
189 return (TableReportModule) mod;
199 GeneralReportModule getGeneralModule() {
200 ReportModule mod = getSelectedModule();
201 if (generalModules.contains(mod)) {
202 return (GeneralReportModule) mod;
212 FileReportModule getFileModule() {
213 ReportModule mod = getSelectedModule();
214 if (fileModules.contains(mod)) {
215 return (FileReportModule) mod;
225 PortableCaseReportModule getPortableCaseModule() {
226 ReportModule mod = getSelectedModule();
227 if (portableCaseModule.equals(mod)) {
228 return (PortableCaseReportModule) mod;
238 Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
239 moduleConfigs =
new HashMap<>();
240 for (ReportModule module : modules) {
242 ReportModuleSettings settings = module.getConfiguration();
243 moduleConfigs.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()),
new ReportModuleConfig(module,
false, settings));
247 ReportModule mod = getSelectedModule();
248 ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(mod.getClass().getCanonicalName()));
249 config.setEnabled(
true);
251 return moduleConfigs;
254 Map<String, ReportModule> getReportModules() {
255 Map<String, ReportModule> modulesMap =
new HashMap<>();
256 for (ReportModule module : modules) {
257 modulesMap.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
268 private void initComponents() {
270 reportModulesLabel =
new javax.swing.JLabel();
271 configurationPanel =
new javax.swing.JPanel();
272 descriptionScrollPane =
new javax.swing.JScrollPane();
273 descriptionTextPane =
new javax.swing.JTextPane();
274 modulesScrollPane =
new javax.swing.JScrollPane();
275 modulesJList =
new javax.swing.JList<>();
277 setPreferredSize(
new java.awt.Dimension(650, 250));
279 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
281 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
282 configurationPanel.setOpaque(
false);
284 javax.swing.GroupLayout configurationPanelLayout =
new javax.swing.GroupLayout(configurationPanel);
285 configurationPanel.setLayout(configurationPanelLayout);
286 configurationPanelLayout.setHorizontalGroup(
287 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addGap(0, 432, Short.MAX_VALUE)
290 configurationPanelLayout.setVerticalGroup(
291 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292 .addGap(0, 168, Short.MAX_VALUE)
295 descriptionScrollPane.setBorder(null);
297 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
298 descriptionTextPane.setBorder(null);
299 descriptionTextPane.setOpaque(
false);
300 descriptionScrollPane.setViewportView(descriptionTextPane);
302 modulesJList.setBackground(
new java.awt.Color(240, 240, 240));
303 modulesJList.setModel(
new javax.swing.AbstractListModel<ReportModule>() {
304 ReportModule[] modules = {};
305 public int getSize() {
return modules.length; }
306 public ReportModule getElementAt(
int i) {
return modules[i]; }
308 modulesJList.setOpaque(
false);
309 modulesScrollPane.setViewportView(modulesJList);
311 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
312 this.setLayout(layout);
313 layout.setHorizontalGroup(
314 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315 .addGroup(layout.createSequentialGroup()
317 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318 .addComponent(reportModulesLabel)
319 .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
320 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
321 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
322 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
323 .addComponent(descriptionScrollPane))
326 layout.setVerticalGroup(
327 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
328 .addGroup(layout.createSequentialGroup()
330 .addComponent(reportModulesLabel)
331 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
332 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
333 .addGroup(layout.createSequentialGroup()
334 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
335 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
336 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
337 .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
342 private javax.swing.JPanel configurationPanel;
343 private javax.swing.JScrollPane descriptionScrollPane;
344 private javax.swing.JTextPane descriptionTextPane;
345 private javax.swing.JList<ReportModule> modulesJList;
346 private javax.swing.JScrollPane modulesScrollPane;
347 private javax.swing.JLabel reportModulesLabel;
351 public void valueChanged(ListSelectionEvent e) {
352 if (e.getValueIsAdjusting()) {
355 configurationPanel.removeAll();
356 ListSelectionModel m = (ListSelectionModel) e.getSource();
358 selectedIndex = m.getMaxSelectionIndex();
360 ReportModule module = modules.get(selectedIndex);
361 JPanel panel = module.getConfigurationPanel();
363 panel =
new JPanel();
366 descriptionTextPane.setText(module.getDescription());
367 configurationPanel.add(panel, BorderLayout.CENTER);
368 configurationPanel.revalidate();
369 configurationPanel.repaint();
371 boolean generalModuleSelected = (module instanceof GeneralReportModule);
373 wizPanel.setNext(!generalModuleSelected);
374 wizPanel.setFinish(generalModuleSelected);
382 this.setEnabled(
true);
383 this.setSelected(isSelected);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)