2853N/A/*
2853N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2853N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2853N/A *
2853N/A * This code is free software; you can redistribute it and/or modify it
2853N/A * under the terms of the GNU General Public License version 2 only, as
2853N/A * published by the Free Software Foundation.
2853N/A *
2853N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2853N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2853N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2853N/A * version 2 for more details (a copy is included in the LICENSE file that
2853N/A * accompanied this code).
2853N/A *
2853N/A * You should have received a copy of the GNU General Public License version
2853N/A * 2 along with this work; if not, write to the Free Software Foundation,
2853N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2853N/A *
2853N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2853N/A * or visit www.oracle.com if you need additional information or have any
2853N/A * questions.
2853N/A */
2853N/A
2853N/A/*
2853N/A @test
2853N/A @bug 6829546
2853N/A @summary tests that an always-on-top modal dialog doesn't make any windows always-on-top
2853N/A @author artem.ananiev: area=awt.modal
2853N/A @library ../../regtesthelpers
2853N/A @build Util
2853N/A @run main MakeWindowAlwaysOnTop
2853N/A*/
2853N/A
2853N/Aimport java.awt.*;
2853N/Aimport java.awt.event.*;
2853N/A
2853N/Aimport test.java.awt.regtesthelpers.Util;
2853N/A
2853N/Apublic class MakeWindowAlwaysOnTop
2853N/A{
2853N/A private static Frame f;
2853N/A private static Dialog d;
2853N/A
2853N/A public static void main(String[] args) throws Exception
2853N/A {
2853N/A Robot r = Util.createRobot();
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A // Frame
2853N/A f = new Frame("Test frame");
2853N/A f.setBounds(100, 100, 400, 300);
2853N/A f.setBackground(Color.RED);
2853N/A f.setVisible(true);
2853N/A r.delay(100);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A // Dialog
2853N/A d = new Dialog(null, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
2853N/A d.setBounds(500, 500, 160, 160);
2853N/A d.setAlwaysOnTop(true);
2853N/A EventQueue.invokeLater(new Runnable()
2853N/A {
2853N/A public void run()
2853N/A {
2853N/A d.setVisible(true);
2853N/A }
2853N/A });
2853N/A // Wait until the dialog is shown
2853N/A EventQueue.invokeAndWait(new Runnable()
2853N/A {
2853N/A public void run()
2853N/A {
2853N/A // Empty
2853N/A }
2853N/A });
2853N/A r.delay(100);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A // Click on the frame to trigger modality
2853N/A Point p = f.getLocationOnScreen();
2853N/A r.mouseMove(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);
2853N/A Util.waitForIdle(r);
2853N/A r.mousePress(InputEvent.BUTTON1_MASK);
2853N/A Util.waitForIdle(r);
2853N/A r.mouseRelease(InputEvent.BUTTON1_MASK);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A r.delay(100);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A // Dispose dialog
2853N/A d.dispose();
2853N/A r.delay(100);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A // Show another frame at the same location
2853N/A Frame t = new Frame("Check");
2853N/A t.setBounds(100, 100, 400, 300);
2853N/A t.setBackground(Color.BLUE);
2853N/A t.setVisible(true);
2853N/A r.delay(100);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A // Bring it above the first frame
2853N/A t.toFront();
2853N/A r.delay(100);
2853N/A Util.waitForIdle(r);
2853N/A
2853N/A Color c = r.getPixelColor(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);
2853N/A System.out.println("Color = " + c);
2853N/A System.out.flush();
2853N/A // If the color is RED, then the first frame is now always-on-top
2853N/A if (Color.RED.equals(c))
2853N/A {
2853N/A throw new RuntimeException("Test FAILED: the frame is always-on-top");
2853N/A }
2853N/A else if (!Color.BLUE.equals(c))
2853N/A {
2853N/A throw new RuntimeException("Test FAILED: unknown window is on top of the frame");
2853N/A }
2853N/A else
2853N/A {
2853N/A System.out.println("Test PASSED");
2853N/A System.out.flush();
2853N/A }
2853N/A
2853N/A // Dispose all the windows
2853N/A t.dispose();
2853N/A f.dispose();
2853N/A }
2853N/A}