19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.EventQueue;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.FocusEvent;
25 import java.awt.event.FocusListener;
26 import java.beans.PropertyChangeEvent;
27 import java.beans.PropertyChangeListener;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.List;
32 import java.util.logging.Level;
33 import javax.swing.JMenuItem;
34 import javax.swing.event.ListSelectionEvent;
35 import org.openide.util.NbBundle;
53 @SuppressWarnings(
"PMD.SingularField")
56 private static final long serialVersionUID = 1L;
70 if (null == defaultInstance) {
73 return defaultInstance;
80 @NbBundle.Messages({
"DropdownSingleTermSearchPanel.selected=Ad Hoc Search data source filter is selected"})
83 customizeComponents();
84 dataSourceList.setModel(getDataSourceListModel());
85 this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
86 firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
95 keywordTextField.addFocusListener(
new FocusListener() {
97 public void focusGained(FocusEvent e) {
101 public void focusLost(FocusEvent e) {
102 if (keywordTextField.getText().isEmpty()) {
108 keywordTextField.setComponentPopupMenu(rightClickMenu);
109 ActionListener actList = (ActionEvent e) -> {
110 JMenuItem jmi = (JMenuItem) e.getSource();
111 if (jmi.equals(cutMenuItem)) {
112 keywordTextField.cut();
113 }
else if (jmi.equals(copyMenuItem)) {
114 keywordTextField.copy();
115 }
else if (jmi.equals(pasteMenuItem)) {
116 keywordTextField.paste();
117 }
else if (jmi.equals(selectAllMenuItem)) {
118 keywordTextField.selectAll();
122 updateIngestIndexLabel();
124 jSaveSearchResults.setSelected(
true);
128 public void propertyChange(PropertyChangeEvent evt) {
129 Object source = evt.getSource();
130 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
131 EventQueue.invokeLater(() -> {
133 updateIngestIndexLabel();
139 cutMenuItem.addActionListener(actList);
140 copyMenuItem.addActionListener(actList);
141 pasteMenuItem.addActionListener(actList);
142 selectAllMenuItem.addActionListener(actList);
150 void addSearchButtonActionListener(ActionListener actionListener) {
151 searchButton.addActionListener(actionListener);
158 void clearSearchBox() {
159 keywordTextField.setText(
"");
162 void setRegexSearchEnabled(
boolean enabled) {
163 exactRadioButton.setSelected(
true);
164 regexRadioButton.setEnabled(enabled);
173 @NbBundle.Messages({
"DropdownSingleTermSearchPanel.warning.title=Warning",
174 "DropdownSingleTermSearchPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
176 List<KeywordList> getKeywordLists() {
177 if (regexRadioButton.isSelected()) {
178 if((keywordTextField.getText() != null) &&
179 (keywordTextField.getText().startsWith(
"^") ||
180 (keywordTextField.getText().endsWith(
"$") && ! keywordTextField.getText().endsWith(
"\\$")))) {
182 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"DropdownSingleTermSearchPanel.warning.title"),
183 NbBundle.getMessage(
this.getClass(),
"DropdownSingleTermSearchPanel.warning.text"),
184 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
187 List<Keyword> keywords =
new ArrayList<>();
188 keywords.add(
new Keyword(keywordTextField.getText(), !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
189 List<KeywordList> keywordLists =
new ArrayList<>();
190 keywordLists.add(
new KeywordList(keywords));
199 updateIngestIndexLabel();
207 @SuppressWarnings(
"unchecked")
209 private
void initComponents() {
211 queryTypeButtonGroup =
new javax.swing.ButtonGroup();
212 rightClickMenu =
new javax.swing.JPopupMenu();
213 cutMenuItem =
new javax.swing.JMenuItem();
214 copyMenuItem =
new javax.swing.JMenuItem();
215 pasteMenuItem =
new javax.swing.JMenuItem();
216 selectAllMenuItem =
new javax.swing.JMenuItem();
217 keywordTextField =
new javax.swing.JTextField();
218 searchButton =
new javax.swing.JButton();
219 exactRadioButton =
new javax.swing.JRadioButton();
220 substringRadioButton =
new javax.swing.JRadioButton();
221 regexRadioButton =
new javax.swing.JRadioButton();
222 dataSourceCheckBox =
new javax.swing.JCheckBox();
223 jScrollPane1 =
new javax.swing.JScrollPane();
224 dataSourceList =
new javax.swing.JList<>();
225 ingestIndexLabel =
new javax.swing.JLabel();
226 jSaveSearchResults =
new javax.swing.JCheckBox();
228 org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.cutMenuItem.text"));
229 rightClickMenu.add(cutMenuItem);
231 org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.copyMenuItem.text"));
232 rightClickMenu.add(copyMenuItem);
234 org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.pasteMenuItem.text"));
235 rightClickMenu.add(pasteMenuItem);
237 org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.selectAllMenuItem.text"));
238 rightClickMenu.add(selectAllMenuItem);
240 keywordTextField.setFont(keywordTextField.getFont().deriveFont(keywordTextField.getFont().getSize()+3f));
242 keywordTextField.setBorder(
new javax.swing.border.LineBorder(
new java.awt.Color(192, 192, 192), 1,
true));
243 keywordTextField.setMinimumSize(
new java.awt.Dimension(2, 25));
244 keywordTextField.setPreferredSize(
new java.awt.Dimension(2, 25));
245 keywordTextField.addMouseListener(
new java.awt.event.MouseAdapter() {
246 public void mouseClicked(java.awt.event.MouseEvent evt) {
247 keywordTextFieldMouseClicked(evt);
250 keywordTextField.addActionListener(
new java.awt.event.ActionListener() {
251 public void actionPerformed(java.awt.event.ActionEvent evt) {
252 keywordTextFieldActionPerformed(evt);
256 searchButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/search-icon.png")));
257 org.openide.awt.Mnemonics.setLocalizedText(searchButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.searchButton.text"));
258 searchButton.addActionListener(
new java.awt.event.ActionListener() {
259 public void actionPerformed(java.awt.event.ActionEvent evt) {
260 searchButtonActionPerformed(evt);
264 queryTypeButtonGroup.add(exactRadioButton);
265 org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.exactRadioButton.text"));
267 queryTypeButtonGroup.add(substringRadioButton);
268 org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.substringRadioButton.text"));
270 queryTypeButtonGroup.add(regexRadioButton);
271 org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.regexRadioButton.text"));
273 org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSingleTermSearchPanel.dataSourceCheckBox.text"));
274 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
275 public void actionPerformed(java.awt.event.ActionEvent evt) {
276 dataSourceCheckBoxActionPerformed(evt);
280 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
281 jScrollPane1.setViewportView(dataSourceList);
283 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getSize()-1f));
284 org.openide.awt.Mnemonics.setLocalizedText(ingestIndexLabel,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSingleTermSearchPanel.ingestIndexLabel.text"));
286 org.openide.awt.Mnemonics.setLocalizedText(jSaveSearchResults,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSingleTermSearchPanel.jSaveSearchResults.text"));
287 jSaveSearchResults.setToolTipText(
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSingleTermSearchPanel.jSaveSearchResults.toolTipText"));
289 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
290 this.setLayout(layout);
291 layout.setHorizontalGroup(
292 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293 .addGroup(layout.createSequentialGroup()
295 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
296 .addGroup(layout.createSequentialGroup()
297 .addComponent(exactRadioButton)
298 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
299 .addComponent(substringRadioButton)
300 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
301 .addComponent(regexRadioButton))
302 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
303 .addComponent(jSaveSearchResults)
304 .addGroup(layout.createSequentialGroup()
305 .addComponent(searchButton)
307 .addComponent(ingestIndexLabel))
308 .addComponent(keywordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
309 .addComponent(dataSourceCheckBox))
310 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
312 layout.setVerticalGroup(
313 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
314 .addGroup(layout.createSequentialGroup()
316 .addComponent(keywordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
317 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
318 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
319 .addComponent(exactRadioButton)
320 .addComponent(substringRadioButton)
321 .addComponent(regexRadioButton))
322 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
323 .addComponent(dataSourceCheckBox)
324 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
326 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
327 .addComponent(jSaveSearchResults)
328 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
329 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
330 .addComponent(searchButton)
331 .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
332 .addContainerGap(22, Short.MAX_VALUE))
342 keywordTextFieldActionPerformed(evt);
352 search(jSaveSearchResults.isSelected());
353 }
catch (Exception e) {
354 LOGGER.log(Level.SEVERE,
"Error performing ad hoc single keyword search", e);
364 if (evt.isPopupTrigger()) {
365 rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
370 updateDataSourceListModel();
376 void updateDataSourceListModel() {
377 getDataSourceListModel().removeAllElements();
378 for (String dsName : getDataSourceArray()) {
379 getDataSourceListModel().addElement(dsName);
381 setComponentsEnabled();
382 firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
389 if (getDataSourceListModel().size() > 1) {
390 this.dataSourceCheckBox.setEnabled(
true);
392 boolean enabled = this.dataSourceCheckBox.isSelected();
393 this.dataSourceList.setEnabled(enabled);
395 this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
397 this.dataSourceList.setSelectedIndices(
new int[0]);
400 this.dataSourceCheckBox.setEnabled(
false);
401 this.dataSourceCheckBox.setSelected(
false);
402 this.dataSourceList.setEnabled(
false);
403 this.dataSourceList.setSelectedIndices(
new int[0]);
412 Set<Long> getDataSourcesSelected() {
413 Set<Long> dataSourceObjIdSet =
new HashSet<>();
414 for (Long key : getDataSourceMap().keySet()) {
415 String value = getDataSourceMap().get(key);
416 for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
417 if (value.equals(dataSource)) {
418 dataSourceObjIdSet.add(key);
422 return dataSourceObjIdSet;
430 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
432 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
javax.swing.JMenuItem copyMenuItem
static synchronized IngestManager getInstance()
javax.swing.JMenuItem pasteMenuItem
void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt)
javax.swing.JMenuItem cutMenuItem
javax.swing.JButton searchButton
boolean isIngestRunning()
void postFilesIndexedChange()
void setComponentsEnabled()
javax.swing.JList< String > dataSourceList
static synchronized DropdownSingleTermSearchPanel getDefault()
javax.swing.JRadioButton substringRadioButton
javax.swing.JPopupMenu rightClickMenu
DropdownSingleTermSearchPanel()
javax.swing.JCheckBox jSaveSearchResults
void updateIngestIndexLabel()
void addIngestJobEventListener(final PropertyChangeListener listener)
javax.swing.JRadioButton exactRadioButton
javax.swing.JLabel ingestIndexLabel
void customizeComponents()
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JRadioButton regexRadioButton
javax.swing.JMenuItem selectAllMenuItem
javax.swing.ButtonGroup queryTypeButtonGroup
javax.swing.JCheckBox dataSourceCheckBox
synchronized static Logger getLogger(String name)
javax.swing.JTextField keywordTextField
void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JScrollPane jScrollPane1
void searchButtonActionPerformed(java.awt.event.ActionEvent evt)