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;
51 @SuppressWarnings(
"PMD.SingularField")
52 final class AddImageWizardSelectDspVisual extends JPanel {
54 private static final Logger logger = Logger.getLogger(AddImageWizardSelectDspVisual.class.getName());
55 private String selectedDsp;
60 AddImageWizardSelectDspVisual(String lastDspUsed) {
62 selectedDsp = lastDspUsed;
65 if ((Case.getCurrentCaseThrows().getCaseType() == Case.CaseType.MULTI_USER_CASE) && selectedDsp.equals(LocalDiskDSProcessor.getType())) {
66 selectedDsp = ImageDSProcessor.getType();
68 createDataSourceProcessorButtons();
69 }
catch (NoCurrentCaseException ex) {
70 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
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();
98 String getSelectedDsp() {
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 {
109 ActionListener cbActionListener =
new ActionListener() {
111 public void actionPerformed(ActionEvent e) {
115 List<String> dspList = getListOfDsps();
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);
125 for (String dspType : dspList) {
126 boolean shouldAddMultiUserWarning =
false;
127 constraints.weightx = 1;
129 Filler spacer =
new Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
130 gridBagLayout.setConstraints(spacer, constraints);
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);
139 dspButton.setSelected(
false);
140 shouldAddMultiUserWarning =
true;
142 jPanel1.add(dspButton);
143 buttonGroup1.add(dspButton);
144 gridBagLayout.setConstraints(dspButton, constraints);
147 Filler buttonTextSpacer =
new Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
148 gridBagLayout.setConstraints(buttonTextSpacer, constraints);
149 jPanel1.add(buttonTextSpacer);
153 JTextArea myLabel =
new JTextArea();
154 if (shouldAddMultiUserWarning) {
155 myLabel.setText(dspType +
" - " + NbBundle.getMessage(
this.getClass(),
"AddImageWizardSelectDspVisual.multiUserWarning.text"));
156 myLabel.setEnabled(
false);
158 myLabel.setText(dspType);
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;
168 constraints.gridx = 0;
170 Component vertGlue = javax.swing.Box.createVerticalGlue();
171 jPanel1.add(vertGlue);
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);
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);
197 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
201 for (DataSourceProcessor dsProcessor : JythonModuleLoader.getDataSourceProcessorModules()) {
202 if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
203 datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
205 logger.log(Level.SEVERE,
"discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType());
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());
215 for (String dspType : datasourceProcessorsMap.keySet()) {
216 if (!dspList.contains(dspType)) {
217 dspList.add(dspType);
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);
242 dspButton.setSelected(
false);
247 @SuppressWarnings(
"unchecked")
249 private
void initComponents() {
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));
256 jPanel1.setLayout(
new java.awt.GridBagLayout());
257 jPanel1.add(filler1,
new java.awt.GridBagConstraints());
259 jScrollPane1.setViewportView(jPanel1);
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))
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))
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;