Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearchGlobalLanguageSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-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.awt.GridLayout;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import javax.swing.JCheckBox;
29 import org.netbeans.spi.options.OptionsPanelController;
34 
38 class KeywordSearchGlobalLanguageSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
39 
40  private final Map<String, StringExtract.StringExtractUnicodeTable.SCRIPT> scripts = new HashMap<>();
41  private ActionListener updateLanguagesAction;
42  private List<SCRIPT> toUpdate;
43 
44  KeywordSearchGlobalLanguageSettingsPanel() {
45  initComponents();
46  customizeComponents();
47  }
48 
49  private void customizeComponents() {
50  updateLanguagesAction = new ActionListener() {
51  @Override
52  public void actionPerformed(ActionEvent e) {
53  toUpdate = new ArrayList<>();
54  final int components = checkPanel.getComponentCount();
55  for (int i = 0; i < components; ++i) {
56  JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
57  if (ch.isSelected()) {
58  SCRIPT s = scripts.get(ch.getText());
59  toUpdate.add(s);
60  }
61  }
62  }
63  };
64 
65  initScriptsCheckBoxes();
66  reloadScriptsCheckBoxes();
67  }
68 
69  private void activateScriptsCheckboxes(boolean activate) {
70  final int components = checkPanel.getComponentCount();
71  for (int i = 0; i < components; ++i) {
72  JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
73  ch.setEnabled(activate);
74  }
75  }
76 
77  private static String getLangText(SCRIPT script) {
78  StringBuilder sb = new StringBuilder();
79  sb.append(script.toString()).append(" (");
80  sb.append(script.getLanguages());
81  sb.append(")");
82  return sb.toString();
83  }
84 
85  private void initScriptsCheckBoxes() {
86  final List<StringExtract.StringExtractUnicodeTable.SCRIPT> supportedScripts = StringExtract.getSupportedScripts();
87  checkPanel.setLayout(new GridLayout(0, 1));
88  for (StringExtract.StringExtractUnicodeTable.SCRIPT s : supportedScripts) {
89  String text = getLangText(s);
90  JCheckBox ch = new JCheckBox(text);
91  ch.addActionListener(new ActionListener() {
92  @Override
93  public void actionPerformed(ActionEvent e) {
94  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
95  }
96  });
97  ch.addActionListener(updateLanguagesAction);
98  checkPanel.add(ch);
99  ch.setSelected(false);
100  scripts.put(text, s);
101  }
102  }
103 
104  private void reloadScriptsCheckBoxes() {
105  boolean utf16
106  = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
107 
108  enableUTF16Checkbox.setSelected(utf16);
109 
110  boolean utf8
111  = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
112  enableUTF8Checkbox.setSelected(utf8);
113 
114  final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
115  final int components = checkPanel.getComponentCount();
116 
117  for (int i = 0; i < components; ++i) {
118  JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
119 
120  StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
121 
122  ch.setSelected(serviceScripts.contains(script));
123  }
124  }
125 
126  private void activateWidgets() {
127  reloadScriptsCheckBoxes();
128 
129  boolean utf16
130  = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
131 
132  enableUTF16Checkbox.setSelected(utf16);
133 
134  boolean utf8
135  = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
136  enableUTF8Checkbox.setSelected(utf8);
137  final boolean extractEnabled = utf16 || utf8;
138 
139  boolean ingestNotRunning = !IngestManager.getInstance().isIngestRunning() && !IngestManager.getInstance().isIngestRunning();
140  //enable / disable checboxes
141  activateScriptsCheckboxes(extractEnabled && ingestNotRunning);
142  enableUTF16Checkbox.setEnabled(ingestNotRunning);
143  enableUTF8Checkbox.setEnabled(ingestNotRunning);
144  }
145 
151  @SuppressWarnings("unchecked")
152  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
153  private void initComponents() {
154 
155  languagesLabel = new javax.swing.JLabel();
156  langPanel = new javax.swing.JScrollPane();
157  checkPanel = new javax.swing.JPanel();
158  enableUTF8Checkbox = new javax.swing.JCheckBox();
159  enableUTF16Checkbox = new javax.swing.JCheckBox();
160  ingestSettingsLabel = new javax.swing.JLabel();
161 
162  org.openide.awt.Mnemonics.setLocalizedText(languagesLabel, org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class, "KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text")); // NOI18N
163 
164  langPanel.setPreferredSize(new java.awt.Dimension(430, 361));
165 
166  checkPanel.setPreferredSize(new java.awt.Dimension(400, 361));
167 
168  javax.swing.GroupLayout checkPanelLayout = new javax.swing.GroupLayout(checkPanel);
169  checkPanel.setLayout(checkPanelLayout);
170  checkPanelLayout.setHorizontalGroup(
171  checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
172  .addGap(0, 428, Short.MAX_VALUE)
173  );
174  checkPanelLayout.setVerticalGroup(
175  checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
176  .addGap(0, 395, Short.MAX_VALUE)
177  );
178 
179  langPanel.setViewportView(checkPanel);
180 
181  org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox, org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class, "KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text")); // NOI18N
182  enableUTF8Checkbox.addActionListener(new java.awt.event.ActionListener() {
183  public void actionPerformed(java.awt.event.ActionEvent evt) {
184  enableUTF8CheckboxActionPerformed(evt);
185  }
186  });
187 
188  org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox, org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class, "KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text")); // NOI18N
189  enableUTF16Checkbox.addActionListener(new java.awt.event.ActionListener() {
190  public void actionPerformed(java.awt.event.ActionEvent evt) {
191  enableUTF16CheckboxActionPerformed(evt);
192  }
193  });
194 
195  org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel, org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class, "KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text")); // NOI18N
196 
197  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
198  this.setLayout(layout);
199  layout.setHorizontalGroup(
200  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201  .addGroup(layout.createSequentialGroup()
202  .addContainerGap()
203  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addComponent(ingestSettingsLabel)
205  .addGroup(layout.createSequentialGroup()
206  .addGap(10, 10, 10)
207  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
208  .addComponent(enableUTF16Checkbox)
209  .addComponent(enableUTF8Checkbox)))
210  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
211  .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.LEADING)
212  .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
213  .addContainerGap(255, Short.MAX_VALUE))
214  );
215  layout.setVerticalGroup(
216  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217  .addGroup(layout.createSequentialGroup()
218  .addContainerGap()
219  .addComponent(ingestSettingsLabel)
220  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
221  .addComponent(enableUTF16Checkbox)
222  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
223  .addComponent(enableUTF8Checkbox)
224  .addGap(18, 18, 18)
225  .addComponent(languagesLabel)
226  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
227  .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
228  .addContainerGap())
229  );
230  }// </editor-fold>//GEN-END:initComponents
231 
232  private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableUTF8CheckboxActionPerformed
233 
234  boolean selected = this.enableUTF8Checkbox.isSelected();
235 
236  activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
237  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
238 
239  }//GEN-LAST:event_enableUTF8CheckboxActionPerformed
240 
241  private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableUTF16CheckboxActionPerformed
242 
243  boolean selected = this.enableUTF16Checkbox.isSelected();
244 
245  activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
246  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
247  }//GEN-LAST:event_enableUTF16CheckboxActionPerformed
248 
249  // Variables declaration - do not modify//GEN-BEGIN:variables
250  private javax.swing.JPanel checkPanel;
251  private javax.swing.JCheckBox enableUTF16Checkbox;
252  private javax.swing.JCheckBox enableUTF8Checkbox;
253  private javax.swing.JLabel ingestSettingsLabel;
254  private javax.swing.JScrollPane langPanel;
255  private javax.swing.JLabel languagesLabel;
256  // End of variables declaration//GEN-END:variables
257 
258  @Override
259  public void store() {
260  KeywordSearchSettings.setStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF8.toString(),
261  Boolean.toString(enableUTF8Checkbox.isSelected()));
262  KeywordSearchSettings.setStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF16.toString(),
263  Boolean.toString(enableUTF16Checkbox.isSelected()));
264 
265  if (toUpdate != null) {
266  KeywordSearchSettings.setStringExtractScripts(toUpdate);
267  }
268 
269  // This is a stop-gap way of notifying the job settings panel of potential changes.
270  XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);
271  }
272 
273  @Override
274  public void load() {
275  activateWidgets();
276  }
277 }

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