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

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