Autopsy  4.9.1
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 javax.swing.SwingUtilities;
40 import org.openide.util.Lookup;
41 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  // now add any addtional DSPs that haven't already been added
204  for (String dspType : datasourceProcessorsMap.keySet()) {
205  if (!dspList.contains(dspType)) {
206  dspList.add(dspType);
207  }
208  }
209  return dspList;
210  }
211 
219  private JToggleButton createDspButton(String dspType) {
220  JToggleButton dspButton = new JToggleButton();
221  dspButton.setMaximumSize(new java.awt.Dimension(48, 48));
222  dspButton.setMinimumSize(new java.awt.Dimension(48, 48));
223  dspButton.setPreferredSize(new java.awt.Dimension(48, 48));
224  dspButton.setName(dspType);
225  dspButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/modules/fileextmismatch/options-icon.png")));
226  dspButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/checkbox32.png")));
227  dspButton.setFocusable(false);
228  if (dspType.equals(selectedDsp)) {
229  dspButton.setSelected(true);
230  } else {
231  dspButton.setSelected(false);
232  }
233  return dspButton;
234  }
235 
236  @SuppressWarnings("unchecked")
237  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
238  private void initComponents() {
239 
240  buttonGroup1 = new javax.swing.ButtonGroup();
241  jScrollPane1 = new javax.swing.JScrollPane();
242  jPanel1 = new javax.swing.JPanel();
243  filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(6, 8), new java.awt.Dimension(6, 8), new java.awt.Dimension(6, 8));
244 
245  jPanel1.setLayout(new java.awt.GridBagLayout());
246  jPanel1.add(filler1, new java.awt.GridBagConstraints());
247 
248  jScrollPane1.setViewportView(jPanel1);
249 
250  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
251  this.setLayout(layout);
252  layout.setHorizontalGroup(
253  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
254  .addGap(0, 588, Short.MAX_VALUE)
255  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE))
257  );
258  layout.setVerticalGroup(
259  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260  .addGap(0, 328, Short.MAX_VALUE)
261  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
262  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
263  );
264  }// </editor-fold>//GEN-END:initComponents
265 
266 
267  // Variables declaration - do not modify//GEN-BEGIN:variables
268  private javax.swing.ButtonGroup buttonGroup1;
269  private javax.swing.Box.Filler filler1;
270  private javax.swing.JPanel jPanel1;
271  private javax.swing.JScrollPane jScrollPane1;
272  // End of variables declaration//GEN-END:variables
273 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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