Autopsy  4.6.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-2016 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.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.FocusEvent;
24 import java.awt.event.FocusListener;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.logging.Level;
28 import javax.swing.JMenuItem;
29 import org.openide.util.NbBundle;
31 
46 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
47 public class DropdownSingleTermSearchPanel extends AdHocSearchPanel {
48 
49  private static final long serialVersionUID = 1L;
50  private static final Logger LOGGER = Logger.getLogger(DropdownSingleTermSearchPanel.class.getName());
51  private static DropdownSingleTermSearchPanel defaultInstance = null;
52 
59  public static synchronized DropdownSingleTermSearchPanel getDefault() {
60  if (null == defaultInstance) {
61  defaultInstance = new DropdownSingleTermSearchPanel();
62  }
63  return defaultInstance;
64  }
65 
71  initComponents();
72  customizeComponents();
73  }
74 
79  private void customizeComponents() {
80  keywordTextField.addFocusListener(new FocusListener() {
81  @Override
82  public void focusGained(FocusEvent e) {
83  }
84 
85  @Override
86  public void focusLost(FocusEvent e) {
87  if (keywordTextField.getText().isEmpty()) {
88  clearSearchBox();
89  }
90  }
91  });
92 
93  keywordTextField.setComponentPopupMenu(rightClickMenu);
94  ActionListener actList = (ActionEvent e) -> {
95  JMenuItem jmi = (JMenuItem) e.getSource();
96  if (jmi.equals(cutMenuItem)) {
97  keywordTextField.cut();
98  } else if (jmi.equals(copyMenuItem)) {
99  keywordTextField.copy();
100  } else if (jmi.equals(pasteMenuItem)) {
101  keywordTextField.paste();
102  } else if (jmi.equals(selectAllMenuItem)) {
103  keywordTextField.selectAll();
104  }
105  };
106  cutMenuItem.addActionListener(actList);
107  copyMenuItem.addActionListener(actList);
108  pasteMenuItem.addActionListener(actList);
109  selectAllMenuItem.addActionListener(actList);
110  }
111 
117  void addSearchButtonActionListener(ActionListener actionListener) {
118  searchButton.addActionListener(actionListener);
119  }
120 
125  void clearSearchBox() {
126  keywordTextField.setText("");
127  }
128 
129  void setRegexSearchEnabled(boolean enabled) {
130  exactRadioButton.setSelected(true);
131  regexRadioButton.setEnabled(enabled);
132  }
133 
140  @NbBundle.Messages({"DropdownSingleTermSearchPanel.warning.title=Warning",
141  "DropdownSingleTermSearchPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
142  @Override
143  List<KeywordList> getKeywordLists() {
144 
145  if (regexRadioButton.isSelected()) {
146  if((keywordTextField.getText() != null) &&
147  (keywordTextField.getText().startsWith("^") ||
148  (keywordTextField.getText().endsWith("$") && ! keywordTextField.getText().endsWith("\\$")))) {
149 
150  KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "DropdownSingleTermSearchPanel.warning.title"),
151  NbBundle.getMessage(this.getClass(), "DropdownSingleTermSearchPanel.warning.text"),
152  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
153  }
154  }
155 
156  List<Keyword> keywords = new ArrayList<>();
157  keywords.add(new Keyword(keywordTextField.getText(), !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
158  List<KeywordList> keywordLists = new ArrayList<>();
159  keywordLists.add(new KeywordList(keywords));
160  return keywordLists;
161  }
162 
166  @Override
167  protected void postFilesIndexedChange() {
168  }
169 
175  @SuppressWarnings("unchecked")
176  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
177  private void initComponents() {
178 
179  queryTypeButtonGroup = new javax.swing.ButtonGroup();
180  rightClickMenu = new javax.swing.JPopupMenu();
181  cutMenuItem = new javax.swing.JMenuItem();
182  copyMenuItem = new javax.swing.JMenuItem();
183  pasteMenuItem = new javax.swing.JMenuItem();
184  selectAllMenuItem = new javax.swing.JMenuItem();
185  keywordTextField = new javax.swing.JTextField();
186  searchButton = new javax.swing.JButton();
187  exactRadioButton = new javax.swing.JRadioButton();
188  substringRadioButton = new javax.swing.JRadioButton();
189  regexRadioButton = new javax.swing.JRadioButton();
190 
191  org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.cutMenuItem.text")); // NOI18N
192  rightClickMenu.add(cutMenuItem);
193 
194  org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.copyMenuItem.text")); // NOI18N
195  rightClickMenu.add(copyMenuItem);
196 
197  org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.pasteMenuItem.text")); // NOI18N
198  rightClickMenu.add(pasteMenuItem);
199 
200  org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.selectAllMenuItem.text")); // NOI18N
201  rightClickMenu.add(selectAllMenuItem);
202 
203  keywordTextField.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
204  keywordTextField.setText(org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.keywordTextField.text")); // NOI18N
205  keywordTextField.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));
206  keywordTextField.setMinimumSize(new java.awt.Dimension(2, 25));
207  keywordTextField.setPreferredSize(new java.awt.Dimension(2, 25));
208  keywordTextField.addMouseListener(new java.awt.event.MouseAdapter() {
209  public void mouseClicked(java.awt.event.MouseEvent evt) {
210  keywordTextFieldMouseClicked(evt);
211  }
212  });
213  keywordTextField.addActionListener(new java.awt.event.ActionListener() {
214  public void actionPerformed(java.awt.event.ActionEvent evt) {
215  keywordTextFieldActionPerformed(evt);
216  }
217  });
218 
219  searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
220  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.searchButton.text")); // NOI18N
221  searchButton.addActionListener(new java.awt.event.ActionListener() {
222  public void actionPerformed(java.awt.event.ActionEvent evt) {
223  searchButtonActionPerformed(evt);
224  }
225  });
226 
227  queryTypeButtonGroup.add(exactRadioButton);
228  exactRadioButton.setSelected(true);
229  org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.exactRadioButton.text")); // NOI18N
230 
231  queryTypeButtonGroup.add(substringRadioButton);
232  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.substringRadioButton.text")); // NOI18N
233 
234  queryTypeButtonGroup.add(regexRadioButton);
235  org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.regexRadioButton.text")); // NOI18N
236 
237  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
238  this.setLayout(layout);
239  layout.setHorizontalGroup(
240  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
241  .addGroup(layout.createSequentialGroup()
242  .addGap(5, 5, 5)
243  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244  .addGroup(layout.createSequentialGroup()
245  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
246  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
247  .addComponent(searchButton))
248  .addGroup(layout.createSequentialGroup()
249  .addComponent(exactRadioButton)
250  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
251  .addComponent(substringRadioButton)
252  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
253  .addComponent(regexRadioButton)
254  .addGap(0, 27, Short.MAX_VALUE)))
255  .addGap(5, 5, 5))
256  );
257  layout.setVerticalGroup(
258  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addGroup(layout.createSequentialGroup()
260  .addContainerGap()
261  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
262  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
263  .addComponent(searchButton, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
264  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
265  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
266  .addComponent(exactRadioButton)
267  .addComponent(substringRadioButton)
268  .addComponent(regexRadioButton))
269  .addContainerGap())
270  );
271  }// </editor-fold>//GEN-END:initComponents
272 
278  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
279  keywordTextFieldActionPerformed(evt);
280  }//GEN-LAST:event_searchButtonActionPerformed
281 
287  private void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keywordTextFieldActionPerformed
288  try {
289  search();
290  } catch (Exception e) {
291  LOGGER.log(Level.SEVERE, "Error performing ad hoc single keyword search", e); //NON-NLS
292  }
293  }//GEN-LAST:event_keywordTextFieldActionPerformed
294 
300  private void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_keywordTextFieldMouseClicked
301  if (evt.isPopupTrigger()) {
302  rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
303  }
304  }//GEN-LAST:event_keywordTextFieldMouseClicked
305 
306  // Variables declaration - do not modify//GEN-BEGIN:variables
307  private javax.swing.JMenuItem copyMenuItem;
308  private javax.swing.JMenuItem cutMenuItem;
309  private javax.swing.JRadioButton exactRadioButton;
310  private javax.swing.JTextField keywordTextField;
311  private javax.swing.JMenuItem pasteMenuItem;
312  private javax.swing.ButtonGroup queryTypeButtonGroup;
313  private javax.swing.JRadioButton regexRadioButton;
314  private javax.swing.JPopupMenu rightClickMenu;
315  private javax.swing.JButton searchButton;
316  private javax.swing.JMenuItem selectAllMenuItem;
317  private javax.swing.JRadioButton substringRadioButton;
318  // End of variables declaration//GEN-END:variables
319 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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