Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardSelectDspVisual.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.Color;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.ArrayList;
29 import java.util.Enumeration;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.logging.Level;
34 import javax.swing.AbstractButton;
35 import javax.swing.Box.Filler;
36 import javax.swing.JPanel;
37 import javax.swing.JTextArea;
38 import javax.swing.JToggleButton;
39 import org.openide.util.Lookup;
40 import org.openide.util.NbBundle;
44 
49 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
50 final class AddImageWizardSelectDspVisual extends JPanel {
51 
52  private static final Logger logger = Logger.getLogger(AddImageWizardSelectDspVisual.class.getName());
53  private String selectedDsp;
54 
58  AddImageWizardSelectDspVisual(String lastDspUsed) {
59  initComponents();
60  selectedDsp = lastDspUsed;
61  //if the last selected DSP was the Local Disk DSP and it would be disabled then we want to select a different DSP
62  try {
63  if ((Case.getCurrentCaseThrows().getCaseType() == Case.CaseType.MULTI_USER_CASE) && selectedDsp.equals(LocalDiskDSProcessor.getType())) {
64  selectedDsp = ImageDSProcessor.getType();
65  }
66  createDataSourceProcessorButtons();
67  } catch (NoCurrentCaseException ex) {
68  logger.log(Level.SEVERE, "Exception while getting open case.", ex);
69  }
70 
71  //add actionlistner to listen for change
72  }
73 
79  private void updateSelectedDsp() {
80  Enumeration<AbstractButton> buttonGroup = buttonGroup1.getElements();
81  while (buttonGroup.hasMoreElements()) {
82  AbstractButton dspButton = buttonGroup.nextElement();
83  if (dspButton.isSelected()) {
84  selectedDsp = dspButton.getName();
85  break;
86  }
87  }
88  }
89 
96  String getSelectedDsp() {
97  return selectedDsp;
98  }
99 
100  @NbBundle.Messages("AddImageWizardSelectDspVisual.multiUserWarning.text=This type of Data Source Processor is not available in multi-user mode")
105  private void createDataSourceProcessorButtons() throws NoCurrentCaseException {
106  //Listener for button selection
107  ActionListener cbActionListener = new ActionListener() {
108  @Override
109  public void actionPerformed(ActionEvent e) {
110  updateSelectedDsp();
111  }
112  };
113  List<String> dspList = getListOfDsps();
114  //Set up the constraints for the panel layout
115  GridBagLayout gridBagLayout = new GridBagLayout();
116  GridBagConstraints constraints = new GridBagConstraints();
117  constraints.fill = GridBagConstraints.HORIZONTAL;
118  constraints.gridx = 0;
119  constraints.gridy = 0;
120  constraints.weighty = 0;
121  constraints.anchor = GridBagConstraints.LINE_START;
122  Dimension spacerBlockDimension = new Dimension(6, 4); // Space between left edge and button, Space between rows
123  for (String dspType : dspList) {
124  boolean shouldAddMultiUserWarning = false;
125  constraints.weightx = 1;
126  //Add a spacer
127  Filler spacer = new Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
128  gridBagLayout.setConstraints(spacer, constraints);
129  jPanel1.add(spacer);
130  constraints.gridx++;
131  constraints.gridy++;
132  //Add the button
133  JToggleButton dspButton = createDspButton(dspType);
134  dspButton.addActionListener(cbActionListener);
135  if ((Case.getCurrentCaseThrows().getCaseType() == Case.CaseType.MULTI_USER_CASE) && dspType.equals(LocalDiskDSProcessor.getType())){
136  dspButton.setEnabled(false); //disable the button for local disk DSP when this is a multi user case
137  dspButton.setSelected(false);
138  shouldAddMultiUserWarning = true;
139  }
140  jPanel1.add(dspButton);
141  buttonGroup1.add(dspButton);
142  gridBagLayout.setConstraints(dspButton, constraints);
143  constraints.gridx++;
144  //Add space between the button and text
145  Filler buttonTextSpacer = new Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
146  gridBagLayout.setConstraints(buttonTextSpacer, constraints);
147  jPanel1.add(buttonTextSpacer);
148  constraints.gridx++;
149  //Add the text area serving as a label to the right of the button
150 
151  JTextArea myLabel = new JTextArea();
152  if (shouldAddMultiUserWarning) {
153  myLabel.setText(dspType + " - " + NbBundle.getMessage(this.getClass(), "AddImageWizardSelectDspVisual.multiUserWarning.text"));
154  myLabel.setEnabled(false); //gray out the text
155  } else {
156  myLabel.setText(dspType);
157  }
158  myLabel.setBackground(new Color(240, 240, 240));//matches background of panel
159  myLabel.setEditable(false);
160  myLabel.setWrapStyleWord(true);
161  myLabel.setLineWrap(true);
162  jPanel1.add(myLabel);
163  gridBagLayout.setConstraints(myLabel, constraints);
164  constraints.weightx = 0;
165  constraints.gridy++;
166  constraints.gridx = 0;
167  }
168  Component vertGlue = javax.swing.Box.createVerticalGlue();
169  jPanel1.add(vertGlue);
170  constraints.gridy++;
171  constraints.gridx = 0;
172  constraints.weighty = 1;
173  gridBagLayout.setConstraints(vertGlue, constraints);
174  jPanel1.setLayout(gridBagLayout);
175  }
176 
185  private List<String> getListOfDsps() {
186  List<String> dspList = new ArrayList<>();
187  final Map<String, DataSourceProcessor> datasourceProcessorsMap = new HashMap<>();
188  for (DataSourceProcessor dsProcessor : Lookup.getDefault().lookupAll(DataSourceProcessor.class)) {
189  if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
190  datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
191  } else {
192  logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
193  }
194  }
195  dspList.add(ImageDSProcessor.getType());
196  dspList.add(LocalDiskDSProcessor.getType());
197  dspList.add(LocalFilesDSProcessor.getType());
198  dspList.add(RawDSProcessor.getType());
199  // now add any addtional DSPs that haven't already been added
200  for (String dspType : datasourceProcessorsMap.keySet()) {
201  if (!dspList.contains(dspType)) {
202  dspList.add(dspType);
203  }
204  }
205  return dspList;
206  }
207 
215  private JToggleButton createDspButton(String dspType) {
216  JToggleButton dspButton = new JToggleButton();
217  dspButton.setMaximumSize(new java.awt.Dimension(48, 48));
218  dspButton.setMinimumSize(new java.awt.Dimension(48, 48));
219  dspButton.setPreferredSize(new java.awt.Dimension(48, 48));
220  dspButton.setName(dspType);
221  dspButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/modules/fileextmismatch/options-icon.png")));
222  dspButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/checkbox32.png")));
223  dspButton.setFocusable(false);
224  if (dspType.equals(selectedDsp)) {
225  dspButton.setSelected(true);
226  } else {
227  dspButton.setSelected(false);
228  }
229  return dspButton;
230  }
231 
232  @SuppressWarnings("unchecked")
233  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
234  private void initComponents() {
235 
236  buttonGroup1 = new javax.swing.ButtonGroup();
237  jScrollPane1 = new javax.swing.JScrollPane();
238  jPanel1 = new javax.swing.JPanel();
239  filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(6, 8), new java.awt.Dimension(6, 8), new java.awt.Dimension(6, 8));
240 
241  jPanel1.setLayout(new java.awt.GridBagLayout());
242  jPanel1.add(filler1, new java.awt.GridBagConstraints());
243 
244  jScrollPane1.setViewportView(jPanel1);
245 
246  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
247  this.setLayout(layout);
248  layout.setHorizontalGroup(
249  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250  .addGap(0, 588, Short.MAX_VALUE)
251  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE))
253  );
254  layout.setVerticalGroup(
255  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256  .addGap(0, 328, Short.MAX_VALUE)
257  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
259  );
260  }// </editor-fold>//GEN-END:initComponents
261 
262 
263  // Variables declaration - do not modify//GEN-BEGIN:variables
264  private javax.swing.ButtonGroup buttonGroup1;
265  private javax.swing.Box.Filler filler1;
266  private javax.swing.JPanel jPanel1;
267  private javax.swing.JScrollPane jScrollPane1;
268  // End of variables declaration//GEN-END:variables
269 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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