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 if (!PlatformUtil.isWindowsOS()) {
72 enableOcrCheckbox.setVisible(
false);
75 initScriptsCheckBoxes();
76 reloadScriptsCheckBoxes();
79 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
81 public void propertyChange(PropertyChangeEvent evt) {
82 Object source = evt.getSource();
83 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
84 EventQueue.invokeLater(() -> {
92 private void activateScriptsCheckboxes(
boolean activate) {
93 final int components = checkPanel.getComponentCount();
94 for (
int i = 0; i < components; ++i) {
95 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
96 ch.setEnabled(activate);
100 private static String getLangText(SCRIPT script) {
101 StringBuilder sb =
new StringBuilder();
102 sb.append(script.toString()).append(
" (");
103 sb.append(script.getLanguages());
105 return sb.toString();
108 private void initScriptsCheckBoxes() {
109 final List<StringExtract.StringExtractUnicodeTable.SCRIPT> supportedScripts = StringExtract.getSupportedScripts();
110 checkPanel.setLayout(
new GridLayout(0, 1));
111 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : supportedScripts) {
112 String text = getLangText(s);
113 JCheckBox ch =
new JCheckBox(text);
114 ch.addActionListener(
new ActionListener() {
116 public void actionPerformed(ActionEvent e) {
117 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
120 ch.addActionListener(updateLanguagesAction);
122 ch.setSelected(
false);
123 scripts.put(text, s);
127 private void reloadScriptsCheckBoxes() {
129 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString()));
131 enableUTF16Checkbox.setSelected(utf16);
134 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString()));
135 enableUTF8Checkbox.setSelected(utf8);
137 boolean ocr = KeywordSearchSettings.getOcrOption();
138 enableOcrCheckbox.setSelected(ocr);
140 final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
141 final int components = checkPanel.getComponentCount();
143 for (
int i = 0; i < components; ++i) {
144 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
146 StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
148 ch.setSelected(serviceScripts.contains(script));
152 private void activateWidgets() {
153 reloadScriptsCheckBoxes();
156 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString()));
158 enableUTF16Checkbox.setSelected(utf16);
161 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString()));
162 enableUTF8Checkbox.setSelected(utf8);
163 final boolean extractEnabled = utf16 || utf8;
165 boolean ingestRunning = IngestManager.getInstance().isIngestRunning();
167 activateScriptsCheckboxes(extractEnabled && !ingestRunning);
168 ingestWarningLabel.setVisible(ingestRunning);
169 enableUTF16Checkbox.setEnabled(!ingestRunning);
170 enableUTF8Checkbox.setEnabled(!ingestRunning);
171 enableOcrCheckbox.setEnabled(!ingestRunning);
179 @SuppressWarnings(
"unchecked")
181 private
void initComponents() {
183 languagesLabel =
new javax.swing.JLabel();
184 langPanel =
new javax.swing.JScrollPane();
185 checkPanel =
new javax.swing.JPanel();
186 enableUTF8Checkbox =
new javax.swing.JCheckBox();
187 enableUTF16Checkbox =
new javax.swing.JCheckBox();
188 ingestSettingsLabel =
new javax.swing.JLabel();
189 enableOcrCheckbox =
new javax.swing.JCheckBox();
190 ingestWarningLabel =
new javax.swing.JLabel();
192 org.openide.awt.Mnemonics.setLocalizedText(languagesLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text"));
194 langPanel.setPreferredSize(
new java.awt.Dimension(430, 361));
196 checkPanel.setPreferredSize(
new java.awt.Dimension(400, 361));
198 javax.swing.GroupLayout checkPanelLayout =
new javax.swing.GroupLayout(checkPanel);
199 checkPanel.setLayout(checkPanelLayout);
200 checkPanelLayout.setHorizontalGroup(
201 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202 .addGap(0, 428, Short.MAX_VALUE)
204 checkPanelLayout.setVerticalGroup(
205 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206 .addGap(0, 378, Short.MAX_VALUE)
209 langPanel.setViewportView(checkPanel);
211 org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text"));
212 enableUTF8Checkbox.addActionListener(
new java.awt.event.ActionListener() {
213 public void actionPerformed(java.awt.event.ActionEvent evt) {
214 enableUTF8CheckboxActionPerformed(evt);
218 org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text"));
219 enableUTF16Checkbox.addActionListener(
new java.awt.event.ActionListener() {
220 public void actionPerformed(java.awt.event.ActionEvent evt) {
221 enableUTF16CheckboxActionPerformed(evt);
225 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text"));
227 org.openide.awt.Mnemonics.setLocalizedText(enableOcrCheckbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableOcrCheckbox.text"));
228 enableOcrCheckbox.addActionListener(
new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 enableOcrCheckboxActionPerformed(evt);
234 ingestWarningLabel.setFont(ingestWarningLabel.getFont().deriveFont(ingestWarningLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
235 ingestWarningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png")));
236 org.openide.awt.Mnemonics.setLocalizedText(ingestWarningLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestWarningLabel.text"));
238 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
239 this.setLayout(layout);
240 layout.setHorizontalGroup(
241 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242 .addGroup(layout.createSequentialGroup()
243 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244 .addGroup(layout.createSequentialGroup()
246 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247 .addComponent(ingestSettingsLabel)
248 .addGroup(layout.createSequentialGroup()
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
250 .addComponent(languagesLabel, javax.swing.GroupLayout.Alignment.LEADING)
251 .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
252 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
253 .addComponent(ingestWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))))
254 .addGroup(layout.createSequentialGroup()
256 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
257 .addComponent(enableUTF16Checkbox)
258 .addComponent(enableUTF8Checkbox)
259 .addComponent(enableOcrCheckbox))))
262 layout.setVerticalGroup(
263 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264 .addGroup(layout.createSequentialGroup()
266 .addComponent(ingestSettingsLabel)
267 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
268 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269 .addGroup(layout.createSequentialGroup()
270 .addComponent(enableOcrCheckbox)
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
272 .addComponent(enableUTF16Checkbox)
273 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
274 .addComponent(enableUTF8Checkbox)
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
276 .addComponent(languagesLabel)
277 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
278 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
279 .addGroup(layout.createSequentialGroup()
280 .addGap(0, 0, Short.MAX_VALUE)
281 .addComponent(ingestWarningLabel)))
286 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
288 boolean selected = this.enableUTF8Checkbox.isSelected();
290 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
291 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
295 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
297 boolean selected = this.enableUTF16Checkbox.isSelected();
299 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
300 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
303 private void enableOcrCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
304 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
308 private javax.swing.JPanel checkPanel;
309 private javax.swing.JCheckBox enableOcrCheckbox;
310 private javax.swing.JCheckBox enableUTF16Checkbox;
311 private javax.swing.JCheckBox enableUTF8Checkbox;
312 private javax.swing.JLabel ingestSettingsLabel;
313 private javax.swing.JLabel ingestWarningLabel;
314 private javax.swing.JScrollPane langPanel;
315 private javax.swing.JLabel languagesLabel;
319 public void store() {
320 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(),
321 Boolean.toString(enableUTF8Checkbox.isSelected()));
322 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(),
323 Boolean.toString(enableUTF16Checkbox.isSelected()));
324 KeywordSearchSettings.setOcrOption(enableOcrCheckbox.isSelected());
326 if (toUpdate != null) {
327 KeywordSearchSettings.setStringExtractScripts(toUpdate);
331 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);