Autopsy  4.21.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-2020 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;
37 
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 final class AddImageWizardDataSourceSettingsVisual extends JPanel {
44 
45  private static final Logger logger = Logger.getLogger(AddImageWizardDataSourceSettingsVisual.class.getName());
46 
47  private final AddImageWizardDataSourceSettingsPanel wizPanel;
48 
49  private JPanel currentPanel;
50 
51  private final Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
52 
53  private final PanelUpdateListener panelUpdateListener;
54 
55  private String currentDsp;
56 
62  AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
63  initComponents();
64  this.wizPanel = wizPanel;
65  this.panelUpdateListener = new PanelUpdateListener();
66  typePanel.setLayout(new BorderLayout());
67  discoverDataSourceProcessors();
68  currentDsp = ImageDSProcessor.getType(); //default value to the ImageDSProcessor
69  }
70 
75  private void discoverDataSourceProcessors() {
76  for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
77  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
78  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
79  } else {
80  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
81  }
82  }
83 
84  for (DataSourceProcessor dsProcessor : JythonModuleLoader.getDataSourceProcessorModules()) {
85  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
86  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
87  } else {
88  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
89  }
90  }
91  }
92 
100  void setDspSelection(String dsType) {
101  currentDsp = dsType;
102  currentPanel = datasourceProcessorsMap.get(dsType).getPanel();
103  updateCurrentPanel(currentPanel);
104  }
105 
111  @SuppressWarnings("deprecation")
112  private void updateCurrentPanel(JPanel panel) {
113  cleanupUpdateListener(currentPanel);
114  currentPanel = panel;
115  typePanel.removeAll();
116  typePanel.add(currentPanel, BorderLayout.CENTER);
117  typePanel.validate();
118  typePanel.repaint();
119  cleanupUpdateListener(currentPanel);
120  currentPanel.addPropertyChangeListener(panelUpdateListener);
121  this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
122  }
123 
128  private void cleanupUpdateListener(JPanel panel) {
129  if (panel == null) {
130  return;
131  }
132 
133  PropertyChangeListener[] listeners = panel.getPropertyChangeListeners();
134  if (listeners == null) {
135  return;
136  }
137 
138  for (PropertyChangeListener listener: listeners) {
139  if (listener instanceof PanelUpdateListener) {
140  panel.removePropertyChangeListener(listener);
141  }
142  }
143  }
144 
151  protected DataSourceProcessor getCurrentDSProcessor() {
152  // get the type of the currently selected panel and then look up
153  // the correspodning DS Handler in the map
154  DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(currentDsp);
155  return dsProcessor;
156 
157  }
158 
165  @Override
166  public String getName() {
167  return NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourceVisual.getName.text");
168  }
169 
175  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
176  private void initComponents() {
177 
178  typePanel = new javax.swing.JPanel();
179 
180  setPreferredSize(new java.awt.Dimension(588, 328));
181 
182  typePanel.setMinimumSize(new java.awt.Dimension(0, 65));
183  typePanel.setPreferredSize(new java.awt.Dimension(521, 65));
184 
185  javax.swing.GroupLayout typePanelLayout = new javax.swing.GroupLayout(typePanel);
186  typePanel.setLayout(typePanelLayout);
187  typePanelLayout.setHorizontalGroup(
188  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
189  .addGap(0, 588, Short.MAX_VALUE)
190  );
191  typePanelLayout.setVerticalGroup(
192  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193  .addGap(0, 328, Short.MAX_VALUE)
194  );
195 
196  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
197  this.setLayout(layout);
198  layout.setHorizontalGroup(
199  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
201  );
202  layout.setVerticalGroup(
203  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
205  );
206  }// </editor-fold>//GEN-END:initComponents
207  // Variables declaration - do not modify//GEN-BEGIN:variables
208  private javax.swing.JPanel typePanel;
209  // End of variables declaration//GEN-END:variables
210 
211  @SuppressWarnings("rawtypes")
212  public abstract class ComboboxSeparatorRenderer implements ListCellRenderer {
213 
214  private final ListCellRenderer delegate;
215 
216  private final JPanel separatorPanel = new JPanel(new BorderLayout());
217 
218  private final JSeparator separator = new JSeparator();
219 
220  public ComboboxSeparatorRenderer(ListCellRenderer delegate) {
221  this.delegate = delegate;
222  }
223 
224  @SuppressWarnings("unchecked")
225  @Override
226  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
227  Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
228  if (index != -1 && addSeparatorAfter(list, value, index)) {
229  separatorPanel.removeAll();
230  separatorPanel.add(comp, BorderLayout.CENTER);
231  separatorPanel.add(separator, BorderLayout.SOUTH);
232  return separatorPanel;
233  } else {
234  return comp;
235  }
236  }
237 
238  protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
239  }
240 
244  private class PanelUpdateListener implements PropertyChangeListener {
245 
246  @Override
247  public void propertyChange(PropertyChangeEvent evt) {
248  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
249  wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
250  }
251  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
252  wizPanel.moveFocusToNext();
253  }
254  }
255  }
256 }
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on: Mon Feb 17 2025
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.