Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardChooseDataSourceVisual.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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.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;
30 import java.util.Map;
31 import java.util.Set;
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;
43 
49 final class AddImageWizardChooseDataSourceVisual extends JPanel {
50 
51  static final Logger logger = Logger.getLogger(AddImageWizardChooseDataSourceVisual.class.getName());
52 
53  private AddImageWizardChooseDataSourcePanel wizPanel;
54 
55  private JPanel currentPanel;
56 
57  private Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
58 
59  List<String> coreDSPTypes = new ArrayList<>();
60 
66  AddImageWizardChooseDataSourceVisual(AddImageWizardChooseDataSourcePanel wizPanel) {
67  initComponents();
68  this.wizPanel = wizPanel;
69 
70  customInit();
71  }
72 
73  @SuppressWarnings({"rawtypes", "unchecked"})
74  private void customInit() {
75 
76  typePanel.setLayout(new BorderLayout());
77 
78  discoverDataSourceProcessors();
79 
80  // set up the DSP type combobox
81  typeComboBox.removeAllItems();
82 
83  Set<String> dspTypes = datasourceProcessorsMap.keySet();
84 
85  // make a list of core DSPs
86  // ensure that the core DSPs are at the top and in a fixed order
87  coreDSPTypes.add(ImageDSProcessor.getType());
88  // Local disk processing is not allowed for multi-user cases
89  if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE) {
90  coreDSPTypes.add(LocalDiskDSProcessor.getType());
91  } else {
92  // remove LocalDiskDSProcessor from list of DSPs
93  datasourceProcessorsMap.remove(LocalDiskDSProcessor.getType());
94  }
95  coreDSPTypes.add(LocalFilesDSProcessor.getType());
96  coreDSPTypes.add(RawDSProcessor.getType());
97 
98  for (String dspType : coreDSPTypes) {
99  typeComboBox.addItem(dspType);
100  }
101 
102  // now add any addtional DSPs that haven't already been added
103  for (String dspType : dspTypes) {
104  if (!coreDSPTypes.contains(dspType)) {
105  typeComboBox.addItem(dspType);
106  }
107  }
108 
109  typeComboBox.setRenderer(new ComboboxSeparatorRenderer(typeComboBox.getRenderer()) {
110 
111  @Override
112  protected boolean addSeparatorAfter(JList list, Object value, int index) {
113  return (index == coreDSPTypes.size() - 1);
114  }
115  });
116 
117  //add actionlistner to listen for change
118  ActionListener cbActionListener = new ActionListener() {
119  @Override
120  public void actionPerformed(ActionEvent e) {
121  dspSelectionChanged();
122  }
123  };
124  typeComboBox.addActionListener(cbActionListener);
125  typeComboBox.setSelectedIndex(0);
126  }
127 
128  private void discoverDataSourceProcessors() {
129 
130  for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
131 
132  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
133  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
134  } else {
135  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
136  }
137  }
138  }
139 
140  private void dspSelectionChanged() {
141  // update the current panel to selection
142  currentPanel = getCurrentDSProcessor().getPanel();
143  updateCurrentPanel(currentPanel);
144  }
145 
151  @SuppressWarnings("deprecation")
152  private void updateCurrentPanel(JPanel panel) {
153  currentPanel = panel;
154  typePanel.removeAll();
155  typePanel.add(currentPanel, BorderLayout.CENTER);
156  typePanel.validate();
157  typePanel.repaint();
158  currentPanel.addPropertyChangeListener(new PropertyChangeListener() {
159  @Override
160  public void propertyChange(PropertyChangeEvent evt) {
161  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
162  updateUI(null);
163  }
164  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
165  wizPanel.moveFocusToNext();
166  }
167  }
168  });
169 
170  updateUI(null);
171  }
172 
179  protected DataSourceProcessor getCurrentDSProcessor() {
180  // get the type of the currently selected panel and then look up
181  // the correspodning DS Handler in the map
182  String dsType = (String) typeComboBox.getSelectedItem();
183  DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(dsType);
184 
185  return dsProcessor;
186 
187  }
188 
195  @Override
196  public String getName() {
197  return NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourceVisual.getName.text");
198  }
199 
205  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
206  private void initComponents() {
207 
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>();
214 
215  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.jLabel2.text")); // NOI18N
216 
217  setPreferredSize(new java.awt.Dimension(588, 328));
218 
219  org.openide.awt.Mnemonics.setLocalizedText(typeTabel, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.typeTabel.text")); // NOI18N
220 
221  typePanel.setMinimumSize(new java.awt.Dimension(0, 65));
222  typePanel.setPreferredSize(new java.awt.Dimension(521, 65));
223 
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)
229  );
230  typePanelLayout.setVerticalGroup(
231  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232  .addGap(0, 225, Short.MAX_VALUE)
233  );
234 
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()
240  .addContainerGap()
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))
248  .addContainerGap())
249  );
250  inputPanelLayout.setVerticalGroup(
251  inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252  .addGroup(inputPanelLayout.createSequentialGroup()
253  .addContainerGap()
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))
260  );
261 
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()
267  .addContainerGap()
268  .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
269  .addContainerGap())
270  );
271  layout.setVerticalGroup(
272  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273  .addGroup(layout.createSequentialGroup()
274  .addGap(6, 6, 6)
275  .addComponent(inputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
276  .addContainerGap(44, Short.MAX_VALUE))
277  );
278  }// </editor-fold>//GEN-END:initComponents
279  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
286  // End of variables declaration//GEN-END:variables
287 
296  public void updateUI(DocumentEvent e) {
297  // Enable the Next button if the current DSP panel is valid
298  this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
299  }
300 
301  @SuppressWarnings("rawtypes")
302  public abstract class ComboboxSeparatorRenderer implements ListCellRenderer {
303 
304  private ListCellRenderer delegate;
305 
306  private JPanel separatorPanel = new JPanel(new BorderLayout());
307 
308  private JSeparator separator = new JSeparator();
309 
310  public ComboboxSeparatorRenderer(ListCellRenderer delegate) {
311  this.delegate = delegate;
312  }
313 
314  @SuppressWarnings("unchecked")
315  @Override
316  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
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;
323  } else {
324  return comp;
325  }
326  }
327 
328  protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
329  }
330 }
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.