Autopsy  3.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;
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  coreDSPTypes.add(LocalDiskDSProcessor.getType());
88  coreDSPTypes.add(LocalFilesDSProcessor.getType());
89 
90  for (String dspType : coreDSPTypes) {
91  typeComboBox.addItem(dspType);
92  }
93 
94  // now add any addtional DSPs that haven't already been added
95  for (String dspType : dspTypes) {
96  if (!coreDSPTypes.contains(dspType)) {
97  typeComboBox.addItem(dspType);
98  }
99  }
100 
101  typeComboBox.setRenderer(new ComboboxSeparatorRenderer(typeComboBox.getRenderer()) {
102 
103  @Override
104  protected boolean addSeparatorAfter(JList list, Object value, int index) {
105  return (index == coreDSPTypes.size() - 1);
106  }
107  });
108 
109  //add actionlistner to listen for change
110  ActionListener cbActionListener = new ActionListener() {
111  @Override
112  public void actionPerformed(ActionEvent e) {
113  dspSelectionChanged();
114  }
115  };
116  typeComboBox.addActionListener(cbActionListener);
117  typeComboBox.setSelectedIndex(0);
118  }
119 
120  private void discoverDataSourceProcessors() {
121 
122  for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
123 
124  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
125  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
126  } else {
127  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
128  }
129  }
130  }
131 
132  private void dspSelectionChanged() {
133  // update the current panel to selection
134  currentPanel = getCurrentDSProcessor().getPanel();
135  updateCurrentPanel(currentPanel);
136  }
137 
143  private void updateCurrentPanel(JPanel panel) {
144  currentPanel = panel;
145  typePanel.removeAll();
146  typePanel.add(currentPanel, BorderLayout.CENTER);
147  typePanel.validate();
148  typePanel.repaint();
149  currentPanel.addPropertyChangeListener(new PropertyChangeListener() {
150  @Override
151  public void propertyChange(PropertyChangeEvent evt) {
152  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString())) {
153  updateUI(null);
154  }
155  if (evt.getPropertyName().equals(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString())) {
156  wizPanel.moveFocusToNext();
157  }
158  }
159  });
160 
161  updateUI(null);
162  }
163 
170  protected DataSourceProcessor getCurrentDSProcessor() {
171  // get the type of the currently selected panel and then look up
172  // the correspodning DS Handler in the map
173  String dsType = (String) typeComboBox.getSelectedItem();
174  DataSourceProcessor dsProcessor = datasourceProcessorsMap.get(dsType);
175 
176  return dsProcessor;
177 
178  }
179 
186  @Override
187  public String getName() {
188  return NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourceVisual.getName.text");
189  }
190 
196  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
197  private void initComponents() {
198 
199  buttonGroup1 = new javax.swing.ButtonGroup();
200  jLabel2 = new javax.swing.JLabel();
201  nextLabel = new javax.swing.JLabel();
202  inputPanel = new javax.swing.JPanel();
203  typeTabel = new javax.swing.JLabel();
204  typePanel = new javax.swing.JPanel();
205  typeComboBox = new javax.swing.JComboBox<String>();
206 
207  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.jLabel2.text")); // NOI18N
208 
209  setPreferredSize(new java.awt.Dimension(588, 328));
210 
211  org.openide.awt.Mnemonics.setLocalizedText(nextLabel, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.nextLabel.text")); // NOI18N
212  nextLabel.setPreferredSize(new java.awt.Dimension(514, 35));
213  nextLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
214 
215  inputPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
216 
217  org.openide.awt.Mnemonics.setLocalizedText(typeTabel, org.openide.util.NbBundle.getMessage(AddImageWizardChooseDataSourceVisual.class, "AddImageWizardChooseDataSourceVisual.typeTabel.text")); // NOI18N
218 
219  typePanel.setMinimumSize(new java.awt.Dimension(0, 65));
220  typePanel.setPreferredSize(new java.awt.Dimension(521, 65));
221 
222  javax.swing.GroupLayout typePanelLayout = new javax.swing.GroupLayout(typePanel);
223  typePanel.setLayout(typePanelLayout);
224  typePanelLayout.setHorizontalGroup(
225  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addGap(0, 544, Short.MAX_VALUE)
227  );
228  typePanelLayout.setVerticalGroup(
229  typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230  .addGap(0, 173, Short.MAX_VALUE)
231  );
232 
233  javax.swing.GroupLayout inputPanelLayout = new javax.swing.GroupLayout(inputPanel);
234  inputPanel.setLayout(inputPanelLayout);
235  inputPanelLayout.setHorizontalGroup(
236  inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237  .addGroup(inputPanelLayout.createSequentialGroup()
238  .addContainerGap()
239  .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240  .addGroup(inputPanelLayout.createSequentialGroup()
241  .addComponent(typeTabel)
242  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
243  .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
244  .addGap(0, 115, Short.MAX_VALUE))
245  .addComponent(typePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE))
246  .addContainerGap())
247  );
248  inputPanelLayout.setVerticalGroup(
249  inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250  .addGroup(inputPanelLayout.createSequentialGroup()
251  .addContainerGap()
252  .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
253  .addComponent(typeTabel)
254  .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
255  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
256  .addComponent(typePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
257  .addContainerGap())
258  );
259 
260  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
261  this.setLayout(layout);
262  layout.setHorizontalGroup(
263  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264  .addGroup(layout.createSequentialGroup()
265  .addContainerGap()
266  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
267  .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
268  .addGroup(layout.createSequentialGroup()
269  .addComponent(nextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
270  .addGap(0, 54, Short.MAX_VALUE)))
271  .addContainerGap())
272  );
273  layout.setVerticalGroup(
274  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275  .addGroup(layout.createSequentialGroup()
276  .addGap(39, 39, 39)
277  .addComponent(inputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
278  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
279  .addComponent(nextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
280  .addGap(0, 0, 0))
281  );
282  }// </editor-fold>//GEN-END:initComponents
283  // Variables declaration - do not modify//GEN-BEGIN:variables
284  private javax.swing.ButtonGroup buttonGroup1;
285  private javax.swing.JPanel inputPanel;
286  private javax.swing.JLabel jLabel2;
287  private javax.swing.JLabel nextLabel;
288  private javax.swing.JComboBox<String> typeComboBox;
289  private javax.swing.JPanel typePanel;
290  private javax.swing.JLabel typeTabel;
291  // End of variables declaration//GEN-END:variables
292 
301  public void updateUI(DocumentEvent e) {
302  // Enable the Next button if the current DSP panel is valid
303  this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid());
304  }
305 
306  @SuppressWarnings("rawtypes")
307  public abstract class ComboboxSeparatorRenderer implements ListCellRenderer {
308 
309  private ListCellRenderer delegate;
310 
311  private JPanel separatorPanel = new JPanel(new BorderLayout());
312 
313  private JSeparator separator = new JSeparator();
314 
315  public ComboboxSeparatorRenderer(ListCellRenderer delegate) {
316  this.delegate = delegate;
317  }
318 
319  @SuppressWarnings("unchecked")
320  @Override
321  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
322  Component comp = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
323  if (index != -1 && addSeparatorAfter(list, value, index)) {
324  separatorPanel.removeAll();
325  separatorPanel.add(comp, BorderLayout.CENTER);
326  separatorPanel.add(separator, BorderLayout.SOUTH);
327  return separatorPanel;
328  } else {
329  return comp;
330  }
331  }
332 
333  protected abstract boolean addSeparatorAfter(JList list, Object value, int index);
334  }
335 }
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
static Logger getLogger(String name)
Definition: Logger.java:131

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