19 package org.sleuthkit.autopsy.keywordsearch;
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;
46 @SuppressWarnings(
"PMD.SingularField")
49 private static final long serialVersionUID = 1L;
60 if (null == defaultInstance) {
63 return defaultInstance;
72 customizeComponents();
80 keywordTextField.addFocusListener(
new FocusListener() {
82 public void focusGained(FocusEvent e) {
86 public void focusLost(FocusEvent e) {
87 if (keywordTextField.getText().isEmpty()) {
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();
106 cutMenuItem.addActionListener(actList);
107 copyMenuItem.addActionListener(actList);
108 pasteMenuItem.addActionListener(actList);
109 selectAllMenuItem.addActionListener(actList);
117 void addSearchButtonActionListener(ActionListener actionListener) {
118 searchButton.addActionListener(actionListener);
125 void clearSearchBox() {
126 keywordTextField.setText(
"");
129 void setRegexSearchEnabled(
boolean enabled) {
130 exactRadioButton.setSelected(
true);
131 regexRadioButton.setEnabled(enabled);
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 [ \\.,]"})
143 List<KeywordList> getKeywordLists() {
145 if (regexRadioButton.isSelected()) {
146 if((keywordTextField.getText() != null) &&
147 (keywordTextField.getText().startsWith(
"^") ||
148 (keywordTextField.getText().endsWith(
"$") && ! keywordTextField.getText().endsWith(
"\\$")))) {
150 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"DropdownSingleTermSearchPanel.warning.title"),
151 NbBundle.getMessage(
this.getClass(),
"DropdownSingleTermSearchPanel.warning.text"),
152 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
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));
175 @SuppressWarnings(
"unchecked")
177 private
void initComponents() {
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();
191 org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.cutMenuItem.text"));
192 rightClickMenu.add(cutMenuItem);
194 org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.copyMenuItem.text"));
195 rightClickMenu.add(copyMenuItem);
197 org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.pasteMenuItem.text"));
198 rightClickMenu.add(pasteMenuItem);
200 org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.selectAllMenuItem.text"));
201 rightClickMenu.add(selectAllMenuItem);
203 keywordTextField.setFont(
new java.awt.Font(
"Monospaced", 0, 14));
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);
213 keywordTextField.addActionListener(
new java.awt.event.ActionListener() {
214 public void actionPerformed(java.awt.event.ActionEvent evt) {
215 keywordTextFieldActionPerformed(evt);
219 searchButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/search-icon.png")));
220 org.openide.awt.Mnemonics.setLocalizedText(searchButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.searchButton.text"));
221 searchButton.addActionListener(
new java.awt.event.ActionListener() {
222 public void actionPerformed(java.awt.event.ActionEvent evt) {
223 searchButtonActionPerformed(evt);
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"));
231 queryTypeButtonGroup.add(substringRadioButton);
232 org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.substringRadioButton.text"));
234 queryTypeButtonGroup.add(regexRadioButton);
235 org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.regexRadioButton.text"));
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()
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)))
257 layout.setVerticalGroup(
258 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259 .addGroup(layout.createSequentialGroup()
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))
279 keywordTextFieldActionPerformed(evt);
290 }
catch (Exception e) {
291 LOGGER.log(Level.SEVERE,
"Error performing ad hoc single keyword search", e);
301 if (evt.isPopupTrigger()) {
302 rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
javax.swing.JMenuItem copyMenuItem
javax.swing.JMenuItem pasteMenuItem
void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt)
javax.swing.JMenuItem cutMenuItem
javax.swing.JButton searchButton
void postFilesIndexedChange()
static synchronized DropdownSingleTermSearchPanel getDefault()
javax.swing.JRadioButton substringRadioButton
javax.swing.JPopupMenu rightClickMenu
DropdownSingleTermSearchPanel()
javax.swing.JRadioButton exactRadioButton
void customizeComponents()
javax.swing.JRadioButton regexRadioButton
javax.swing.JMenuItem selectAllMenuItem
javax.swing.ButtonGroup queryTypeButtonGroup
synchronized static Logger getLogger(String name)
javax.swing.JTextField keywordTextField
void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt)
void searchButtonActionPerformed(java.awt.event.ActionEvent evt)