Autopsy  4.14.0
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;
35 
39 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
40 public final class KeywordSearchJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements PropertyChangeListener {
41 
42  private final KeywordListsTableModel tableModel = new KeywordListsTableModel();
43  private final List<String> keywordListNames = new ArrayList<>();
44  private final Map<String, Boolean> keywordListStates = new HashMap<>();
45  private final XmlKeywordSearchList keywordListsManager = XmlKeywordSearchList.getCurrent();
46 
47  KeywordSearchJobSettingsPanel(KeywordSearchJobSettings initialSettings) {
48  initializeKeywordListSettings(initialSettings);
49  initComponents();
50  customizeComponents();
51  }
52 
53  private void initializeKeywordListSettings(KeywordSearchJobSettings settings) {
54  keywordListNames.clear();
55  keywordListStates.clear();
56  List<KeywordList> keywordLists = keywordListsManager.getListsL();
57  for (KeywordList list : keywordLists) {
58  String listName = list.getName();
59  keywordListNames.add(listName);
60  keywordListStates.put(listName, settings.keywordListIsEnabled(listName));
61  }
62  }
63 
64  private void customizeComponents() {
65  customizeKeywordListsTable();
66  displayLanguages();
67  displayEncodings();
68  keywordListsManager.addPropertyChangeListener(this);
69  languagesLabel.setText("<html>" + org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text") + "</html>"); // NOI18N NON-NLS
70  }
71 
72  private void customizeKeywordListsTable() {
73  listsTable.setModel(tableModel);
74  listsTable.setTableHeader(null);
75  listsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
76  final int width = listsScrollPane.getPreferredSize().width;
77  listsTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
78  TableColumn column;
79  for (int i = 0; i < listsTable.getColumnCount(); i++) {
80  column = listsTable.getColumnModel().getColumn(i);
81  if (i == 0) {
82  column.setPreferredWidth(((int) (width * 0.07)));
83  } else {
84  column.setPreferredWidth(((int) (width * 0.92)));
85  }
86  }
87  }
88 
89  private void displayLanguages() {
90  List<SCRIPT> scripts = KeywordSearchSettings.getStringExtractScripts();
91  StringBuilder langs = new StringBuilder();
92  langs.append("<html>"); //NON-NLS
93  for (int i = 0; i < scripts.size(); i++) {
94  langs.append(scripts.get(i).toString());
95  if (i + 1 < scripts.size()) {
96  langs.append(", ");
97  }
98  }
99  langs.append("</html>"); //NON-NLS
100  String langsS = langs.toString();
101  this.languagesValLabel.setText(langsS);
102  this.languagesValLabel.setToolTipText(langsS);
103  }
104 
105  private void displayEncodings() {
106  String utf8 = KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString());
107  String utf16 = KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString());
108  ArrayList<String> encodingsList = new ArrayList<>();
109  if (utf8 == null || Boolean.parseBoolean(utf8)) {
110  encodingsList.add("UTF8");
111  }
112  if (utf16 == null || Boolean.parseBoolean(utf16)) {
113  encodingsList.add("UTF16"); //NON-NLS
114  }
115  String encodings = encodingsList.toString();
116  encodings = encodings.substring(1, encodings.length() - 1);
117  keywordSearchEncodings.setText(encodings);
118  }
119 
120  @Override
121  public void propertyChange(PropertyChangeEvent event) {
122  if (event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_ADDED.name())
123  || event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_DELETED.name())
124  || event.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_UPDATED.name())
125  || event.getPropertyName().equals(XmlKeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED.name())) {
126  update();
127  }
128  }
129 
130  private void update() {
131  updateKeywordListSettings();
132  displayLanguages();
133  displayEncodings();
134  tableModel.fireTableDataChanged();
135  }
136 
137  private void updateKeywordListSettings() {
138  // Get the names of the current set of keyword lists.
139  List<KeywordList> keywordLists = keywordListsManager.getListsL();
140  List<String> currentListNames = new ArrayList<>();
141  for (KeywordList list : keywordLists) {
142  currentListNames.add(list.getName());
143  }
144 
145  // Remove deleted lists from the list states map.
146  for (String listName : keywordListNames) {
147  if (!currentListNames.contains(listName)) {
148  keywordListStates.remove(listName);
149  }
150  }
151 
152  // Reset the names list and add any new lists to the states map.
153  keywordListNames.clear();
154  for (String currentListName : currentListNames) {
155  keywordListNames.add(currentListName);
156  if (!keywordListStates.containsKey(currentListName)) {
157  keywordListStates.put(currentListName, Boolean.TRUE);
158  }
159  }
160  }
161 
162  @Override
164  List<String> enabledListNames = new ArrayList<>();
165  List<String> disabledListNames = new ArrayList<>();
166  for (String listName : keywordListNames) {
167  if (keywordListStates.get(listName)) {
168  enabledListNames.add(listName);
169  } else {
170  disabledListNames.add(listName);
171  }
172  }
173  return new KeywordSearchJobSettings(enabledListNames, disabledListNames);
174  }
175 
176  void reset(KeywordSearchJobSettings newSettings) {
177  initializeKeywordListSettings(newSettings);
178  displayLanguages();
179  displayEncodings();
180  tableModel.fireTableDataChanged();
181  }
182 
183  private class KeywordListsTableModel extends AbstractTableModel {
184 
185  @Override
186  public int getRowCount() {
188  }
189 
190  @Override
191  public int getColumnCount() {
192  return 2;
193  }
194 
195  @Override
196  public Object getValueAt(int rowIndex, int columnIndex) {
197  String listName = KeywordSearchJobSettingsPanel.this.keywordListNames.get(rowIndex);
198  if (columnIndex == 0) {
199  return keywordListStates.get(listName);
200  } else {
201  return listName;
202  }
203  }
204 
205  @Override
206  public boolean isCellEditable(int rowIndex, int columnIndex) {
207  return columnIndex == 0;
208  }
209 
210  @Override
211  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
212  String listName = KeywordSearchJobSettingsPanel.this.keywordListNames.get(rowIndex);
213  if (columnIndex == 0) {
214  keywordListStates.put(listName, (Boolean) aValue);
215  }
216  }
217 
218  @Override
219  public Class<?> getColumnClass(int c) {
220  return getValueAt(0, c).getClass();
221  }
222  }
223 
229  @SuppressWarnings("unchecked")
230  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
231  private void initComponents() {
232 
233  listsScrollPane = new javax.swing.JScrollPane();
234  listsTable = new javax.swing.JTable();
235  titleLabel = new javax.swing.JLabel();
236  languagesLabel = new javax.swing.JLabel();
237  languagesValLabel = new javax.swing.JLabel();
238  encodingsLabel = new javax.swing.JLabel();
239  keywordSearchEncodings = new javax.swing.JLabel();
240 
241  setPreferredSize(new java.awt.Dimension(300, 170));
242 
243  listsScrollPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
244  listsScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));
245 
246  listsTable.setBackground(new java.awt.Color(240, 240, 240));
247  listsTable.setModel(new javax.swing.table.DefaultTableModel(
248  new Object [][] {
249 
250  },
251  new String [] {
252 
253  }
254  ));
255  listsTable.setShowHorizontalLines(false);
256  listsTable.setShowVerticalLines(false);
257  listsScrollPane.setViewportView(listsTable);
258 
259  titleLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.titleLabel.text")); // NOI18N
260 
261  languagesLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.text")); // NOI18N
262  languagesLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesLabel.toolTipText")); // NOI18N
263  languagesLabel.setPreferredSize(new java.awt.Dimension(294, 35));
264  languagesLabel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
265 
266  languagesValLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.text")); // NOI18N
267  languagesValLabel.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.languagesValLabel.toolTipText")); // NOI18N
268 
269  encodingsLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.encodingsLabel.text")); // NOI18N
270 
271  keywordSearchEncodings.setText(org.openide.util.NbBundle.getMessage(KeywordSearchJobSettingsPanel.class, "KeywordSearchJobSettingsPanel.keywordSearchEncodings.text")); // NOI18N
272 
273  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
274  this.setLayout(layout);
275  layout.setHorizontalGroup(
276  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
277  .addGroup(layout.createSequentialGroup()
278  .addContainerGap()
279  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
280  .addGroup(layout.createSequentialGroup()
281  .addComponent(listsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
282  .addContainerGap())
283  .addGroup(layout.createSequentialGroup()
284  .addGap(10, 10, 10)
285  .addComponent(languagesValLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
286  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
287  .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
288  .addGroup(layout.createSequentialGroup()
289  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290  .addComponent(titleLabel)
291  .addGroup(layout.createSequentialGroup()
292  .addComponent(encodingsLabel)
293  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
294  .addComponent(keywordSearchEncodings)))
295  .addGap(0, 0, Short.MAX_VALUE))))
296  );
297  layout.setVerticalGroup(
298  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299  .addGroup(layout.createSequentialGroup()
300  .addGap(7, 7, 7)
301  .addComponent(titleLabel)
302  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
303  .addComponent(listsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
304  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
305  .addComponent(languagesLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
306  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307  .addComponent(languagesValLabel)
308  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
309  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
310  .addComponent(encodingsLabel)
311  .addComponent(keywordSearchEncodings))
312  .addContainerGap())
313  );
314  }// </editor-fold>//GEN-END:initComponents
315  // Variables declaration - do not modify//GEN-BEGIN:variables
316  private javax.swing.JLabel encodingsLabel;
317  private javax.swing.JLabel keywordSearchEncodings;
318  private javax.swing.JLabel languagesLabel;
319  private javax.swing.JLabel languagesValLabel;
320  private javax.swing.JScrollPane listsScrollPane;
321  private javax.swing.JTable listsTable;
322  private javax.swing.JLabel titleLabel;
323  // End of variables declaration//GEN-END:variables
324 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.