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;
49 @SuppressWarnings(
"PMD.SingularField")
50 final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
52 private static final Logger logger = Logger.
getLogger(ReportVisualPanel1.class.getName());
53 private final ReportWizardPanel1 wizPanel;
54 private final List<ReportModule> modules =
new ArrayList<>();
55 private List<GeneralReportModule> generalModules =
new ArrayList<>();
56 private List<TableReportModule> tableModules =
new ArrayList<>();
57 private List<FileReportModule> fileModules =
new ArrayList<>();
58 private PortableCaseReportModule portableCaseModule;
59 private Map<String, ReportModuleConfig> moduleConfigs;
60 private Integer selectedIndex;
65 public ReportVisualPanel1(ReportWizardPanel1 wizPanel, Map<String, ReportModuleConfig> moduleConfigs) {
66 this.wizPanel = wizPanel;
67 this.moduleConfigs = moduleConfigs;
69 configurationPanel.setLayout(
new BorderLayout());
70 descriptionTextPane.setEditable(
false);
75 private void initModules() {
77 tableModules = ReportModuleLoader.getTableReportModules();
78 generalModules = ReportModuleLoader.getGeneralReportModules();
79 fileModules = ReportModuleLoader.getFileReportModules();
81 for (TableReportModule module : tableModules) {
82 if (!moduleIsValid(module)) {
84 tableModules.remove(module);
88 for (GeneralReportModule module : generalModules) {
89 if (!moduleIsValid(module)) {
91 generalModules.remove(module);
95 for (FileReportModule module : fileModules) {
96 if (!moduleIsValid(module)) {
98 fileModules.remove(module);
103 modules.addAll(tableModules);
104 modules.addAll(fileModules);
105 modules.addAll(generalModules);
107 portableCaseModule =
new PortableCaseReportModule();
108 if (moduleIsValid(portableCaseModule)) {
109 modules.add(portableCaseModule);
111 popupWarning(portableCaseModule);
115 int indexOfHTMLReportModule = 0;
116 for (ReportModule module : modules) {
117 if (module instanceof HTMLReport) {
120 indexOfHTMLReportModule++;
122 swap(modules, indexOfHTMLReportModule, 0);
127 for (ReportModule module : modules) {
128 ReportModuleSettings settings = null;
129 if (moduleConfigs != null) {
131 ReportModuleConfig config = moduleConfigs.get(module.getClass().getCanonicalName());
132 if (config != null) {
134 settings = config.getModuleSettings();
137 if (config.isEnabled()) {
139 selectedIndex = indx;
143 if (settings == null) {
145 settings = module.getDefaultConfiguration();
148 module.setConfiguration(settings);
152 modulesJList.getSelectionModel().addListSelectionListener(
this);
153 modulesJList.setCellRenderer(
new ModuleCellRenderer());
154 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
155 modulesJList.setSelectedIndex(selectedIndex);
159 private boolean moduleIsValid(ReportModule module) {
160 return module.getName() != null && !module.getName().isEmpty();
163 private void popupWarning(ReportModule module) {
164 String moduleClassName = module.getClass().getSimpleName();
165 logger.log(Level.WARNING,
"Invalid ReportModule: {0}", moduleClassName);
166 DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
167 NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.invalidModuleWarning", moduleClassName),
168 NotifyDescriptor.ERROR_MESSAGE));
172 public String getName() {
173 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
176 public ReportModule getSelectedModule() {
177 return modules.get(selectedIndex);
185 TableReportModule getTableModule() {
186 ReportModule mod = getSelectedModule();
187 if (tableModules.contains(mod)) {
188 return (TableReportModule) mod;
198 GeneralReportModule getGeneralModule() {
199 ReportModule mod = getSelectedModule();
200 if (generalModules.contains(mod)) {
201 return (GeneralReportModule) mod;
211 FileReportModule getFileModule() {
212 ReportModule mod = getSelectedModule();
213 if (fileModules.contains(mod)) {
214 return (FileReportModule) mod;
224 PortableCaseReportModule getPortableCaseModule() {
225 ReportModule mod = getSelectedModule();
226 if (portableCaseModule.equals(mod)) {
227 return (PortableCaseReportModule) mod;
237 Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
238 moduleConfigs =
new HashMap<>();
239 for (ReportModule module : modules) {
241 ReportModuleSettings settings = module.getConfiguration();
242 moduleConfigs.put(module.getClass().getCanonicalName(),
new ReportModuleConfig(module,
false, settings));
246 ReportModule mod = getSelectedModule();
247 ReportModuleConfig config = moduleConfigs.get(mod.getClass().getCanonicalName());
248 config.setEnabled(
true);
250 return moduleConfigs;
259 private void initComponents() {
261 reportModulesLabel =
new javax.swing.JLabel();
262 configurationPanel =
new javax.swing.JPanel();
263 descriptionScrollPane =
new javax.swing.JScrollPane();
264 descriptionTextPane =
new javax.swing.JTextPane();
265 modulesScrollPane =
new javax.swing.JScrollPane();
266 modulesJList =
new javax.swing.JList<>();
268 setPreferredSize(
new java.awt.Dimension(650, 250));
270 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
272 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
273 configurationPanel.setOpaque(
false);
275 javax.swing.GroupLayout configurationPanelLayout =
new javax.swing.GroupLayout(configurationPanel);
276 configurationPanel.setLayout(configurationPanelLayout);
277 configurationPanelLayout.setHorizontalGroup(
278 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279 .addGap(0, 432, Short.MAX_VALUE)
281 configurationPanelLayout.setVerticalGroup(
282 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283 .addGap(0, 168, Short.MAX_VALUE)
286 descriptionScrollPane.setBorder(null);
288 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
289 descriptionTextPane.setBorder(null);
290 descriptionTextPane.setOpaque(
false);
291 descriptionScrollPane.setViewportView(descriptionTextPane);
293 modulesJList.setBackground(
new java.awt.Color(240, 240, 240));
294 modulesJList.setModel(
new javax.swing.AbstractListModel<ReportModule>() {
295 ReportModule[] modules = {};
296 public int getSize() {
return modules.length; }
297 public ReportModule getElementAt(
int i) {
return modules[i]; }
299 modulesJList.setOpaque(
false);
300 modulesScrollPane.setViewportView(modulesJList);
302 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
303 this.setLayout(layout);
304 layout.setHorizontalGroup(
305 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306 .addGroup(layout.createSequentialGroup()
308 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
309 .addComponent(reportModulesLabel)
310 .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
311 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
312 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
314 .addComponent(descriptionScrollPane))
317 layout.setVerticalGroup(
318 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
319 .addGroup(layout.createSequentialGroup()
321 .addComponent(reportModulesLabel)
322 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
323 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324 .addGroup(layout.createSequentialGroup()
325 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
326 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
327 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
328 .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
333 private javax.swing.JPanel configurationPanel;
334 private javax.swing.JScrollPane descriptionScrollPane;
335 private javax.swing.JTextPane descriptionTextPane;
336 private javax.swing.JList<ReportModule> modulesJList;
337 private javax.swing.JScrollPane modulesScrollPane;
338 private javax.swing.JLabel reportModulesLabel;
342 public void valueChanged(ListSelectionEvent e) {
343 if (e.getValueIsAdjusting()) {
346 configurationPanel.removeAll();
347 ListSelectionModel m = (ListSelectionModel) e.getSource();
349 selectedIndex = m.getMaxSelectionIndex();
351 ReportModule module = modules.get(selectedIndex);
352 JPanel panel = module.getConfigurationPanel();
354 panel =
new JPanel();
357 descriptionTextPane.setText(module.getDescription());
358 configurationPanel.add(panel, BorderLayout.CENTER);
359 configurationPanel.revalidate();
360 configurationPanel.repaint();
362 boolean generalModuleSelected = (module instanceof GeneralReportModule);
364 wizPanel.setNext(!generalModuleSelected);
365 wizPanel.setFinish(generalModuleSelected);
373 this.setEnabled(
true);
374 this.setSelected(isSelected);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)
synchronized static Logger getLogger(String name)