< prev index next >

test/jdk/java/awt/Focus/ClearLwQueueBreakTest/ClearLwQueueBreakTest.java

Print this page




   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 /*
  25   @test
  26   @key headful
  27   @bug       6496958
  28   @summary   Tests that breaking the proccess of clearing LW requests doesn't break focus.
  29   @author    anton.tarasov@...: area=awt-focus
  30   @library    ../../regtesthelpers
  31   @build      Util
  32   @run       main ClearLwQueueBreakTest
  33 */
  34 
  35 import java.awt.*;
  36 import javax.swing.*;
  37 import java.awt.event.*;
  38 import java.applet.Applet;
  39 import test.java.awt.regtesthelpers.Util;
  40 import java.util.concurrent.atomic.AtomicBoolean;
  41 
  42 public class ClearLwQueueBreakTest extends Applet {
  43     JFrame f1 = new JFrame("frame");
  44     JFrame f2 = new JFrame("frame");
  45     JButton b = new JButton("button");
  46     JTextField tf1 = new JTextField("     ");
  47     JTextField tf2 = new JTextField("     ");
  48     JTextField tf3 = new JTextField("     ");
  49     AtomicBoolean typed = new AtomicBoolean(false);
  50     FocusListener listener1;
  51     FocusListener listener2;
  52 
  53     Robot robot;
  54 
  55     public static void main(String[] args) {
  56         ClearLwQueueBreakTest app = new ClearLwQueueBreakTest();
  57         app.init();
  58         app.start();
  59     }
  60 
  61     public void init() {
  62         robot = Util.createRobot();
  63 
  64         // Create instructions for the user here, as well as set up
  65         // the environment -- set the layout manager, add buttons,
  66         // etc.
  67         this.setLayout (new BorderLayout ());
  68     }
  69 
  70     public void start() {
  71         b.addActionListener(new ActionListener() {
  72                 public void actionPerformed(ActionEvent e) {
  73                     f2.setVisible(true);
  74                 }
  75             });
  76         tf2.addKeyListener(new KeyAdapter() {
  77                 public void keyTyped(KeyEvent e) {
  78                     if (e.getKeyChar() == '9') {
  79                         synchronized (typed) {
  80                             typed.set(true);
  81                             typed.notifyAll();
  82                         }
  83                     }
  84                 }
  85             });
  86         tf3.addKeyListener(new KeyAdapter() {
  87                 public void keyTyped(KeyEvent e) {


 101                     tf1.setFocusable(false);
 102                     tf2.requestFocus();
 103                 }
 104             };
 105 
 106         listener2 = new FocusAdapter() {
 107                 public void focusGained(FocusEvent e) {
 108                     b.requestFocus();
 109                     tf1.requestFocus();
 110                     tf2.requestFocus();
 111                     tf2.setFocusable(false);
 112                 }
 113             };
 114 
 115         f1.add(b);
 116         f1.add(tf1);
 117         f1.add(tf2);
 118         f1.add(tf3);
 119         f1.setLayout(new FlowLayout());
 120         f1.pack();

 121         f1.setVisible(true);
 122         Util.waitForIdle(robot);
 123 
 124         /*
 125          * Break the sequence of LW requests in the middle.
 126          * Test that the last request succeeds
 127          */
 128         f2.addFocusListener(listener1);
 129         System.out.println("Stage 1.");
 130         test1();
 131 
 132 
 133         /*
 134          * Break the last LW request.
 135          * Test that focus is restored correctly.
 136          */
 137         f2.removeFocusListener(listener1);
 138         f2.addFocusListener(listener2);
 139         System.out.println("Stage 2.");
 140         test2();




   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 /*
  25   @test
  26   @key headful
  27   @bug       6496958
  28   @summary   Tests that breaking the proccess of clearing LW requests doesn't break focus.

  29   @library    ../../regtesthelpers
  30   @build      Util
  31   @run       main ClearLwQueueBreakTest
  32 */
  33 
  34 import java.awt.*;
  35 import javax.swing.*;
  36 import java.awt.event.*;

  37 import test.java.awt.regtesthelpers.Util;
  38 import java.util.concurrent.atomic.AtomicBoolean;
  39 
  40 public class ClearLwQueueBreakTest {
  41     JFrame f1 = new JFrame("frame");
  42     JFrame f2 = new JFrame("frame");
  43     JButton b = new JButton("button");
  44     JTextField tf1 = new JTextField("     ");
  45     JTextField tf2 = new JTextField("     ");
  46     JTextField tf3 = new JTextField("     ");
  47     AtomicBoolean typed = new AtomicBoolean(false);
  48     FocusListener listener1;
  49     FocusListener listener2;
  50 
  51     Robot robot;
  52 
  53     public static void main(String[] args) {
  54         ClearLwQueueBreakTest app = new ClearLwQueueBreakTest();
  55         app.init();
  56         app.start();
  57     }
  58 
  59     public void init() {
  60         robot = Util.createRobot();





  61     }
  62 
  63     public void start() {
  64         b.addActionListener(new ActionListener() {
  65                 public void actionPerformed(ActionEvent e) {
  66                     f2.setVisible(true);
  67                 }
  68             });
  69         tf2.addKeyListener(new KeyAdapter() {
  70                 public void keyTyped(KeyEvent e) {
  71                     if (e.getKeyChar() == '9') {
  72                         synchronized (typed) {
  73                             typed.set(true);
  74                             typed.notifyAll();
  75                         }
  76                     }
  77                 }
  78             });
  79         tf3.addKeyListener(new KeyAdapter() {
  80                 public void keyTyped(KeyEvent e) {


  94                     tf1.setFocusable(false);
  95                     tf2.requestFocus();
  96                 }
  97             };
  98 
  99         listener2 = new FocusAdapter() {
 100                 public void focusGained(FocusEvent e) {
 101                     b.requestFocus();
 102                     tf1.requestFocus();
 103                     tf2.requestFocus();
 104                     tf2.setFocusable(false);
 105                 }
 106             };
 107 
 108         f1.add(b);
 109         f1.add(tf1);
 110         f1.add(tf2);
 111         f1.add(tf3);
 112         f1.setLayout(new FlowLayout());
 113         f1.pack();
 114         f1.setLocationRelativeTo(null);
 115         f1.setVisible(true);
 116         Util.waitForIdle(robot);
 117 
 118         /*
 119          * Break the sequence of LW requests in the middle.
 120          * Test that the last request succeeds
 121          */
 122         f2.addFocusListener(listener1);
 123         System.out.println("Stage 1.");
 124         test1();
 125 
 126 
 127         /*
 128          * Break the last LW request.
 129          * Test that focus is restored correctly.
 130          */
 131         f2.removeFocusListener(listener1);
 132         f2.addFocusListener(listener2);
 133         System.out.println("Stage 2.");
 134         test2();


< prev index next >