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;
46 @SuppressWarnings(
"PMD.SingularField")
47 final class ReportVisualPanel1 extends JPanel implements ListSelectionListener {
49 private static final Logger logger = Logger.getLogger(ReportVisualPanel1.class.getName());
50 private final ReportWizardPanel1 wizPanel;
51 private final List<ReportModule> modules =
new ArrayList<>();
52 private final List<GeneralReportModule> generalModules =
new ArrayList<>();
53 private final List<TableReportModule> tableModules =
new ArrayList<>();
54 private final List<FileReportModule> fileModules =
new ArrayList<>();
55 private Integer selectedIndex;
60 public ReportVisualPanel1(ReportWizardPanel1 wizPanel) {
61 this.wizPanel = wizPanel;
63 configurationPanel.setLayout(
new BorderLayout());
64 descriptionTextPane.setEditable(
false);
69 private void initModules() {
70 for (TableReportModule module : Lookup.getDefault().lookupAll(TableReportModule.class)) {
71 if (moduleIsValid(module)) {
72 tableModules.add(module);
79 for (GeneralReportModule module : Lookup.getDefault().lookupAll(GeneralReportModule.class)) {
80 if (moduleIsValid(module)) {
81 generalModules.add(module);
88 for (GeneralReportModule module : JythonModuleLoader.getGeneralReportModules()) {
89 if (moduleIsValid(module)) {
90 generalModules.add(module);
97 for (FileReportModule module : Lookup.getDefault().lookupAll(FileReportModule.class)) {
98 if (moduleIsValid(module)) {
99 fileModules.add(module);
102 popupWarning(module);
106 Collections.sort(modules,
new Comparator<ReportModule>() {
108 public int compare(ReportModule rm1, ReportModule rm2) {
110 boolean rm1isTable = (rm1 instanceof TableReportModule);
111 boolean rm2isTable = (rm2 instanceof TableReportModule);
112 if (rm1isTable && !rm2isTable) {
115 if (!rm1isTable && rm2isTable) {
119 return rm1.getName().compareTo(rm2.getName());
124 int indexOfHTMLReportModule = 0;
125 for (ReportModule module : modules) {
126 if (module instanceof ReportHTML) {
129 indexOfHTMLReportModule++;
131 swap(modules, indexOfHTMLReportModule, 0);
133 modulesJList.getSelectionModel().addListSelectionListener(
this);
134 modulesJList.setCellRenderer(
new ModuleCellRenderer());
135 modulesJList.setListData(modules.toArray(
new ReportModule[modules.size()]));
137 modulesJList.setSelectedIndex(selectedIndex);
141 private boolean moduleIsValid(ReportModule module) {
142 return module.getName() != null && !module.getName().isEmpty()
143 && module.getRelativeFilePath() != null;
146 private void popupWarning(ReportModule module) {
147 String moduleClassName = module.getClass().getSimpleName();
148 logger.log(Level.WARNING,
"Invalid ReportModule: {0}", moduleClassName);
149 DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(
150 NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.invalidModuleWarning", moduleClassName),
151 NotifyDescriptor.ERROR_MESSAGE));
155 public String getName() {
156 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel1.getName.text");
159 public ReportModule getSelectedModule() {
160 return modules.get(selectedIndex);
168 TableReportModule getTableModule() {
169 ReportModule mod = getSelectedModule();
170 if (tableModules.contains(mod)) {
171 return (TableReportModule) mod;
181 GeneralReportModule getGeneralModule() {
182 ReportModule mod = getSelectedModule();
183 if (generalModules.contains(mod)) {
184 return (GeneralReportModule) mod;
194 FileReportModule getFileModule() {
195 ReportModule mod = getSelectedModule();
196 if (fileModules.contains(mod)) {
197 return (FileReportModule) mod;
208 private void initComponents() {
210 reportModulesLabel =
new javax.swing.JLabel();
211 configurationPanel =
new javax.swing.JPanel();
212 descriptionScrollPane =
new javax.swing.JScrollPane();
213 descriptionTextPane =
new javax.swing.JTextPane();
214 modulesScrollPane =
new javax.swing.JScrollPane();
215 modulesJList =
new javax.swing.JList<>();
217 setPreferredSize(
new java.awt.Dimension(650, 250));
219 org.openide.awt.Mnemonics.setLocalizedText(reportModulesLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel1.class,
"ReportVisualPanel1.reportModulesLabel.text"));
221 configurationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(125, 125, 125)));
222 configurationPanel.setOpaque(
false);
224 javax.swing.GroupLayout configurationPanelLayout =
new javax.swing.GroupLayout(configurationPanel);
225 configurationPanel.setLayout(configurationPanelLayout);
226 configurationPanelLayout.setHorizontalGroup(
227 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228 .addGap(0, 432, Short.MAX_VALUE)
230 configurationPanelLayout.setVerticalGroup(
231 configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addGap(0, 168, Short.MAX_VALUE)
235 descriptionScrollPane.setBorder(null);
237 descriptionTextPane.setBackground(
new java.awt.Color(240, 240, 240));
238 descriptionTextPane.setBorder(null);
239 descriptionTextPane.setOpaque(
false);
240 descriptionScrollPane.setViewportView(descriptionTextPane);
242 modulesJList.setBackground(
new java.awt.Color(240, 240, 240));
243 modulesJList.setModel(
new javax.swing.AbstractListModel<ReportModule>() {
244 ReportModule[] modules = {};
245 public int getSize() {
return modules.length; }
246 public ReportModule getElementAt(
int i) {
return modules[i]; }
248 modulesJList.setOpaque(
false);
249 modulesScrollPane.setViewportView(modulesJList);
251 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
252 this.setLayout(layout);
253 layout.setHorizontalGroup(
254 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255 .addGroup(layout.createSequentialGroup()
257 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258 .addComponent(reportModulesLabel)
259 .addComponent(modulesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
260 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
261 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
262 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
263 .addComponent(descriptionScrollPane))
266 layout.setVerticalGroup(
267 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addGroup(layout.createSequentialGroup()
270 .addComponent(reportModulesLabel)
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
272 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 .addGroup(layout.createSequentialGroup()
274 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
276 .addComponent(configurationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
277 .addComponent(modulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
282 private javax.swing.JPanel configurationPanel;
283 private javax.swing.JScrollPane descriptionScrollPane;
284 private javax.swing.JTextPane descriptionTextPane;
285 private javax.swing.JList<ReportModule> modulesJList;
286 private javax.swing.JScrollPane modulesScrollPane;
287 private javax.swing.JLabel reportModulesLabel;
291 public void valueChanged(ListSelectionEvent e) {
292 if (e.getValueIsAdjusting()) {
295 configurationPanel.removeAll();
296 ListSelectionModel m = (ListSelectionModel) e.getSource();
298 selectedIndex = m.getMaxSelectionIndex();
300 ReportModule module = modules.get(selectedIndex);
301 JPanel panel = module.getConfigurationPanel();
303 panel =
new JPanel();
306 descriptionTextPane.setText(module.getDescription());
307 configurationPanel.add(panel, BorderLayout.CENTER);
308 configurationPanel.revalidate();
309 configurationPanel.repaint();
311 boolean generalModuleSelected = (module instanceof GeneralReportModule);
313 wizPanel.setNext(!generalModuleSelected);
314 wizPanel.setFinish(generalModuleSelected);
320 public Component
getListCellRendererComponent(JList<? extends ReportModule> list, ReportModule value,
int index,
boolean isSelected,
boolean cellHasFocus) {
321 this.setText(value.getName());
322 this.setEnabled(
true);
323 this.setSelected(isSelected);
Component getListCellRendererComponent(JList<?extends ReportModule > list, ReportModule value, int index, boolean isSelected, boolean cellHasFocus)