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 @SuppressWarnings(
"PMD.SingularField")
39 class AddKeywordsDialog extends javax.swing.JDialog {
41 List<String> newKeywords =
new ArrayList<>();
42 private javax.swing.JTextArea keywordTextArea;
51 super((JFrame) WindowManager.getDefault().getMainWindow(),
52 NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.addKeywordsTitle.text"),
56 addButton.setEnabled(
false);
57 initKeywordTextArea();
65 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
69 private void initKeywordTextArea() {
70 keywordTextArea =
new javax.swing.JTextArea() {
75 if (!(keywordTextArea.getDocument().getLength()==0) && !keywordTextArea.getText().endsWith(
"\n")) {
76 keywordTextArea.append(System.getProperty(
"line.separator"));
78 keywordTextArea.setCaretPosition(keywordTextArea.getDocument().getLength());
82 keywordTextArea.setColumns(
84 keywordTextArea.setRows(
86 keywordTextArea.addMouseListener(
87 new java.awt.event.MouseAdapter() {
89 public void mouseClicked(java.awt.event.MouseEvent evt
91 keywordTextAreaMouseClicked(evt);
95 jScrollPane1.setViewportView(keywordTextArea);
97 keywordTextArea.getDocument()
98 .addDocumentListener(
new DocumentListener() {
100 public void changedUpdate(DocumentEvent e
106 public void removeUpdate(DocumentEvent e
112 public void insertUpdate(DocumentEvent e
117 private void fire() {
130 void setInitialKeywordList(String initialKeywords,
boolean isLiteral,
boolean isWholeWord) {
131 keywordTextArea.setText(initialKeywords);
133 regexRadioButton.setSelected(
true);
134 }
else if (isWholeWord) {
135 exactRadioButton.setSelected(
true);
137 substringRadioButton.setSelected(
true);
141 private void enableButtons() {
142 addButton.setEnabled(!keywordTextArea.getText().isEmpty());
150 List<String> getKeywords() {
159 boolean isKeywordRegex() {
160 return regexRadioButton.isSelected();
168 boolean isKeywordExact() {
169 return exactRadioButton.isSelected();
177 @SuppressWarnings(
"unchecked")
179 private
void initComponents() {
181 keywordTypeButtonGroup =
new javax.swing.ButtonGroup();
182 exactRadioButton =
new javax.swing.JRadioButton();
183 substringRadioButton =
new javax.swing.JRadioButton();
184 regexRadioButton =
new javax.swing.JRadioButton();
185 jScrollPane1 =
new javax.swing.JScrollPane();
186 enterKeywordsLabel =
new javax.swing.JLabel();
187 keywordTypeLabel =
new javax.swing.JLabel();
188 addButton =
new javax.swing.JButton();
189 cancelButton =
new javax.swing.JButton();
190 pasteButton =
new javax.swing.JButton();
192 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
194 keywordTypeButtonGroup.add(exactRadioButton);
195 exactRadioButton.setSelected(
true);
196 org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.exactRadioButton.text"));
198 keywordTypeButtonGroup.add(substringRadioButton);
199 org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.substringRadioButton.text"));
201 keywordTypeButtonGroup.add(regexRadioButton);
202 org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.regexRadioButton.text"));
204 org.openide.awt.Mnemonics.setLocalizedText(enterKeywordsLabel,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.enterKeywordsLabel.text"));
206 org.openide.awt.Mnemonics.setLocalizedText(keywordTypeLabel,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.keywordTypeLabel.text"));
208 org.openide.awt.Mnemonics.setLocalizedText(addButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.addButton.text"));
209 addButton.addActionListener(
new java.awt.event.ActionListener() {
210 public void actionPerformed(java.awt.event.ActionEvent evt) {
211 addButtonActionPerformed(evt);
215 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.cancelButton.text"));
216 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
217 public void actionPerformed(java.awt.event.ActionEvent evt) {
218 cancelButtonActionPerformed(evt);
222 org.openide.awt.Mnemonics.setLocalizedText(pasteButton,
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class,
"AddKeywordsDialog.pasteButton.text"));
223 pasteButton.addActionListener(
new java.awt.event.ActionListener() {
224 public void actionPerformed(java.awt.event.ActionEvent evt) {
225 pasteButtonActionPerformed(evt);
229 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
230 getContentPane().setLayout(layout);
231 layout.setHorizontalGroup(
232 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233 .addGroup(layout.createSequentialGroup()
235 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
236 .addComponent(enterKeywordsLabel)
237 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
238 .addComponent(pasteButton))
239 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
240 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
241 .addGroup(layout.createSequentialGroup()
242 .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
243 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
244 .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
245 .addComponent(keywordTypeLabel)
246 .addGroup(layout.createSequentialGroup()
248 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249 .addComponent(substringRadioButton)
250 .addComponent(exactRadioButton)
251 .addComponent(regexRadioButton))))
252 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
254 layout.setVerticalGroup(
255 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
258 .addComponent(enterKeywordsLabel)
259 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
260 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261 .addGroup(layout.createSequentialGroup()
262 .addComponent(keywordTypeLabel)
263 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
264 .addComponent(exactRadioButton)
265 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
266 .addComponent(substringRadioButton)
267 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
268 .addComponent(regexRadioButton)
269 .addGap(194, 194, 194))
270 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
271 .addGap(0, 0, Short.MAX_VALUE)
272 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
274 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
276 .addComponent(addButton)
277 .addComponent(cancelButton))
278 .addComponent(pasteButton))
285 private void pasteButtonActionPerformed(java.awt.event.ActionEvent evt) {
286 keywordTextArea.paste();
289 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
291 newKeywords.addAll(Arrays.asList(keywordTextArea.getText().split(
"\\r?\\n")));
297 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
302 private void keywordTextAreaMouseClicked(java.awt.event.MouseEvent evt) {
303 if (SwingUtilities.isRightMouseButton(evt)) {
304 JPopupMenu popup =
new JPopupMenu();
306 JMenuItem cutMenu =
new JMenuItem(
"Cut");
307 cutMenu.addActionListener(
new ActionListener() {
309 public void actionPerformed(ActionEvent e) {
310 keywordTextArea.cut();
314 JMenuItem copyMenu =
new JMenuItem(
"Copy");
315 copyMenu.addActionListener(
new ActionListener() {
317 public void actionPerformed(ActionEvent e) {
318 keywordTextArea.copy();
322 JMenuItem pasteMenu =
new JMenuItem(
"Paste");
323 pasteMenu.addActionListener(
new ActionListener() {
325 public void actionPerformed(ActionEvent e) {
326 keywordTextArea.paste();
332 popup.add(pasteMenu);
333 popup.show(keywordTextArea, evt.getX(), evt.getY());
337 private javax.swing.JButton addButton;
338 private javax.swing.JButton cancelButton;
339 private javax.swing.JLabel enterKeywordsLabel;
340 private javax.swing.JRadioButton exactRadioButton;
341 private javax.swing.JScrollPane jScrollPane1;
342 private javax.swing.ButtonGroup keywordTypeButtonGroup;
343 private javax.swing.JLabel keywordTypeLabel;
344 private javax.swing.JButton pasteButton;
345 private javax.swing.JRadioButton regexRadioButton;
346 private javax.swing.JRadioButton substringRadioButton;