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

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