Autopsy  4.0
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;
42 
48 final class AddImageWizardChooseDataSourceVisual extends JPanel {
49 
50  static final Logger logger = Logger.getLogger(AddImageWizardChooseDataSourceVisual.class.getName());
51 
52  private AddImageWizardChooseDataSourcePanel wizPanel;
53 
54  private JPanel currentPanel;
55 
56  private Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
57 
58  List<String> coreDSPTypes = new ArrayList<>();
59 
65  AddImageWizardChooseDataSourceVisual(AddImageWizardChooseDataSourcePanel wizPanel) {
66  initComponents();
67  this.wizPanel = wizPanel;
68 
69  customInit();
70  }
71 
72  @SuppressWarnings({"rawtypes", "unchecked"})
73  private void customInit() {
74 
75  typePanel.setLayout(new BorderLayout());
76 
77  discoverDataSourceProcessors();
78 
79  // set up the DSP type combobox
80  typeComboBox.removeAllItems();
81 
82  Set<String> dspTypes = datasourceProcessorsMap.keySet();
83 
84  // make a list of core DSPs
85  // ensure that the core DSPs are at the top and in a fixed order
86  coreDSPTypes.add(ImageDSProcessor.getType());
87  // Local disk processing is not allowed for multi-user cases
88  if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE) {
89  coreDSPTypes.add(LocalDiskDSProcessor.getType());
90  } else {
91  // remove LocalDiskDSProcessor from list of DSPs
92  datasourceProcessorsMap.remove(LocalDiskDSProcessor.getType());
93  }
94  coreDSPTypes.add(LocalFilesDSProcessor.getType());
95 
96  for (String dspType : coreDSPTypes) {
97  typeComboBox.addItem(dspType);
98  }
99 
100  // now add any addtional DSPs that haven't already been added
101  for (String dspType : dspTypes) {
102  if (!coreDSPTypes.contains(dspType)) {
103  typeComboBox.addItem(dspType);
104  }
105  }
106 
107  typeComboBox.setRenderer(new ComboboxSeparatorRenderer(typeComboBox.getRenderer()) {
108 
109  @Override
110  protected boolean addSeparatorAfter(JList list, Object value, int index) {
111  return (index == coreDSPTypes.size() - 1);
112  }
113  });
114 
115  //add actionlistner to listen for change
116  ActionListener cbActionListener = new ActionListener() {
117  @Override
118  public void actionPerformed(ActionEvent e) {
119  dspSelectionChanged();
120  }
121  };
122  typeComboBox.addActionListener(cbActionListener);
123  typeComboBox.setSelectedIndex(0);
124  }
125 
126  private void discoverDataSourceProcessors() {
127 
128  for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
129 
130  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
131  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
132  } else {
133  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
134  }
135  }
136  }
137 
138  private void dspSelectionChanged() {
139  // update the current panel to selection
140  currentPanel = getCurrentDSProcessor().getPanel();
141  updateCurrentPanel(currentPanel);
142  }
143 
149  @SuppressWarnings("deprecation")
150  private void updateCurrentPanel(JPanel panel) {
151  currentPanel = panel;
152  typePanel.removeAll();
153  typePanel.add(currentPanel, BorderLayout.CENTER);
154  typePanel.validate();
155  typePanel.repaint();
156  currentPanel.addPropertyChangeListener(new PropertyChangeListener() {
157  @Override
158  public void propertyChange(PropertyChangeEvent evt) {
159  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
160  updateUI(null);
161  }
162  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
163  wizPanel.moveFocusToNext();
164  }
165  }
166  });
167 
168  updateUI(null);
169  }
170 
177  protected DataSourceProcessor getCurrentDSProcessor() {
178  // get the type of the currently selected panel and then look up
179  // the correspodning DS Handler in the map
180  String dsType = (String) typeComboBox.getSelectedItem();
181  DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(dsType);
182 
183  return dsProcessor;
184 
185  }
186 
193  @Override
194  public String getName() {
195  return NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourceVisual.getName.text");
196  }
197 
203  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
204  private void initComponents() {
205 
206  buttonGroup1 = new javax.swing.ButtonGroup();
207  jLabel2 = new javax.swing.JLabel();
208  nextLabel = new javax.swing.JLabel();
209  inputPanel = new javax.swing.JPanel();
210  typeTabel = new javax.swing.JLabel();
211  typePanel = new javax.swing.JPanel();
212  typeComboBox = new javax.swing.JComboBox<String>();
213 
214  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.jLabel2.text")); // NOI18N
215 
216  setPreferredSize(new java.awt.Dimension(588, 328));
217 
218  org.openide.awt.Mnemonics.setLocalizedText(nextLabel, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.nextLabel.text")); // NOI18N
219  nextLabel.setPreferredSize(new java.awt.Dimension(514, 35));
220  nextLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
221 
222  inputPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
223 
224  org.openide.awt.Mnemonics.setLocalizedText(typeTabel, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.typeTabel.text")); // NOI18N
225 
226  typePanel.setMinimumSize(new java.awt.Dimension(0, 65));
227  typePanel.setPreferredSize(new java.awt.Dimension(521, 65));
228 
229  javax.swing.GroupLayout typePanelLayout = new javax.swing.GroupLayout(typePanel);
230  typePanel.setLayout(typePanelLayout);
231  typePanelLayout.setHorizontalGroup(
232  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233  .addGap(0, 544, Short.MAX_VALUE)
234  );
235  typePanelLayout.setVerticalGroup(
236  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237  .addGap(0, 173, Short.MAX_VALUE)
238  );
239 
240  javax.swing.GroupLayout inputPanelLayout = new javax.swing.GroupLayout(inputPanel);
241  inputPanel.setLayout(inputPanelLayout);
242  inputPanelLayout.setHorizontalGroup(
243  inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244  .addGroup(inputPanelLayout.createSequentialGroup()
245  .addContainerGap()
246  .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247  .addGroup(inputPanelLayout.createSequentialGroup()
248  .addComponent(typeTabel)
249  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
250  .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
251  .addGap(0, 115, Short.MAX_VALUE))
252  .addComponent(typePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE))
253  .addContainerGap())
254  );
255  inputPanelLayout.setVerticalGroup(
256  inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257  .addGroup(inputPanelLayout.createSequentialGroup()
258  .addContainerGap()
259  .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
260  .addComponent(typeTabel)
261  .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
262  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
263  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
264  .addContainerGap())
265  );
266 
267  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
268  this.setLayout(layout);
269  layout.setHorizontalGroup(
270  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271  .addGroup(layout.createSequentialGroup()
272  .addContainerGap()
273  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
274  .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
275  .addGroup(layout.createSequentialGroup()
276  .addComponent(nextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
277  .addGap(0, 54, Short.MAX_VALUE)))
278  .addContainerGap())
279  );
280  layout.setVerticalGroup(
281  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
282  .addGroup(layout.createSequentialGroup()
283  .addGap(39, 39, 39)
284  .addComponent(inputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
285  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
286  .addComponent(nextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
287  .addGap(0, 0, 0))
288  );
289  }// </editor-fold>//GEN-END:initComponents
290  // Variables declaration - do not modify//GEN-BEGIN:variables
291  private javax.swing.ButtonGroup buttonGroup1;
292  private javax.swing.JPanel inputPanel;
293  private javax.swing.JLabel jLabel2;
294  private javax.swing.JLabel nextLabel;
295  private javax.swing.JComboBox<String> typeComboBox;
296  private javax.swing.JPanel typePanel;
297  private javax.swing.JLabel typeTabel;
298  // End of variables declaration//GEN-END:variables
299 
308  public void updateUI(DocumentEvent e) {
309  // Enable the Next button if the current DSP panel is valid
310  this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
311  }
312 
313  @SuppressWarnings("rawtypes")
314  public abstract class ComboboxSeparatorRenderer implements ListCellRenderer {
315 
316  private ListCellRenderer delegate;
317 
318  private JPanel separatorPanel = new JPanel(new BorderLayout());
319 
320  private JSeparator separator = new JSeparator();
321 
322  public ComboboxSeparatorRenderer(ListCellRenderer delegate) {
323  this.delegate = delegate;
324  }
325 
326  @SuppressWarnings("unchecked")
327  @Override
328  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
329  Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
330  if (index != -1 && addSeparatorAfter(list, value, index)) {
331  separatorPanel.removeAll();
332  separatorPanel.add(comp, BorderLayout.CENTER);
333  separatorPanel.add(separator, BorderLayout.SOUTH);
334  return separatorPanel;
335  } else {
336  return comp;
337  }
338  }
339 
340  protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
341  }
342 }
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.