Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DropdownSingleTermSearchPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.FocusEvent;
25 import java.awt.event.FocusListener;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseMotionListener;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import java.util.ArrayList;
31 import java.util.HashSet;
32 import java.util.List;
33 import java.util.Set;
34 import java.util.logging.Level;
35 import javax.swing.JList;
36 import javax.swing.JMenuItem;
37 import javax.swing.event.ListSelectionEvent;
38 import org.openide.util.NbBundle;
41 
56 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
57 public class DropdownSingleTermSearchPanel extends AdHocSearchPanel {
58 
59  private static final long serialVersionUID = 1L;
60  private static final Logger LOGGER = Logger.getLogger(DropdownSingleTermSearchPanel.class.getName());
61  private static DropdownSingleTermSearchPanel defaultInstance = null;
62  private boolean ingestRunning;
63 
64 
72  public static synchronized DropdownSingleTermSearchPanel getDefault() {
73  if (null == defaultInstance) {
74  defaultInstance = new DropdownSingleTermSearchPanel();
75  }
76  return defaultInstance;
77  }
78 
83  @NbBundle.Messages({"DropdownSingleTermSearchPanel.selected=Ad Hoc Search data source filter is selected"})
85  initComponents();
86  customizeComponents();
87  dataSourceList.setModel(getDataSourceListModel());
88  this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
89  firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
90  });
91  this.dataSourceList.addMouseMotionListener(new MouseMotionListener() {
92 
93  @Override
94  public void mouseDragged(MouseEvent evt) {
95  //Unused by now
96  }
97 
98  @Override
99  public void mouseMoved(MouseEvent evt) {
100  JList<String> DsList = (JList<String>) evt.getSource();
101  int index = DsList.locationToIndex(evt.getPoint());
102  if (index > -1) {
103  DsList.setToolTipText(getDataSourceToolTipList().get(index));
104  }
105  }
106  });
107  }
108 
113  private void customizeComponents() {
114  keywordTextField.addFocusListener(new FocusListener() {
115  @Override
116  public void focusGained(FocusEvent e) {
117  }
118 
119  @Override
120  public void focusLost(FocusEvent e) {
121  if (keywordTextField.getText().isEmpty()) {
122  clearSearchBox();
123  }
124  }
125  });
126 
127  keywordTextField.setComponentPopupMenu(rightClickMenu);
128  ActionListener actList = (ActionEvent e) -> {
129  JMenuItem jmi = (JMenuItem) e.getSource();
130  if (jmi.equals(cutMenuItem)) {
131  keywordTextField.cut();
132  } else if (jmi.equals(copyMenuItem)) {
133  keywordTextField.copy();
134  } else if (jmi.equals(pasteMenuItem)) {
135  keywordTextField.paste();
136  } else if (jmi.equals(selectAllMenuItem)) {
137  keywordTextField.selectAll();
138  }
139  };
140  ingestRunning = IngestManager.getInstance().isIngestRunning();
141  updateIngestIndexLabel();
142 
143  IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
144  @Override
145  public void propertyChange(PropertyChangeEvent evt) {
146  Object source = evt.getSource();
147  if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
148  EventQueue.invokeLater(() -> {
149  ingestRunning = IngestManager.getInstance().isIngestRunning();
150  updateIngestIndexLabel();
151  });
152  }
153  }
154  });
155 
156  cutMenuItem.addActionListener(actList);
157  copyMenuItem.addActionListener(actList);
158  pasteMenuItem.addActionListener(actList);
159  selectAllMenuItem.addActionListener(actList);
160  }
161 
167  void addSearchButtonActionListener(ActionListener actionListener) {
168  searchButton.addActionListener(actionListener);
169  }
170 
175  void clearSearchBox() {
176  keywordTextField.setText("");
177  }
178 
179  void setRegexSearchEnabled(boolean enabled) {
180  exactRadioButton.setSelected(true);
181  regexRadioButton.setEnabled(enabled);
182  }
183 
190  @NbBundle.Messages({"DropdownSingleTermSearchPanel.warning.title=Warning",
191  "DropdownSingleTermSearchPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
192  @Override
193  List<KeywordList> getKeywordLists() {
194  if (regexRadioButton.isSelected()) {
195  if((keywordTextField.getText() != null) &&
196  (keywordTextField.getText().startsWith("^") ||
197  (keywordTextField.getText().endsWith("$") && ! keywordTextField.getText().endsWith("\\$")))) {
198 
199  KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "DropdownSingleTermSearchPanel.warning.title"),
200  NbBundle.getMessage(this.getClass(), "DropdownSingleTermSearchPanel.warning.text"),
201  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
202  }
203  }
204  List<Keyword> keywords = new ArrayList<>();
205  keywords.add(new Keyword(keywordTextField.getText(), !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
206  List<KeywordList> keywordLists = new ArrayList<>();
207  keywordLists.add(new KeywordList(keywords));
208  return keywordLists;
209  }
210 
214  @Override
215  protected void postFilesIndexedChange() {
216  updateIngestIndexLabel();
217  }
218 
224  @SuppressWarnings("unchecked")
225  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
226  private void initComponents() {
227 
228  queryTypeButtonGroup = new javax.swing.ButtonGroup();
229  rightClickMenu = new javax.swing.JPopupMenu();
230  cutMenuItem = new javax.swing.JMenuItem();
231  copyMenuItem = new javax.swing.JMenuItem();
232  pasteMenuItem = new javax.swing.JMenuItem();
233  selectAllMenuItem = new javax.swing.JMenuItem();
234  keywordTextField = new javax.swing.JTextField();
235  searchButton = new javax.swing.JButton();
236  exactRadioButton = new javax.swing.JRadioButton();
237  substringRadioButton = new javax.swing.JRadioButton();
238  regexRadioButton = new javax.swing.JRadioButton();
239  dataSourceCheckBox = new javax.swing.JCheckBox();
240  jScrollPane1 = new javax.swing.JScrollPane();
241  dataSourceList = new javax.swing.JList<>();
242  ingestIndexLabel = new javax.swing.JLabel();
243 
244  org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.cutMenuItem.text")); // NOI18N
245  rightClickMenu.add(cutMenuItem);
246 
247  org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.copyMenuItem.text")); // NOI18N
248  rightClickMenu.add(copyMenuItem);
249 
250  org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.pasteMenuItem.text")); // NOI18N
251  rightClickMenu.add(pasteMenuItem);
252 
253  org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.selectAllMenuItem.text")); // NOI18N
254  rightClickMenu.add(selectAllMenuItem);
255 
256  keywordTextField.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
257  keywordTextField.setText(org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.keywordTextField.text")); // NOI18N
258  keywordTextField.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));
259  keywordTextField.setMinimumSize(new java.awt.Dimension(2, 25));
260  keywordTextField.setPreferredSize(new java.awt.Dimension(2, 25));
261  keywordTextField.addMouseListener(new java.awt.event.MouseAdapter() {
262  public void mouseClicked(java.awt.event.MouseEvent evt) {
263  keywordTextFieldMouseClicked(evt);
264  }
265  });
266  keywordTextField.addActionListener(new java.awt.event.ActionListener() {
267  public void actionPerformed(java.awt.event.ActionEvent evt) {
268  keywordTextFieldActionPerformed(evt);
269  }
270  });
271 
272  searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
273  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.searchButton.text")); // NOI18N
274  searchButton.addActionListener(new java.awt.event.ActionListener() {
275  public void actionPerformed(java.awt.event.ActionEvent evt) {
276  searchButtonActionPerformed(evt);
277  }
278  });
279 
280  queryTypeButtonGroup.add(exactRadioButton);
281  org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.exactRadioButton.text")); // NOI18N
282 
283  queryTypeButtonGroup.add(substringRadioButton);
284  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.substringRadioButton.text")); // NOI18N
285 
286  queryTypeButtonGroup.add(regexRadioButton);
287  org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.regexRadioButton.text")); // NOI18N
288 
289  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSingleTermSearchPanel.dataSourceCheckBox.text")); // NOI18N
290  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
291  public void actionPerformed(java.awt.event.ActionEvent evt) {
292  dataSourceCheckBoxActionPerformed(evt);
293  }
294  });
295 
296  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
297  jScrollPane1.setViewportView(dataSourceList);
298 
299  ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
300  org.openide.awt.Mnemonics.setLocalizedText(ingestIndexLabel, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSingleTermSearchPanel.ingestIndexLabel.text")); // NOI18N
301 
302  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
303  this.setLayout(layout);
304  layout.setHorizontalGroup(
305  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306  .addGroup(layout.createSequentialGroup()
307  .addGap(5, 5, 5)
308  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
309  .addGroup(layout.createSequentialGroup()
310  .addComponent(exactRadioButton)
311  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
312  .addComponent(substringRadioButton)
313  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
314  .addComponent(regexRadioButton))
315  .addComponent(dataSourceCheckBox)
316  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
317  .addGroup(layout.createSequentialGroup()
318  .addComponent(searchButton)
319  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
320  .addComponent(ingestIndexLabel))
321  .addComponent(keywordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
322  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
323  );
324  layout.setVerticalGroup(
325  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326  .addGroup(layout.createSequentialGroup()
327  .addContainerGap()
328  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
329  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
330  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
331  .addComponent(exactRadioButton)
332  .addComponent(substringRadioButton)
333  .addComponent(regexRadioButton))
334  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
335  .addComponent(dataSourceCheckBox)
336  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
338  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
340  .addComponent(searchButton)
341  .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
342  .addContainerGap())
343  );
344  }// </editor-fold>//GEN-END:initComponents
345 
351  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
352  keywordTextFieldActionPerformed(evt);
353  }//GEN-LAST:event_searchButtonActionPerformed
354 
360  private void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keywordTextFieldActionPerformed
361  try {
362  search();
363  } catch (Exception e) {
364  LOGGER.log(Level.SEVERE, "Error performing ad hoc single keyword search", e); //NON-NLS
365  }
366  }//GEN-LAST:event_keywordTextFieldActionPerformed
367 
373  private void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_keywordTextFieldMouseClicked
374  if (evt.isPopupTrigger()) {
375  rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
376  }
377  }//GEN-LAST:event_keywordTextFieldMouseClicked
378 
379  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
380  updateDataSourceListModel();
381  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
382 
386  void updateDataSourceListModel() {
387  getDataSourceListModel().removeAllElements();
388  for (String dsName : getDataSourceArray()) {
389  getDataSourceListModel().addElement(dsName);
390  }
391  setComponentsEnabled();
392  firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
393 
394  }
395 
399  private void setComponentsEnabled() {
400  boolean enabled = this.dataSourceCheckBox.isSelected();
401  this.dataSourceList.setEnabled(enabled);
402  if (enabled) {
403  this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
404  } else {
405  this.dataSourceList.setSelectedIndices(new int[0]);
406  }
407  }
408 
413  @Override
414  Set<Long> getDataSourcesSelected() {
415  Set<Long> dataSourceObjIdSet = new HashSet<>();
416  for (Long key : getDataSourceMap().keySet()) {
417  String value = getDataSourceMap().get(key);
418  for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
419  if (value.equals(dataSource)) {
420  dataSourceObjIdSet.add(key);
421  }
422  }
423  }
424  return dataSourceObjIdSet;
425  }
426 
430  private void updateIngestIndexLabel() {
431  if (ingestRunning) {
432  ingestIndexLabel.setText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
433  } else {
434  ingestIndexLabel.setText(NbBundle.getMessage(this.getClass(), "KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
435  }
436  }
437 
438  // Variables declaration - do not modify//GEN-BEGIN:variables
439  private javax.swing.JMenuItem copyMenuItem;
440  private javax.swing.JMenuItem cutMenuItem;
441  private javax.swing.JCheckBox dataSourceCheckBox;
442  private javax.swing.JList<String> dataSourceList;
443  private javax.swing.JRadioButton exactRadioButton;
444  private javax.swing.JLabel ingestIndexLabel;
445  private javax.swing.JScrollPane jScrollPane1;
446  private javax.swing.JTextField keywordTextField;
447  private javax.swing.JMenuItem pasteMenuItem;
448  private javax.swing.ButtonGroup queryTypeButtonGroup;
449  private javax.swing.JRadioButton regexRadioButton;
450  private javax.swing.JPopupMenu rightClickMenu;
451  private javax.swing.JButton searchButton;
452  private javax.swing.JMenuItem selectAllMenuItem;
453  private javax.swing.JRadioButton substringRadioButton;
454  // End of variables declaration//GEN-END:variables
455 }
static synchronized IngestManager getInstance()
void addIngestJobEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.