Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DropdownSingleKeywordSearchPanel.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 DropdownSingleKeywordSearchPanel extends KeywordSearchPanel {
46 
47  private static final long serialVersionUID = 1L;
48  private static final Logger LOGGER = Logger.getLogger(DropdownSingleKeywordSearchPanel.class.getName());
50 
57  public static synchronized DropdownSingleKeywordSearchPanel getDefault() {
58  if (null == defaultInstance) {
59  defaultInstance = new DropdownSingleKeywordSearchPanel();
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().equals("")) {
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 
133  @Override
134  List<KeywordList> getKeywordLists() {
135  List<Keyword> keywords = new ArrayList<>();
136  keywords.add(new Keyword(keywordTextField.getText(), !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
137  List<KeywordList> keywordLists = new ArrayList<>();
138  keywordLists.add(new KeywordList(keywords));
139  return keywordLists;
140  }
141 
145  @Override
146  protected void postFilesIndexedChange() {
147  }
148 
154  @SuppressWarnings("unchecked")
155  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
156  private void initComponents() {
157 
158  queryTypeButtonGroup = new javax.swing.ButtonGroup();
159  rightClickMenu = new javax.swing.JPopupMenu();
160  cutMenuItem = new javax.swing.JMenuItem();
161  copyMenuItem = new javax.swing.JMenuItem();
162  pasteMenuItem = new javax.swing.JMenuItem();
163  selectAllMenuItem = new javax.swing.JMenuItem();
164  keywordTextField = new javax.swing.JTextField();
165  searchButton = new javax.swing.JButton();
166  exactRadioButton = new javax.swing.JRadioButton();
167  substringRadioButton = new javax.swing.JRadioButton();
168  regexRadioButton = new javax.swing.JRadioButton();
169 
170  org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.cutMenuItem.text")); // NOI18N
172 
173  org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.copyMenuItem.text")); // NOI18N
175 
176  org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.pasteMenuItem.text")); // NOI18N
178 
179  org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.selectAllMenuItem.text")); // NOI18N
181 
182  keywordTextField.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
183  keywordTextField.setText(org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.keywordTextField.text")); // NOI18N
184  keywordTextField.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));
185  keywordTextField.setMinimumSize(new java.awt.Dimension(2, 25));
186  keywordTextField.setPreferredSize(new java.awt.Dimension(2, 25));
187  keywordTextField.addMouseListener(new java.awt.event.MouseAdapter() {
188  public void mouseClicked(java.awt.event.MouseEvent evt) {
190  }
191  });
192  keywordTextField.addActionListener(new java.awt.event.ActionListener() {
193  public void actionPerformed(java.awt.event.ActionEvent evt) {
195  }
196  });
197 
198  searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
199  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.searchButton.text")); // NOI18N
200  searchButton.addActionListener(new java.awt.event.ActionListener() {
201  public void actionPerformed(java.awt.event.ActionEvent evt) {
203  }
204  });
205 
207  exactRadioButton.setSelected(true);
208  org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.exactRadioButton.text")); // NOI18N
209 
211  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.substringRadioButton.text")); // NOI18N
212 
214  org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleKeywordSearchPanel.class, "DropdownSearchPanel.regexRadioButton.text")); // NOI18N
215 
216  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
217  this.setLayout(layout);
218  layout.setHorizontalGroup(
219  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220  .addGroup(layout.createSequentialGroup()
221  .addGap(5, 5, 5)
222  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
223  .addGroup(layout.createSequentialGroup()
224  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
225  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226  .addComponent(searchButton))
227  .addGroup(layout.createSequentialGroup()
228  .addComponent(exactRadioButton)
229  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
230  .addComponent(substringRadioButton)
231  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
232  .addComponent(regexRadioButton)
233  .addGap(0, 27, Short.MAX_VALUE)))
234  .addGap(5, 5, 5))
235  );
236  layout.setVerticalGroup(
237  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
238  .addGroup(layout.createSequentialGroup()
239  .addContainerGap()
240  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
241  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
242  .addComponent(searchButton, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
243  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
244  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
245  .addComponent(exactRadioButton)
246  .addComponent(substringRadioButton)
247  .addComponent(regexRadioButton))
248  .addContainerGap())
249  );
250  }// </editor-fold>//GEN-END:initComponents
251 
257  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
259  }//GEN-LAST:event_searchButtonActionPerformed
260 
266  private void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keywordTextFieldActionPerformed
267  try {
268  search();
269  } catch (Exception e) {
270  LOGGER.log(Level.SEVERE, "Error performing ad hoc single keyword search", e); //NON-NLS
271  }
272  }//GEN-LAST:event_keywordTextFieldActionPerformed
273 
279  private void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_keywordTextFieldMouseClicked
280  if (evt.isPopupTrigger()) {
281  rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
282  }
283  }//GEN-LAST:event_keywordTextFieldMouseClicked
284 
285  // Variables declaration - do not modify//GEN-BEGIN:variables
286  private javax.swing.JMenuItem copyMenuItem;
287  private javax.swing.JMenuItem cutMenuItem;
288  private javax.swing.JRadioButton exactRadioButton;
289  private javax.swing.JTextField keywordTextField;
290  private javax.swing.JMenuItem pasteMenuItem;
291  private javax.swing.ButtonGroup queryTypeButtonGroup;
292  private javax.swing.JRadioButton regexRadioButton;
293  private javax.swing.JPopupMenu rightClickMenu;
294  private javax.swing.JButton searchButton;
295  private javax.swing.JMenuItem selectAllMenuItem;
296  private javax.swing.JRadioButton substringRadioButton;
297  // End of variables declaration//GEN-END:variables
298 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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