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;
37 class KeywordSearchGlobalLanguageSettingsPanel
extends javax.swing.JPanel implements OptionsPanel {
39 private final Map<String, StringExtract.StringExtractUnicodeTable.SCRIPT> scripts =
new HashMap<>();
40 private ActionListener updateLanguagesAction;
41 private List<SCRIPT> toUpdate;
43 KeywordSearchGlobalLanguageSettingsPanel() {
45 customizeComponents();
48 private void customizeComponents() {
49 updateLanguagesAction =
new ActionListener() {
51 public void actionPerformed(ActionEvent e) {
52 toUpdate =
new ArrayList<>();
53 final int components = checkPanel.getComponentCount();
54 for (
int i = 0; i < components; ++i) {
55 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
56 if (ch.isSelected()) {
57 SCRIPT s = scripts.get(ch.getText());
64 initScriptsCheckBoxes();
65 reloadScriptsCheckBoxes();
68 private void activateScriptsCheckboxes(
boolean activate) {
69 final int components = checkPanel.getComponentCount();
70 for (
int i = 0; i < components; ++i) {
71 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
72 ch.setEnabled(activate);
76 private static String getLangText(SCRIPT script) {
77 StringBuilder sb =
new StringBuilder();
78 sb.append(script.toString()).append(
" (");
79 sb.append(script.getLanguages());
84 private void initScriptsCheckBoxes() {
85 final List<StringExtract.StringExtractUnicodeTable.SCRIPT> supportedScripts = StringExtract.getSupportedScripts();
86 checkPanel.setLayout(
new GridLayout(0, 1));
87 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : supportedScripts) {
88 String text = getLangText(s);
89 JCheckBox ch =
new JCheckBox(text);
90 ch.addActionListener(updateLanguagesAction);
92 ch.setSelected(
false);
97 private void reloadScriptsCheckBoxes() {
99 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
101 enableUTF16Checkbox.setSelected(utf16);
104 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
105 enableUTF8Checkbox.setSelected(utf8);
107 final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
108 final int components = checkPanel.getComponentCount();
110 for (
int i = 0; i < components; ++i) {
111 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
113 StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
115 ch.setSelected(serviceScripts.contains(script));
119 private void activateWidgets() {
120 reloadScriptsCheckBoxes();
123 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString()));
125 enableUTF16Checkbox.setSelected(utf16);
128 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString()));
129 enableUTF8Checkbox.setSelected(utf8);
130 final boolean extractEnabled = utf16 || utf8;
132 boolean ingestNotRunning = !IngestManager.getInstance().isIngestRunning() && !IngestManager.getInstance().isIngestRunning();
134 activateScriptsCheckboxes(extractEnabled && ingestNotRunning);
135 enableUTF16Checkbox.setEnabled(ingestNotRunning);
136 enableUTF8Checkbox.setEnabled(ingestNotRunning);
144 @SuppressWarnings(
"unchecked")
146 private
void initComponents() {
148 languagesLabel =
new javax.swing.JLabel();
149 langPanel =
new javax.swing.JScrollPane();
150 checkPanel =
new javax.swing.JPanel();
151 enableUTF8Checkbox =
new javax.swing.JCheckBox();
152 enableUTF16Checkbox =
new javax.swing.JCheckBox();
153 ingestSettingsLabel =
new javax.swing.JLabel();
155 org.openide.awt.Mnemonics.setLocalizedText(languagesLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text"));
157 langPanel.setPreferredSize(
new java.awt.Dimension(430, 361));
159 checkPanel.setPreferredSize(
new java.awt.Dimension(400, 361));
161 javax.swing.GroupLayout checkPanelLayout =
new javax.swing.GroupLayout(checkPanel);
162 checkPanel.setLayout(checkPanelLayout);
163 checkPanelLayout.setHorizontalGroup(
164 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
165 .addGap(0, 428, Short.MAX_VALUE)
167 checkPanelLayout.setVerticalGroup(
168 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
169 .addGap(0, 395, Short.MAX_VALUE)
172 langPanel.setViewportView(checkPanel);
174 org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text"));
175 enableUTF8Checkbox.addActionListener(
new java.awt.event.ActionListener() {
176 public void actionPerformed(java.awt.event.ActionEvent evt) {
177 enableUTF8CheckboxActionPerformed(evt);
181 org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text"));
182 enableUTF16Checkbox.addActionListener(
new java.awt.event.ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent evt) {
184 enableUTF16CheckboxActionPerformed(evt);
188 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text"));
190 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
191 this.setLayout(layout);
192 layout.setHorizontalGroup(
193 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194 .addGroup(layout.createSequentialGroup()
196 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addComponent(ingestSettingsLabel)
198 .addGroup(layout.createSequentialGroup()
200 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
201 .addComponent(enableUTF16Checkbox)
202 .addComponent(enableUTF8Checkbox)))
203 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
204 .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.LEADING)
205 .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
206 .addContainerGap(255, Short.MAX_VALUE))
208 layout.setVerticalGroup(
209 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210 .addGroup(layout.createSequentialGroup()
212 .addComponent(ingestSettingsLabel)
213 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
214 .addComponent(enableUTF16Checkbox)
215 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
216 .addComponent(enableUTF8Checkbox)
218 .addComponent(languagesLabel)
219 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
220 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
225 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
227 boolean selected = this.enableUTF8Checkbox.isSelected();
229 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
233 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
235 boolean selected = this.enableUTF16Checkbox.isSelected();
237 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
241 private javax.swing.JPanel checkPanel;
242 private javax.swing.JCheckBox enableUTF16Checkbox;
243 private javax.swing.JCheckBox enableUTF8Checkbox;
244 private javax.swing.JLabel ingestSettingsLabel;
245 private javax.swing.JScrollPane langPanel;
246 private javax.swing.JLabel languagesLabel;
250 public void store() {
251 KeywordSearchSettings.setStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString(),
252 Boolean.toString(enableUTF8Checkbox.isSelected()));
253 KeywordSearchSettings.setStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString(),
254 Boolean.toString(enableUTF16Checkbox.isSelected()));
256 if (toUpdate != null) {
257 KeywordSearchSettings.setStringExtractScripts(toUpdate);
261 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);