ScreenInsetsTest.java revision 2362
3551N/A/*
3551N/A * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
3551N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3551N/A *
3551N/A * This code is free software; you can redistribute it and/or modify it
3551N/A * under the terms of the GNU General Public License version 2 only, as
3551N/A * published by the Free Software Foundation.
3551N/A *
3551N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3551N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6982N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6982N/A * version 2 for more details (a copy is included in the LICENSE file that
3551N/A * accompanied this code).
3551N/A *
3551N/A * You should have received a copy of the GNU General Public License version
6982N/A * 2 along with this work; if not, write to the Free Software Foundation,
6982N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6982N/A *
6982N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6982N/A * or visit www.oracle.com if you need additional information or have any
3551N/A * questions.
3551N/A */
3551N/A
3551N/A/*
3551N/A @test
3551N/A @bug 4737732
3551N/A @summary Tests that Toolkit.getScreenInsets() returns correct insets
3551N/A @author artem.ananiev: area=awt.toplevel
3551N/A @library ../../regtesthelpers
3551N/A @build Util
3551N/A @run main ScreenInsetsTest
3551N/A*/
3551N/A
3551N/Aimport java.awt.*;
3551N/Aimport java.awt.event.*;
3551N/A
3551N/Aimport test.java.awt.regtesthelpers.Util;
3551N/A
3551N/Apublic class ScreenInsetsTest
3551N/A{
3551N/A public static void main(String[] args)
3551N/A {
3551N/A if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
3551N/A {
3551N/A // this state is used in the test - sorry
3551N/A return;
3551N/A }
3551N/A
3551N/A boolean passed = true;
3551N/A
3551N/A GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
3551N/A GraphicsDevice[] gds = ge.getScreenDevices();
3551N/A for (GraphicsDevice gd : gds)
3551N/A {
3551N/A GraphicsConfiguration gc = gd.getDefaultConfiguration();
3551N/A Rectangle gcBounds = gc.getBounds();
3551N/A Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
3551N/A
3551N/A Frame f = new Frame("Test", gc);
3551N/A f.setUndecorated(true);
3551N/A f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
3551N/A f.setVisible(true);
3551N/A Util.waitForIdle(null);
3551N/A
3551N/A f.setExtendedState(Frame.MAXIMIZED_BOTH);
3551N/A Util.waitForIdle(null);
3551N/A
3551N/A Rectangle fBounds = f.getBounds();
3551N/A // workaround: on Windows maximized windows have negative coordinates
3551N/A if (fBounds.x < gcBounds.x)
3551N/A {
3551N/A fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
3612N/A fBounds.x = gcBounds.x;
3551N/A }
3551N/A if (fBounds.y < gcBounds.y)
3551N/A {
3551N/A fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased
3551N/A fBounds.y = gcBounds.y;
3551N/A }
3551N/A Insets expected = new Insets(fBounds.y - gcBounds.y,
3551N/A fBounds.x - gcBounds.x,
3551N/A gcBounds.y + gcBounds.height - fBounds.y - fBounds.height,
3551N/A gcBounds.x + gcBounds.width - fBounds.x - fBounds.width);
3551N/A
3551N/A if (!expected.equals(gcInsets))
3551N/A {
3551N/A passed = false;
3551N/A System.err.println("Wrong insets for GraphicsConfig: " + gc);
3551N/A System.err.println("\tExpected: " + expected);
3551N/A System.err.println("\tActual: " + gcInsets);
3551N/A }
3551N/A
3551N/A f.dispose();
3551N/A }
3551N/A
3551N/A if (!passed)
3551N/A {
3551N/A throw new RuntimeException("TEST FAILED: Toolkit.getScreenInsets() returns wrong value for some screens");
3551N/A }
}
}