19 package org.sleuthkit.autopsy.modules.encryptiondetection;
21 import java.text.ParseException;
22 import java.util.logging.Level;
23 import javax.swing.text.DefaultFormatter;
24 import javax.swing.text.DefaultFormatterFactory;
32 @SuppressWarnings(
"PMD.SingularField")
33 final class EncryptionDetectionIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel {
35 private static final int MEGABYTE_SIZE = 1048576;
36 private static final int INVALID_TEXT_FIELD_INPUT_RETURN = -1;
38 private final Logger logger = Logger.getLogger(EncryptionDetectionIngestJobSettingsPanel.class.getName());
40 private final DefaultFormatterFactory minimumFileSizeTextFormatterFactory =
new DefaultFormatterFactory(
new StringIntegerFormatter());
41 private final DefaultFormatterFactory minimumEntropyTextFormatterFactory =
new DefaultFormatterFactory(
new StringDoubleFormatter());
48 public EncryptionDetectionIngestJobSettingsPanel(EncryptionDetectionIngestJobSettings settings) {
50 customizeComponents(settings);
58 private void customizeComponents(EncryptionDetectionIngestJobSettings settings) {
59 minimumEntropyTextbox.setText(String.valueOf(settings.getMinimumEntropy()));
60 minimumFileSizeTextbox.setText(String.valueOf(settings.getMinimumFileSize() / MEGABYTE_SIZE));
61 fileSizeMultiplesEnforcedCheckbox.setSelected(settings.isFileSizeMultipleEnforced());
62 slackFilesAllowedCheckbox.setSelected(settings.isSlackFilesAllowed());
66 public IngestModuleIngestJobSettings getSettings() {
67 return new EncryptionDetectionIngestJobSettings(
68 Double.valueOf(minimumEntropyTextbox.getText()),
69 Integer.valueOf(minimumFileSizeTextbox.getText()) * MEGABYTE_SIZE,
70 fileSizeMultiplesEnforcedCheckbox.isSelected(),
71 slackFilesAllowedCheckbox.isSelected());
82 return Double.parseDouble(
string);
83 }
catch (NumberFormatException ex) {
84 logger.log(Level.WARNING, String.format(
"The String input '%s' is not valid for Double conversion.",
string), ex);
90 return new Double(INVALID_TEXT_FIELD_INPUT_RETURN);
103 return Integer.parseInt(
string);
104 }
catch (NumberFormatException ex) {
105 logger.log(Level.WARNING, String.format(
"The String input '%s' is not valid for Integer conversion.",
string), ex);
111 return INVALID_TEXT_FIELD_INPUT_RETURN;
121 @SuppressWarnings(
"unchecked")
123 private
void initComponents() {
125 fileSizeMultiplesEnforcedCheckbox =
new javax.swing.JCheckBox();
126 slackFilesAllowedCheckbox =
new javax.swing.JCheckBox();
127 minimumEntropyLabel =
new javax.swing.JLabel();
128 minimumFileSizeLabel =
new javax.swing.JLabel();
129 mbLabel =
new javax.swing.JLabel();
130 detectionSettingsLabel =
new javax.swing.JLabel();
131 minimumFileSizeTextbox =
new javax.swing.JFormattedTextField();
132 minimumEntropyTextbox =
new javax.swing.JFormattedTextField();
134 org.openide.awt.Mnemonics.setLocalizedText(fileSizeMultiplesEnforcedCheckbox,
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.fileSizeMultiplesEnforcedCheckbox.text"));
136 org.openide.awt.Mnemonics.setLocalizedText(slackFilesAllowedCheckbox,
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.slackFilesAllowedCheckbox.text"));
138 org.openide.awt.Mnemonics.setLocalizedText(minimumEntropyLabel,
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.minimumEntropyLabel.text"));
140 org.openide.awt.Mnemonics.setLocalizedText(minimumFileSizeLabel,
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.minimumFileSizeLabel.text"));
142 org.openide.awt.Mnemonics.setLocalizedText(mbLabel,
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.mbLabel.text"));
144 detectionSettingsLabel.setFont(detectionSettingsLabel.getFont().deriveFont(detectionSettingsLabel.getFont().getStyle() | java.awt.Font.BOLD));
145 org.openide.awt.Mnemonics.setLocalizedText(detectionSettingsLabel,
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.detectionSettingsLabel.text"));
147 minimumFileSizeTextbox.setFormatterFactory(minimumFileSizeTextFormatterFactory);
148 minimumFileSizeTextbox.setText(
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.minimumFileSizeTextbox.text"));
149 minimumFileSizeTextbox.addActionListener(
new java.awt.event.ActionListener() {
150 public void actionPerformed(java.awt.event.ActionEvent evt) {
151 minimumFileSizeTextboxActionPerformed(evt);
155 minimumEntropyTextbox.setFormatterFactory(minimumEntropyTextFormatterFactory);
156 minimumEntropyTextbox.setText(
org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class,
"EncryptionDetectionIngestJobSettingsPanel.minimumEntropyTextbox.text"));
158 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
159 this.setLayout(layout);
160 layout.setHorizontalGroup(
161 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162 .addGroup(layout.createSequentialGroup()
164 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
165 .addComponent(slackFilesAllowedCheckbox)
166 .addComponent(detectionSettingsLabel)
167 .addComponent(fileSizeMultiplesEnforcedCheckbox)
168 .addGroup(layout.createSequentialGroup()
169 .addComponent(minimumFileSizeLabel)
170 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
171 .addComponent(minimumFileSizeTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
172 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
173 .addComponent(mbLabel))
174 .addGroup(layout.createSequentialGroup()
175 .addComponent(minimumEntropyLabel)
176 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
177 .addComponent(minimumEntropyTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
178 .addContainerGap(33, Short.MAX_VALUE))
180 layout.setVerticalGroup(
181 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
182 .addGroup(layout.createSequentialGroup()
184 .addComponent(detectionSettingsLabel)
186 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
187 .addComponent(minimumEntropyLabel)
188 .addComponent(minimumEntropyTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
189 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
190 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
191 .addComponent(mbLabel)
192 .addComponent(minimumFileSizeLabel)
193 .addComponent(minimumFileSizeTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
194 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
195 .addComponent(fileSizeMultiplesEnforcedCheckbox)
196 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
197 .addComponent(slackFilesAllowedCheckbox)
198 .addContainerGap(60, Short.MAX_VALUE))
202 private void minimumFileSizeTextboxActionPerformed(java.awt.event.ActionEvent evt) {
207 private javax.swing.JLabel detectionSettingsLabel;
208 private javax.swing.JCheckBox fileSizeMultiplesEnforcedCheckbox;
209 private javax.swing.JLabel mbLabel;
210 private javax.swing.JLabel minimumEntropyLabel;
211 private javax.swing.JFormattedTextField minimumEntropyTextbox;
212 private javax.swing.JLabel minimumFileSizeLabel;
213 private javax.swing.JFormattedTextField minimumFileSizeTextbox;
214 private javax.swing.JCheckBox slackFilesAllowedCheckbox;
Object stringToValue(String string)
Object stringToValue(String string)