Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java
38828 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 682954626@summary tests that an always-on-top modal dialog doesn't make any windows always-on-top27@author artem.ananiev: area=awt.modal28@library ../../regtesthelpers29@build Util30@run main MakeWindowAlwaysOnTop31*/3233import java.awt.*;34import java.awt.event.*;3536import test.java.awt.regtesthelpers.Util;3738public class MakeWindowAlwaysOnTop39{40private static Frame f;41private static Dialog d;4243public static void main(String[] args) throws Exception44{45Robot r = Util.createRobot();46Util.waitForIdle(r);4748// Frame49f = new Frame("Test frame");50f.setBounds(100, 100, 400, 300);51f.setBackground(Color.RED);52f.setVisible(true);53r.delay(100);54Util.waitForIdle(r);5556// Dialog57d = new Dialog(null, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);58d.setBounds(500, 500, 160, 160);59d.setAlwaysOnTop(true);60EventQueue.invokeLater(new Runnable()61{62public void run()63{64d.setVisible(true);65}66});67// Wait until the dialog is shown68EventQueue.invokeAndWait(new Runnable()69{70public void run()71{72// Empty73}74});75r.delay(100);76Util.waitForIdle(r);7778// Click on the frame to trigger modality79Point p = f.getLocationOnScreen();80r.mouseMove(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);81Util.waitForIdle(r);82r.mousePress(InputEvent.BUTTON1_MASK);83Util.waitForIdle(r);84r.mouseRelease(InputEvent.BUTTON1_MASK);85Util.waitForIdle(r);8687r.delay(100);88Util.waitForIdle(r);8990// Dispose dialog91d.dispose();92r.delay(100);93Util.waitForIdle(r);9495// Show another frame at the same location96Frame t = new Frame("Check");97t.setBounds(100, 100, 400, 300);98t.setBackground(Color.BLUE);99t.setVisible(true);100r.delay(100);101Util.waitForIdle(r);102103// Bring it above the first frame104t.toFront();105r.delay(100);106Util.waitForIdle(r);107108Color c = r.getPixelColor(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);109System.out.println("Color = " + c);110System.out.flush();111// If the color is RED, then the first frame is now always-on-top112if (Color.RED.equals(c))113{114throw new RuntimeException("Test FAILED: the frame is always-on-top");115}116else if (!Color.BLUE.equals(c))117{118throw new RuntimeException("Test FAILED: unknown window is on top of the frame");119}120else121{122System.out.println("Test PASSED");123System.out.flush();124}125126// Dispose all the windows127t.dispose();128f.dispose();129}130}131132133