Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearchGlobalSearchSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2022 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.awt.EventQueue;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.util.logging.Level;
25 import org.netbeans.spi.options.OptionsPanelController;
26 import org.openide.util.NbBundle;
30 
34 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
35 class KeywordSearchGlobalSearchSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
36 
37  private static final long serialVersionUID = 1L;
38  private final Logger logger = Logger.getLogger(KeywordSearchGlobalSearchSettingsPanel.class.getName());
39 
43  KeywordSearchGlobalSearchSettingsPanel() {
44  initComponents();
45  customizeComponents();
46  }
47 
48  private void activateWidgets() {
49  skipNSRLCheckBox.setSelected(KeywordSearchSettings.getSkipKnown());
50  showSnippetsCB.setSelected(KeywordSearchSettings.getShowSnippets());
51  boolean ingestRunning = IngestManager.getInstance().isIngestRunning();
52  ingestWarningLabel.setVisible(ingestRunning);
53  skipNSRLCheckBox.setEnabled(!ingestRunning);
54  }
55 
61  @SuppressWarnings("unchecked")
62  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
63  private void initComponents() {
64 
65  skipNSRLCheckBox = new javax.swing.JCheckBox();
66  filesIndexedLabel = new javax.swing.JLabel();
67  filesIndexedValue = new javax.swing.JLabel();
68  chunksLabel = new javax.swing.JLabel();
69  chunksValLabel = new javax.swing.JLabel();
70  settingsLabel = new javax.swing.JLabel();
71  informationLabel = new javax.swing.JLabel();
72  settingsSeparator = new javax.swing.JSeparator();
73  informationSeparator = new javax.swing.JSeparator();
74  showSnippetsCB = new javax.swing.JCheckBox();
75  ingestWarningLabel = new javax.swing.JLabel();
76 
77  skipNSRLCheckBox.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.skipNSRLCheckBox.text")); // NOI18N
78  skipNSRLCheckBox.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.skipNSRLCheckBox.toolTipText")); // NOI18N
79  skipNSRLCheckBox.addActionListener(new java.awt.event.ActionListener() {
80  public void actionPerformed(java.awt.event.ActionEvent evt) {
81  skipNSRLCheckBoxActionPerformed(evt);
82  }
83  });
84 
85  filesIndexedLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.filesIndexedLabel.text")); // NOI18N
86 
87  filesIndexedValue.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.filesIndexedValue.text")); // NOI18N
88 
89  chunksLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.chunksLabel.text")); // NOI18N
90 
91  chunksValLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.chunksValLabel.text")); // NOI18N
92 
93  settingsLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.settingsLabel.text")); // NOI18N
94 
95  informationLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.informationLabel.text")); // NOI18N
96 
97  showSnippetsCB.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.showSnippetsCB.text")); // NOI18N
98  showSnippetsCB.addActionListener(new java.awt.event.ActionListener() {
99  public void actionPerformed(java.awt.event.ActionEvent evt) {
100  showSnippetsCBActionPerformed(evt);
101  }
102  });
103 
104  ingestWarningLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png"))); // NOI18N
105  ingestWarningLabel.setText(org.openide.util.NbBundle.getMessage(KeywordSearchGlobalSearchSettingsPanel.class, "KeywordSearchGlobalSearchSettingsPanel.ingestWarningLabel.text")); // NOI18N
106 
107  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
108  this.setLayout(layout);
109  layout.setHorizontalGroup(
110  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111  .addGroup(layout.createSequentialGroup()
112  .addContainerGap()
113  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
114  .addGroup(layout.createSequentialGroup()
115  .addGap(16, 16, 16)
116  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117  .addComponent(skipNSRLCheckBox)
118  .addComponent(showSnippetsCB))
119  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
120  .addGroup(layout.createSequentialGroup()
121  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122  .addComponent(ingestWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
123  .addGroup(layout.createSequentialGroup()
124  .addComponent(informationLabel)
125  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
126  .addComponent(informationSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE))
127  .addGroup(layout.createSequentialGroup()
128  .addGap(16, 16, 16)
129  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
130  .addGroup(layout.createSequentialGroup()
131  .addComponent(filesIndexedLabel)
132  .addGap(18, 18, 18)
133  .addComponent(filesIndexedValue))
134  .addGroup(layout.createSequentialGroup()
135  .addComponent(chunksLabel)
136  .addGap(18, 18, 18)
137  .addComponent(chunksValLabel)))
138  .addGap(132, 132, 132)))
139  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
140  .addGroup(layout.createSequentialGroup()
141  .addComponent(settingsLabel)
142  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
143  .addComponent(settingsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
144  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
145  );
146 
147  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {chunksLabel, filesIndexedLabel});
148 
149  layout.setVerticalGroup(
150  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151  .addGroup(layout.createSequentialGroup()
152  .addContainerGap()
153  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
154  .addComponent(settingsLabel)
155  .addComponent(settingsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE))
156  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
157  .addComponent(skipNSRLCheckBox)
158  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
159  .addComponent(showSnippetsCB)
160  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
161  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
162  .addComponent(informationLabel)
163  .addComponent(informationSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
164  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
165  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
166  .addComponent(filesIndexedLabel)
167  .addComponent(filesIndexedValue))
168  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
169  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
170  .addComponent(chunksLabel)
171  .addComponent(chunksValLabel))
172  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
173  .addComponent(ingestWarningLabel)
174  .addContainerGap(151, Short.MAX_VALUE))
175  );
176  }// </editor-fold>//GEN-END:initComponents
177 
178  private void skipNSRLCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skipNSRLCheckBoxActionPerformed
179  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
180  }//GEN-LAST:event_skipNSRLCheckBoxActionPerformed
181 
182  private void showSnippetsCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSnippetsCBActionPerformed
183  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
184  }//GEN-LAST:event_showSnippetsCBActionPerformed
185 
186  // Variables declaration - do not modify//GEN-BEGIN:variables
187  private javax.swing.JLabel chunksLabel;
188  private javax.swing.JLabel chunksValLabel;
189  private javax.swing.JLabel filesIndexedLabel;
190  private javax.swing.JLabel filesIndexedValue;
191  private javax.swing.JLabel informationLabel;
192  private javax.swing.JSeparator informationSeparator;
193  private javax.swing.JLabel ingestWarningLabel;
194  private javax.swing.JLabel settingsLabel;
195  private javax.swing.JSeparator settingsSeparator;
196  private javax.swing.JCheckBox showSnippetsCB;
197  private javax.swing.JCheckBox skipNSRLCheckBox;
198  // End of variables declaration//GEN-END:variables
199 
200  @Override
201  public void store() {
202  KeywordSearchSettings.setSkipKnown(skipNSRLCheckBox.isSelected());
203  KeywordSearchSettings.setShowSnippets(showSnippetsCB.isSelected());
204  }
205 
206  @Override
207  public void load() {
208  activateWidgets();
209  }
210 
211  @NbBundle.Messages({"KeywordSearchGlobalSearchSettingsPanel.customizeComponents.windowsOCR=Enable Optical Character Recognition (OCR) (Requires Windows 64-bit)",
212  "KeywordSearchGlobalSearchSettingsPanel.customizeComponents.windowsLimitedOCR=Only process images which are over 100KB in size or extracted from a document. (Beta) (Requires Windows 64-bit)"})
213  private void customizeComponents() {
214 
215  this.skipNSRLCheckBox.setSelected(KeywordSearchSettings.getSkipKnown());
216 
217  try {
218  filesIndexedValue.setText(Integer.toString(KeywordSearch.getServer().queryNumIndexedFiles()));
219  chunksValLabel.setText(Integer.toString(KeywordSearch.getServer().queryNumIndexedChunks()));
220  } catch (KeywordSearchModuleException | NoOpenCoreException ex) {
221  logger.log(Level.WARNING, "Could not get number of indexed files/chunks"); //NON-NLS
222  }
223 
224  KeywordSearch.addNumIndexedFilesChangeListener(
225  new PropertyChangeListener() {
226  @Override
227  public void propertyChange(PropertyChangeEvent evt) {
228  String changed = evt.getPropertyName();
229  Object newValue = evt.getNewValue();
230 
231  if (changed.equals(KeywordSearch.NUM_FILES_CHANGE_EVT)) {
232  int newFilesIndexed = ((Integer) newValue);
233  filesIndexedValue.setText(Integer.toString(newFilesIndexed));
234  try {
235  chunksValLabel.setText(Integer.toString(KeywordSearch.getServer().queryNumIndexedChunks()));
236  } catch (KeywordSearchModuleException | NoOpenCoreException ex) {
237  logger.log(Level.WARNING, "Could not get number of indexed chunks"); //NON-NLS
238 
239  }
240  }
241  }
242  });
243 
244  //allow panel to toggle its enabled status while it is open based on ingest events
245  IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
246  @Override
247  public void propertyChange(PropertyChangeEvent evt) {
248  Object source = evt.getSource();
249  if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
250  EventQueue.invokeLater(() -> {
251  activateWidgets();
252  });
253  }
254  }
255  });
256  }
257 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.