Tweaked the ImageFilePanel so it can be used by any other DataSourceProcessor that needs

an image path, a timezone string and the "no fat orphans" flag.
This commit is contained in:
raman-bt 2013-11-04 12:47:44 -05:00
parent 0b985703b7
commit 1bdc69dc1e
6 changed files with 90 additions and 44 deletions

View File

@ -41,8 +41,8 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
/** /**
* visual component for the first panel of add image wizard. Allows user to pick * visual component for the first panel of add image wizard.
* data source and timezone. * Allows the user to choose the data source type and then select the data source
* *
*/ */
final class AddImageWizardChooseDataSourceVisual extends JPanel { final class AddImageWizardChooseDataSourceVisual extends JPanel {

View File

@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.casemodule;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Arrays;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
/** /**
@ -28,6 +29,16 @@ import javax.swing.filechooser.FileFilter;
*/ */
public class GeneralFilter extends FileFilter{ public class GeneralFilter extends FileFilter{
// Extensions & Descriptions for commonly used filters
public static final List<String> RAW_IMAGE_EXTS = Arrays.asList(new String[]{".img", ".dd", ".001", ".aa", ".raw", ".bin"});
public static final String RAW_IMAGE_DESC = "Raw Images (*.img, *.dd, *.001, *.aa, *.raw, *.bin)";
public static final List<String> ENCASE_IMAGE_EXTS = Arrays.asList(new String[]{".e01"});
public static final String ENCASE_IMAGE_DESC = "Encase Images (*.e01)";
private List<String> extensions; private List<String> extensions;
private String desc; private String desc;

View File

@ -21,6 +21,10 @@ package org.sleuthkit.autopsy.casemodule;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.filechooser.FileFilter;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.corecomponentinterfaces.DSPProgressMonitor; import org.sleuthkit.autopsy.corecomponentinterfaces.DSPProgressMonitor;
@ -37,6 +41,8 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
@ServiceProvider(service = DataSourceProcessor.class) @ServiceProvider(service = DataSourceProcessor.class)
public class ImageDSProcessor implements DataSourceProcessor { public class ImageDSProcessor implements DataSourceProcessor {
static final Logger logger = Logger.getLogger(ImageDSProcessor.class.getName()); static final Logger logger = Logger.getLogger(ImageDSProcessor.class.getName());
// Data source type handled by this processor // Data source type handled by this processor
@ -60,7 +66,29 @@ public class ImageDSProcessor implements DataSourceProcessor {
private String imagePath; private String imagePath;
private String timeZone; private String timeZone;
private boolean noFatOrphans; private boolean noFatOrphans;
static final GeneralFilter rawFilter = new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
static final GeneralFilter encaseFilter = new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
static final List<String> allExt = new ArrayList<String>();
static {
allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
}
static final String allDesc = "All Supported Types";
static final GeneralFilter allFilter = new GeneralFilter(allExt, allDesc);
static final List<FileFilter> filtersList = new ArrayList<FileFilter>();
static {
filtersList.add(allFilter);
filtersList.add(rawFilter);
filtersList.add(encaseFilter);
}
/* /*
* A no argument constructor is required for the NM lookup() method to create an object * A no argument constructor is required for the NM lookup() method to create an object
@ -68,7 +96,7 @@ public class ImageDSProcessor implements DataSourceProcessor {
public ImageDSProcessor() { public ImageDSProcessor() {
// Create the config panel // Create the config panel
imageFilePanel = ImageFilePanel.getDefault(); imageFilePanel = ImageFilePanel.createInstance(ImageDSProcessor.class.getName(), filtersList);
} }

View File

@ -66,7 +66,7 @@
<Component id="noFatOrphansCheckbox" min="-2" max="-2" attributes="0"/> <Component id="noFatOrphansCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="descLabel" min="-2" max="-2" attributes="0"/> <Component id="descLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="33" max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>

View File

@ -31,6 +31,7 @@ import javax.swing.JFileChooser;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
@ -40,57 +41,52 @@ import org.sleuthkit.autopsy.coreutils.ModuleSettings;
*/ */
public class ImageFilePanel extends JPanel implements DocumentListener { public class ImageFilePanel extends JPanel implements DocumentListener {
private final String PROP_LASTIMAGE_PATH = "LBL_LastImage_PATH";
private static final String PROP_LASTIMAGE_PATH = "LBL_LastImage_PATH";
static final List<String> rawExt = Arrays.asList(new String[]{".img", ".dd", ".001", ".aa", ".raw"});
static final String rawDesc = "Raw Images (*.img, *.dd, *.001, *.aa, *.raw)";
static GeneralFilter rawFilter = new GeneralFilter(rawExt, rawDesc);
static final List<String> encaseExt = Arrays.asList(new String[]{".e01"});
static final String encaseDesc = "Encase Images (*.e01)";
static GeneralFilter encaseFilter = new GeneralFilter(encaseExt, encaseDesc);
static final List<String> allExt = new ArrayList<String>();
static {
allExt.addAll(rawExt);
allExt.addAll(encaseExt);
}
static final String allDesc = "All Supported Types";
static GeneralFilter allFilter = new GeneralFilter(allExt, allDesc);
private static ImageFilePanel instance = null;
private PropertyChangeSupport pcs = null; private PropertyChangeSupport pcs = null;
private JFileChooser fc = new JFileChooser(); private JFileChooser fc = new JFileChooser();
// Externally supplied name is used to store settings
private String contextName;
/** /**
* Creates new form ImageFilePanel * Creates new form ImageFilePanel
* @param context a string context name used to read/store last used settings
* @param fileChooserFilters a list of filters to be used with the FileChooser
*/ */
public ImageFilePanel() { private ImageFilePanel(String context, List<FileFilter> fileChooserFilters) {
initComponents(); initComponents();
fc.setDragEnabled(false); fc.setDragEnabled(false);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.addChoosableFileFilter(rawFilter);
fc.addChoosableFileFilter(encaseFilter);
fc.setFileFilter(allFilter);
boolean firstFilter = true;
for (FileFilter filter: fileChooserFilters ) {
if (firstFilter) { // set the first on the list as the default selection
fc.setFileFilter(filter);
firstFilter = false;
}
else {
fc.addChoosableFileFilter(filter);
}
}
this.contextName = context;
pcs = new PropertyChangeSupport(this); pcs = new PropertyChangeSupport(this);
createTimeZoneList(); createTimeZoneList();
} }
/** /**
* Returns the default instance of a ImageFilePanel. * Creates and returns an instance of a ImageFilePanel.
*/ */
public static synchronized ImageFilePanel getDefault() { public static synchronized ImageFilePanel createInstance(String context, List<FileFilter> fileChooserFilters) {
if (instance == null) {
instance = new ImageFilePanel(); ImageFilePanel instance = new ImageFilePanel(context, fileChooserFilters );
instance.postInit();
} instance.postInit();
return instance;
return instance;
} }
//post-constructor initialization to properly initialize listener support //post-constructor initialization to properly initialize listener support
@ -230,7 +226,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener {
} }
boolean getNoFatOrphans() { public boolean getNoFatOrphans() {
return noFatOrphansCheckbox.isSelected(); return noFatOrphansCheckbox.isSelected();
} }
@ -263,12 +259,12 @@ public class ImageFilePanel extends JPanel implements DocumentListener {
String imagePathName = getContentPaths(); String imagePathName = getContentPaths();
if (null != imagePathName ) { if (null != imagePathName ) {
String imagePath = imagePathName.substring(0, imagePathName.lastIndexOf(File.separator) + 1); String imagePath = imagePathName.substring(0, imagePathName.lastIndexOf(File.separator) + 1);
ModuleSettings.setConfigSetting(ImageFilePanel.class.getName(), PROP_LASTIMAGE_PATH, imagePath); ModuleSettings.setConfigSetting(contextName, PROP_LASTIMAGE_PATH, imagePath);
} }
} }
public void readSettings() { public void readSettings() {
String lastImagePath = ModuleSettings.getConfigSetting(ImageFilePanel.class.getName(), PROP_LASTIMAGE_PATH); String lastImagePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTIMAGE_PATH);
if (null != lastImagePath) { if (null != lastImagePath) {
if (!lastImagePath.isEmpty()) if (!lastImagePath.isEmpty())
pathTextField.setText(lastImagePath); pathTextField.setText(lastImagePath);

View File

@ -24,12 +24,14 @@ import java.awt.Toolkit;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.io.File; import java.io.File;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.sleuthkit.autopsy.casemodule.ImageFilePanel; import org.sleuthkit.autopsy.casemodule.GeneralFilter;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
@ -44,6 +46,16 @@ public class MissingImageDialog extends javax.swing.JDialog {
static final GeneralFilter rawFilter = new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
static final GeneralFilter encaseFilter = new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
static final List<String> allExt = new ArrayList<String>();
static {
allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
}
static final String allDesc = "All Supported Types";
static final GeneralFilter allFilter = new GeneralFilter(allExt, allDesc);
private JFileChooser fc = new JFileChooser(); private JFileChooser fc = new JFileChooser();
@ -57,10 +69,9 @@ public class MissingImageDialog extends javax.swing.JDialog {
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
// borrow the filters from ImageFilePanel fc.addChoosableFileFilter(rawFilter);
fc.addChoosableFileFilter(ImageFilePanel.rawFilter); fc.addChoosableFileFilter(encaseFilter);
fc.addChoosableFileFilter(ImageFilePanel.encaseFilter); fc.setFileFilter(allFilter);
fc.setFileFilter(ImageFilePanel.allFilter);
customInit(); customInit();