java/awt/Focus/WindowUpdateFocusabilityTest/WindowUpdateFocusabilityTest.java

Print this page


   1 /*























   2   test
   3   @bug       6253913
   4   @summary   Tests that a Window shown before its owner is focusable.
   5   @author    anton.tarasov@sun.com: area=awt-focus
   6   @run       applet WindowUpdateFocusabilityTest.html
   7 */
   8 
   9 import java.awt.*;
  10 import java.awt.event.*;
  11 import java.applet.Applet;
  12 import java.lang.reflect.*;
  13 
  14 public class WindowUpdateFocusabilityTest extends Applet {
  15     Robot robot;
  16     boolean focusGained = false;
  17     final Object monitor = new Object();
  18     FocusListener listener = new FocusAdapter () {
  19             public void focusGained(FocusEvent e) {
  20                 Sysout.println(e.toString());
  21                 synchronized (monitor) {


 118 
 119         Sysout.println("Test for " + owner.getName() + " passed.");
 120         owner.dispose();
 121     }
 122 
 123     void clickOn(Component c) {
 124         Point p = c.getLocationOnScreen();
 125         Dimension d = c.getSize();
 126 
 127         Sysout.println("Clicking " + c);
 128 
 129         robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
 130 
 131         robot.mousePress(InputEvent.BUTTON1_MASK);
 132         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 133         waitForIdle();
 134     }
 135 
 136     void waitForIdle() {
 137         try {
 138             Toolkit.getDefaultToolkit().sync();
 139             sun.awt.SunToolkit.flushPendingEvents();
 140             EventQueue.invokeAndWait( new Runnable() {
 141                     public void run() {} // Dummy implementation
 142                 });
 143         } catch(InterruptedException ie) {
 144             Sysout.println("waitForIdle, non-fatal exception caught:");
 145             ie.printStackTrace();
 146         } catch(InvocationTargetException ite) {
 147             Sysout.println("waitForIdle, non-fatal exception caught:");
 148             ite.printStackTrace();
 149         }
 150     }
 151 
 152     boolean isFocusGained() {
 153         synchronized (monitor) {
 154             if (!focusGained) {
 155                 try {
 156                     monitor.wait(3000);
 157                 } catch (InterruptedException e) {
 158                     Sysout.println("Interrupted unexpectedly!");
 159                     throw new RuntimeException(e);


   1 /*
   2  * Copyright (c) 2005, 2015, 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   @bug       6253913
  27   @summary   Tests that a Window shown before its owner is focusable.
  28   @author    anton.tarasov@sun.com: area=awt-focus
  29   @run       applet WindowUpdateFocusabilityTest.html
  30 */
  31 
  32 import java.awt.*;
  33 import java.awt.event.*;
  34 import java.applet.Applet;
  35 import java.lang.reflect.*;
  36 
  37 public class WindowUpdateFocusabilityTest extends Applet {
  38     Robot robot;
  39     boolean focusGained = false;
  40     final Object monitor = new Object();
  41     FocusListener listener = new FocusAdapter () {
  42             public void focusGained(FocusEvent e) {
  43                 Sysout.println(e.toString());
  44                 synchronized (monitor) {


 141 
 142         Sysout.println("Test for " + owner.getName() + " passed.");
 143         owner.dispose();
 144     }
 145 
 146     void clickOn(Component c) {
 147         Point p = c.getLocationOnScreen();
 148         Dimension d = c.getSize();
 149 
 150         Sysout.println("Clicking " + c);
 151 
 152         robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
 153 
 154         robot.mousePress(InputEvent.BUTTON1_MASK);
 155         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 156         waitForIdle();
 157     }
 158 
 159     void waitForIdle() {
 160         try {
 161             robot.waitForIdle();
 162             robot.delay(50);
 163             EventQueue.invokeAndWait( new Runnable() {
 164                     public void run() {} // Dummy implementation
 165                 });
 166         } catch(InterruptedException ie) {
 167             Sysout.println("waitForIdle, non-fatal exception caught:");
 168             ie.printStackTrace();
 169         } catch(InvocationTargetException ite) {
 170             Sysout.println("waitForIdle, non-fatal exception caught:");
 171             ite.printStackTrace();
 172         }
 173     }
 174 
 175     boolean isFocusGained() {
 176         synchronized (monitor) {
 177             if (!focusGained) {
 178                 try {
 179                     monitor.wait(3000);
 180                 } catch (InterruptedException e) {
 181                     Sysout.println("Interrupted unexpectedly!");
 182                     throw new RuntimeException(e);