19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.List;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import javax.swing.JFrame;
27 import javax.swing.JMenuItem;
28 import javax.swing.JPopupMenu;
29 import javax.swing.SwingUtilities;
30 import javax.swing.event.DocumentEvent;
31 import javax.swing.event.DocumentListener;
32 import org.openide.util.NbBundle;
33 import org.openide.windows.WindowManager;
38 class AddKeywordsDialog
extends javax.swing.JDialog {
40 List<String> newKeywords =
new ArrayList<>();
41 private javax.swing.JTextArea keywordTextArea;
50 super((JFrame) WindowManager.getDefault().getMainWindow(),
51 NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.addKeywordsTitle.text"),
55 addButton.setEnabled(
false);
56 initKeywordTextArea();
64 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
68 private void initKeywordTextArea() {
69 keywordTextArea =
new javax.swing.JTextArea() {
74 if (!(keywordTextArea.getDocument().getLength()==0) && !keywordTextArea.getText().endsWith(
"\n")) {
75 keywordTextArea.append(System.getProperty(
"line.separator"));
77 keywordTextArea.setCaretPosition(keywordTextArea.getDocument().getLength());
81 keywordTextArea.setColumns(
83 keywordTextArea.setRows(
85 keywordTextArea.addMouseListener(
86 new java.awt.event.MouseAdapter() {
88 public void mouseClicked(java.awt.event.MouseEvent evt
90 keywordTextAreaMouseClicked(evt);
94 jScrollPane1.setViewportView(keywordTextArea);
96 keywordTextArea.getDocument()
97 .addDocumentListener(
new DocumentListener() {
99 public void changedUpdate(DocumentEvent e
105 public void removeUpdate(DocumentEvent e
111 public void insertUpdate(DocumentEvent e
116 private void fire() {
129 void setInitialKeywordList(String initialKeywords,
boolean isLiteral,
boolean isWholeWord) {
130 keywordTextArea.setText(initialKeywords);
132 regexRadioButton.setSelected(
true);
133 }
else if (isWholeWord) {
134 exactRadioButton.setSelected(
true);
136 substringRadioButton.setSelected(
true);
140 private void enableButtons() {
141 addButton.setEnabled(!keywordTextArea.getText().isEmpty());
149 List<String> getKeywords() {
158 boolean isKeywordRegex() {
159 return regexRadioButton.isSelected();
167 boolean isKeywordExact() {
168 return exactRadioButton.isSelected();
176 @SuppressWarnings(
"unchecked")
178 private
void initComponents() {
180 keywordTypeButtonGroup =
new javax.swing.ButtonGroup();
181 exactRadioButton =
new javax.swing.JRadioButton();
182 substringRadioButton =
new javax.swing.JRadioButton();
183 regexRadioButton =
new javax.swing.JRadioButton();
184 jScrollPane1 =
new javax.swing.JScrollPane();
185 enterKeywordsLabel =
new javax.swing.JLabel();
186 keywordTypeLabel =
new javax.swing.JLabel();
187 addButton =
new javax.swing.JButton();
188 cancelButton =
new javax.swing.JButton();
189 pasteButton =
new javax.swing.JButton();
191 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
193 keywordTypeButtonGroup.add(exactRadioButton);
194 exactRadioButton.setSelected(
true);
195 org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.exactRadioButton.text"));
197 keywordTypeButtonGroup.add(substringRadioButton);
198 org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.substringRadioButton.text"));
200 keywordTypeButtonGroup.add(regexRadioButton);
201 org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.regexRadioButton.text"));
203 org.openide.awt.Mnemonics.setLocalizedText(enterKeywordsLabel,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.enterKeywordsLabel.text"));
205 org.openide.awt.Mnemonics.setLocalizedText(keywordTypeLabel,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.keywordTypeLabel.text"));
207 org.openide.awt.Mnemonics.setLocalizedText(addButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.addButton.text"));
208 addButton.addActionListener(
new java.awt.event.ActionListener() {
209 public void actionPerformed(java.awt.event.ActionEvent evt) {
210 addButtonActionPerformed(evt);
214 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.cancelButton.text"));
215 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
216 public void actionPerformed(java.awt.event.ActionEvent evt) {
217 cancelButtonActionPerformed(evt);
221 org.openide.awt.Mnemonics.setLocalizedText(pasteButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.pasteButton.text"));
222 pasteButton.addActionListener(
new java.awt.event.ActionListener() {
223 public void actionPerformed(java.awt.event.ActionEvent evt) {
224 pasteButtonActionPerformed(evt);
228 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
229 getContentPane().setLayout(layout);
230 layout.setHorizontalGroup(
231 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addGroup(layout.createSequentialGroup()
234 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235 .addComponent(enterKeywordsLabel)
236 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
237 .addComponent(pasteButton))
238 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
239 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240 .addGroup(layout.createSequentialGroup()
241 .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
243 .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
244 .addComponent(keywordTypeLabel)
245 .addGroup(layout.createSequentialGroup()
247 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addComponent(substringRadioButton)
249 .addComponent(exactRadioButton)
250 .addComponent(regexRadioButton))))
251 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
253 layout.setVerticalGroup(
254 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
257 .addComponent(enterKeywordsLabel)
258 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
259 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260 .addGroup(layout.createSequentialGroup()
261 .addComponent(keywordTypeLabel)
262 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
263 .addComponent(exactRadioButton)
264 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
265 .addComponent(substringRadioButton)
266 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
267 .addComponent(regexRadioButton)
268 .addGap(194, 194, 194))
269 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
270 .addGap(0, 0, Short.MAX_VALUE)
271 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
273 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
274 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
275 .addComponent(addButton)
276 .addComponent(cancelButton))
277 .addComponent(pasteButton))
284 private void pasteButtonActionPerformed(java.awt.event.ActionEvent evt) {
285 keywordTextArea.paste();
288 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
290 newKeywords.addAll(Arrays.asList(keywordTextArea.getText().split(
"\\r?\\n")));
296 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
301 private void keywordTextAreaMouseClicked(java.awt.event.MouseEvent evt) {
302 if (SwingUtilities.isRightMouseButton(evt)) {
303 JPopupMenu popup =
new JPopupMenu();
305 JMenuItem cutMenu =
new JMenuItem(
"Cut");
306 cutMenu.addActionListener(
new ActionListener() {
308 public void actionPerformed(ActionEvent e) {
309 keywordTextArea.cut();
313 JMenuItem copyMenu =
new JMenuItem(
"Copy");
314 copyMenu.addActionListener(
new ActionListener() {
316 public void actionPerformed(ActionEvent e) {
317 keywordTextArea.copy();
321 JMenuItem pasteMenu =
new JMenuItem(
"Paste");
322 pasteMenu.addActionListener(
new ActionListener() {
324 public void actionPerformed(ActionEvent e) {
325 keywordTextArea.paste();
331 popup.add(pasteMenu);
332 popup.show(keywordTextArea, evt.getX(), evt.getY());
336 private javax.swing.JButton addButton;
337 private javax.swing.JButton cancelButton;
338 private javax.swing.JLabel enterKeywordsLabel;
339 private javax.swing.JRadioButton exactRadioButton;
340 private javax.swing.JScrollPane jScrollPane1;
341 private javax.swing.ButtonGroup keywordTypeButtonGroup;
342 private javax.swing.JLabel keywordTypeLabel;
343 private javax.swing.JButton pasteButton;
344 private javax.swing.JRadioButton regexRadioButton;
345 private javax.swing.JRadioButton substringRadioButton;