19 package org.sleuthkit.autopsy.casemodule;
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;
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;
41 @SuppressWarnings(
"PMD.SingularField")
42 final class AddImageWizardDataSourceSettingsVisual extends JPanel {
44 private static final Logger logger = Logger.
getLogger(AddImageWizardDataSourceSettingsVisual.class.getName());
46 private final AddImageWizardDataSourceSettingsPanel wizPanel;
48 private JPanel currentPanel;
50 private final Map<String, DataSourceProcessor> datasourceProcessorsMap =
new HashMap<>();
52 private String currentDsp;
59 AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
61 this.wizPanel = wizPanel;
62 typePanel.setLayout(
new BorderLayout());
63 discoverDataSourceProcessors();
64 currentDsp = ImageDSProcessor.getType();
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);
76 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
88 void setDspSelection(String dsType) {
90 currentPanel = datasourceProcessorsMap.get(dsType).getPanel();
91 updateCurrentPanel(currentPanel);
99 @SuppressWarnings(
"deprecation")
100 private
void updateCurrentPanel(JPanel panel) {
101 currentPanel = panel;
102 typePanel.removeAll();
103 typePanel.add(currentPanel, BorderLayout.CENTER);
104 typePanel.validate();
106 currentPanel.addPropertyChangeListener(
new PropertyChangeListener() {
108 public void propertyChange(PropertyChangeEvent evt) {
109 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
110 wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
112 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
113 wizPanel.moveFocusToNext();
117 this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
126 protected DataSourceProcessor getCurrentDSProcessor() {
129 DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(currentDsp);
141 public String getName() {
142 return NbBundle.getMessage(this.getClass(),
"AddImageWizardChooseDataSourceVisual.getName.text");
151 private void initComponents() {
153 typePanel =
new javax.swing.JPanel();
155 setPreferredSize(
new java.awt.Dimension(588, 328));
157 typePanel.setMinimumSize(
new java.awt.Dimension(0, 65));
158 typePanel.setPreferredSize(
new java.awt.Dimension(521, 65));
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)
166 typePanelLayout.setVerticalGroup(
167 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168 .addGap(0, 328, Short.MAX_VALUE)
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)
177 layout.setVerticalGroup(
178 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
179 .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
183 private javax.swing.JPanel typePanel;
186 @SuppressWarnings(
"rawtypes")
191 private final JPanel separatorPanel =
new JPanel(
new BorderLayout());
193 private final JSeparator separator =
new JSeparator();
196 this.delegate = delegate;
199 @SuppressWarnings(
"unchecked")
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;
213 protected abstract boolean addSeparatorAfter(JList list, Object value,
int index);
ComboboxSeparatorRenderer(ListCellRenderer delegate)
synchronized static Logger getLogger(String name)
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
final ListCellRenderer delegate