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

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