Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PhotoRecCarverIngestJobSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-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.modules.photoreccarver;
20 
21 import java.awt.Color;
22 import java.awt.Cursor;
23 import java.awt.Desktop;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.io.IOException;
27 import java.net.URI;
28 import java.net.URISyntaxException;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.logging.Level;
32 import java.util.stream.Collectors;
33 import java.util.stream.Stream;
34 import org.apache.commons.lang.StringUtils;
38 
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 final class PhotoRecCarverIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel {
44 
45  private static final Logger logger = Logger.getLogger(PhotoRecCarverIngestJobSettingsPanel.class.getName());
46  private static final String EXTENSION_LIST_SEPARATOR = ",";
47  private static final String PHOTOREC_TYPES_URL = "http://sleuthkit.org/autopsy/docs/user-docs/latest/photorec_carver_page.html";
48 
54  public PhotoRecCarverIngestJobSettingsPanel(PhotoRecCarverIngestJobSettings settings) {
55  initComponents();
56  customizeComponents(settings);
57  }
58 
64  private void customizeComponents(PhotoRecCarverIngestJobSettings settings) {
65  includeExcludeCheckbox.setSelected(settings.getExtensionFilterOption() != PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER);
66  extensionListTextfield.setText(String.join(EXTENSION_LIST_SEPARATOR, settings.getExtensions()));
67  includeRadioButton.setSelected(settings.getExtensionFilterOption() == PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE);
68  excludeRadioButton.setSelected(settings.getExtensionFilterOption() == PhotoRecCarverIngestJobSettings.ExtensionFilterOption.EXCLUDE);
69  keepCorruptedFilesCheckbox.setSelected(settings.isKeepCorruptedFiles());
70  setupTypesHyperlink();
71  setIncludePanelEnabled();
72  }
73 
78  private void setupTypesHyperlink() {
79  // taken from https://www.codejava.net/java-se/swing/how-to-create-hyperlink-with-jlabel-in-java-swing
80  this.fullListOfTypesHyperlink.setForeground(Color.BLUE.darker());
81  this.fullListOfTypesHyperlink.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
82  this.fullListOfTypesHyperlink.addMouseListener(new MouseAdapter() {
83  @Override
84  public void mouseClicked(MouseEvent e) {
85  try {
86  Desktop.getDesktop().browse(new URI(PHOTOREC_TYPES_URL));
87  } catch (IOException | URISyntaxException ex) {
88  logger.log(Level.WARNING, "There was an error going to types hyperlink: " + PHOTOREC_TYPES_URL, ex);
89  }
90  }
91  });
92 
93  }
94 
99  private void setIncludePanelEnabled() {
100  setIncludePanelEnabled(includeExcludeCheckbox.isSelected());
101  }
102 
109  private void setIncludePanelEnabled(boolean enabled) {
110  includeRadioButton.setEnabled(enabled);
111  excludeRadioButton.setEnabled(enabled);
112  extensionListLabel.setEnabled(enabled);
113  extensionListTextfield.setEnabled(enabled);
114  exampleLabel.setEnabled(enabled);
115  fullListOfTypesLabel.setEnabled(enabled);
116  }
117 
118  @Override
119  public IngestModuleIngestJobSettings getSettings() {
120  PhotoRecCarverIngestJobSettings.ExtensionFilterOption filterOption =
121  PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER;
122 
123  if (includeExcludeCheckbox.isSelected()) {
124  if (includeRadioButton.isSelected()) {
125  filterOption = PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE;
126  } else {
127  filterOption = PhotoRecCarverIngestJobSettings.ExtensionFilterOption.EXCLUDE;
128  }
129  }
130 
131 
132  return new PhotoRecCarverIngestJobSettings(
133  keepCorruptedFilesCheckbox.isSelected(),
134  filterOption,
135  getExtensions(extensionListTextfield.getText())
136  );
137  }
138 
139 
140 
149  private List<String> getExtensions(String combinedList) {
150  if (StringUtils.isBlank(combinedList)) {
151  return Collections.emptyList();
152  }
153 
154  return Stream.of(combinedList.split(EXTENSION_LIST_SEPARATOR))
155  .map(ext -> ext.trim())
156  .filter(ext -> StringUtils.isNotBlank(ext))
157  .sorted((a, b) -> a.toLowerCase().compareTo(b.toLowerCase()))
158  .collect(Collectors.toList());
159  }
160 
166  @SuppressWarnings("unchecked")
167  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
168  private void initComponents() {
169 
170  includeExcludeButtonGroup = new javax.swing.ButtonGroup();
171  keepCorruptedFilesCheckbox = new javax.swing.JCheckBox();
172  javax.swing.JLabel detectionSettingsLabel = new javax.swing.JLabel();
173  includeExcludeCheckbox = new javax.swing.JCheckBox();
174  excludeRadioButton = new javax.swing.JRadioButton();
175  exampleLabel = new javax.swing.JLabel();
176  fullListOfTypesLabel = new javax.swing.JLabel();
177  extensionListLabel = new javax.swing.JLabel();
178  extensionListTextfield = new javax.swing.JTextField();
179  includeRadioButton = new javax.swing.JRadioButton();
180  fullListOfTypesHyperlink = new javax.swing.JTextArea();
181 
182  setPreferredSize(null);
183 
184  org.openide.awt.Mnemonics.setLocalizedText(keepCorruptedFilesCheckbox, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.keepCorruptedFilesCheckbox.text")); // NOI18N
185 
186  detectionSettingsLabel.setFont(detectionSettingsLabel.getFont().deriveFont(detectionSettingsLabel.getFont().getStyle() | java.awt.Font.BOLD));
187  org.openide.awt.Mnemonics.setLocalizedText(detectionSettingsLabel, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.detectionSettingsLabel.text")); // NOI18N
188 
189  org.openide.awt.Mnemonics.setLocalizedText(includeExcludeCheckbox, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.includeExcludeCheckbox.text")); // NOI18N
190  includeExcludeCheckbox.addActionListener(new java.awt.event.ActionListener() {
191  public void actionPerformed(java.awt.event.ActionEvent evt) {
192  includeExcludeCheckboxActionPerformed(evt);
193  }
194  });
195 
196  includeExcludeButtonGroup.add(excludeRadioButton);
197  org.openide.awt.Mnemonics.setLocalizedText(excludeRadioButton, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.excludeRadioButton.text")); // NOI18N
198 
199  org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.exampleLabel.text")); // NOI18N
200 
201  org.openide.awt.Mnemonics.setLocalizedText(fullListOfTypesLabel, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.fullListOfTypesLabel.text")); // NOI18N
202 
203  org.openide.awt.Mnemonics.setLocalizedText(extensionListLabel, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.extensionListLabel.text")); // NOI18N
204 
205  extensionListTextfield.setText(org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.extensionListTextfield.text")); // NOI18N
206 
207  includeExcludeButtonGroup.add(includeRadioButton);
208  includeRadioButton.setSelected(true);
209  org.openide.awt.Mnemonics.setLocalizedText(includeRadioButton, org.openide.util.NbBundle.getMessage(PhotoRecCarverIngestJobSettingsPanel.class, "PhotoRecCarverIngestJobSettingsPanel.includeRadioButton.text")); // NOI18N
210 
211  fullListOfTypesHyperlink.setEditable(false);
212  fullListOfTypesHyperlink.setColumns(20);
213  fullListOfTypesHyperlink.setLineWrap(true);
214  fullListOfTypesHyperlink.setRows(5);
215  fullListOfTypesHyperlink.setText(PHOTOREC_TYPES_URL);
216  fullListOfTypesHyperlink.setFocusable(false);
217  fullListOfTypesHyperlink.setOpaque(false);
218 
219  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
220  this.setLayout(layout);
221  layout.setHorizontalGroup(
222  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
223  .addGroup(layout.createSequentialGroup()
224  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
225  .addGroup(layout.createSequentialGroup()
226  .addContainerGap()
227  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addComponent(detectionSettingsLabel)
229  .addComponent(keepCorruptedFilesCheckbox)
230  .addComponent(includeExcludeCheckbox)))
231  .addGroup(layout.createSequentialGroup()
232  .addGap(31, 31, 31)
233  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234  .addComponent(includeRadioButton)
235  .addComponent(excludeRadioButton)
236  .addComponent(exampleLabel)
237  .addComponent(extensionListTextfield, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
238  .addComponent(fullListOfTypesLabel)
239  .addComponent(extensionListLabel)
240  .addComponent(fullListOfTypesHyperlink, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))))
241  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
242  );
243  layout.setVerticalGroup(
244  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245  .addGroup(layout.createSequentialGroup()
246  .addContainerGap()
247  .addComponent(detectionSettingsLabel)
248  .addGap(0, 2, 2)
249  .addComponent(keepCorruptedFilesCheckbox)
250  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
251  .addComponent(includeExcludeCheckbox)
252  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
253  .addComponent(includeRadioButton)
254  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
255  .addComponent(excludeRadioButton)
256  .addGap(4, 4, 4)
257  .addComponent(extensionListLabel)
258  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
259  .addComponent(extensionListTextfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
260  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
261  .addComponent(exampleLabel)
262  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
263  .addComponent(fullListOfTypesLabel)
264  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
265  .addComponent(fullListOfTypesHyperlink, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
266  .addContainerGap())
267  );
268  }// </editor-fold>//GEN-END:initComponents
269 
270  private void includeExcludeCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_includeExcludeCheckboxActionPerformed
271  setIncludePanelEnabled();
272  }//GEN-LAST:event_includeExcludeCheckboxActionPerformed
273 
274  // Variables declaration - do not modify//GEN-BEGIN:variables
275  private javax.swing.JLabel exampleLabel;
276  private javax.swing.JRadioButton excludeRadioButton;
277  private javax.swing.JLabel extensionListLabel;
278  private javax.swing.JTextField extensionListTextfield;
279  private javax.swing.JTextArea fullListOfTypesHyperlink;
280  private javax.swing.JLabel fullListOfTypesLabel;
281  private javax.swing.ButtonGroup includeExcludeButtonGroup;
282  private javax.swing.JCheckBox includeExcludeCheckbox;
283  private javax.swing.JRadioButton includeRadioButton;
284  private javax.swing.JCheckBox keepCorruptedFilesCheckbox;
285  // End of variables declaration//GEN-END:variables
286 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.