0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/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.
0N/A */
0N/A
0N/A/*
0N/A @test
0N/A @bug 6232687
0N/A @summary Tests that Window.setLocationRelativeTo() method works correctly
0N/Afor different multiscreen configurations
0N/A @author artem.ananiev, area=awt.multiscreen
0N/A @library ../../regtesthelpers
0N/A @build Util
0N/A @run main LocationRelativeToTest
0N/A*/
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/A
0N/Aimport javax.swing.*;
0N/A
0N/Aimport test.java.awt.regtesthelpers.Util;
0N/A
0N/Apublic class LocationRelativeToTest
0N/A{
0N/A private static int FRAME_WIDTH = 400;
0N/A private static int FRAME_HEIGHT = 300;
0N/A
0N/A public static void main(String[] args)
0N/A {
0N/A Robot r = Util.createRobot();
0N/A
0N/A GraphicsEnvironment ge =
0N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
0N/A System.out.println("Center point: " + ge.getCenterPoint());
0N/A GraphicsDevice[] gds = ge.getScreenDevices();
0N/A GraphicsDevice gdDef = ge.getDefaultScreenDevice();
0N/A GraphicsConfiguration gcDef =
0N/A gdDef.getDefaultConfiguration();
0N/A
0N/A Frame f = new Frame("F", gcDef);
0N/A f.setSize(FRAME_WIDTH, FRAME_HEIGHT);
0N/A f.setVisible(true);
0N/A Util.waitForIdle(r);
0N/A
0N/A // first, check setLocationRelativeTo(null)
0N/A f.setLocationRelativeTo(null);
0N/A Util.waitForIdle(r);
0N/A checkLocation(f, ge.getCenterPoint());
0N/A
0N/A for (GraphicsDevice gd : gds)
0N/A {
0N/A GraphicsConfiguration gc = gd.getDefaultConfiguration();
0N/A Rectangle gcBounds = gc.getBounds();
0N/A Frame f2 = new Frame("F2", gc);
0N/A f2.setBounds(gcBounds.x + 100, gcBounds.y + 100,
0N/A FRAME_WIDTH, FRAME_HEIGHT);
0N/A
0N/A // second, check setLocationRelativeTo(invisible)
0N/A f.setLocationRelativeTo(f2);
0N/A Util.waitForIdle(r);
0N/A checkLocation(f, new Point(gcBounds.x + gcBounds.width / 2,
0N/A gcBounds.y + gcBounds.height / 2));
0N/A
0N/A // third, check setLocationRelativeTo(visible)
0N/A f2.setVisible(true);
0N/A Util.waitForIdle(r);
0N/A Point f2Loc = f2.getLocationOnScreen();
0N/A f.setLocationRelativeTo(f2);
0N/A Util.waitForIdle(r);
0N/A checkLocation(f, new Point(f2Loc.x + f2.getWidth() / 2,
0N/A f2Loc.y + f2.getHeight() / 2));
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Here the check is performed. Note this check works correctly both
0N/A * for virtual (Win32, X11/Xinerama) and non-virtual (X11/non-Xinerama)
0N/A * screen configurations.
0N/A */
0N/A private static void checkLocation(Frame f, Point rightLoc)
0N/A {
0N/A Point actualLoc = new Point(f.getBounds().x + f.getWidth() / 2,
0N/A f.getBounds().y + f.getHeight() / 2);
0N/A if (!rightLoc.equals(actualLoc))
0N/A {
0N/A System.err.println("Right location for the window center: " + rightLoc);
0N/A System.err.println("Actual location for the window center: " + actualLoc);
0N/A throw new RuntimeException("Test FAILED: setLocationRelativeTo() operates incorrectly");
0N/A }
0N/A }
0N/A}