Autopsy  4.19.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  */
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  listsScrollPane = new javax.swing.JScrollPane();
258  listsTable = new javax.swing.JTable();
259  titleLabel = new javax.swing.JLabel();
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 
270  listsScrollPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
271  listsScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));
272 
273  listsTable.setBackground(new java.awt.Color(240, 240, 240));
274  listsTable.setModel(new javax.swing.table.DefaultTableModel(
275  new Object [][] {
276 
277  },
278  new String [] {
279 
280  }
281  ));
282  listsTable.setMaximumSize(new java.awt.Dimension(32767, 32767));
283  listsTable.setMinimumSize(new java.awt.Dimension(20, 200));
284  listsTable.setPreferredSize(null);
285  listsScrollPane.setViewportView(listsTable);
286  listsTable.setDefaultRenderer(String.class, new SimpleTableCellRenderer());
287 
288  titleLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.titleLabel.text")); // NOI18N
289 
290  languagesLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text")); // NOI18N
291  languagesLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.toolTipText")); // NOI18N
292  languagesLabel.setPreferredSize(new java.awt.Dimension(294, 35));
293  languagesLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
294 
295  languagesValLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.text")); // NOI18N
296  languagesValLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.toolTipText")); // NOI18N
297 
298  encodingsLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.encodingsLabel.text")); // NOI18N
299 
300  keywordSearchEncodings.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.keywordSearchEncodings.text")); // NOI18N
301 
302  ocrCheckBox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.ocrCheckBox.text")); // NOI18N
303  ocrCheckBox.addActionListener(new java.awt.event.ActionListener() {
304  public void actionPerformed(java.awt.event.ActionEvent evt) {
305  ocrCheckBoxActionPerformed(evt);
306  }
307  });
308 
309  limitedOcrCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.limitedOcrCheckbox.text")); // NOI18N
310  limitedOcrCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
311  limitedOcrCheckbox.addActionListener(new java.awt.event.ActionListener() {
312  public void actionPerformed(java.awt.event.ActionEvent evt) {
313  limitedOcrCheckboxActionPerformed(evt);
314  }
315  });
316 
317  ocrOnlyCheckbox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.ocrOnlyCheckbox.text")); // NOI18N
318  ocrOnlyCheckbox.addActionListener(new java.awt.event.ActionListener() {
319  public void actionPerformed(java.awt.event.ActionEvent evt) {
320  ocrOnlyCheckboxActionPerformed(evt);
321  }
322  });
323 
324  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
325  this.setLayout(layout);
326  layout.setHorizontalGroup(
327  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
328  .addGroup(layout.createSequentialGroup()
329  .addContainerGap()
330  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331  .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
332  .addGroup(layout.createSequentialGroup()
333  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334  .addComponent(listsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
335  .addComponent(titleLabel)
336  .addGroup(layout.createSequentialGroup()
337  .addComponent(encodingsLabel)
338  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
339  .addComponent(keywordSearchEncodings))
340  .addGroup(layout.createSequentialGroup()
341  .addGap(10, 10, 10)
342  .addComponent(languagesValLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
343  .addComponent(ocrCheckBox)
344  .addGroup(layout.createSequentialGroup()
345  .addGap(21, 21, 21)
346  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347  .addComponent(ocrOnlyCheckbox)
348  .addComponent(limitedOcrCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE))))
349  .addContainerGap())))
350  );
351  layout.setVerticalGroup(
352  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
353  .addGroup(layout.createSequentialGroup()
354  .addGap(7, 7, 7)
355  .addComponent(titleLabel)
356  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
357  .addComponent(listsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
358  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
359  .addComponent(languagesLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
360  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
361  .addComponent(languagesValLabel)
362  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
363  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
364  .addComponent(encodingsLabel)
365  .addComponent(keywordSearchEncodings))
366  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
367  .addComponent(ocrCheckBox)
368  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
369  .addComponent(ocrOnlyCheckbox)
370  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371  .addComponent(limitedOcrCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
372  .addContainerGap())
373  );
374  }// </editor-fold>//GEN-END:initComponents
375 
376  private void ocrCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocrCheckBoxActionPerformed
377  handleOcrEnabled(ocrCheckBox.isSelected());
378  firePropertyChange(KeywordSearchOptionsPanelController.PROP_CHANGED, null, null);
379  }//GEN-LAST:event_ocrCheckBoxActionPerformed
380 
381  private void limitedOcrCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limitedOcrCheckboxActionPerformed
382  firePropertyChange(KeywordSearchOptionsPanelController.PROP_CHANGED, null, null);
383  }//GEN-LAST:event_limitedOcrCheckboxActionPerformed
384 
385  private void ocrOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ocrOnlyCheckboxActionPerformed
386  // TODO add your handling code here:
387  }//GEN-LAST:event_ocrOnlyCheckboxActionPerformed
388 
389  // Variables declaration - do not modify//GEN-BEGIN:variables
390  private javax.swing.JLabel encodingsLabel;
391  private javax.swing.JLabel keywordSearchEncodings;
392  private javax.swing.JLabel languagesLabel;
393  private javax.swing.JLabel languagesValLabel;
394  private javax.swing.JCheckBox limitedOcrCheckbox;
395  private javax.swing.JScrollPane listsScrollPane;
396  private javax.swing.JTable listsTable;
397  private javax.swing.JCheckBox ocrCheckBox;
398  private javax.swing.JCheckBox ocrOnlyCheckbox;
399  private javax.swing.JLabel titleLabel;
400  // End of variables declaration//GEN-END:variables
401 }

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