Path: blob/master/test/jdk/java/awt/Multiscreen/MultiScreenInsetsTest/MultiScreenInsetsTest.java
41153 views
/*1* Copyright (c) 2014, 2020, 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@key headful26@bug 802044327@summary Frame is not created on the specified GraphicsDevice with two28monitors29@author Oleg Pekhovskiy30@library /test/lib31@build jdk.test.lib.Platform32@run main MultiScreenInsetsTest33*/3435import java.awt.Frame;36import java.awt.GraphicsConfiguration;37import java.awt.GraphicsDevice;38import java.awt.GraphicsEnvironment;39import java.awt.Insets;40import java.awt.Rectangle;41import java.awt.Toolkit;4243import jdk.test.lib.Platform;4445public class MultiScreenInsetsTest {46private static final int SIZE = 100;4748public static void main(String[] args) throws InterruptedException {49if (!Platform.isLinux()) {50System.out.println("This test is for Linux only..." +51"skipping!");52return;53}5455GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();56GraphicsDevice[] gds = ge.getScreenDevices();57if (gds.length < 2) {58System.out.println("It's a multi-screen test... skipping!");59return;60}6162for (int screen = 0; screen < gds.length; ++screen) {63GraphicsDevice gd = gds[screen];64GraphicsConfiguration gc = gd.getDefaultConfiguration();65Rectangle bounds = gc.getBounds();66Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);6768Frame frame = new Frame(gc);69frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,70bounds.y + (bounds.height - SIZE) / 2);71frame.setSize(SIZE, SIZE);72frame.setUndecorated(true);73frame.setVisible(true);7475// Maximize Frame to reach the struts76frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);77Thread.sleep(2000);7879Rectangle frameBounds = frame.getBounds();80frame.dispose();81if (bounds.x + insets.left != frameBounds.x82|| bounds.y + insets.top != frameBounds.y83|| bounds.width - insets.right - insets.left != frameBounds.width84|| bounds.height - insets.bottom - insets.top != frameBounds.height) {85throw new RuntimeException("Test FAILED! Wrong screen #" +86screen + " insets: " + insets);87}88}89System.out.println("Test PASSED!");90}91}929394