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.setFont(ingestWarningLabel.getFont().deriveFont(ingestWarningLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
237 ingestWarningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png")));
238 org.openide.awt.Mnemonics.setLocalizedText(ingestWarningLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestWarningLabel.text"));
240 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
241 this.setLayout(layout);
242 layout.setHorizontalGroup(
243 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244 .addGroup(layout.createSequentialGroup()
245 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246 .addGroup(layout.createSequentialGroup()
248 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249 .addComponent(ingestSettingsLabel)
250 .addGroup(layout.createSequentialGroup()
251 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
252 .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.LEADING)
253 .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
254 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
255 .addComponent(ingestWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))))
256 .addGroup(layout.createSequentialGroup()
258 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
259 .addComponent(enableUTF16Checkbox)
260 .addComponent(enableUTF8Checkbox)
261 .addComponent(enableOcrCheckbox))))
264 layout.setVerticalGroup(
265 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266 .addGroup(layout.createSequentialGroup()
268 .addComponent(ingestSettingsLabel)
269 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
270 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271 .addGroup(layout.createSequentialGroup()
272 .addComponent(enableOcrCheckbox)
273 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
274 .addComponent(enableUTF16Checkbox)
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
276 .addComponent(enableUTF8Checkbox)
277 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
278 .addComponent(languagesLabel)
279 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
280 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
281 .addGroup(layout.createSequentialGroup()
282 .addGap(0, 0, Short.MAX_VALUE)
283 .addComponent(ingestWarningLabel)))
288 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
290 boolean selected = this.enableUTF8Checkbox.isSelected();
292 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
293 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
297 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
299 boolean selected = this.enableUTF16Checkbox.isSelected();
301 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
302 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
305 private void enableOcrCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
306 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
310 private javax.swing.JPanel checkPanel;
311 private javax.swing.JCheckBox enableOcrCheckbox;
312 private javax.swing.JCheckBox enableUTF16Checkbox;
313 private javax.swing.JCheckBox enableUTF8Checkbox;
314 private javax.swing.JLabel ingestSettingsLabel;
315 private javax.swing.JLabel ingestWarningLabel;
316 private javax.swing.JScrollPane langPanel;
317 private javax.swing.JLabel languagesLabel;
321 public void store() {
322 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(),
323 Boolean.toString(enableUTF8Checkbox.isSelected()));
324 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(),
325 Boolean.toString(enableUTF16Checkbox.isSelected()));
326 KeywordSearchSettings.setOcrOption(enableOcrCheckbox.isSelected());
328 if (toUpdate != null) {
329 KeywordSearchSettings.setStringExtractScripts(toUpdate);
333 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);