Autopsy  4.19.3
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 String currentDsp;
54 
60  AddImageWizardDataSourceSettingsVisual(AddImageWizardDataSourceSettingsPanel wizPanel) {
61  initComponents();
62  this.wizPanel = wizPanel;
63  typePanel.setLayout(new BorderLayout());
64  discoverDataSourceProcessors();
65  currentDsp = ImageDSProcessor.getType(); //default value to the ImageDSProcessor
66  }
67 
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);
76  } else {
77  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
78  }
79  }
80 
81  for (DataSourceProcessor dsProcessor : JythonModuleLoader.getDataSourceProcessorModules()) {
82  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
83  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
84  } else {
85  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
86  }
87  }
88  }
89 
97  void setDspSelection(String dsType) {
98  currentDsp = dsType;
99  currentPanel = datasourceProcessorsMap.get(dsType).getPanel();
100  updateCurrentPanel(currentPanel);
101  }
102 
108  @SuppressWarnings("deprecation")
109  private void updateCurrentPanel(JPanel panel) {
110  currentPanel = panel;
111  typePanel.removeAll();
112  typePanel.add(currentPanel, BorderLayout.CENTER);
113  typePanel.validate();
114  typePanel.repaint();
115  currentPanel.addPropertyChangeListener(new PropertyChangeListener() {
116  @Override
117  public void propertyChange(PropertyChangeEvent evt) {
118  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
119  wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
120  }
121  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
122  wizPanel.moveFocusToNext();
123  }
124  }
125  });
126  this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
127  }
128 
135  protected DataSourceProcessor getCurrentDSProcessor() {
136  // get the type of the currently selected panel and then look up
137  // the correspodning DS Handler in the map
138  DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(currentDsp);
139  return dsProcessor;
140 
141  }
142 
149  @Override
150  public String getName() {
151  return NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourceVisual.getName.text");
152  }
153 
159  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
160  private void initComponents() {
161 
162  typePanel = new javax.swing.JPanel();
163 
164  setPreferredSize(new java.awt.Dimension(588, 328));
165 
166  typePanel.setMinimumSize(new java.awt.Dimension(0, 65));
167  typePanel.setPreferredSize(new java.awt.Dimension(521, 65));
168 
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)
174  );
175  typePanelLayout.setVerticalGroup(
176  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177  .addGap(0, 328, Short.MAX_VALUE)
178  );
179 
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)
185  );
186  layout.setVerticalGroup(
187  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
189  );
190  }// </editor-fold>//GEN-END:initComponents
191  // Variables declaration - do not modify//GEN-BEGIN:variables
192  private javax.swing.JPanel typePanel;
193  // End of variables declaration//GEN-END:variables
194 
195  @SuppressWarnings("rawtypes")
196  public abstract class ComboboxSeparatorRenderer implements ListCellRenderer {
197 
198  private final ListCellRenderer delegate;
199 
200  private final JPanel separatorPanel = new JPanel(new BorderLayout());
201 
202  private final JSeparator separator = new JSeparator();
203 
204  public ComboboxSeparatorRenderer(ListCellRenderer delegate) {
205  this.delegate = delegate;
206  }
207 
208  @SuppressWarnings("unchecked")
209  @Override
210  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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;
217  } else {
218  return comp;
219  }
220  }
221 
222  protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
223  }
224 }
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Oct 4 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.