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.List;
28 import java.util.logging.Level;
29 import javax.swing.JList;
30 import javax.swing.JPanel;
31 import javax.swing.JRadioButton;
32 import javax.swing.ListCellRenderer;
33 import javax.swing.ListSelectionModel;
34 import javax.swing.event.ListSelectionEvent;
35 import javax.swing.event.ListSelectionListener;
36 import org.openide.DialogDisplayer;
37 import org.openide.NotifyDescriptor;
38 import org.openide.util.Lookup;
39 import org.openide.util.NbBundle;
43 final class ReportVisualPanel1
extends JPanel implements ListSelectionListener {
45 private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
46 private ReportWizardPanel1 wizPanel;
47 private List<ReportModule> modules =
new ArrayList<>();
48 private List<GeneralReportModule> generalModules =
new ArrayList<>();
49 private List<TableReportModule> tableModules =
new ArrayList<>();
50 private List<FileReportModule> fileModules =
new ArrayList<>();
51 private Integer selectedIndex;
56 public ReportVisualPanel1(ReportWizardPanel1 wizPanel) {
57 this.wizPanel = wizPanel;
59 configurationPanel.setLayout(
new BorderLayout());
60 descriptionTextPane.setEditable(
false);
65 private void initModules() {
66 for (TableReportModule module : Lookup.getDefault().lookupAll(TableReportModule.class)) {
67 if (moduleIsValid(module)) {
68 tableModules.add(module);
75 for (GeneralReportModule module : Lookup.getDefault().lookupAll(GeneralReportModule.class)) {
76 if (moduleIsValid(module)) {
77 generalModules.add(module);
84 for (GeneralReportModule module : JythonModuleLoader.getGeneralReportModules()) {
85 if (moduleIsValid(module)) {
86 generalModules.add(module);
93 for (FileReportModule module : Lookup.getDefault().lookupAll(FileReportModule.class)) {
94 if (moduleIsValid(module)) {
95 fileModules.add(module);
102 Collections.sort(modules,
new Comparator<ReportModule>() {
104 public int compare(ReportModule rm1, ReportModule rm2) {
106 boolean rm1isTable = (rm1 instanceof TableReportModule);
107 boolean rm2isTable = (rm2 instanceof TableReportModule);
108 if (rm1isTable && !rm2isTable) {
111 if (!rm1isTable && rm2isTable) {
115 return rm1.getName().compareTo(rm2.getName());
120 int indexOfHTMLReportModule = 0;
121 for (ReportModule module : modules) {
122 if (module instanceof ReportHTML) {
125 indexOfHTMLReportModule++;
127 swap(modules, indexOfHTMLReportModule, 0);
129 modulesJList.getSelectionModel().addListSelectionListener(
this);
130 modulesJList.setCellRenderer(
new ModuleCellRenderer());
131 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
133 modulesJList.setSelectedIndex(selectedIndex);
137 private boolean moduleIsValid(ReportModule module) {
138 return module.getName() != null && !module.getName().isEmpty()
139 && module.getRelativeFilePath() != null;
142 private void popupWarning(ReportModule module) {
143 String moduleClassName = module.getClass().getSimpleName();
144 logger.log(Level.WARNING,
"Invalid ReportModule: {0}", moduleClassName);
145 DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
146 NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.invalidModuleWarning", moduleClassName),
147 NotifyDescriptor.ERROR_MESSAGE));
151 public String getName() {
152 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
155 public ReportModule getSelectedModule() {
156 return modules.get(selectedIndex);
164 TableReportModule getTableModule() {
165 ReportModule mod = getSelectedModule();
166 if (tableModules.contains(mod)) {
167 return (TableReportModule) mod;
177 GeneralReportModule getGeneralModule() {
178 ReportModule mod = getSelectedModule();
179 if (generalModules.contains(mod)) {
180 return (GeneralReportModule) mod;
190 FileReportModule getFileModule() {
191 ReportModule mod = getSelectedModule();
192 if (fileModules.contains(mod)) {
193 return (FileReportModule) mod;
204 private void initComponents() {
206 reportModulesLabel =
new javax.swing.JLabel();
207 configurationPanel =
new javax.swing.JPanel();
208 descriptionScrollPane =
new javax.swing.JScrollPane();
209 descriptionTextPane =
new javax.swing.JTextPane();
210 modulesScrollPane =
new javax.swing.JScrollPane();
211 modulesJList =
new javax.swing.JList<>();
213 setPreferredSize(
new java.awt.Dimension(650, 250));
215 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
217 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
219 javax.swing.GroupLayout configurationPanelLayout =
new javax.swing.GroupLayout(configurationPanel);
220 configurationPanel.setLayout(configurationPanelLayout);
221 configurationPanelLayout.setHorizontalGroup(
222 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
223 .addGap(0, 432, Short.MAX_VALUE)
225 configurationPanelLayout.setVerticalGroup(
226 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
227 .addGap(0, 168, Short.MAX_VALUE)
230 descriptionScrollPane.setBorder(null);
232 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
233 descriptionTextPane.setBorder(null);
234 descriptionScrollPane.setViewportView(descriptionTextPane);
236 modulesJList.setBackground(
new java.awt.Color(240, 240, 240));
237 modulesJList.setModel(
new javax.swing.AbstractListModel<ReportModule>() {
238 ReportModule[] modules = {};
239 public int getSize() {
return modules.length; }
240 public ReportModule getElementAt(
int i) {
return modules[i]; }
242 modulesScrollPane.setViewportView(modulesJList);
244 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
245 this.setLayout(layout);
246 layout.setHorizontalGroup(
247 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addGroup(layout.createSequentialGroup()
250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251 .addComponent(reportModulesLabel)
252 .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
253 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
254 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
256 .addComponent(descriptionScrollPane))
259 layout.setVerticalGroup(
260 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261 .addGroup(layout.createSequentialGroup()
263 .addComponent(reportModulesLabel)
264 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
265 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266 .addGroup(layout.createSequentialGroup()
267 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
268 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
269 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
270 .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
275 private javax.swing.JPanel configurationPanel;
276 private javax.swing.JScrollPane descriptionScrollPane;
277 private javax.swing.JTextPane descriptionTextPane;
278 private javax.swing.JList<ReportModule> modulesJList;
279 private javax.swing.JScrollPane modulesScrollPane;
280 private javax.swing.JLabel reportModulesLabel;
284 public void valueChanged(ListSelectionEvent e) {
285 if (e.getValueIsAdjusting()) {
288 configurationPanel.removeAll();
289 ListSelectionModel m = (ListSelectionModel) e.getSource();
291 selectedIndex = m.getMaxSelectionIndex();
293 JPanel panel =
new DefaultReportConfigurationPanel();
294 ReportModule module = modules.get(selectedIndex);
295 boolean generalModuleSelected =
false;
296 if (module instanceof GeneralReportModule) {
297 JPanel generalPanel = ((GeneralReportModule) module).getConfigurationPanel();
298 panel = (generalPanel == null) ?
new JPanel() : generalPanel;
299 generalModuleSelected =
true;
302 descriptionTextPane.setText(module.getDescription());
303 configurationPanel.add(panel, BorderLayout.CENTER);
304 configurationPanel.revalidate();
306 wizPanel.setNext(!generalModuleSelected);
307 wizPanel.setFinish(generalModuleSelected);
313 public Component
getListCellRendererComponent(JList<? extends ReportModule> list, ReportModule value,
int index,
boolean isSelected,
boolean cellHasFocus) {
314 this.setText(value.getName());
315 this.setEnabled(
true);
316 this.setSelected(isSelected);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)