19 package org.sleuthkit.autopsy.keywordsearch;
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;
28 import javax.swing.JCheckBox;
29 import org.netbeans.spi.options.OptionsPanelController;
38 class KeywordSearchGlobalLanguageSettingsPanel
extends javax.swing.JPanel implements OptionsPanel {
40 private final Map<String, StringExtract.StringExtractUnicodeTable.SCRIPT> scripts =
new HashMap<>();
41 private ActionListener updateLanguagesAction;
42 private List<SCRIPT> toUpdate;
44 KeywordSearchGlobalLanguageSettingsPanel() {
46 customizeComponents();
49 private void customizeComponents() {
50 updateLanguagesAction =
new ActionListener() {
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());
65 initScriptsCheckBoxes();
66 reloadScriptsCheckBoxes();
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);
77 private static String getLangText(SCRIPT script) {
78 StringBuilder sb =
new StringBuilder();
79 sb.append(script.toString()).append(
" (");
80 sb.append(script.getLanguages());
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() {
93 public void actionPerformed(ActionEvent e) {
94 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
97 ch.addActionListener(updateLanguagesAction);
99 ch.setSelected(
false);
100 scripts.put(text, s);
104 private void reloadScriptsCheckBoxes() {
106 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
108 enableUTF16Checkbox.setSelected(utf16);
111 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
112 enableUTF8Checkbox.setSelected(utf8);
114 final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
115 final int components = checkPanel.getComponentCount();
117 for (
int i = 0; i < components; ++i) {
118 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
120 StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
122 ch.setSelected(serviceScripts.contains(script));
126 private void activateWidgets() {
127 reloadScriptsCheckBoxes();
130 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
132 enableUTF16Checkbox.setSelected(utf16);
135 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsTextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
136 enableUTF8Checkbox.setSelected(utf8);
137 final boolean extractEnabled = utf16 || utf8;
139 boolean ingestNotRunning = !IngestManager.getInstance().isIngestRunning() && !IngestManager.getInstance().isIngestRunning();
141 activateScriptsCheckboxes(extractEnabled && ingestNotRunning);
142 enableUTF16Checkbox.setEnabled(ingestNotRunning);
143 enableUTF8Checkbox.setEnabled(ingestNotRunning);
151 @SuppressWarnings(
"unchecked")
153 private
void initComponents() {
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();
162 org.openide.awt.Mnemonics.setLocalizedText(languagesLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text"));
164 langPanel.setPreferredSize(
new java.awt.Dimension(430, 361));
166 checkPanel.setPreferredSize(
new java.awt.Dimension(400, 361));
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)
174 checkPanelLayout.setVerticalGroup(
175 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
176 .addGap(0, 395, Short.MAX_VALUE)
179 langPanel.setViewportView(checkPanel);
181 org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text"));
182 enableUTF8Checkbox.addActionListener(
new java.awt.event.ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent evt) {
184 enableUTF8CheckboxActionPerformed(evt);
188 org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text"));
189 enableUTF16Checkbox.addActionListener(
new java.awt.event.ActionListener() {
190 public void actionPerformed(java.awt.event.ActionEvent evt) {
191 enableUTF16CheckboxActionPerformed(evt);
195 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text"));
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()
203 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addComponent(ingestSettingsLabel)
205 .addGroup(layout.createSequentialGroup()
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))
215 layout.setVerticalGroup(
216 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217 .addGroup(layout.createSequentialGroup()
219 .addComponent(ingestSettingsLabel)
220 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
221 .addComponent(enableUTF16Checkbox)
222 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
223 .addComponent(enableUTF8Checkbox)
225 .addComponent(languagesLabel)
226 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
227 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
232 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
234 boolean selected = this.enableUTF8Checkbox.isSelected();
236 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
237 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
241 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
243 boolean selected = this.enableUTF16Checkbox.isSelected();
245 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
246 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
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;
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()));
265 if (toUpdate != null) {
266 KeywordSearchSettings.setStringExtractScripts(toUpdate);
270 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);