19 package org.sleuthkit.autopsy.casemodule;
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;
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;
50 @SuppressWarnings(
"PMD.SingularField")
51 final class AddImageWizardSelectDspVisual extends JPanel {
53 private static final Logger logger = Logger.getLogger(AddImageWizardSelectDspVisual.class.getName());
54 private String selectedDsp;
59 AddImageWizardSelectDspVisual(String lastDspUsed) {
61 selectedDsp = lastDspUsed;
64 if ((Case.getCurrentCaseThrows().getCaseType() == Case.CaseType.MULTI_USER_CASE) && selectedDsp.equals(LocalDiskDSProcessor.getType())) {
65 selectedDsp = ImageDSProcessor.getType();
67 createDataSourceProcessorButtons();
68 }
catch (NoCurrentCaseException ex) {
69 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
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();
97 String getSelectedDsp() {
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 {
108 ActionListener cbActionListener =
new ActionListener() {
110 public void actionPerformed(ActionEvent e) {
114 List<String> dspList = getListOfDsps();
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);
124 for (String dspType : dspList) {
125 boolean shouldAddMultiUserWarning =
false;
126 constraints.weightx = 1;
128 Filler spacer =
new Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
129 gridBagLayout.setConstraints(spacer, constraints);
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);
138 dspButton.setSelected(
false);
139 shouldAddMultiUserWarning =
true;
141 jPanel1.add(dspButton);
142 buttonGroup1.add(dspButton);
143 gridBagLayout.setConstraints(dspButton, constraints);
146 Filler buttonTextSpacer =
new Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
147 gridBagLayout.setConstraints(buttonTextSpacer, constraints);
148 jPanel1.add(buttonTextSpacer);
152 JTextArea myLabel =
new JTextArea();
153 if (shouldAddMultiUserWarning) {
154 myLabel.setText(dspType +
" - " + NbBundle.getMessage(
this.getClass(),
"AddImageWizardSelectDspVisual.multiUserWarning.text"));
155 myLabel.setEnabled(
false);
157 myLabel.setText(dspType);
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;
167 constraints.gridx = 0;
169 Component vertGlue = javax.swing.Box.createVerticalGlue();
170 jPanel1.add(vertGlue);
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);
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);
196 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
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());
205 for (String dspType : datasourceProcessorsMap.keySet()) {
206 if (!dspList.contains(dspType)) {
207 dspList.add(dspType);
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);
232 dspButton.setSelected(
false);
237 @SuppressWarnings(
"unchecked")
239 private
void initComponents() {
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));
246 jPanel1.setLayout(
new java.awt.GridBagLayout());
247 jPanel1.add(filler1,
new java.awt.GridBagConstraints());
249 jScrollPane1.setViewportView(jPanel1);
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))
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))
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;