Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddKeywordsDialog.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.Dimension;
22 import java.awt.Toolkit;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.List;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import javax.swing.JFrame;
29 import javax.swing.JMenuItem;
30 import javax.swing.JPopupMenu;
31 import javax.swing.SwingUtilities;
32 import javax.swing.event.DocumentEvent;
33 import javax.swing.event.DocumentListener;
34 import org.openide.util.NbBundle;
35 import org.openide.windows.WindowManager;
36 
40 class AddKeywordsDialog extends javax.swing.JDialog {
41 
42  List<String> newKeywords = new ArrayList<>();
43 
50  AddKeywordsDialog(){
51  super((JFrame) WindowManager.getDefault().getMainWindow(),
52  NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.addKeywordsTitle.text"),
53  true);
54  initComponents();
55 
56  // Set the add button to only be active when there is text in the text area
57  addButton.setEnabled(false);
58  keywordTextArea.getDocument().addDocumentListener(new DocumentListener() {
59  @Override
60  public void changedUpdate(DocumentEvent e) {
61  fire();
62  }
63  @Override
64  public void removeUpdate(DocumentEvent e) {
65  fire();
66  }
67  @Override
68  public void insertUpdate(DocumentEvent e) {
69  fire();
70  }
71  private void fire() {
72  enableButtons();
73  }
74  });
75  }
76 
80  void display() {
81  newKeywords.clear();
82  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
83  setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
84  setVisible(true);
85  }
86 
92  void setInitialKeywordList(String initialKeywords){
93  keywordTextArea.setText(initialKeywords);
94  }
95 
96 
97  private void enableButtons(){
98  addButton.setEnabled(! keywordTextArea.getText().isEmpty());
99  }
100 
105  List<String> getKeywords(){
106  return newKeywords;
107  }
108 
113  boolean isKeywordRegex(){
114  return regexRadioButton.isSelected();
115  }
116 
121  boolean isKeywordExact(){
122  return exactRadioButton.isSelected();
123  }
124 
130  @SuppressWarnings("unchecked")
131  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
132  private void initComponents() {
133 
134  keywordTypeButtonGroup = new javax.swing.ButtonGroup();
135  exactRadioButton = new javax.swing.JRadioButton();
136  substringRadioButton = new javax.swing.JRadioButton();
137  regexRadioButton = new javax.swing.JRadioButton();
138  jScrollPane1 = new javax.swing.JScrollPane();
139  keywordTextArea = new javax.swing.JTextArea();
140  enterKeywordsLabel = new javax.swing.JLabel();
141  keywordTypeLabel = new javax.swing.JLabel();
142  addButton = new javax.swing.JButton();
143  cancelButton = new javax.swing.JButton();
144  pasteButton = new javax.swing.JButton();
145 
146  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
147 
148  keywordTypeButtonGroup.add(exactRadioButton);
149  exactRadioButton.setSelected(true);
150  org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.exactRadioButton.text")); // NOI18N
151 
152  keywordTypeButtonGroup.add(substringRadioButton);
153  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.substringRadioButton.text")); // NOI18N
154 
155  keywordTypeButtonGroup.add(regexRadioButton);
156  org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.regexRadioButton.text")); // NOI18N
157 
158  keywordTextArea.setColumns(20);
159  keywordTextArea.setRows(5);
160  keywordTextArea.addMouseListener(new java.awt.event.MouseAdapter() {
161  public void mouseClicked(java.awt.event.MouseEvent evt) {
162  keywordTextAreaMouseClicked(evt);
163  }
164  });
165  jScrollPane1.setViewportView(keywordTextArea);
166 
167  org.openide.awt.Mnemonics.setLocalizedText(enterKeywordsLabel, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.enterKeywordsLabel.text")); // NOI18N
168 
169  org.openide.awt.Mnemonics.setLocalizedText(keywordTypeLabel, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.keywordTypeLabel.text")); // NOI18N
170 
171  org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.addButton.text")); // NOI18N
172  addButton.addActionListener(new java.awt.event.ActionListener() {
173  public void actionPerformed(java.awt.event.ActionEvent evt) {
174  addButtonActionPerformed(evt);
175  }
176  });
177 
178  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.cancelButton.text")); // NOI18N
179  cancelButton.addActionListener(new java.awt.event.ActionListener() {
180  public void actionPerformed(java.awt.event.ActionEvent evt) {
181  cancelButtonActionPerformed(evt);
182  }
183  });
184 
185  org.openide.awt.Mnemonics.setLocalizedText(pasteButton, org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, "AddKeywordsDialog.pasteButton.text")); // NOI18N
186  pasteButton.addActionListener(new java.awt.event.ActionListener() {
187  public void actionPerformed(java.awt.event.ActionEvent evt) {
188  pasteButtonActionPerformed(evt);
189  }
190  });
191 
192  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
193  getContentPane().setLayout(layout);
194  layout.setHorizontalGroup(
195  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196  .addGroup(layout.createSequentialGroup()
197  .addContainerGap()
198  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199  .addComponent(enterKeywordsLabel)
200  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
201  .addComponent(pasteButton))
202  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
203  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addGroup(layout.createSequentialGroup()
205  .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
206  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
207  .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
208  .addComponent(keywordTypeLabel)
209  .addGroup(layout.createSequentialGroup()
210  .addGap(10, 10, 10)
211  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212  .addComponent(substringRadioButton)
213  .addComponent(exactRadioButton)
214  .addComponent(regexRadioButton))))
215  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
216  );
217  layout.setVerticalGroup(
218  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
220  .addContainerGap()
221  .addComponent(enterKeywordsLabel)
222  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
223  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224  .addGroup(layout.createSequentialGroup()
225  .addComponent(keywordTypeLabel)
226  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
227  .addComponent(exactRadioButton)
228  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
229  .addComponent(substringRadioButton)
230  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
231  .addComponent(regexRadioButton)
232  .addGap(194, 194, 194))
233  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
234  .addGap(0, 0, Short.MAX_VALUE)
235  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
236  .addGap(5, 5, 5)))
237  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
238  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
239  .addComponent(addButton)
240  .addComponent(cancelButton))
241  .addComponent(pasteButton))
242  .addContainerGap())
243  );
244 
245  pack();
246  }// </editor-fold>//GEN-END:initComponents
247 
248  private void pasteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteButtonActionPerformed
249  keywordTextArea.paste();
250  }//GEN-LAST:event_pasteButtonActionPerformed
251 
252  private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
253  // Save the values from the list
254  newKeywords.addAll(Arrays.asList(keywordTextArea.getText().split("\\r?\\n")));
255 
256  setVisible(false);
257  dispose();
258  }//GEN-LAST:event_addButtonActionPerformed
259 
260  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
261  setVisible(false);
262  dispose();
263  }//GEN-LAST:event_cancelButtonActionPerformed
264 
265  private void keywordTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_keywordTextAreaMouseClicked
266  if (SwingUtilities.isRightMouseButton(evt)) {
267  JPopupMenu popup = new JPopupMenu();
268 
269  JMenuItem cutMenu = new JMenuItem("Cut"); // NON-NLS
270  cutMenu.addActionListener(new ActionListener() {
271  @Override
272  public void actionPerformed(ActionEvent e) {
273  keywordTextArea.cut();
274  }
275  });
276 
277  JMenuItem copyMenu = new JMenuItem("Copy"); // NON-NLS
278  copyMenu.addActionListener(new ActionListener() {
279  @Override
280  public void actionPerformed(ActionEvent e) {
281  keywordTextArea.copy();
282  }
283  });
284 
285  JMenuItem pasteMenu = new JMenuItem("Paste"); // NON-NLS
286  pasteMenu.addActionListener(new ActionListener() {
287  @Override
288  public void actionPerformed(ActionEvent e) {
289  keywordTextArea.paste();
290  }
291  });
292 
293  popup.add(cutMenu);
294  popup.add(copyMenu);
295  popup.add(pasteMenu);
296  popup.show(keywordTextArea, evt.getX(), evt.getY());
297  }
298  }//GEN-LAST:event_keywordTextAreaMouseClicked
299 
300 
301  // Variables declaration - do not modify//GEN-BEGIN:variables
302  private javax.swing.JButton addButton;
303  private javax.swing.JButton cancelButton;
304  private javax.swing.JLabel enterKeywordsLabel;
305  private javax.swing.JRadioButton exactRadioButton;
306  private javax.swing.JScrollPane jScrollPane1;
307  private javax.swing.JTextArea keywordTextArea;
308  private javax.swing.ButtonGroup keywordTypeButtonGroup;
309  private javax.swing.JLabel keywordTypeLabel;
310  private javax.swing.JButton pasteButton;
311  private javax.swing.JRadioButton regexRadioButton;
312  private javax.swing.JRadioButton substringRadioButton;
313  // End of variables declaration//GEN-END:variables
314 }

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.