19 package org.sleuthkit.autopsy.casemodule;
 
   21 import java.awt.BorderLayout;
 
   22 import java.awt.Component;
 
   23 import java.awt.event.ActionEvent;
 
   24 import java.awt.event.ActionListener;
 
   25 import java.beans.PropertyChangeEvent;
 
   26 import java.beans.PropertyChangeListener;
 
   27 import java.util.ArrayList;
 
   28 import java.util.HashMap;
 
   29 import java.util.List;
 
   32 import java.util.logging.Level;
 
   33 import javax.swing.JList;
 
   34 import javax.swing.JPanel;
 
   35 import javax.swing.JSeparator;
 
   36 import javax.swing.ListCellRenderer;
 
   37 import javax.swing.event.DocumentEvent;
 
   38 import org.openide.util.Lookup;
 
   39 import org.openide.util.NbBundle;
 
   48 final class AddImageWizardChooseDataSourceVisual 
extends JPanel {
 
   50     static final Logger logger = Logger.
getLogger(AddImageWizardChooseDataSourceVisual.class.getName());
 
   52     private AddImageWizardChooseDataSourcePanel wizPanel;
 
   54     private JPanel currentPanel;
 
   56     private Map<String, DataSourceProcessor> datasourceProcessorsMap = 
new HashMap<>();
 
   58     List<String> coreDSPTypes = 
new ArrayList<>();
 
   65     AddImageWizardChooseDataSourceVisual(AddImageWizardChooseDataSourcePanel wizPanel) {
 
   67         this.wizPanel = wizPanel;
 
   72     @SuppressWarnings({
"rawtypes", 
"unchecked"})
 
   73     private void customInit() {
 
   75         typePanel.setLayout(
new BorderLayout());
 
   77         discoverDataSourceProcessors();
 
   80         typeComboBox.removeAllItems();
 
   82         Set<String> dspTypes = datasourceProcessorsMap.keySet();
 
   86         coreDSPTypes.add(ImageDSProcessor.getType());
 
   88         if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE) {
 
   89             coreDSPTypes.add(LocalDiskDSProcessor.getType());
 
   92             datasourceProcessorsMap.remove(LocalDiskDSProcessor.getType());
 
   94         coreDSPTypes.add(LocalFilesDSProcessor.getType());
 
   96         for (String dspType : coreDSPTypes) {
 
   97             typeComboBox.addItem(dspType);
 
  101         for (String dspType : dspTypes) {
 
  102             if (!coreDSPTypes.contains(dspType)) {
 
  103                 typeComboBox.addItem(dspType);
 
  107         typeComboBox.setRenderer(
new ComboboxSeparatorRenderer(typeComboBox.getRenderer()) {
 
  110             protected boolean addSeparatorAfter(JList list, Object value, 
int index) {
 
  111                 return (index == coreDSPTypes.size() - 1);
 
  116         ActionListener cbActionListener = 
new ActionListener() {
 
  118             public void actionPerformed(ActionEvent e) {
 
  119                 dspSelectionChanged();
 
  122         typeComboBox.addActionListener(cbActionListener);
 
  123         typeComboBox.setSelectedIndex(0);
 
  126     private void discoverDataSourceProcessors() {
 
  128         for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
 
  130             if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
 
  131                 datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
 
  133                 logger.log(Level.SEVERE, 
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); 
 
  138     private void dspSelectionChanged() {
 
  140         currentPanel = getCurrentDSProcessor().getPanel();
 
  141         updateCurrentPanel(currentPanel);
 
  149     @SuppressWarnings(
"deprecation")
 
  150     private 
void updateCurrentPanel(JPanel panel) {
 
  151         currentPanel = panel;
 
  152         typePanel.removeAll();
 
  153         typePanel.add(currentPanel, BorderLayout.CENTER);
 
  154         typePanel.validate();
 
  156         currentPanel.addPropertyChangeListener(
new PropertyChangeListener() {
 
  158             public void propertyChange(PropertyChangeEvent evt) {
 
  159                 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
 
  162                 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
 
  163                     wizPanel.moveFocusToNext();
 
  177     protected DataSourceProcessor getCurrentDSProcessor() {
 
  180         String dsType = (String) typeComboBox.getSelectedItem();
 
  181         DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(dsType);
 
  194     public String getName() {
 
  195         return NbBundle.getMessage(this.getClass(), 
"AddImageWizardChooseDataSourceVisual.getName.text");
 
  204     private void initComponents() {
 
  206         buttonGroup1 = 
new javax.swing.ButtonGroup();
 
  207         jLabel2 = 
new javax.swing.JLabel();
 
  208         inputPanel = 
new javax.swing.JPanel();
 
  209         typeTabel = 
new javax.swing.JLabel();
 
  210         typePanel = 
new javax.swing.JPanel();
 
  211         typeComboBox = 
new javax.swing.JComboBox<String>();
 
  213         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, 
org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, 
"AddImageWizardChooseDataSourceVisual.jLabel2.text")); 
 
  215         setPreferredSize(
new java.awt.Dimension(588, 328));
 
  217         org.openide.awt.Mnemonics.setLocalizedText(typeTabel, 
org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, 
"AddImageWizardChooseDataSourceVisual.typeTabel.text")); 
 
  219         typePanel.setMinimumSize(
new java.awt.Dimension(0, 65));
 
  220         typePanel.setPreferredSize(
new java.awt.Dimension(521, 65));
 
  222         javax.swing.GroupLayout typePanelLayout = 
new javax.swing.GroupLayout(typePanel);
 
  223         typePanel.setLayout(typePanelLayout);
 
  224         typePanelLayout.setHorizontalGroup(
 
  225             typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  226             .addGap(0, 548, Short.MAX_VALUE)
 
  228         typePanelLayout.setVerticalGroup(
 
  229             typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  230             .addGap(0, 225, Short.MAX_VALUE)
 
  233         javax.swing.GroupLayout inputPanelLayout = 
new javax.swing.GroupLayout(inputPanel);
 
  234         inputPanel.setLayout(inputPanelLayout);
 
  235         inputPanelLayout.setHorizontalGroup(
 
  236             inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  237             .addGroup(inputPanelLayout.createSequentialGroup()
 
  239                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  240                     .addGroup(inputPanelLayout.createSequentialGroup()
 
  241                         .addComponent(typeTabel)
 
  242                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
  243                         .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  244                         .addGap(0, 119, Short.MAX_VALUE))
 
  245                     .addComponent(typePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))
 
  248         inputPanelLayout.setVerticalGroup(
 
  249             inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  250             .addGroup(inputPanelLayout.createSequentialGroup()
 
  252                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  253                     .addComponent(typeTabel)
 
  254                     .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  255                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
  256                 .addComponent(typePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  257                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  260         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(
this);
 
  261         this.setLayout(layout);
 
  262         layout.setHorizontalGroup(
 
  263             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  264             .addGroup(layout.createSequentialGroup()
 
  266                 .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  269         layout.setVerticalGroup(
 
  270             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  271             .addGroup(layout.createSequentialGroup()
 
  273                 .addComponent(inputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  274                 .addContainerGap(44, Short.MAX_VALUE))
 
  278     private javax.swing.ButtonGroup buttonGroup1;
 
  279     private javax.swing.JPanel inputPanel;
 
  280     private javax.swing.JLabel jLabel2;
 
  281     private javax.swing.JComboBox<String> typeComboBox;
 
  282     private javax.swing.JPanel typePanel;
 
  283     private javax.swing.JLabel typeTabel;
 
  294     public void updateUI(DocumentEvent e) {
 
  296         this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
 
  299     @SuppressWarnings(
"rawtypes")
 
  304         private JPanel separatorPanel = 
new JPanel(
new BorderLayout());
 
  306         private JSeparator separator = 
new JSeparator();
 
  309             this.delegate = delegate;
 
  312         @SuppressWarnings(
"unchecked")
 
  315             Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
 
  316             if (index != -1 && addSeparatorAfter(list, value, index)) {
 
  317                 separatorPanel.removeAll();
 
  318                 separatorPanel.add(comp, BorderLayout.CENTER);
 
  319                 separatorPanel.add(separator, BorderLayout.SOUTH);
 
  320                 return separatorPanel;
 
  326         protected abstract boolean addSeparatorAfter(JList list, Object value, 
int index);
 
ComboboxSeparatorRenderer(ListCellRenderer delegate)
ListCellRenderer delegate
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
synchronized static Logger getLogger(String name)