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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.