Autopsy  4.5.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;
30 
45 public class DropdownSingleTermSearchPanel extends KeywordSearchPanel {
46 
47  private static final long serialVersionUID = 1L;
48  private static final Logger LOGGER = Logger.getLogger(DropdownSingleTermSearchPanel.class.getName());
50 
57  public static synchronized DropdownSingleTermSearchPanel getDefault() {
58  if (null == defaultInstance) {
59  defaultInstance = new DropdownSingleTermSearchPanel();
60  }
61  return defaultInstance;
62  }
63 
71  }
72 
77  private void customizeComponents() {
78  keywordTextField.addFocusListener(new FocusListener() {
79  @Override
80  public void focusGained(FocusEvent e) {
81  }
82 
83  @Override
84  public void focusLost(FocusEvent e) {
85  if (keywordTextField.getText().isEmpty()) {
86  clearSearchBox();
87  }
88  }
89  });
90 
91  keywordTextField.setComponentPopupMenu(rightClickMenu);
92  ActionListener actList = (ActionEvent e) -> {
93  JMenuItem jmi = (JMenuItem) e.getSource();
94  if (jmi.equals(cutMenuItem)) {
95  keywordTextField.cut();
96  } else if (jmi.equals(copyMenuItem)) {
97  keywordTextField.copy();
98  } else if (jmi.equals(pasteMenuItem)) {
99  keywordTextField.paste();
100  } else if (jmi.equals(selectAllMenuItem)) {
101  keywordTextField.selectAll();
102  }
103  };
104  cutMenuItem.addActionListener(actList);
105  copyMenuItem.addActionListener(actList);
106  pasteMenuItem.addActionListener(actList);
107  selectAllMenuItem.addActionListener(actList);
108  }
109 
115  void addSearchButtonActionListener(ActionListener actionListener) {
116  searchButton.addActionListener(actionListener);
117  }
118 
123  void clearSearchBox() {
124  keywordTextField.setText("");
125  }
126 
127  void setRegexSearchEnabled(boolean enabled) {
128  exactRadioButton.setSelected(true);
129  regexRadioButton.setEnabled(enabled);
130  }
131 
138  @Override
139  List<KeywordList> getKeywordLists() {
140  List<Keyword> keywords = new ArrayList<>();
141  keywords.add(new Keyword(keywordTextField.getText(), !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
142  List<KeywordList> keywordLists = new ArrayList<>();
143  keywordLists.add(new KeywordList(keywords));
144  return keywordLists;
145  }
146 
150  @Override
151  protected void postFilesIndexedChange() {
152  }
153 
159  @SuppressWarnings("unchecked")
160  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
161  private void initComponents() {
162 
163  queryTypeButtonGroup = new javax.swing.ButtonGroup();
164  rightClickMenu = new javax.swing.JPopupMenu();
165  cutMenuItem = new javax.swing.JMenuItem();
166  copyMenuItem = new javax.swing.JMenuItem();
167  pasteMenuItem = new javax.swing.JMenuItem();
168  selectAllMenuItem = new javax.swing.JMenuItem();
169  keywordTextField = new javax.swing.JTextField();
170  searchButton = new javax.swing.JButton();
171  exactRadioButton = new javax.swing.JRadioButton();
172  substringRadioButton = new javax.swing.JRadioButton();
173  regexRadioButton = new javax.swing.JRadioButton();
174 
175  org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.cutMenuItem.text")); // NOI18N
177 
178  org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.copyMenuItem.text")); // NOI18N
180 
181  org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.pasteMenuItem.text")); // NOI18N
183 
184  org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.selectAllMenuItem.text")); // NOI18N
186 
187  keywordTextField.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
188  keywordTextField.setText(org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.keywordTextField.text")); // NOI18N
189  keywordTextField.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));
190  keywordTextField.setMinimumSize(new java.awt.Dimension(2, 25));
191  keywordTextField.setPreferredSize(new java.awt.Dimension(2, 25));
192  keywordTextField.addMouseListener(new java.awt.event.MouseAdapter() {
193  public void mouseClicked(java.awt.event.MouseEvent evt) {
195  }
196  });
197  keywordTextField.addActionListener(new java.awt.event.ActionListener() {
198  public void actionPerformed(java.awt.event.ActionEvent evt) {
200  }
201  });
202 
203  searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
204  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.searchButton.text")); // NOI18N
205  searchButton.addActionListener(new java.awt.event.ActionListener() {
206  public void actionPerformed(java.awt.event.ActionEvent evt) {
208  }
209  });
210 
212  exactRadioButton.setSelected(true);
213  org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.exactRadioButton.text")); // NOI18N
214 
216  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.substringRadioButton.text")); // NOI18N
217 
219  org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.regexRadioButton.text")); // NOI18N
220 
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()
226  .addGap(5, 5, 5)
227  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addGroup(layout.createSequentialGroup()
229  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
230  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
231  .addComponent(searchButton))
232  .addGroup(layout.createSequentialGroup()
233  .addComponent(exactRadioButton)
234  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
235  .addComponent(substringRadioButton)
236  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
237  .addComponent(regexRadioButton)
238  .addGap(0, 27, Short.MAX_VALUE)))
239  .addGap(5, 5, 5))
240  );
241  layout.setVerticalGroup(
242  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243  .addGroup(layout.createSequentialGroup()
244  .addContainerGap()
245  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
246  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
247  .addComponent(searchButton, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
248  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
249  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
250  .addComponent(exactRadioButton)
251  .addComponent(substringRadioButton)
252  .addComponent(regexRadioButton))
253  .addContainerGap())
254  );
255  }// </editor-fold>//GEN-END:initComponents
256 
262  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
264  }//GEN-LAST:event_searchButtonActionPerformed
265 
271  private void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keywordTextFieldActionPerformed
272  try {
273  search();
274  } catch (Exception e) {
275  LOGGER.log(Level.SEVERE, "Error performing ad hoc single keyword search", e); //NON-NLS
276  }
277  }//GEN-LAST:event_keywordTextFieldActionPerformed
278 
284  private void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_keywordTextFieldMouseClicked
285  if (evt.isPopupTrigger()) {
286  rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
287  }
288  }//GEN-LAST:event_keywordTextFieldMouseClicked
289 
290  // Variables declaration - do not modify//GEN-BEGIN:variables
291  private javax.swing.JMenuItem copyMenuItem;
292  private javax.swing.JMenuItem cutMenuItem;
293  private javax.swing.JRadioButton exactRadioButton;
294  private javax.swing.JTextField keywordTextField;
295  private javax.swing.JMenuItem pasteMenuItem;
296  private javax.swing.ButtonGroup queryTypeButtonGroup;
297  private javax.swing.JRadioButton regexRadioButton;
298  private javax.swing.JPopupMenu rightClickMenu;
299  private javax.swing.JButton searchButton;
300  private javax.swing.JMenuItem selectAllMenuItem;
301  private javax.swing.JRadioButton substringRadioButton;
302  // End of variables declaration//GEN-END:variables
303 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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