20 package org.sleuthkit.autopsy.keywordsearch;
22 import java.awt.GridLayout;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.swing.JCheckBox;
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(updateLanguagesAction);
93 ch.setSelected(
false);
98 private void reloadScriptsCheckBoxes() {
100 Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
102 enableUTF16Checkbox.setSelected(utf16);
105 Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
106 enableUTF8Checkbox.setSelected(utf8);
108 final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
109 final int components = checkPanel.getComponentCount();
111 for (
int i = 0; i < components; ++i) {
112 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
114 StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
116 ch.setSelected(serviceScripts.contains(script));
120 private void activateWidgets() {
121 reloadScriptsCheckBoxes();
124 Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
126 enableUTF16Checkbox.setSelected(utf16);
129 Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
130 enableUTF8Checkbox.setSelected(utf8);
131 final boolean extractEnabled = utf16 || utf8;
133 boolean ingestNotRunning = !IngestManager.getInstance().isIngestRunning() && !IngestManager.getInstance().isIngestRunning();
135 activateScriptsCheckboxes(extractEnabled && ingestNotRunning);
136 enableUTF16Checkbox.setEnabled(ingestNotRunning);
137 enableUTF8Checkbox.setEnabled(ingestNotRunning);
145 @SuppressWarnings(
"unchecked")
147 private
void initComponents() {
149 languagesLabel =
new javax.swing.JLabel();
150 langPanel =
new javax.swing.JScrollPane();
151 checkPanel =
new javax.swing.JPanel();
152 enableUTF8Checkbox =
new javax.swing.JCheckBox();
153 enableUTF16Checkbox =
new javax.swing.JCheckBox();
154 ingestSettingsLabel =
new javax.swing.JLabel();
156 org.openide.awt.Mnemonics.setLocalizedText(languagesLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text"));
158 langPanel.setPreferredSize(
new java.awt.Dimension(430, 361));
160 checkPanel.setPreferredSize(
new java.awt.Dimension(400, 361));
162 javax.swing.GroupLayout checkPanelLayout =
new javax.swing.GroupLayout(checkPanel);
163 checkPanel.setLayout(checkPanelLayout);
164 checkPanelLayout.setHorizontalGroup(
165 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addGap(0, 428, Short.MAX_VALUE)
168 checkPanelLayout.setVerticalGroup(
169 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170 .addGap(0, 395, Short.MAX_VALUE)
173 langPanel.setViewportView(checkPanel);
175 org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text"));
176 enableUTF8Checkbox.addActionListener(
new java.awt.event.ActionListener() {
177 public void actionPerformed(java.awt.event.ActionEvent evt) {
178 enableUTF8CheckboxActionPerformed(evt);
182 org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text"));
183 enableUTF16Checkbox.addActionListener(
new java.awt.event.ActionListener() {
184 public void actionPerformed(java.awt.event.ActionEvent evt) {
185 enableUTF16CheckboxActionPerformed(evt);
189 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text"));
191 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
192 this.setLayout(layout);
193 layout.setHorizontalGroup(
194 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195 .addGroup(layout.createSequentialGroup()
197 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198 .addComponent(ingestSettingsLabel)
199 .addGroup(layout.createSequentialGroup()
201 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
202 .addComponent(enableUTF16Checkbox)
203 .addComponent(enableUTF8Checkbox)))
204 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
205 .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.LEADING)
206 .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
207 .addContainerGap(255, Short.MAX_VALUE))
209 layout.setVerticalGroup(
210 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211 .addGroup(layout.createSequentialGroup()
213 .addComponent(ingestSettingsLabel)
214 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215 .addComponent(enableUTF16Checkbox)
216 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
217 .addComponent(enableUTF8Checkbox)
219 .addComponent(languagesLabel)
220 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
221 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
226 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
228 boolean selected = this.enableUTF8Checkbox.isSelected();
230 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
234 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
236 boolean selected = this.enableUTF16Checkbox.isSelected();
238 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
242 private javax.swing.JPanel checkPanel;
243 private javax.swing.JCheckBox enableUTF16Checkbox;
244 private javax.swing.JCheckBox enableUTF8Checkbox;
245 private javax.swing.JLabel ingestSettingsLabel;
246 private javax.swing.JScrollPane langPanel;
247 private javax.swing.JLabel languagesLabel;
251 public void store() {
252 KeywordSearchSettings.setStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString(),
253 Boolean.toString(enableUTF8Checkbox.isSelected()));
254 KeywordSearchSettings.setStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString(),
255 Boolean.toString(enableUTF16Checkbox.isSelected()));
258 KeywordSearchSettings.setStringExtractScripts(toUpdate);
262 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);