From 0b985703b738ee6b9af65dbb224917fbd9a3daa7 Mon Sep 17 00:00:00 2001 From: raman-bt Date: Tue, 29 Oct 2013 14:30:51 -0400 Subject: [PATCH] Ensure that the core DataSourceProcessors appear at the top in the wizard, and in a specific order. And there is a separator between 'core' DSPs and others. --- .../AddImageWizardChooseDataSourceVisual.java | 67 +++++++++++++++---- .../autopsy/casemodule/ImageDSProcessor.java | 2 +- .../casemodule/LocalDiskDSProcessor.java | 2 +- .../casemodule/LocalFilesDSProcessor.java | 2 +- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index 42a49daf56..dacec10e23 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -22,22 +22,20 @@ package org.sleuthkit.autopsy.casemodule; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.Component; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.SimpleTimeZone; -import java.util.TimeZone; import java.util.logging.Level; -import javax.swing.ComboBoxModel; import javax.swing.JPanel; +import javax.swing.JList; +import javax.swing.JSeparator; import javax.swing.event.DocumentEvent; -import javax.swing.event.ListDataListener; +import javax.swing.ListCellRenderer; import org.openide.util.Lookup; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; @@ -57,6 +55,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { private Map datasourceProcessorsMap = new HashMap(); + List coreDSPTypes = new ArrayList(); /** * Creates new form AddImageVisualPanel1 @@ -71,28 +70,49 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { } private void customInit() { + + typePanel.setLayout(new BorderLayout()); discoverDataSourceProcessors(); - + // set up the DSP type combobox typeComboBox.removeAllItems(); + Set dspTypes = datasourceProcessorsMap.keySet(); - for(String dspType:dspTypes){ + + // make a list of core DSPs + // ensure that the core DSPs are at the top and in a fixed order + coreDSPTypes.add(ImageDSProcessor.dsType); + coreDSPTypes.add(LocalDiskDSProcessor.dsType); + coreDSPTypes.add(LocalFilesDSProcessor.dsType); + + for(String dspType:coreDSPTypes){ typeComboBox.addItem(dspType); } + // now add any addtional DSPs that haven't already been added + for(String dspType:dspTypes){ + if (!coreDSPTypes.contains(dspType)) { + typeComboBox.addItem(dspType); + } + } + + // set a custom renderer that draws a separator at the end of the core DSPs in the combobox + typeComboBox.setRenderer(new ComboboxSeparatorRenderer(typeComboBox.getRenderer()){ + @Override + protected boolean addSeparatorAfter(JList list, Object value, int index){ + return (index == coreDSPTypes.size() - 1); + } + }); + //add actionlistner to listen for change ActionListener cbActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dspSelectionChanged(); - } }; typeComboBox.addActionListener(cbActionListener); - - typePanel.setLayout(new BorderLayout()); - typeComboBox.setSelectedIndex(0); } @@ -290,4 +310,27 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { this.wizPanel.enableNextButton(getCurrentDSProcessor().validatePanel()); } + + public abstract class ComboboxSeparatorRenderer implements ListCellRenderer{ + private ListCellRenderer delegate; + private JPanel separatorPanel = new JPanel(new BorderLayout()); + private JSeparator separator = new JSeparator(); + + public ComboboxSeparatorRenderer(ListCellRenderer delegate){ + this.delegate = delegate; + } + + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){ + Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if(index!=-1 && addSeparatorAfter(list, value, index)){ + separatorPanel.removeAll(); + separatorPanel.add(comp, BorderLayout.CENTER); + separatorPanel.add(separator, BorderLayout.SOUTH); + return separatorPanel; + }else + return comp; + } + + protected abstract boolean addSeparatorAfter(JList list, Object value, int index); + } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java index b82f59a4c6..0a56499828 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java @@ -40,7 +40,7 @@ public class ImageDSProcessor implements DataSourceProcessor { static final Logger logger = Logger.getLogger(ImageDSProcessor.class.getName()); // Data source type handled by this processor - private final String dsType = "Image File"; + protected final static String dsType = "Image File"; // The Config UI panel that plugins into the Choose Data Source Wizard private ImageFilePanel imageFilePanel; diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskDSProcessor.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskDSProcessor.java index 325d9d9a2f..cbaa520249 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskDSProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskDSProcessor.java @@ -33,7 +33,7 @@ public class LocalDiskDSProcessor implements DataSourceProcessor { static final Logger logger = Logger.getLogger(ImageDSProcessor.class.getName()); // Data source type handled by this processor - private final String dsType = "Local Disk"; + static protected final String dsType = "Local Disk"; // The Config UI panel that plugins into the Choose Data Source Wizard private LocalDiskPanel localDiskPanel; diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java index 539bb2e050..3c6089d4a3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java @@ -32,7 +32,7 @@ public class LocalFilesDSProcessor implements DataSourceProcessor { static final Logger logger = Logger.getLogger(LocalFilesDSProcessor.class.getName()); // Data source type handled by this processor - private final String dsType = "Logical Files"; + protected static final String dsType = "Logical Files"; // The Config UI panel that plugins into the Choose Data Source Wizard private LocalFilesPanel localFilesPanel;