Autopsy  3.1
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 2014 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.*;
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.util.ArrayList;
27 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.JMenuItem;
30 
32 
40 public class DropdownSingleTermSearchPanel extends KeywordSearchPanel {
41  private static final Logger logger = Logger.getLogger(DropdownSingleTermSearchPanel.class.getName());
42  private static DropdownSingleTermSearchPanel instance = null;
43 
50  }
51 
52  private void customizeComponents() {
53  keywordTextField.addFocusListener(new FocusListener() {
54  @Override
55  public void focusGained(FocusEvent e) {
56  //do nothing
57  }
58 
59  @Override
60  public void focusLost(FocusEvent e) {
61  if (keywordTextField.getText().equals("")) {
62  resetSearchBox();
63  }
64  }
65  });
66 
67  keywordTextField.setComponentPopupMenu(rightClickMenu);
68  ActionListener actList = new ActionListener() {
69  @Override
70  public void actionPerformed(ActionEvent e) {
71  JMenuItem jmi = (JMenuItem) e.getSource();
72  if (jmi.equals(cutMenuItem)) {
73  keywordTextField.cut();
74  } else if (jmi.equals(copyMenuItem)) {
75  keywordTextField.copy();
76  } else if (jmi.equals(pasteMenuItem)) {
77  keywordTextField.paste();
78  } else if (jmi.equals(selectAllMenuItem)) {
79  keywordTextField.selectAll();
80  }
81  }
82  };
83  cutMenuItem.addActionListener(actList);
84  copyMenuItem.addActionListener(actList);
85  pasteMenuItem.addActionListener(actList);
86  selectAllMenuItem.addActionListener(actList);
87  }
88 
89  public static synchronized DropdownSingleTermSearchPanel getDefault() {
90  if (instance == null) {
91  instance = new DropdownSingleTermSearchPanel();
92  }
93  return instance;
94  }
95 
96  void addSearchButtonActionListener(ActionListener actionListener) {
97  searchButton.addActionListener(actionListener);
98  }
99 
100  void resetSearchBox() {
101  keywordTextField.setText("");
102  }
103 
104  @Override
105  List<KeywordList> getKeywordLists() {
106  List<Keyword> keywords = new ArrayList<>();
107  keywords.add(new Keyword(keywordTextField.getText(),
108  !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
109 
110  List <KeywordList> keywordLists = new ArrayList<>();
111  keywordLists.add(new KeywordList(keywords));
112 
113  return keywordLists;
114  }
115 
116  @Override
117  protected void postFilesIndexedChange() {
118  //nothing to update
119  }
120 
126  @SuppressWarnings("unchecked")
127  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
128  private void initComponents() {
129 
130  queryTypeButtonGroup = new javax.swing.ButtonGroup();
131  rightClickMenu = new javax.swing.JPopupMenu();
132  cutMenuItem = new javax.swing.JMenuItem();
133  copyMenuItem = new javax.swing.JMenuItem();
134  pasteMenuItem = new javax.swing.JMenuItem();
135  selectAllMenuItem = new javax.swing.JMenuItem();
136  keywordTextField = new javax.swing.JTextField();
137  searchButton = new javax.swing.JButton();
138  exactRadioButton = new javax.swing.JRadioButton();
139  substringRadioButton = new javax.swing.JRadioButton();
140  regexRadioButton = new javax.swing.JRadioButton();
141 
142  org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.cutMenuItem.text")); // NOI18N
144 
145  org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.copyMenuItem.text")); // NOI18N
147 
148  org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.pasteMenuItem.text")); // NOI18N
150 
151  org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.selectAllMenuItem.text")); // NOI18N
153 
154  keywordTextField.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
155  keywordTextField.setText(org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.keywordTextField.text")); // NOI18N
156  keywordTextField.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));
157  keywordTextField.setMinimumSize(new java.awt.Dimension(2, 25));
158  keywordTextField.setPreferredSize(new java.awt.Dimension(2, 25));
159  keywordTextField.addMouseListener(new java.awt.event.MouseAdapter() {
160  public void mouseClicked(java.awt.event.MouseEvent evt) {
162  }
163  });
164  keywordTextField.addActionListener(new java.awt.event.ActionListener() {
165  public void actionPerformed(java.awt.event.ActionEvent evt) {
167  }
168  });
169 
170  searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/search-icon.png"))); // NOI18N
171  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.searchButton.text")); // NOI18N
172  searchButton.addActionListener(new java.awt.event.ActionListener() {
173  public void actionPerformed(java.awt.event.ActionEvent evt) {
175  }
176  });
177 
179  exactRadioButton.setSelected(true);
180  org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.exactRadioButton.text")); // NOI18N
181 
183  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.substringRadioButton.text")); // NOI18N
184 
186  org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, org.openide.util.NbBundle.getMessage(DropdownSingleTermSearchPanel.class, "DropdownSearchPanel.regexRadioButton.text")); // NOI18N
187 
188  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
189  this.setLayout(layout);
190  layout.setHorizontalGroup(
191  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192  .addGroup(layout.createSequentialGroup()
193  .addGap(5, 5, 5)
194  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195  .addGroup(layout.createSequentialGroup()
196  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
197  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198  .addComponent(searchButton))
199  .addGroup(layout.createSequentialGroup()
200  .addComponent(exactRadioButton)
201  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
202  .addComponent(substringRadioButton)
203  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
204  .addComponent(regexRadioButton)
205  .addGap(0, 27, Short.MAX_VALUE)))
206  .addGap(5, 5, 5))
207  );
208  layout.setVerticalGroup(
209  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210  .addGroup(layout.createSequentialGroup()
211  .addContainerGap()
212  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
213  .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
214  .addComponent(searchButton, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
215  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
216  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
217  .addComponent(exactRadioButton)
218  .addComponent(substringRadioButton)
219  .addComponent(regexRadioButton))
220  .addContainerGap())
221  );
222  }// </editor-fold>//GEN-END:initComponents
223 
224  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
226  }//GEN-LAST:event_searchButtonActionPerformed
227 
228  private void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keywordTextFieldActionPerformed
229  try {
230  search();
231  } catch(Exception e) {
232  logger.log(Level.SEVERE, "search() threw exception", e); //NON-NLS
233  }
234  }//GEN-LAST:event_keywordTextFieldActionPerformed
235 
236  private void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_keywordTextFieldMouseClicked
237  if(evt.isPopupTrigger()) {
238  rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
239  }
240  }//GEN-LAST:event_keywordTextFieldMouseClicked
241 
242  // Variables declaration - do not modify//GEN-BEGIN:variables
243  private javax.swing.JMenuItem copyMenuItem;
244  private javax.swing.JMenuItem cutMenuItem;
245  private javax.swing.JRadioButton exactRadioButton;
246  private javax.swing.JTextField keywordTextField;
247  private javax.swing.JMenuItem pasteMenuItem;
248  private javax.swing.ButtonGroup queryTypeButtonGroup;
249  private javax.swing.JRadioButton regexRadioButton;
250  private javax.swing.JPopupMenu rightClickMenu;
251  private javax.swing.JButton searchButton;
252  private javax.swing.JMenuItem selectAllMenuItem;
253  private javax.swing.JRadioButton substringRadioButton;
254  // End of variables declaration//GEN-END:variables
255 }
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.