19 package org.sleuthkit.autopsy.casemodule;
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;
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;
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());
204 for (String dspType : datasourceProcessorsMap.keySet()) {
205 if (!dspList.contains(dspType)) {
206 dspList.add(dspType);
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);
231 dspButton.setSelected(
false);
236 @SuppressWarnings(
"unchecked")
238 private
void initComponents() {
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));
245 jPanel1.setLayout(
new java.awt.GridBagLayout());
246 jPanel1.add(filler1,
new java.awt.GridBagConstraints());
248 jScrollPane1.setViewportView(jPanel1);
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))
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))
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;
synchronized static Logger getLogger(String name)