200N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
200N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
200N/A *
200N/A * This code is free software; you can redistribute it and/or modify it
200N/A * under the terms of the GNU General Public License version 2 only, as
200N/A * published by the Free Software Foundation.
200N/A *
200N/A * This code is distributed in the hope that it will be useful, but WITHOUT
200N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
200N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
200N/A * version 2 for more details (a copy is included in the LICENSE file that
200N/A * accompanied this code).
200N/A *
200N/A * You should have received a copy of the GNU General Public License version
200N/A * 2 along with this work; if not, write to the Free Software Foundation,
200N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
200N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
200N/A */
200N/A
200N/A/*
200N/A @test
200N/A @bug 6182359
200N/A @summary Tests that Window having non-focusable owner can't be a focus owner.
202N/A @author Anton.Tarasov: area=awt.focus
202N/A @library ../../regtesthelpers
202N/A @build Util
202N/A @run main NonfocusableOwnerTest
200N/A*/
200N/A
200N/Aimport java.awt.*;
200N/Aimport java.awt.event.*;
200N/Aimport java.applet.Applet;
200N/Aimport java.lang.reflect.*;
200N/Aimport java.io.*;
202N/Aimport test.java.awt.regtesthelpers.Util;
200N/A
200N/Apublic class NonfocusableOwnerTest extends Applet {
202N/A Robot robot = Util.createRobot();
200N/A Frame frame;
200N/A Dialog dialog;
200N/A Window window1;
200N/A Window window2;
200N/A Button button = new Button("button");
200N/A
200N/A public static void main(String[] args) {
200N/A NonfocusableOwnerTest test = new NonfocusableOwnerTest();
200N/A test.start();
200N/A }
200N/A
200N/A public void start() {
200N/A Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
200N/A public void eventDispatched(AWTEvent e) {
202N/A System.out.println(e.toString());
200N/A }
200N/A }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK | WindowEvent.WINDOW_EVENT_MASK);
200N/A
200N/A frame = new Frame("Frame");
200N/A frame.setName("Frame-owner");
202N/A frame.setBounds(100, 0, 100, 100);
200N/A dialog = new Dialog(frame, "Dialog");
200N/A dialog.setName("Dialog-owner");
202N/A dialog.setBounds(100, 0, 100, 100);
200N/A
200N/A window1 = new Window(frame);
200N/A window1.setName("1st child");
202N/A window1.setBounds(100, 300, 100, 100);
200N/A window2 = new Window(window1);
200N/A window2.setName("2nd child");
202N/A window2.setBounds(100, 500, 100, 100);
200N/A
200N/A test1(frame, window1);
200N/A test2(frame, window1, window2);
200N/A test3(frame, window1, window2);
200N/A
200N/A window1 = new Window(dialog);
202N/A window1.setBounds(100, 300, 100, 100);
200N/A window1.setName("1st child");
200N/A window2 = new Window(window1);
200N/A window2.setName("2nd child");
202N/A window2.setBounds(100, 500, 100, 100);
200N/A
200N/A test1(dialog, window1);
200N/A test2(dialog, window1, window2);
200N/A test3(dialog, window1, window2);
200N/A
202N/A System.out.println("Test passed.");
200N/A }
200N/A
200N/A void test1(Window owner, Window child) {
202N/A System.out.println("* * * STAGE 1 * * *\nWindow owner: " + owner);
200N/A
200N/A owner.setFocusableWindowState(false);
200N/A owner.setVisible(true);
200N/A
200N/A child.add(button);
200N/A child.setVisible(true);
200N/A
202N/A Util.waitTillShown(child);
200N/A
202N/A Util.clickOnComp(button, robot);
200N/A if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
200N/A throw new RuntimeException("Test Failed.");
200N/A }
202N/A child.dispose();
200N/A owner.dispose();
200N/A }
200N/A
200N/A void test2(Window owner, Window child1, Window child2) {
202N/A System.out.println("* * * STAGE 2 * * *\nWindow nowner: " + owner);
200N/A
200N/A owner.setFocusableWindowState(false);
200N/A owner.setVisible(true);
200N/A
200N/A child1.setFocusableWindowState(true);
200N/A child1.setVisible(true);
200N/A
200N/A child2.add(button);
200N/A child2.setVisible(true);
200N/A
202N/A Util.waitTillShown(child2);
202N/A
202N/A Util.clickOnComp(button, robot);
200N/A if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
200N/A throw new RuntimeException("Test failed.");
200N/A }
202N/A child2.dispose();
200N/A child1.dispose();
202N/A owner.dispose();
200N/A }
200N/A
200N/A void test3(Window owner, Window child1, Window child2) {
202N/A System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);
200N/A
200N/A owner.setFocusableWindowState(true);
200N/A owner.setVisible(true);
200N/A
200N/A child1.setFocusableWindowState(false);
200N/A child1.setVisible(true);
200N/A
200N/A child2.setFocusableWindowState(true);
200N/A child2.add(button);
200N/A child2.setVisible(true);
200N/A
202N/A Util.waitTillShown(child2);
200N/A
202N/A Util.clickOnComp(button, robot);
200N/A System.err.println("focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
200N/A if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
200N/A throw new RuntimeException("Test failed.");
200N/A }
200N/A child1.dispose();
200N/A child2.dispose();
202N/A owner.dispose();
200N/A }
200N/A}