Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearchJobSettingsPanel.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2011-2018 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 */
19package org.sleuthkit.autopsy.keywordsearch;
20
21import java.beans.PropertyChangeEvent;
22import java.beans.PropertyChangeListener;
23import java.util.ArrayList;
24import java.util.HashMap;
25import java.util.List;
26import java.util.Map;
27import javax.swing.JTable;
28import javax.swing.ListSelectionModel;
29import javax.swing.table.AbstractTableModel;
30import javax.swing.table.TableColumn;
31import org.sleuthkit.autopsy.coreutils.PlatformUtil;
32import org.sleuthkit.autopsy.coreutils.StringExtract.StringExtractUnicodeTable.SCRIPT;
33import org.sleuthkit.autopsy.guiutils.SimpleTableCellRenderer;
34import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings;
35import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettingsPanel;
36import org.sleuthkit.autopsy.keywordsearch.KeywordSearchIngestModule.StringsExtractOptions;
37
41@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42public final class KeywordSearchJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements PropertyChangeListener {
43
44 private static final long serialVersionUID = 1L;
46 private final List<String> keywordListNames = new ArrayList<>();
47 private final Map<String, Boolean> keywordListStates = new HashMap<>();
48 private final XmlKeywordSearchList keywordListsManager = XmlKeywordSearchList.getCurrent();
49
50
51 KeywordSearchJobSettingsPanel(KeywordSearchJobSettings initialSettings) {
54 initializeKeywordListSettings(initialSettings);
55 }
56
58 keywordListNames.clear();
59 keywordListStates.clear();
60 List<KeywordList> keywordLists = keywordListsManager.getListsL();
61 for (KeywordList list : keywordLists) {
62 String listName = list.getName();
63 keywordListNames.add(listName);
64 keywordListStates.put(listName, settings.keywordListIsEnabled(listName));
65 }
66
67 ocrCheckBox.setSelected(settings.isOCREnabled());
68 limitedOcrCheckbox.setSelected(settings.isLimitedOCREnabled());
69 ocrOnlyCheckbox.setSelected(settings.isOCROnly());
70 solrCheckbox.setSelected(settings.isIndexToSolrEnabled());
71
73 }
74
79 private void handleOcrEnabled(boolean ocrEnabled) {
80 boolean platformSupported = PlatformUtil.isWindowsOS() && PlatformUtil.is64BitOS();
81 ocrCheckBox.setEnabled(platformSupported);
82 limitedOcrCheckbox.setEnabled(platformSupported && ocrEnabled);
83 ocrOnlyCheckbox.setEnabled(platformSupported && ocrEnabled);
84 }
85
86 private void customizeComponents() {
90 keywordListsManager.addPropertyChangeListener(this);
91 languagesLabel.setText("<html>" + org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text") + "</html>"); // NOI18N NON-NLS
92
93 // the gui builder does not explicitly set these to false.
94 listsTable.setShowHorizontalLines(false);
95 listsTable.setShowVerticalLines(false);
96 }
97
99 listsTable.setModel(tableModel);
100 listsTable.setTableHeader(null);
101 listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
102 final int width = listsScrollPane.getPreferredSize().width;
103 listsTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
104 TableColumn column;
105 for (int i = 0; i < listsTable.getColumnCount(); i++) {
106 column = listsTable.getColumnModel().getColumn(i);
107 if (i == 0) {
108 column.setPreferredWidth(((int) (width * 0.07)));
109 } else {
110 column.setPreferredWidth(((int) (width * 0.92)));
111 }
112 }
113 }
114
115 private void displayLanguages() {
116 List<SCRIPT> scripts = KeywordSearchSettings.getStringExtractScripts();
117 StringBuilder langs = new StringBuilder();
118 langs.append("<html>"); //NON-NLS
119 for (int i = 0; i < scripts.size(); i++) {
120 langs.append(scripts.get(i).toString());
121 if (i + 1 < scripts.size()) {
122 langs.append(", ");
123 }
124 }
125 langs.append("</html>"); //NON-NLS
126 String langsS = langs.toString();
127 this.languagesValLabel.setText(langsS);
128 this.languagesValLabel.setToolTipText(langsS);
129 }
130
131 private void displayEncodings() {
132 String utf8 = KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString());
133 String utf16 = KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString());
134 ArrayList<String> encodingsList = new ArrayList<>();
135 if (utf8 == null || Boolean.parseBoolean(utf8)) {
136 encodingsList.add("UTF8");
137 }
138 if (utf16 == null || Boolean.parseBoolean(utf16)) {
139 encodingsList.add("UTF16"); //NON-NLS
140 }
141 String encodings = encodingsList.toString();
142 encodings = encodings.substring(1, encodings.length() - 1);
143 keywordSearchEncodings.setText(encodings);
144 }
145
146 @Override
147 public void propertyChange(PropertyChangeEvent event) {
148 if (event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_ADDED.name())
149 || event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_DELETED.name())
150 || event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_UPDATED.name())
151 || event.getPropertyName().equals(XmlKeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED.name())) {
152 update();
153 }
154 }
155
156 private void update() {
160 tableModel.fireTableDataChanged();
161 }
162
164 // Get the names of the current set of keyword lists.
165 List<KeywordList> keywordLists = keywordListsManager.getListsL();
166 List<String> currentListNames = new ArrayList<>();
167 for (KeywordList list : keywordLists) {
168 currentListNames.add(list.getName());
169 }
170
171 // Remove deleted lists from the list states map.
172 for (String listName : keywordListNames) {
173 if (!currentListNames.contains(listName)) {
174 keywordListStates.remove(listName);
175 }
176 }
177
178 // Reset the names list and add any new lists to the states map.
179 keywordListNames.clear();
180 for (String currentListName : currentListNames) {
181 keywordListNames.add(currentListName);
182 if (!keywordListStates.containsKey(currentListName)) {
183 keywordListStates.put(currentListName, Boolean.TRUE);
184 }
185 }
186 }
187
188 @Override
190 List<String> enabledListNames = new ArrayList<>();
191 List<String> disabledListNames = new ArrayList<>();
192 for (String listName : keywordListNames) {
193 if (keywordListStates.get(listName)) {
194 enabledListNames.add(listName);
195 } else {
196 disabledListNames.add(listName);
197 }
198 }
199 return new KeywordSearchJobSettings(enabledListNames, disabledListNames,
200 this.ocrCheckBox.isSelected(), this.limitedOcrCheckbox.isSelected(), this.ocrOnlyCheckbox.isSelected(), this.solrCheckbox.isSelected());
201 }
202
203 void reset(KeywordSearchJobSettings newSettings) {
204 initializeKeywordListSettings(newSettings);
205 displayLanguages();
206 displayEncodings();
207 tableModel.fireTableDataChanged();
208 }
209
210 private class KeywordListsTableModel extends AbstractTableModel {
211
212 @Override
213 public int getRowCount() {
214 return KeywordSearchJobSettingsPanel.this.keywordListNames.size();
215 }
216
217 @Override
218 public int getColumnCount() {
219 return 2;
220 }
221
222 @Override
223 public Object getValueAt(int rowIndex, int columnIndex) {
224 String listName = KeywordSearchJobSettingsPanel.this.keywordListNames.get(rowIndex);
225 if (columnIndex == 0) {
226 return keywordListStates.get(listName);
227 } else {
228 return listName;
229 }
230 }
231
232 @Override
233 public boolean isCellEditable(int rowIndex, int columnIndex) {
234 return columnIndex == 0;
235 }
236
237 @Override
238 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
239 String listName = KeywordSearchJobSettingsPanel.this.keywordListNames.get(rowIndex);
240 if (columnIndex == 0) {
241 keywordListStates.put(listName, (Boolean) aValue);
242 }
243 }
244
245 @Override
246 public Class<?> getColumnClass(int c) {
247 return getValueAt(0, c).getClass();
248 }
249 }
250
256 @SuppressWarnings("unchecked")
257 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
258 private void initComponents() {
259 java.awt.GridBagConstraints gridBagConstraints;
260
261 listsScrollPane = new javax.swing.JScrollPane();
262 listsTable = new javax.swing.JTable();
263 titleLabel = new javax.swing.JLabel();
264 languagesLabel = new javax.swing.JLabel();
265 languagesValLabel = new javax.swing.JLabel();
266 encodingsLabel = new javax.swing.JLabel();
267 keywordSearchEncodings = new javax.swing.JLabel();
268 ocrCheckBox = new javax.swing.JCheckBox();
269 limitedOcrCheckbox = new javax.swing.JCheckBox();
270 ocrOnlyCheckbox = new javax.swing.JCheckBox();
271 solrCheckbox = new javax.swing.JCheckBox();
272
273 setMinimumSize(new java.awt.Dimension(250, 250));
274 setPreferredSize(new java.awt.Dimension(250, 250));
275 setLayout(new java.awt.GridBagLayout());
276
277 listsScrollPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
278 listsScrollPane.setMinimumSize(new java.awt.Dimension(250, 48));
279 listsScrollPane.setPreferredSize(new java.awt.Dimension(250, 48));
280
281 listsTable.setBackground(new java.awt.Color(240, 240, 240));
282 listsTable.setModel(new javax.swing.table.DefaultTableModel(
283 new Object [][] {
284
285 },
286 new String [] {
287
288 }
289 ));
290 listsTable.setMaximumSize(new java.awt.Dimension(32767, 32767));
291 listsTable.setMinimumSize(new java.awt.Dimension(20, 200));
292 listsTable.setPreferredSize(null);
293 listsScrollPane.setViewportView(listsTable);
294 listsTable.setDefaultRenderer(String.class, new SimpleTableCellRenderer());
295
296 gridBagConstraints = new java.awt.GridBagConstraints();
297 gridBagConstraints.gridx = 0;
298 gridBagConstraints.gridy = 1;
299 gridBagConstraints.gridwidth = 2;
300 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
301 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
302 gridBagConstraints.weightx = 1.0;
303 gridBagConstraints.weighty = 1.0;
304 gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
305 add(listsScrollPane, gridBagConstraints);
306
307 titleLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.titleLabel.text")); // NOI18N
308 gridBagConstraints = new java.awt.GridBagConstraints();
309 gridBagConstraints.gridx = 0;
310 gridBagConstraints.gridy = 0;
311 gridBagConstraints.gridwidth = 2;
312 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
313 gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
314 add(titleLabel, gridBagConstraints);
315
316 languagesLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text")); // NOI18N
317 languagesLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.toolTipText")); // NOI18N
318 languagesLabel.setPreferredSize(new java.awt.Dimension(294, 35));
319 languagesLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
320 gridBagConstraints = new java.awt.GridBagConstraints();
321 gridBagConstraints.gridx = 0;
322 gridBagConstraints.gridy = 2;
323 gridBagConstraints.gridwidth = 2;
324 gridBagConstraints.ipadx = 25;
325 gridBagConstraints.ipady = -22;
326 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
327 gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
328 add(languagesLabel, gridBagConstraints);
329
330 languagesValLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.text")); // NOI18N
331 languagesValLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.toolTipText")); // NOI18N
332 gridBagConstraints = new java.awt.GridBagConstraints();
333 gridBagConstraints.gridx = 0;
334 gridBagConstraints.gridy = 3;
335 gridBagConstraints.gridwidth = 2;
336 gridBagConstraints.ipadx = 270;
337 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
338 gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
339 add(languagesValLabel, gridBagConstraints);
340
341 encodingsLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.encodingsLabel.text")); // NOI18N
342 gridBagConstraints = new java.awt.GridBagConstraints();
343 gridBagConstraints.gridx = 0;
344 gridBagConstraints.gridy = 4;
345 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
346 gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
347 add(encodingsLabel, gridBagConstraints);
348
349 keywordSearchEncodings.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.keywordSearchEncodings.text")); // NOI18N
350 gridBagConstraints = new java.awt.GridBagConstraints();
351 gridBagConstraints.gridx = 1;
352 gridBagConstraints.gridy = 4;
353 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
354 gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
355 add(keywordSearchEncodings, gridBagConstraints);
356
357 ocrCheckBox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.ocrCheckBox.text")); // NOI18N
358 ocrCheckBox.addActionListener(new java.awt.event.ActionListener() {
359 public void actionPerformed(java.awt.event.ActionEvent evt) {
360 ocrCheckBoxActionPerformed(evt);
361 }
362 });
363 gridBagConstraints = new java.awt.GridBagConstraints();
364 gridBagConstraints.gridx = 0;
365 gridBagConstraints.gridy = 5;
366 gridBagConstraints.gridwidth = 2;
367 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
368 gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
369 add(ocrCheckBox, gridBagConstraints);
370
371 limitedOcrCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.limitedOcrCheckbox.text")); // NOI18N
372 limitedOcrCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
373 limitedOcrCheckbox.addActionListener(new java.awt.event.ActionListener() {
374 public void actionPerformed(java.awt.event.ActionEvent evt) {
375 limitedOcrCheckboxActionPerformed(evt);
376 }
377 });
378 gridBagConstraints = new java.awt.GridBagConstraints();
379 gridBagConstraints.gridx = 0;
380 gridBagConstraints.gridy = 7;
381 gridBagConstraints.gridwidth = 2;
382 gridBagConstraints.ipadx = 216;
383 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
384 gridBagConstraints.insets = new java.awt.Insets(0, 31, 0, 0);
385 add(limitedOcrCheckbox, gridBagConstraints);
386
387 ocrOnlyCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.ocrOnlyCheckbox.text")); // NOI18N
388 ocrOnlyCheckbox.addActionListener(new java.awt.event.ActionListener() {
389 public void actionPerformed(java.awt.event.ActionEvent evt) {
390 ocrOnlyCheckboxActionPerformed(evt);
391 }
392 });
393 gridBagConstraints = new java.awt.GridBagConstraints();
394 gridBagConstraints.gridx = 0;
395 gridBagConstraints.gridy = 6;
396 gridBagConstraints.gridwidth = 2;
397 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
398 gridBagConstraints.insets = new java.awt.Insets(0, 31, 0, 0);
399 add(ocrOnlyCheckbox, gridBagConstraints);
400
401 solrCheckbox.setSelected(true);
402 solrCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.solrCheckbox.text")); // NOI18N
403 gridBagConstraints = new java.awt.GridBagConstraints();
404 gridBagConstraints.gridx = 0;
405 gridBagConstraints.gridy = 8;
406 gridBagConstraints.gridwidth = 2;
407 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
408 gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 0);
409 add(solrCheckbox, gridBagConstraints);
410 }// </editor-fold>//GEN-END:initComponents
411
412 private void ocrCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocrCheckBoxActionPerformed
413 handleOcrEnabled(ocrCheckBox.isSelected());
414 firePropertyChange(KeywordSearchOptionsPanelController.PROP_CHANGED, null, null);
415 }//GEN-LAST:event_ocrCheckBoxActionPerformed
416
417 private void limitedOcrCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limitedOcrCheckboxActionPerformed
418 firePropertyChange(KeywordSearchOptionsPanelController.PROP_CHANGED, null, null);
419 }//GEN-LAST:event_limitedOcrCheckboxActionPerformed
420
421 private void ocrOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocrOnlyCheckboxActionPerformed
422 // TODO add your handling code here:
423 }//GEN-LAST:event_ocrOnlyCheckboxActionPerformed
424
425 // Variables declaration - do not modify//GEN-BEGIN:variables
426 private javax.swing.JLabel encodingsLabel;
427 private javax.swing.JLabel keywordSearchEncodings;
428 private javax.swing.JLabel languagesLabel;
429 private javax.swing.JLabel languagesValLabel;
430 private javax.swing.JCheckBox limitedOcrCheckbox;
431 private javax.swing.JScrollPane listsScrollPane;
432 private javax.swing.JTable listsTable;
433 private javax.swing.JCheckBox ocrCheckBox;
434 private javax.swing.JCheckBox ocrOnlyCheckbox;
435 private javax.swing.JCheckBox solrCheckbox;
436 private javax.swing.JLabel titleLabel;
437 // End of variables declaration//GEN-END:variables
438}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.