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

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.