19 package org.sleuthkit.autopsy.keywordsearch;
 
   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;
 
   40 class AddKeywordsDialog 
extends javax.swing.JDialog {
 
   42     List<String> newKeywords = 
new ArrayList<>();
 
   43     private javax.swing.JTextArea keywordTextArea;
 
   52         super((JFrame) WindowManager.getDefault().getMainWindow(),
 
   53                 NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.addKeywordsTitle.text"),
 
   57         addButton.setEnabled(
false);
 
   58         initKeywordTextArea();      
 
   66         Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
 
   67         setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
 
   71     private void initKeywordTextArea() {
 
   72         keywordTextArea = 
new javax.swing.JTextArea() {
 
   77                 if (!(keywordTextArea.getDocument().getLength()==0) && !keywordTextArea.getText().endsWith(
"\n")) {
 
   78                     keywordTextArea.append(System.getProperty(
"line.separator"));
 
   80                 keywordTextArea.setCaretPosition(keywordTextArea.getDocument().getLength());
 
   84         keywordTextArea.setColumns(
 
   86         keywordTextArea.setRows(
 
   88         keywordTextArea.addMouseListener(
 
   89                 new java.awt.event.MouseAdapter() {
 
   91             public void mouseClicked(java.awt.event.MouseEvent evt
 
   93                 keywordTextAreaMouseClicked(evt);
 
   97         jScrollPane1.setViewportView(keywordTextArea);
 
   99         keywordTextArea.getDocument()
 
  100                 .addDocumentListener(
new DocumentListener() {
 
  102                     public void changedUpdate(DocumentEvent e
 
  108                     public void removeUpdate(DocumentEvent e
 
  114                     public void insertUpdate(DocumentEvent e
 
  119                     private void fire() {
 
  132     void setInitialKeywordList(String initialKeywords, 
boolean isLiteral, 
boolean isWholeWord) {
 
  133         keywordTextArea.setText(initialKeywords);
 
  135             regexRadioButton.setSelected(
true);
 
  136         } 
else if (isWholeWord) {
 
  137             exactRadioButton.setSelected(
true);
 
  139             substringRadioButton.setSelected(
true);
 
  143     private void enableButtons() {
 
  144         addButton.setEnabled(!keywordTextArea.getText().isEmpty());
 
  152     List<String> getKeywords() {
 
  161     boolean isKeywordRegex() {
 
  162         return regexRadioButton.isSelected();
 
  170     boolean isKeywordExact() {
 
  171         return exactRadioButton.isSelected();
 
  179     @SuppressWarnings(
"unchecked")
 
  181     private 
void initComponents() {
 
  183         keywordTypeButtonGroup = 
new javax.swing.ButtonGroup();
 
  184         exactRadioButton = 
new javax.swing.JRadioButton();
 
  185         substringRadioButton = 
new javax.swing.JRadioButton();
 
  186         regexRadioButton = 
new javax.swing.JRadioButton();
 
  187         jScrollPane1 = 
new javax.swing.JScrollPane();
 
  188         enterKeywordsLabel = 
new javax.swing.JLabel();
 
  189         keywordTypeLabel = 
new javax.swing.JLabel();
 
  190         addButton = 
new javax.swing.JButton();
 
  191         cancelButton = 
new javax.swing.JButton();
 
  192         pasteButton = 
new javax.swing.JButton();
 
  194         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
  196         keywordTypeButtonGroup.add(exactRadioButton);
 
  197         exactRadioButton.setSelected(
true);
 
  198         org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.exactRadioButton.text")); 
 
  200         keywordTypeButtonGroup.add(substringRadioButton);
 
  201         org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.substringRadioButton.text")); 
 
  203         keywordTypeButtonGroup.add(regexRadioButton);
 
  204         org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.regexRadioButton.text")); 
 
  206         org.openide.awt.Mnemonics.setLocalizedText(enterKeywordsLabel, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.enterKeywordsLabel.text")); 
 
  208         org.openide.awt.Mnemonics.setLocalizedText(keywordTypeLabel, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.keywordTypeLabel.text")); 
 
  210         org.openide.awt.Mnemonics.setLocalizedText(addButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.addButton.text")); 
 
  211         addButton.addActionListener(
new java.awt.event.ActionListener() {
 
  212             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  213                 addButtonActionPerformed(evt);
 
  217         org.openide.awt.Mnemonics.setLocalizedText(cancelButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.cancelButton.text")); 
 
  218         cancelButton.addActionListener(
new java.awt.event.ActionListener() {
 
  219             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  220                 cancelButtonActionPerformed(evt);
 
  224         org.openide.awt.Mnemonics.setLocalizedText(pasteButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.pasteButton.text")); 
 
  225         pasteButton.addActionListener(
new java.awt.event.ActionListener() {
 
  226             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  227                 pasteButtonActionPerformed(evt);
 
  231         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  232         getContentPane().setLayout(layout);
 
  233         layout.setHorizontalGroup(
 
  234             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  235             .addGroup(layout.createSequentialGroup()
 
  237                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  238                     .addComponent(enterKeywordsLabel)
 
  239                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  240                     .addComponent(pasteButton))
 
  241                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  242                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  243                     .addGroup(layout.createSequentialGroup()
 
  244                         .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  245                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  246                         .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  247                     .addComponent(keywordTypeLabel)
 
  248                     .addGroup(layout.createSequentialGroup()
 
  250                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  251                             .addComponent(substringRadioButton)
 
  252                             .addComponent(exactRadioButton)
 
  253                             .addComponent(regexRadioButton))))
 
  254                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  256         layout.setVerticalGroup(
 
  257             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  258             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
  260                 .addComponent(enterKeywordsLabel)
 
  261                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  262                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  263                     .addGroup(layout.createSequentialGroup()
 
  264                         .addComponent(keywordTypeLabel)
 
  265                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  266                         .addComponent(exactRadioButton)
 
  267                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  268                         .addComponent(substringRadioButton)
 
  269                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  270                         .addComponent(regexRadioButton)
 
  271                         .addGap(194, 194, 194))
 
  272                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
  273                         .addGap(0, 0, Short.MAX_VALUE)
 
  274                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  276                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  277                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  278                         .addComponent(addButton)
 
  279                         .addComponent(cancelButton))
 
  280                     .addComponent(pasteButton))
 
  287     private void pasteButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  288         keywordTextArea.paste();
 
  291     private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  293         newKeywords.addAll(Arrays.asList(keywordTextArea.getText().split(
"\\r?\\n")));
 
  299     private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  304     private void keywordTextAreaMouseClicked(java.awt.event.MouseEvent evt) {
 
  305         if (SwingUtilities.isRightMouseButton(evt)) {
 
  306             JPopupMenu popup = 
new JPopupMenu();
 
  308             JMenuItem cutMenu = 
new JMenuItem(
"Cut"); 
 
  309             cutMenu.addActionListener(
new ActionListener() {
 
  311                 public void actionPerformed(ActionEvent e) {
 
  312                     keywordTextArea.cut();
 
  316             JMenuItem copyMenu = 
new JMenuItem(
"Copy"); 
 
  317             copyMenu.addActionListener(
new ActionListener() {
 
  319                 public void actionPerformed(ActionEvent e) {
 
  320                     keywordTextArea.copy();
 
  324             JMenuItem pasteMenu = 
new JMenuItem(
"Paste"); 
 
  325             pasteMenu.addActionListener(
new ActionListener() {
 
  327                 public void actionPerformed(ActionEvent e) {
 
  328                     keywordTextArea.paste();
 
  334             popup.add(pasteMenu);
 
  335             popup.show(keywordTextArea, evt.getX(), evt.getY());
 
  339     private javax.swing.JButton addButton;
 
  340     private javax.swing.JButton cancelButton;
 
  341     private javax.swing.JLabel enterKeywordsLabel;
 
  342     private javax.swing.JRadioButton exactRadioButton;
 
  343     private javax.swing.JScrollPane jScrollPane1;
 
  344     private javax.swing.ButtonGroup keywordTypeButtonGroup;
 
  345     private javax.swing.JLabel keywordTypeLabel;
 
  346     private javax.swing.JButton pasteButton;
 
  347     private javax.swing.JRadioButton regexRadioButton;
 
  348     private javax.swing.JRadioButton substringRadioButton;