< prev index next >

test/jdk/java/awt/Focus/ConsumeNextKeyTypedOnModalShowTest/ConsumeNextKeyTypedOnModalShowTest.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2016, 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 /*
  25   @test      %W% %E%
  26   @key headful
  27   @bug       6637607
  28   @summary   Showing a modal dlg on TAB KEY_PRESS shouldn't consume inappropriate KEY_TYPED.
  29   @author    Anton Tarasov: area=awt-focus
  30   @library   ../../regtesthelpers
  31   @build     Util
  32   @run       main ConsumeNextKeyTypedOnModalShowTest
  33 */
  34 
  35 import java.awt.*;
  36 import java.awt.event.*;
  37 import java.applet.Applet;
  38 import java.util.concurrent.atomic.AtomicBoolean;
  39 import java.lang.reflect.InvocationTargetException;
  40 import test.java.awt.regtesthelpers.Util;
  41 
  42 public class ConsumeNextKeyTypedOnModalShowTest extends Applet {
  43     Robot robot;
  44     Frame frame = new Frame("Frame");
  45     Dialog dialog = new Dialog(frame, "Dialog", true);
  46     TextField tf0 = new TextField();
  47     TextField tf1 = new TextField();
  48     Button button = new Button("Button");
  49 
  50     public static void main(String[] args) {
  51         ConsumeNextKeyTypedOnModalShowTest app = new ConsumeNextKeyTypedOnModalShowTest();
  52         app.init();
  53         app.start();
  54     }
  55 
  56     public void init() {
  57         robot = Util.createRobot();
  58 
  59         tf0.setPreferredSize(new Dimension(50, 30));
  60         tf1.setPreferredSize(new Dimension(50, 30));
  61         frame.setLayout(new FlowLayout());
  62         frame.add(tf0);
  63         frame.add(tf1);
  64         frame.pack();
  65 
  66         dialog.add(button);
  67         dialog.pack();
  68 
  69         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
  70             public void eventDispatched(AWTEvent e) {
  71                 if (e.getID() == KeyEvent.KEY_PRESSED && e.getSource() == tf0) {
  72                     dialog.setVisible(true);
  73                 }
  74             }
  75         }, KeyEvent.KEY_EVENT_MASK);
  76     }
  77 
  78     public void start() {

  79         frame.setVisible(true);
  80         Util.waitTillShown(frame);
  81 
  82         // Show the dialog.
  83         robot.keyPress(KeyEvent.VK_TAB);
  84         robot.delay(50);
  85         robot.keyRelease(KeyEvent.VK_TAB);
  86 
  87         Util.waitForIdle(robot);
  88 
  89         // Dispose the dialog.
  90         Runnable action = new Runnable() {
  91             public void run() {
  92                 dialog.dispose();
  93             }
  94         };
  95         if (!Util.trackFocusGained(tf1, action, 2000, false)) {
  96             throw new RuntimeException("Test failed: TAB was processed incorrectly!");
  97         }
  98 
   1 /*
   2  * Copyright (c) 2008, 2018, 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 /*
  25   @test
  26   @key headful
  27   @bug       6637607
  28   @summary   Showing a modal dlg on TAB KEY_PRESS shouldn't consume inappropriate KEY_TYPED.

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



  36 import test.java.awt.regtesthelpers.Util;
  37 
  38 public class ConsumeNextKeyTypedOnModalShowTest {
  39     Robot robot;
  40     Frame frame = new Frame("Frame");
  41     Dialog dialog = new Dialog(frame, "Dialog", true);
  42     TextField tf0 = new TextField();
  43     TextField tf1 = new TextField();
  44     Button button = new Button("Button");
  45 
  46     public static void main(String[] args) {
  47         ConsumeNextKeyTypedOnModalShowTest app = new ConsumeNextKeyTypedOnModalShowTest();
  48         app.init();
  49         app.start();
  50     }
  51 
  52     public void init() {
  53         robot = Util.createRobot();
  54 
  55         tf0.setPreferredSize(new Dimension(50, 30));
  56         tf1.setPreferredSize(new Dimension(50, 30));
  57         frame.setLayout(new FlowLayout());
  58         frame.add(tf0);
  59         frame.add(tf1);
  60         frame.pack();
  61 
  62         dialog.add(button);
  63         dialog.pack();
  64 
  65         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
  66             public void eventDispatched(AWTEvent e) {
  67                 if (e.getID() == KeyEvent.KEY_PRESSED && e.getSource() == tf0) {
  68                     dialog.setVisible(true);
  69                 }
  70             }
  71         }, KeyEvent.KEY_EVENT_MASK);
  72     }
  73 
  74     public void start() {
  75         frame.setLocationRelativeTo(null);
  76         frame.setVisible(true);
  77         Util.waitTillShown(frame);
  78 
  79         // Show the dialog.
  80         robot.keyPress(KeyEvent.VK_TAB);
  81         robot.delay(50);
  82         robot.keyRelease(KeyEvent.VK_TAB);
  83 
  84         Util.waitForIdle(robot);
  85 
  86         // Dispose the dialog.
  87         Runnable action = new Runnable() {
  88             public void run() {
  89                 dialog.dispose();
  90             }
  91         };
  92         if (!Util.trackFocusGained(tf1, action, 2000, false)) {
  93             throw new RuntimeException("Test failed: TAB was processed incorrectly!");
  94         }
  95 
< prev index next >