Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardDataSourceSettingsVisual.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.logging.Level;
28 import javax.swing.JList;
29 import javax.swing.JPanel;
30 import javax.swing.JSeparator;
31 import javax.swing.ListCellRenderer;
32 import org.openide.util.Lookup;
33 import org.openide.util.NbBundle;
36 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 final class AddImageWizardDataSourceSettingsVisual extends JPanel {
43 
44  private static final Logger logger = Logger.getLogger(AddImageWizardDataSourceSettingsVisual.class.getName());
45 
46  private final AddImageWizardDataSourceSettingsPanel wizPanel;
47 
48  private JPanel currentPanel;
49 
50  private final Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
51 
52  private String currentDsp;
53 
59  AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
60  initComponents();
61  this.wizPanel = wizPanel;
62  typePanel.setLayout(new BorderLayout());
63  discoverDataSourceProcessors();
64  currentDsp = ImageDSProcessor.getType(); //default value to the ImageDSProcessor
65  }
66 
71  private void discoverDataSourceProcessors() {
72  for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
73  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
74  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
75  } else {
76  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
77  }
78  }
79  }
80 
88  void setDspSelection(String dsType) {
89  currentDsp = dsType;
90  currentPanel = datasourceProcessorsMap.get(dsType).getPanel();
91  updateCurrentPanel(currentPanel);
92  }
93 
99  @SuppressWarnings("deprecation")
100  private void updateCurrentPanel(JPanel panel) {
101  currentPanel = panel;
102  typePanel.removeAll();
103  typePanel.add(currentPanel, BorderLayout.CENTER);
104  typePanel.validate();
105  typePanel.repaint();
106  currentPanel.addPropertyChangeListener(new PropertyChangeListener() {
107  @Override
108  public void propertyChange(PropertyChangeEvent evt) {
109  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
110  wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
111  }
112  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
113  wizPanel.moveFocusToNext();
114  }
115  }
116  });
117  this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
118  }
119 
126  protected DataSourceProcessor getCurrentDSProcessor() {
127  // get the type of the currently selected panel and then look up
128  // the correspodning DS Handler in the map
129  DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(currentDsp);
130  return dsProcessor;
131 
132  }
133 
140  @Override
141  public String getName() {
142  return NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourceVisual.getName.text");
143  }
144 
150  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
151  private void initComponents() {
152 
153  typePanel = new javax.swing.JPanel();
154 
155  setPreferredSize(new java.awt.Dimension(588, 328));
156 
157  typePanel.setMinimumSize(new java.awt.Dimension(0, 65));
158  typePanel.setPreferredSize(new java.awt.Dimension(521, 65));
159 
160  javax.swing.GroupLayout typePanelLayout = new javax.swing.GroupLayout(typePanel);
161  typePanel.setLayout(typePanelLayout);
162  typePanelLayout.setHorizontalGroup(
163  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164  .addGap(0, 588, Short.MAX_VALUE)
165  );
166  typePanelLayout.setVerticalGroup(
167  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168  .addGap(0, 328, Short.MAX_VALUE)
169  );
170 
171  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
172  this.setLayout(layout);
173  layout.setHorizontalGroup(
174  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
176  );
177  layout.setVerticalGroup(
178  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
179  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
180  );
181  }// </editor-fold>//GEN-END:initComponents
182  // Variables declaration - do not modify//GEN-BEGIN:variables
183  private javax.swing.JPanel typePanel;
184  // End of variables declaration//GEN-END:variables
185 
186  @SuppressWarnings("rawtypes")
187  public abstract class ComboboxSeparatorRenderer implements ListCellRenderer {
188 
189  private final ListCellRenderer delegate;
190 
191  private final JPanel separatorPanel = new JPanel(new BorderLayout());
192 
193  private final JSeparator separator = new JSeparator();
194 
195  public ComboboxSeparatorRenderer(ListCellRenderer delegate) {
196  this.delegate = delegate;
197  }
198 
199  @SuppressWarnings("unchecked")
200  @Override
201  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
202  Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
203  if (index != -1 && addSeparatorAfter(list, value, index)) {
204  separatorPanel.removeAll();
205  separatorPanel.add(comp, BorderLayout.CENTER);
206  separatorPanel.add(separator, BorderLayout.SOUTH);
207  return separatorPanel;
208  } else {
209  return comp;
210  }
211  }
212 
213  protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
214  }
215 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.