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();
75 IngestManager.getInstance().addIngestJobEventListener(
new PropertyChangeListener() {
77 public void propertyChange(PropertyChangeEvent evt) {
78 Object source = evt.getSource();
79 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
80 EventQueue.invokeLater(() -> {
88 private void activateScriptsCheckboxes(
boolean activate) {
89 final int components = checkPanel.getComponentCount();
90 for (
int i = 0; i < components; ++i) {
91 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
92 ch.setEnabled(activate);
96 private static String getLangText(SCRIPT script) {
97 StringBuilder sb =
new StringBuilder();
98 sb.append(script.toString()).append(
" (");
99 sb.append(script.getLanguages());
101 return sb.toString();
104 private void initScriptsCheckBoxes() {
105 final List<StringExtract.StringExtractUnicodeTable.SCRIPT> supportedScripts = StringExtract.getSupportedScripts();
106 checkPanel.setLayout(
new GridLayout(0, 1));
107 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : supportedScripts) {
108 String text = getLangText(s);
109 JCheckBox ch =
new JCheckBox(text);
110 ch.addActionListener(
new ActionListener() {
112 public void actionPerformed(ActionEvent e) {
113 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
116 ch.addActionListener(updateLanguagesAction);
118 ch.setSelected(
false);
119 scripts.put(text, s);
123 private void reloadScriptsCheckBoxes() {
125 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString()));
127 enableUTF16Checkbox.setSelected(utf16);
130 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString()));
131 enableUTF8Checkbox.setSelected(utf8);
133 final List<SCRIPT> serviceScripts = KeywordSearchSettings.getStringExtractScripts();
134 final int components = checkPanel.getComponentCount();
136 for (
int i = 0; i < components; ++i) {
137 JCheckBox ch = (JCheckBox) checkPanel.getComponent(i);
139 StringExtract.StringExtractUnicodeTable.SCRIPT script = scripts.get(ch.getText());
141 ch.setSelected(serviceScripts.contains(script));
145 private void activateWidgets() {
146 reloadScriptsCheckBoxes();
149 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString()));
151 enableUTF16Checkbox.setSelected(utf16);
154 = Boolean.parseBoolean(KeywordSearchSettings.getStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString()));
155 enableUTF8Checkbox.setSelected(utf8);
156 final boolean extractEnabled = utf16 || utf8;
158 boolean ingestRunning = IngestManager.getInstance().isIngestRunning();
160 activateScriptsCheckboxes(extractEnabled && !ingestRunning);
161 ingestWarningLabel.setVisible(ingestRunning);
162 enableUTF16Checkbox.setEnabled(!ingestRunning);
163 enableUTF8Checkbox.setEnabled(!ingestRunning);
171 @SuppressWarnings(
"unchecked")
173 private
void initComponents() {
175 languagesLabel =
new javax.swing.JLabel();
176 langPanel =
new javax.swing.JScrollPane();
177 checkPanel =
new javax.swing.JPanel();
178 enableUTF8Checkbox =
new javax.swing.JCheckBox();
179 enableUTF16Checkbox =
new javax.swing.JCheckBox();
180 ingestSettingsLabel =
new javax.swing.JLabel();
181 ingestWarningLabel =
new javax.swing.JLabel();
183 org.openide.awt.Mnemonics.setLocalizedText(languagesLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.languagesLabel.text"));
185 langPanel.setPreferredSize(
new java.awt.Dimension(430, 361));
187 checkPanel.setPreferredSize(
new java.awt.Dimension(400, 361));
189 javax.swing.GroupLayout checkPanelLayout =
new javax.swing.GroupLayout(checkPanel);
190 checkPanel.setLayout(checkPanelLayout);
191 checkPanelLayout.setHorizontalGroup(
192 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193 .addGap(0, 428, Short.MAX_VALUE)
195 checkPanelLayout.setVerticalGroup(
196 checkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addGap(0, 406, Short.MAX_VALUE)
200 langPanel.setViewportView(checkPanel);
202 org.openide.awt.Mnemonics.setLocalizedText(enableUTF8Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF8Checkbox.text"));
203 enableUTF8Checkbox.addActionListener(
new java.awt.event.ActionListener() {
204 public void actionPerformed(java.awt.event.ActionEvent evt) {
205 enableUTF8CheckboxActionPerformed(evt);
209 org.openide.awt.Mnemonics.setLocalizedText(enableUTF16Checkbox,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.enableUTF16Checkbox.text"));
210 enableUTF16Checkbox.addActionListener(
new java.awt.event.ActionListener() {
211 public void actionPerformed(java.awt.event.ActionEvent evt) {
212 enableUTF16CheckboxActionPerformed(evt);
216 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestSettingsLabel.text"));
218 ingestWarningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png")));
219 org.openide.awt.Mnemonics.setLocalizedText(ingestWarningLabel,
org.openide.util.NbBundle.getMessage(KeywordSearchGlobalLanguageSettingsPanel.class,
"KeywordSearchGlobalLanguageSettingsPanel.ingestWarningLabel.text"));
221 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
222 this.setLayout(layout);
223 layout.setHorizontalGroup(
224 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
225 .addGroup(layout.createSequentialGroup()
227 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228 .addGroup(layout.createSequentialGroup()
229 .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
230 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
231 .addComponent(ingestWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
232 .addGroup(layout.createSequentialGroup()
233 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234 .addComponent(languagesLabel)
235 .addGroup(layout.createSequentialGroup()
237 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
238 .addComponent(enableUTF16Checkbox)
239 .addComponent(enableUTF8Checkbox)))
240 .addComponent(ingestSettingsLabel))
241 .addGap(0, 0, Short.MAX_VALUE)))
244 layout.setVerticalGroup(
245 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246 .addGroup(layout.createSequentialGroup()
248 .addComponent(ingestSettingsLabel)
249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251 .addGroup(layout.createSequentialGroup()
252 .addComponent(enableUTF16Checkbox)
253 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
254 .addComponent(enableUTF8Checkbox)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
256 .addComponent(languagesLabel)
257 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
258 .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
259 .addGroup(layout.createSequentialGroup()
260 .addGap(0, 0, Short.MAX_VALUE)
261 .addComponent(ingestWarningLabel)))
266 private void enableUTF8CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
268 boolean selected = this.enableUTF8Checkbox.isSelected();
270 activateScriptsCheckboxes(selected || this.enableUTF16Checkbox.isSelected());
271 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
275 private void enableUTF16CheckboxActionPerformed(java.awt.event.ActionEvent evt) {
277 boolean selected = this.enableUTF16Checkbox.isSelected();
279 activateScriptsCheckboxes(selected || this.enableUTF8Checkbox.isSelected());
280 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
284 private javax.swing.JPanel checkPanel;
285 private javax.swing.JCheckBox enableUTF16Checkbox;
286 private javax.swing.JCheckBox enableUTF8Checkbox;
287 private javax.swing.JLabel ingestSettingsLabel;
288 private javax.swing.JLabel ingestWarningLabel;
289 private javax.swing.JScrollPane langPanel;
290 private javax.swing.JLabel languagesLabel;
294 public void store() {
295 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(),
296 Boolean.toString(enableUTF8Checkbox.isSelected()));
297 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(),
298 Boolean.toString(enableUTF16Checkbox.isSelected()));
300 if (toUpdate != null) {
301 KeywordSearchSettings.setStringExtractScripts(toUpdate);
305 XmlKeywordSearchList.getCurrent().fireLanguagesEvent(KeywordSearchList.LanguagesEvent.LANGUAGES_CHANGED);