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;
42 @SuppressWarnings(
"PMD.SingularField")
43 final class AddImageWizardDataSourceSettingsVisual extends JPanel {
45 private static final Logger logger = Logger.getLogger(AddImageWizardDataSourceSettingsVisual.class.getName());
47 private final AddImageWizardDataSourceSettingsPanel wizPanel;
49 private JPanel currentPanel;
51 private final Map<String, DataSourceProcessor> datasourceProcessorsMap =
new HashMap<>();
53 private String currentDsp;
60 AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
62 this.wizPanel = wizPanel;
63 typePanel.setLayout(
new BorderLayout());
64 discoverDataSourceProcessors();
65 currentDsp = ImageDSProcessor.getType();
72 private void discoverDataSourceProcessors() {
73 for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
74 if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
75 datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
77 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
81 for (DataSourceProcessor dsProcessor : JythonModuleLoader.getDataSourceProcessorModules()) {
82 if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
83 datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
85 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
97 void setDspSelection(String dsType) {
99 currentPanel = datasourceProcessorsMap.get(dsType).getPanel();
100 updateCurrentPanel(currentPanel);
108 @SuppressWarnings(
"deprecation")
109 private
void updateCurrentPanel(JPanel panel) {
110 currentPanel = panel;
111 typePanel.removeAll();
112 typePanel.add(currentPanel, BorderLayout.CENTER);
113 typePanel.validate();
115 currentPanel.addPropertyChangeListener(
new PropertyChangeListener() {
117 public void propertyChange(PropertyChangeEvent evt) {
118 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
119 wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
121 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
122 wizPanel.moveFocusToNext();
126 this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
135 protected DataSourceProcessor getCurrentDSProcessor() {
138 DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(currentDsp);
150 public String getName() {
151 return NbBundle.getMessage(this.getClass(),
"AddImageWizardChooseDataSourceVisual.getName.text");
160 private void initComponents() {
162 typePanel =
new javax.swing.JPanel();
164 setPreferredSize(
new java.awt.Dimension(588, 328));
166 typePanel.setMinimumSize(
new java.awt.Dimension(0, 65));
167 typePanel.setPreferredSize(
new java.awt.Dimension(521, 65));
169 javax.swing.GroupLayout typePanelLayout =
new javax.swing.GroupLayout(typePanel);
170 typePanel.setLayout(typePanelLayout);
171 typePanelLayout.setHorizontalGroup(
172 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
173 .addGap(0, 588, Short.MAX_VALUE)
175 typePanelLayout.setVerticalGroup(
176 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177 .addGap(0, 328, Short.MAX_VALUE)
180 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
181 this.setLayout(layout);
182 layout.setHorizontalGroup(
183 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184 .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
186 layout.setVerticalGroup(
187 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188 .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
192 private javax.swing.JPanel typePanel;
195 @SuppressWarnings(
"rawtypes")
200 private final JPanel separatorPanel =
new JPanel(
new BorderLayout());
202 private final JSeparator separator =
new JSeparator();
205 this.delegate = delegate;
208 @SuppressWarnings(
"unchecked")
211 Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
212 if (index != -1 && addSeparatorAfter(list, value, index)) {
213 separatorPanel.removeAll();
214 separatorPanel.add(comp, BorderLayout.CENTER);
215 separatorPanel.add(separator, BorderLayout.SOUTH);
216 return separatorPanel;
222 protected abstract boolean addSeparatorAfter(JList list, Object value,
int index);
ComboboxSeparatorRenderer(ListCellRenderer delegate)
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
final ListCellRenderer delegate