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

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