19 package org.sleuthkit.autopsy.casemodule;
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.beans.PropertyChangeEvent;
26 import java.beans.PropertyChangeListener;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
32 import java.util.logging.Level;
33 import javax.swing.JList;
34 import javax.swing.JPanel;
35 import javax.swing.JSeparator;
36 import javax.swing.ListCellRenderer;
37 import javax.swing.event.DocumentEvent;
38 import org.openide.util.Lookup;
39 import org.openide.util.NbBundle;
49 final class AddImageWizardChooseDataSourceVisual
extends JPanel {
51 static final Logger logger = Logger.getLogger(AddImageWizardChooseDataSourceVisual.class.getName());
53 private AddImageWizardChooseDataSourcePanel wizPanel;
55 private JPanel currentPanel;
57 private Map<String, DataSourceProcessor> datasourceProcessorsMap =
new HashMap<>();
59 List<String> coreDSPTypes =
new ArrayList<>();
66 AddImageWizardChooseDataSourceVisual(AddImageWizardChooseDataSourcePanel wizPanel) {
68 this.wizPanel = wizPanel;
73 @SuppressWarnings({
"rawtypes",
"unchecked"})
74 private void customInit() {
76 typePanel.setLayout(
new BorderLayout());
78 discoverDataSourceProcessors();
81 typeComboBox.removeAllItems();
83 Set<String> dspTypes = datasourceProcessorsMap.keySet();
87 coreDSPTypes.add(ImageDSProcessor.getType());
89 if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE) {
90 coreDSPTypes.add(LocalDiskDSProcessor.getType());
93 datasourceProcessorsMap.remove(LocalDiskDSProcessor.getType());
95 coreDSPTypes.add(LocalFilesDSProcessor.getType());
96 coreDSPTypes.add(RawDSProcessor.getType());
98 for (String dspType : coreDSPTypes) {
99 typeComboBox.addItem(dspType);
103 for (String dspType : dspTypes) {
104 if (!coreDSPTypes.contains(dspType)) {
105 typeComboBox.addItem(dspType);
109 typeComboBox.setRenderer(
new ComboboxSeparatorRenderer(typeComboBox.getRenderer()) {
112 protected boolean addSeparatorAfter(JList list, Object value,
int index) {
113 return (index == coreDSPTypes.size() - 1);
118 ActionListener cbActionListener =
new ActionListener() {
120 public void actionPerformed(ActionEvent e) {
121 dspSelectionChanged();
124 typeComboBox.addActionListener(cbActionListener);
125 typeComboBox.setSelectedIndex(0);
128 private void discoverDataSourceProcessors() {
130 for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
132 if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
133 datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
135 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
140 private void dspSelectionChanged() {
142 currentPanel = getCurrentDSProcessor().getPanel();
143 updateCurrentPanel(currentPanel);
151 @SuppressWarnings(
"deprecation")
152 private
void updateCurrentPanel(JPanel panel) {
153 currentPanel = panel;
154 typePanel.removeAll();
155 typePanel.add(currentPanel, BorderLayout.CENTER);
156 typePanel.validate();
158 currentPanel.addPropertyChangeListener(
new PropertyChangeListener() {
160 public void propertyChange(PropertyChangeEvent evt) {
161 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
164 if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
165 wizPanel.moveFocusToNext();
179 protected DataSourceProcessor getCurrentDSProcessor() {
182 String dsType = (String) typeComboBox.getSelectedItem();
183 DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(dsType);
196 public String getName() {
197 return NbBundle.getMessage(this.getClass(),
"AddImageWizardChooseDataSourceVisual.getName.text");
206 private void initComponents() {
208 buttonGroup1 =
new javax.swing.ButtonGroup();
209 jLabel2 =
new javax.swing.JLabel();
210 inputPanel =
new javax.swing.JPanel();
211 typeTabel =
new javax.swing.JLabel();
212 typePanel =
new javax.swing.JPanel();
213 typeComboBox =
new javax.swing.JComboBox<String>();
215 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class,
"AddImageWizardChooseDataSourceVisual.jLabel2.text"));
217 setPreferredSize(
new java.awt.Dimension(588, 328));
219 org.openide.awt.Mnemonics.setLocalizedText(typeTabel,
org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class,
"AddImageWizardChooseDataSourceVisual.typeTabel.text"));
221 typePanel.setMinimumSize(
new java.awt.Dimension(0, 65));
222 typePanel.setPreferredSize(
new java.awt.Dimension(521, 65));
224 javax.swing.GroupLayout typePanelLayout =
new javax.swing.GroupLayout(typePanel);
225 typePanel.setLayout(typePanelLayout);
226 typePanelLayout.setHorizontalGroup(
227 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228 .addGap(0, 548, Short.MAX_VALUE)
230 typePanelLayout.setVerticalGroup(
231 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addGap(0, 225, Short.MAX_VALUE)
235 javax.swing.GroupLayout inputPanelLayout =
new javax.swing.GroupLayout(inputPanel);
236 inputPanel.setLayout(inputPanelLayout);
237 inputPanelLayout.setHorizontalGroup(
238 inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addGroup(inputPanelLayout.createSequentialGroup()
241 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242 .addGroup(inputPanelLayout.createSequentialGroup()
243 .addComponent(typeTabel)
244 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
245 .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
246 .addGap(0, 119, Short.MAX_VALUE))
247 .addComponent(typePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))
250 inputPanelLayout.setVerticalGroup(
251 inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addGroup(inputPanelLayout.createSequentialGroup()
254 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
255 .addComponent(typeTabel)
256 .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
257 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
258 .addComponent(typePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
259 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
262 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
263 this.setLayout(layout);
264 layout.setHorizontalGroup(
265 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266 .addGroup(layout.createSequentialGroup()
268 .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
271 layout.setVerticalGroup(
272 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 .addGroup(layout.createSequentialGroup()
275 .addComponent(inputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
276 .addContainerGap(44, Short.MAX_VALUE))
280 private javax.swing.ButtonGroup buttonGroup1;
281 private javax.swing.JPanel inputPanel;
282 private javax.swing.JLabel jLabel2;
283 private javax.swing.JComboBox<String> typeComboBox;
284 private javax.swing.JPanel typePanel;
285 private javax.swing.JLabel typeTabel;
296 public void updateUI(DocumentEvent e) {
298 this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
301 @SuppressWarnings(
"rawtypes")
306 private JPanel separatorPanel =
new JPanel(
new BorderLayout());
308 private JSeparator separator =
new JSeparator();
311 this.delegate = delegate;
314 @SuppressWarnings(
"unchecked")
317 Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
318 if (index != -1 && addSeparatorAfter(list, value, index)) {
319 separatorPanel.removeAll();
320 separatorPanel.add(comp, BorderLayout.CENTER);
321 separatorPanel.add(separator, BorderLayout.SOUTH);
322 return separatorPanel;
328 protected abstract boolean addSeparatorAfter(JList list, Object value,
int index);
ComboboxSeparatorRenderer(ListCellRenderer delegate)
ListCellRenderer delegate
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)