19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.EventQueue;
22 import java.awt.GridLayout;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.beans.PropertyChangeEvent;
26 import java.beans.PropertyChangeListener;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import javax.swing.JCheckBox;
32 import org.netbeans.spi.options.OptionsPanelController;
43 @SuppressWarnings(
"PMD.SingularField")
44 class KeywordSearchGlobalLanguageSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
46 private final Map<String, StringExtract.StringExtractUnicodeTable.SCRIPT> scripts =
new HashMap<>();
47 private ActionListener updateLanguagesAction;
48 private List<SCRIPT> toUpdate;
50 KeywordSearchGlobalLanguageSettingsPanel() {
52 customizeComponents();
55 private void customizeComponents() {
56 updateLanguagesAction =
new ActionListener() {
58 public void actionPerformed(ActionEvent e) {
59 toUpdate =
new ArrayList<>();
60 final int components = checkPanel.getComponentCount();
61 for (
int i = 0; i < components; ++i) {
62 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
63 if (ch.isSelected()) {
64 SCRIPT s = scripts.get(ch.getText());
71 initScriptsCheckBoxes();
72 reloadScriptsCheckBoxes();
74 if (!PlatformUtil.isWindowsOS() || !PlatformUtil.is64BitOS()) {
75 enableOcrCheckbox.setText(
"Enable Optical Character Recognition (OCR) (Requires Windows 64-bit)");
76 enableOcrCheckbox.setSelected(
false);
77 enableOcrCheckbox.setEnabled(
false);
81 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
83 public void propertyChange(PropertyChangeEvent evt) {
84 Object source = evt.getSource();
85 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
86 EventQueue.invokeLater(() -> {
94 private void activateScriptsCheckboxes(
boolean activate) {
95 final int components = checkPanel.getComponentCount();
96 for (
int i = 0; i < components; ++i) {
97 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
98 ch.setEnabled(activate);
102 private static String getLangText(SCRIPT script) {
103 StringBuilder sb =
new StringBuilder();
104 sb.append(script.toString()).append(
" (");
105 sb.append(script.getLanguages());
107 return sb.toString();
110 private void initScriptsCheckBoxes() {
111 final List<StringExtract.StringExtractUnicodeTable.SCRIPT> supportedScripts = StringExtract.getSupportedScripts();
112 checkPanel.setLayout(
new GridLayout(0, 1));
113 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : supportedScripts) {
114 String text = getLangText(s);
115 JCheckBox ch =
new JCheckBox(text);
116 ch.addActionListener(
new ActionListener() {
118 public void actionPerformed(ActionEvent e) {
119 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
122 ch.addActionListener(updateLanguagesAction);
124 ch.setSelected(
false);
125 scripts.put(text, s);
129 private void reloadScriptsCheckBoxes() {
131 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString()));
133 enableUTF16Checkbox.setSelected(utf16);
136 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString()));
137 enableUTF8Checkbox.setSelected(utf8);
139 boolean ocr = KeywordSearchSettings.getOcrOption();
140 enableOcrCheckbox.setSelected(ocr);
142 final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
143 final int components = checkPanel.getComponentCount();
145 for (
int i = 0; i < components; ++i) {
146 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
148 StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
150 ch.setSelected(serviceScripts.contains(script));
154 private void activateWidgets() {
155 reloadScriptsCheckBoxes();
158 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString()));
160 enableUTF16Checkbox.setSelected(utf16);
163 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString()));
164 enableUTF8Checkbox.setSelected(utf8);
165 final boolean extractEnabled = utf16 || utf8;
167 boolean ingestRunning = IngestManager.getInstance().isIngestRunning();
169 activateScriptsCheckboxes(extractEnabled && !ingestRunning);
170 ingestWarningLabel.setVisible(ingestRunning);
171 enableUTF16Checkbox.setEnabled(!ingestRunning);
172 enableUTF8Checkbox.setEnabled(!ingestRunning);
173 enableOcrCheckbox.setEnabled(!ingestRunning);
181 @SuppressWarnings(
"unchecked")
183 private
void initComponents() {
185 languagesLabel =
new javax.swing.JLabel();
186 langPanel =
new javax.swing.JScrollPane();
187 checkPanel =
new javax.swing.JPanel();
188 enableUTF8Checkbox =
new javax.swing.JCheckBox();
189 enableUTF16Checkbox =
new javax.swing.JCheckBox();
190 ingestSettingsLabel =
new javax.swing.JLabel();
191 enableOcrCheckbox =
new javax.swing.JCheckBox();
192 ingestWarningLabel =
new javax.swing.JLabel();
194 org.openide.awt.Mnemonics.setLocalizedText(languagesLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text"));
196 langPanel.setPreferredSize(
new java.awt.Dimension(430, 361));
198 checkPanel.setPreferredSize(
new java.awt.Dimension(400, 361));
200 javax.swing.GroupLayout checkPanelLayout =
new javax.swing.GroupLayout(checkPanel);
201 checkPanel.setLayout(checkPanelLayout);
202 checkPanelLayout.setHorizontalGroup(
203 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addGap(0, 428, Short.MAX_VALUE)
206 checkPanelLayout.setVerticalGroup(
207 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGap(0, 378, Short.MAX_VALUE)
211 langPanel.setViewportView(checkPanel);
213 org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text"));
214 enableUTF8Checkbox.addActionListener(
new java.awt.event.ActionListener() {
215 public void actionPerformed(java.awt.event.ActionEvent evt) {
216 enableUTF8CheckboxActionPerformed(evt);
220 org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text"));
221 enableUTF16Checkbox.addActionListener(
new java.awt.event.ActionListener() {
222 public void actionPerformed(java.awt.event.ActionEvent evt) {
223 enableUTF16CheckboxActionPerformed(evt);
227 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text"));
229 org.openide.awt.Mnemonics.setLocalizedText(enableOcrCheckbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableOcrCheckbox.text"));
230 enableOcrCheckbox.addActionListener(
new java.awt.event.ActionListener() {
231 public void actionPerformed(java.awt.event.ActionEvent evt) {
232 enableOcrCheckboxActionPerformed(evt);
236 ingestWarningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png")));
237 org.openide.awt.Mnemonics.setLocalizedText(ingestWarningLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestWarningLabel.text"));
239 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
240 this.setLayout(layout);
241 layout.setHorizontalGroup(
242 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243 .addGroup(layout.createSequentialGroup()
244 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245 .addGroup(layout.createSequentialGroup()
247 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addComponent(ingestSettingsLabel)
249 .addGroup(layout.createSequentialGroup()
250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
251 .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.LEADING)
252 .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
253 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
254 .addComponent(ingestWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))))
255 .addGroup(layout.createSequentialGroup()
257 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
258 .addComponent(enableUTF16Checkbox)
259 .addComponent(enableUTF8Checkbox)
260 .addComponent(enableOcrCheckbox))))
263 layout.setVerticalGroup(
264 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265 .addGroup(layout.createSequentialGroup()
267 .addComponent(ingestSettingsLabel)
268 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
269 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270 .addGroup(layout.createSequentialGroup()
271 .addComponent(enableOcrCheckbox)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
273 .addComponent(enableUTF16Checkbox)
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
275 .addComponent(enableUTF8Checkbox)
276 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
277 .addComponent(languagesLabel)
278 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
279 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
280 .addGroup(layout.createSequentialGroup()
281 .addGap(0, 0, Short.MAX_VALUE)
282 .addComponent(ingestWarningLabel)))
287 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
289 boolean selected = this.enableUTF8Checkbox.isSelected();
291 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
292 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
296 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
298 boolean selected = this.enableUTF16Checkbox.isSelected();
300 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
301 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
304 private void enableOcrCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
305 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
309 private javax.swing.JPanel checkPanel;
310 private javax.swing.JCheckBox enableOcrCheckbox;
311 private javax.swing.JCheckBox enableUTF16Checkbox;
312 private javax.swing.JCheckBox enableUTF8Checkbox;
313 private javax.swing.JLabel ingestSettingsLabel;
314 private javax.swing.JLabel ingestWarningLabel;
315 private javax.swing.JScrollPane langPanel;
316 private javax.swing.JLabel languagesLabel;
320 public void store() {
321 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(),
322 Boolean.toString(enableUTF8Checkbox.isSelected()));
323 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(),
324 Boolean.toString(enableUTF16Checkbox.isSelected()));
325 KeywordSearchSettings.setOcrOption(enableOcrCheckbox.isSelected());
327 if (toUpdate != null) {
328 KeywordSearchSettings.setStringExtractScripts(toUpdate);
332 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);