test/java/awt/Focus/OverrideRedirectWindowActivationTest/OverrideRedirectWindowActivationTest.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 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  */


  98         window.setFocusableWindowState(false);
  99         toolkit.realSync();
 100 
 101 
 102         clickOn(getClickPoint(label));
 103 
 104         if (window.isFocused()) {
 105             throw new RuntimeException("Test failed: unfocusable window got activated by click!");
 106         }
 107         System.out.println("Test passed.");
 108 
 109     }
 110 
 111     private static void createAndShowWindow() {
 112 
 113         frame = new Frame("Test Frame");
 114         window = new Window(frame);
 115         wbutton = new Button("wbutton");
 116         label = new Label("label");
 117 
 118         window.setBounds(800, 200, 200, 100);
 119         window.setLayout(new FlowLayout());
 120         window.add(wbutton);
 121         window.add(label);
 122         window.setVisible(true);
 123 
 124     }
 125 
 126     private static void createAndShowFrame() {
 127         fbutton = new Button("fbutton");
 128 
 129         frame.setBounds(800, 0, 200, 100);
 130         frame.setLayout(new FlowLayout());
 131         frame.add(fbutton);
 132         frame.setVisible(true);
 133 
 134     }
 135 
 136     static void clickOn(Point point) {
 137 
 138         robot.mouseMove(point.x, point.y);
 139 
 140         robot.mousePress(InputEvent.BUTTON1_MASK);
 141         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 142 
 143         toolkit.realSync();
 144     }
 145 
 146     static Point getClickPoint(Component c) {
 147         Point p = c.getLocationOnScreen();
 148         Dimension d = c.getSize();
 149         return new Point(p.x + (int) (d.getWidth() / 2), p.y + (int) (d.getHeight() / 2));
   1 /*
   2  * Copyright (c) 2012, 2013, 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  */


  98         window.setFocusableWindowState(false);
  99         toolkit.realSync();
 100 
 101 
 102         clickOn(getClickPoint(label));
 103 
 104         if (window.isFocused()) {
 105             throw new RuntimeException("Test failed: unfocusable window got activated by click!");
 106         }
 107         System.out.println("Test passed.");
 108 
 109     }
 110 
 111     private static void createAndShowWindow() {
 112 
 113         frame = new Frame("Test Frame");
 114         window = new Window(frame);
 115         wbutton = new Button("wbutton");
 116         label = new Label("label");
 117 
 118         window.setBounds(800, 200, 300, 100);
 119         window.setLayout(new FlowLayout());
 120         window.add(wbutton);
 121         window.add(label);
 122         window.setVisible(true);
 123 
 124     }
 125 
 126     private static void createAndShowFrame() {
 127         fbutton = new Button("fbutton");
 128 
 129         frame.setBounds(800, 0, 300, 100);
 130         frame.setLayout(new FlowLayout());
 131         frame.add(fbutton);
 132         frame.setVisible(true);
 133 
 134     }
 135 
 136     static void clickOn(Point point) {
 137 
 138         robot.mouseMove(point.x, point.y);
 139 
 140         robot.mousePress(InputEvent.BUTTON1_MASK);
 141         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 142 
 143         toolkit.realSync();
 144     }
 145 
 146     static Point getClickPoint(Component c) {
 147         Point p = c.getLocationOnScreen();
 148         Dimension d = c.getSize();
 149         return new Point(p.x + (int) (d.getWidth() / 2), p.y + (int) (d.getHeight() / 2));