Autopsy  4.19.3
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  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import javax.swing.JTable;
28 import javax.swing.ListSelectionModel;
29 import javax.swing.table.AbstractTableModel;
30 import javax.swing.table.TableColumn;
37 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 public final class KeywordSearchJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements PropertyChangeListener {
43  private final KeywordListsTableModel tableModel = new KeywordListsTableModel();
44  private final List<String> keywordListNames = new ArrayList<>();
45  private final Map<String, Boolean> keywordListStates = new HashMap<>();
46  private final XmlKeywordSearchList keywordListsManager = XmlKeywordSearchList.getCurrent();
47 
48 
50  initComponents();
51  customizeComponents();
52  initializeKeywordListSettings(initialSettings);
53  }
54 
56  keywordListNames.clear();
57  keywordListStates.clear();
58  List<KeywordList> keywordLists = keywordListsManager.getListsL();
59  for (KeywordList list : keywordLists) {
60  String listName = list.getName();
61  keywordListNames.add(listName);
62  keywordListStates.put(listName, settings.keywordListIsEnabled(listName));
63  }
64 
65  ocrCheckBox.setSelected(settings.isOCREnabled());
66  limitedOcrCheckbox.setSelected(settings.isLimitedOCREnabled());
67  ocrOnlyCheckbox.setSelected(settings.isOCROnly());
68 
69  handleOcrEnabled(settings.isOCREnabled());
70  }
71 
76  private void handleOcrEnabled(boolean ocrEnabled) {
77  boolean platformSupported = PlatformUtil.isWindowsOS() && PlatformUtil.is64BitOS();
78  ocrCheckBox.setEnabled(platformSupported);
79  limitedOcrCheckbox.setEnabled(platformSupported && ocrEnabled);
80  ocrOnlyCheckbox.setEnabled(platformSupported && ocrEnabled);
81  }
82 
83  private void customizeComponents() {
84  customizeKeywordListsTable();
85  displayLanguages();
86  displayEncodings();
87  keywordListsManager.addPropertyChangeListener(this);
88  languagesLabel.setText("<html>" + org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text") + "</html>"); // NOI18N NON-NLS
89 
90  // the gui builder does not explicitly set these to false.
91  listsTable.setShowHorizontalLines(false);
92  listsTable.setShowVerticalLines(false);
93  }
94 
95  private void customizeKeywordListsTable() {
96  listsTable.setModel(tableModel);
97  listsTable.setTableHeader(null);
98  listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
99  final int width = listsScrollPane.getPreferredSize().width;
100  listsTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
101  TableColumn column;
102  for (int i = 0; i < listsTable.getColumnCount(); i++) {
103  column = listsTable.getColumnModel().getColumn(i);
104  if (i == 0) {
105  column.setPreferredWidth(((int) (width * 0.07)));
106  } else {
107  column.setPreferredWidth(((int) (width * 0.92)));
108  }
109  }
110  }
111 
112  private void displayLanguages() {
113  List<SCRIPT> scripts = KeywordSearchSettings.getStringExtractScripts();
114  StringBuilder langs = new StringBuilder();
115  langs.append("<html>"); //NON-NLS
116  for (int i = 0; i < scripts.size(); i++) {
117  langs.append(scripts.get(i).toString());
118  if (i + 1 < scripts.size()) {
119  langs.append(", ");
120  }
121  }
122  langs.append("</html>"); //NON-NLS
123  String langsS = langs.toString();
124  this.languagesValLabel.setText(langsS);
125  this.languagesValLabel.setToolTipText(langsS);
126  }
127 
128  private void displayEncodings() {
129  String utf8 = KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString());
130  String utf16 = KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString());
131  ArrayList<String> encodingsList = new ArrayList<>();
132  if (utf8 == null || Boolean.parseBoolean(utf8)) {
133  encodingsList.add("UTF8");
134  }
135  if (utf16 == null || Boolean.parseBoolean(utf16)) {
136  encodingsList.add("UTF16"); //NON-NLS
137  }
138  String encodings = encodingsList.toString();
139  encodings = encodings.substring(1, encodings.length() - 1);
140  keywordSearchEncodings.setText(encodings);
141  }
142 
143  @Override
144  public void propertyChange(PropertyChangeEvent event) {
145  if (event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_ADDED.name())
146  || event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_DELETED.name())
147  || event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_UPDATED.name())
148  || event.getPropertyName().equals(XmlKeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED.name())) {
149  update();
150  }
151  }
152 
153  private void update() {
154  updateKeywordListSettings();
155  displayLanguages();
156  displayEncodings();
157  tableModel.fireTableDataChanged();
158  }
159 
160  private void updateKeywordListSettings() {
161  // Get the names of the current set of keyword lists.
162  List<KeywordList> keywordLists = keywordListsManager.getListsL();
163  List<String> currentListNames = new ArrayList<>();
164  for (KeywordList list : keywordLists) {
165  currentListNames.add(list.getName());
166  }
167 
168  // Remove deleted lists from the list states map.
169  for (String listName : keywordListNames) {
170  if (!currentListNames.contains(listName)) {
171  keywordListStates.remove(listName);
172  }
173  }
174 
175  // Reset the names list and add any new lists to the states map.
176  keywordListNames.clear();
177  for (String currentListName : currentListNames) {
178  keywordListNames.add(currentListName);
179  if (!keywordListStates.containsKey(currentListName)) {
180  keywordListStates.put(currentListName, Boolean.TRUE);
181  }
182  }
183  }
184 
185  @Override
187  List<String> enabledListNames = new ArrayList<>();
188  List<String> disabledListNames = new ArrayList<>();
189  for (String listName : keywordListNames) {
190  if (keywordListStates.get(listName)) {
191  enabledListNames.add(listName);
192  } else {
193  disabledListNames.add(listName);
194  }
195  }
196  return new KeywordSearchJobSettings(enabledListNames, disabledListNames,
197  this.ocrCheckBox.isSelected(), this.limitedOcrCheckbox.isSelected(), this.ocrOnlyCheckbox.isSelected());
198  }
199 
200  void reset(KeywordSearchJobSettings newSettings) {
201  initializeKeywordListSettings(newSettings);
202  displayLanguages();
203  displayEncodings();
204  tableModel.fireTableDataChanged();
205  }
206 
207  private class KeywordListsTableModel extends AbstractTableModel {
208 
209  @Override
210  public int getRowCount() {
212  }
213 
214  @Override
215  public int getColumnCount() {
216  return 2;
217  }
218 
219  @Override
220  public Object getValueAt(int rowIndex, int columnIndex) {
221  String listName = KeywordSearchJobSettingsPanel.this.keywordListNames.get(rowIndex);
222  if (columnIndex == 0) {
223  return keywordListStates.get(listName);
224  } else {
225  return listName;
226  }
227  }
228 
229  @Override
230  public boolean isCellEditable(int rowIndex, int columnIndex) {
231  return columnIndex == 0;
232  }
233 
234  @Override
235  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
236  String listName = KeywordSearchJobSettingsPanel.this.keywordListNames.get(rowIndex);
237  if (columnIndex == 0) {
238  keywordListStates.put(listName, (Boolean) aValue);
239  }
240  }
241 
242  @Override
243  public Class<?> getColumnClass(int c) {
244  return getValueAt(0, c).getClass();
245  }
246  }
247 
253  @SuppressWarnings("unchecked")
254  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
255  private void initComponents() {
256 
257  titleLabel = new javax.swing.JLabel();
258  listsScrollPane = new javax.swing.JScrollPane();
259  listsTable = new javax.swing.JTable();
260  languagesLabel = new javax.swing.JLabel();
261  languagesValLabel = new javax.swing.JLabel();
262  encodingsLabel = new javax.swing.JLabel();
263  keywordSearchEncodings = new javax.swing.JLabel();
264  ocrCheckBox = new javax.swing.JCheckBox();
265  limitedOcrCheckbox = new javax.swing.JCheckBox();
266  ocrOnlyCheckbox = new javax.swing.JCheckBox();
267 
268  setPreferredSize(new java.awt.Dimension(300, 170));
269  setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
270 
271  titleLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.titleLabel.text")); // NOI18N
272  add(titleLabel);
273 
274  listsScrollPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
275  listsScrollPane.setAlignmentX(0.0F);
276  listsScrollPane.setMaximumSize(new java.awt.Dimension(800, 200));
277  listsScrollPane.setMinimumSize(new java.awt.Dimension(300, 100));
278  listsScrollPane.setPreferredSize(new java.awt.Dimension(400, 100));
279 
280  listsTable.setBackground(new java.awt.Color(240, 240, 240));
281  listsTable.setModel(new javax.swing.table.DefaultTableModel(
282  new Object [][] {
283 
284  },
285  new String [] {
286 
287  }
288  ));
289  listsTable.setAlignmentX(0.0F);
290  listsTable.setMaximumSize(new java.awt.Dimension(20, 200));
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  add(listsScrollPane);
297 
298  languagesLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text")); // NOI18N
299  languagesLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.toolTipText")); // NOI18N
300  languagesLabel.setPreferredSize(new java.awt.Dimension(294, 35));
301  languagesLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
302  add(languagesLabel);
303 
304  languagesValLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.text")); // NOI18N
305  languagesValLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.toolTipText")); // NOI18N
306  languagesValLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 1, 1, 1));
307  add(languagesValLabel);
308 
309  encodingsLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.encodingsLabel.text")); // NOI18N
310  encodingsLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 1, 1, 1));
311  add(encodingsLabel);
312 
313  keywordSearchEncodings.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.keywordSearchEncodings.text")); // NOI18N
314  keywordSearchEncodings.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 1, 5, 1));
315  add(keywordSearchEncodings);
316 
317  ocrCheckBox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.ocrCheckBox.text")); // NOI18N
318  ocrCheckBox.addActionListener(new java.awt.event.ActionListener() {
319  public void actionPerformed(java.awt.event.ActionEvent evt) {
320  ocrCheckBoxActionPerformed(evt);
321  }
322  });
323  add(ocrCheckBox);
324 
325  limitedOcrCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.limitedOcrCheckbox.text")); // NOI18N
326  limitedOcrCheckbox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 20, 1, 1));
327  limitedOcrCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
328  limitedOcrCheckbox.addActionListener(new java.awt.event.ActionListener() {
329  public void actionPerformed(java.awt.event.ActionEvent evt) {
330  limitedOcrCheckboxActionPerformed(evt);
331  }
332  });
333  add(limitedOcrCheckbox);
334 
335  ocrOnlyCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.ocrOnlyCheckbox.text")); // NOI18N
336  ocrOnlyCheckbox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 20, 1, 1));
337  ocrOnlyCheckbox.addActionListener(new java.awt.event.ActionListener() {
338  public void actionPerformed(java.awt.event.ActionEvent evt) {
339  ocrOnlyCheckboxActionPerformed(evt);
340  }
341  });
342  add(ocrOnlyCheckbox);
343  }// </editor-fold>//GEN-END:initComponents
344 
345  private void ocrCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocrCheckBoxActionPerformed
346  handleOcrEnabled(ocrCheckBox.isSelected());
347  firePropertyChange(KeywordSearchOptionsPanelController.PROP_CHANGED, null, null);
348  }//GEN-LAST:event_ocrCheckBoxActionPerformed
349 
350  private void limitedOcrCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limitedOcrCheckboxActionPerformed
351  firePropertyChange(KeywordSearchOptionsPanelController.PROP_CHANGED, null, null);
352  }//GEN-LAST:event_limitedOcrCheckboxActionPerformed
353 
354  private void ocrOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocrOnlyCheckboxActionPerformed
355  // TODO add your handling code here:
356  }//GEN-LAST:event_ocrOnlyCheckboxActionPerformed
357 
358  // Variables declaration - do not modify//GEN-BEGIN:variables
359  private javax.swing.JLabel encodingsLabel;
360  private javax.swing.JLabel keywordSearchEncodings;
361  private javax.swing.JLabel languagesLabel;
362  private javax.swing.JLabel languagesValLabel;
363  private javax.swing.JCheckBox limitedOcrCheckbox;
364  private javax.swing.JScrollPane listsScrollPane;
365  private javax.swing.JTable listsTable;
366  private javax.swing.JCheckBox ocrCheckBox;
367  private javax.swing.JCheckBox ocrOnlyCheckbox;
368  private javax.swing.JLabel titleLabel;
369  // End of variables declaration//GEN-END:variables
370 }

Copyright © 2012-2022 Basis Technology. Generated on: Mon Apr 17 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.