1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package org.jemmy.browser;
  25 
  26 import javax.swing.JTextField;
  27 
  28 /**
  29  *
  30  * @author shura
  31  */
  32 public class SearchDialog extends javax.swing.JDialog {
  33     private boolean doSearch;
  34 
  35     /** Creates new form SearchDialog */
  36     public SearchDialog(java.awt.Frame parent) {
  37         super(parent, true);
  38         initComponents();
  39         getRootPane().setDefaultButton(searchBtn);
  40     }
  41 
  42     public boolean isConfirmed() {
  43         return doSearch;
  44     }
  45 
  46     /** This method is called from within the constructor to
  47      * initialize the form.
  48      * WARNING: Do NOT modify this code. The content of this method is
  49      * always regenerated by the Form Editor.
  50      */
  51     @SuppressWarnings("unchecked")
  52     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  53     private void initComponents() {
  54 
  55         jLabel1 = new javax.swing.JLabel();
  56         searchTF = new javax.swing.JTextField();
  57         cancelBtn = new javax.swing.JButton();
  58         searchBtn = new javax.swing.JButton();
  59         useProp = new javax.swing.JCheckBox();
  60         propSearch = new javax.swing.JTextField();
  61 
  62         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  63         setModal(true);
  64 
  65         jLabel1.setText("Class name");
  66 
  67         cancelBtn.setText("Cancel");
  68         cancelBtn.addActionListener(new java.awt.event.ActionListener() {
  69             public void actionPerformed(java.awt.event.ActionEvent evt) {
  70                 cancelBtnActionPerformed(evt);
  71             }
  72         });
  73 
  74         searchBtn.setText("Search");
  75         searchBtn.addActionListener(new java.awt.event.ActionListener() {
  76             public void actionPerformed(java.awt.event.ActionEvent evt) {
  77                 searchBtnActionPerformed(evt);
  78             }
  79         });
  80 
  81         useProp.setText("Property value");
  82         useProp.addActionListener(new java.awt.event.ActionListener() {
  83             public void actionPerformed(java.awt.event.ActionEvent evt) {
  84                 usePropActionPerformed(evt);
  85             }
  86         });
  87 
  88         propSearch.setEnabled(false);
  89 
  90         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  91         getContentPane().setLayout(layout);
  92         layout.setHorizontalGroup(
  93             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  94             .addGroup(layout.createSequentialGroup()
  95                 .addContainerGap()
  96                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  97                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  98                         .addComponent(searchBtn)
  99                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 100                         .addComponent(cancelBtn))
 101                     .addGroup(layout.createSequentialGroup()
 102                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 103                             .addComponent(useProp)
 104                             .addComponent(jLabel1))
 105                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 106                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 107                             .addComponent(searchTF, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
 108                             .addComponent(propSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE))))
 109                 .addContainerGap())
 110         );
 111         layout.setVerticalGroup(
 112             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 113             .addGroup(layout.createSequentialGroup()
 114                 .addContainerGap()
 115                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 116                     .addComponent(jLabel1)
 117                     .addComponent(searchTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 118                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 119                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 120                     .addComponent(useProp)
 121                     .addComponent(propSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 122                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 123                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 124                     .addComponent(cancelBtn)
 125                     .addComponent(searchBtn))
 126                 .addContainerGap())
 127         );
 128 
 129         pack();
 130     }// </editor-fold>//GEN-END:initComponents
 131 
 132     private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
 133         doSearch = false;
 134         setVisible(false);
 135     }//GEN-LAST:event_cancelBtnActionPerformed
 136 
 137     private void searchBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchBtnActionPerformed
 138         doSearch = true;
 139         setVisible(false);
 140     }//GEN-LAST:event_searchBtnActionPerformed
 141 
 142     private void usePropActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usePropActionPerformed
 143         propSearch.setEnabled(useProp.isSelected());
 144         if(useProp.isSelected()) {
 145             propSearch.requestFocus();
 146         }
 147     }//GEN-LAST:event_usePropActionPerformed
 148 
 149     public String getClassNameFilter() {
 150         return searchTF.getText();
 151     }
 152 
 153     public String getPropertyFilter() {
 154         return useProp.isSelected() ? propSearch.getText() : null;
 155     }
 156 
 157 
 158     // Variables declaration - do not modify//GEN-BEGIN:variables
 159     private javax.swing.JButton cancelBtn;
 160     private javax.swing.JLabel jLabel1;
 161     private javax.swing.JTextField propSearch;
 162     private javax.swing.JButton searchBtn;
 163     private javax.swing.JTextField searchTF;
 164     private javax.swing.JCheckBox useProp;
 165     // End of variables declaration//GEN-END:variables
 166 
 167 }