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<>();
 
   51         super((JFrame) WindowManager.getDefault().getMainWindow(),
 
   52                 NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.addKeywordsTitle.text"),
 
   57         addButton.setEnabled(
false);
 
   58         keywordTextArea.getDocument().addDocumentListener(
new DocumentListener() {
 
   60             public void changedUpdate(DocumentEvent e) {
 
   64             public void removeUpdate(DocumentEvent e) {
 
   68             public void insertUpdate(DocumentEvent e) {
 
   82         Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
 
   83         setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
 
   92     void setInitialKeywordList(String initialKeywords){
 
   93         keywordTextArea.setText(initialKeywords);
 
   97     private void enableButtons(){
 
   98         addButton.setEnabled(! keywordTextArea.getText().isEmpty());
 
  105     List<String> getKeywords(){
 
  113     boolean isKeywordRegex(){
 
  114         return regexRadioButton.isSelected();
 
  121     boolean isKeywordExact(){
 
  122         return exactRadioButton.isSelected();
 
  130     @SuppressWarnings(
"unchecked")
 
  132     private 
void initComponents() {
 
  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();
 
  146         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
  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")); 
 
  152         keywordTypeButtonGroup.add(substringRadioButton);
 
  153         org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.substringRadioButton.text")); 
 
  155         keywordTypeButtonGroup.add(regexRadioButton);
 
  156         org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.regexRadioButton.text")); 
 
  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);
 
  165         jScrollPane1.setViewportView(keywordTextArea);
 
  167         org.openide.awt.Mnemonics.setLocalizedText(enterKeywordsLabel, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.enterKeywordsLabel.text")); 
 
  169         org.openide.awt.Mnemonics.setLocalizedText(keywordTypeLabel, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.keywordTypeLabel.text")); 
 
  171         org.openide.awt.Mnemonics.setLocalizedText(addButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.addButton.text")); 
 
  172         addButton.addActionListener(
new java.awt.event.ActionListener() {
 
  173             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  174                 addButtonActionPerformed(evt);
 
  178         org.openide.awt.Mnemonics.setLocalizedText(cancelButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.cancelButton.text")); 
 
  179         cancelButton.addActionListener(
new java.awt.event.ActionListener() {
 
  180             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  181                 cancelButtonActionPerformed(evt);
 
  185         org.openide.awt.Mnemonics.setLocalizedText(pasteButton, 
org.openide.util.NbBundle.getMessage(AddKeywordsDialog.class, 
"AddKeywordsDialog.pasteButton.text")); 
 
  186         pasteButton.addActionListener(
new java.awt.event.ActionListener() {
 
  187             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  188                 pasteButtonActionPerformed(evt);
 
  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()
 
  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()
 
  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))
 
  217         layout.setVerticalGroup(
 
  218             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  219             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
 
  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)
 
  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))
 
  248     private void pasteButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  249         keywordTextArea.paste();
 
  252     private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  254         newKeywords.addAll(Arrays.asList(keywordTextArea.getText().split(
"\\r?\\n")));
 
  260     private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  265     private void keywordTextAreaMouseClicked(java.awt.event.MouseEvent evt) {
 
  266         if (SwingUtilities.isRightMouseButton(evt)) {
 
  267             JPopupMenu popup = 
new JPopupMenu();
 
  269             JMenuItem cutMenu = 
new JMenuItem(
"Cut"); 
 
  270             cutMenu.addActionListener(
new ActionListener() {
 
  272                 public void actionPerformed(ActionEvent e) {
 
  273                     keywordTextArea.cut();
 
  277             JMenuItem copyMenu = 
new JMenuItem(
"Copy"); 
 
  278             copyMenu.addActionListener(
new ActionListener() {
 
  280                 public void actionPerformed(ActionEvent e) {
 
  281                     keywordTextArea.copy();
 
  285             JMenuItem pasteMenu = 
new JMenuItem(
"Paste"); 
 
  286             pasteMenu.addActionListener(
new ActionListener() {
 
  288                 public void actionPerformed(ActionEvent e) {
 
  289                     keywordTextArea.paste();
 
  295             popup.add(pasteMenu);
 
  296             popup.show(keywordTextArea, evt.getX(), evt.getY());
 
  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;