1 /* 2 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @bug 4737732 27 @summary Tests that Toolkit.getScreenInsets() returns correct insets 28 @author artem.ananiev: area=awt.toplevel 29 @library ../../regtesthelpers 30 @build Util 31 @run main ScreenInsetsTest 32 */ 33 34 import java.awt.*; 35 import java.awt.event.*; 36 37 import test.java.awt.regtesthelpers.Util; 38 39 public class ScreenInsetsTest 40 { 41 public static void main(String[] args) 42 { 43 if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) 44 { 45 // this state is used in the test - sorry 46 return; 47 } 48 49 boolean passed = true; 50 51 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 52 GraphicsDevice[] gds = ge.getScreenDevices(); 53 for (GraphicsDevice gd : gds) 54 { 55 GraphicsConfiguration gc = gd.getDefaultConfiguration(); 56 Rectangle gcBounds = gc.getBounds(); 57 Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc); 58 59 Frame f = new Frame("Test", gc); 60 f.setUndecorated(true); 61 f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240); 62 f.setVisible(true); 63 Util.waitForIdle(null); 64 65 f.setExtendedState(Frame.MAXIMIZED_BOTH); 66 Util.waitForIdle(null); 67 68 Rectangle fBounds = f.getBounds(); 69 // workaround: on Windows maximized windows have negative coordinates 70 if (fBounds.x < gcBounds.x) 71 { 72 fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased 73 fBounds.x = gcBounds.x; 74 } 75 if (fBounds.y < gcBounds.y) 76 { 77 fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased | 1 /* 2 * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @bug 4737732 27 @summary Tests that Toolkit.getScreenInsets() returns correct insets 28 @author artem.ananiev: area=awt.toplevel 29 @library ../../regtesthelpers 30 @build Util 31 @run main ScreenInsetsTest 32 */ 33 34 import java.awt.Frame; 35 import java.awt.GraphicsConfiguration; 36 import java.awt.GraphicsDevice; 37 import java.awt.GraphicsEnvironment; 38 import java.awt.Insets; 39 import java.awt.Rectangle; 40 import java.awt.Toolkit; 41 42 import test.java.awt.regtesthelpers.Util; 43 44 public class ScreenInsetsTest 45 { 46 public static void main(String[] args) 47 { 48 boolean passed = true; 49 50 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 51 GraphicsDevice[] gds = ge.getScreenDevices(); 52 for (GraphicsDevice gd : gds) { 53 54 GraphicsConfiguration gc = gd.getDefaultConfiguration(); 55 Rectangle gcBounds = gc.getBounds(); 56 Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc); 57 int left = gcInsets.left; 58 int right = gcInsets.right; 59 int bottom = gcInsets.bottom; 60 int top = gcInsets.top; 61 if (left < 0 || right < 0 || bottom < 0 || top < 0) { 62 throw new RuntimeException("Negative value: " + gcInsets); 63 } 64 int maxW = gcBounds.width / 3; 65 int maxH = gcBounds.height / 3; 66 if (left > maxW || right > maxW || bottom > maxH || top > maxH) { 67 throw new RuntimeException("Big value: " + gcInsets); 68 } 69 70 if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) 71 { 72 // this state is used in the test - sorry 73 continue; 74 } 75 76 Frame f = new Frame("Test", gc); 77 f.setUndecorated(true); 78 f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240); 79 f.setVisible(true); 80 Util.waitForIdle(null); 81 82 f.setExtendedState(Frame.MAXIMIZED_BOTH); 83 Util.waitForIdle(null); 84 85 Rectangle fBounds = f.getBounds(); 86 // workaround: on Windows maximized windows have negative coordinates 87 if (fBounds.x < gcBounds.x) 88 { 89 fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased 90 fBounds.x = gcBounds.x; 91 } 92 if (fBounds.y < gcBounds.y) 93 { 94 fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased |