< prev index next >
test/jdk/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -20,15 +20,17 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.*;
+import java.lang.Math;
/**
* @test
* @key headful
- * @bug 8065739 8131339
+ * @bug 8065739 8131339 8196006
+ * @requires (os.family == "windows" | os.family == "mac")
* @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH)
* is called for a Frame after been called setMaximizedBounds() with
* certain value, Frame bounds must equal to this value.
*
* @run main SetMaximizedBounds
@@ -36,42 +38,27 @@
public class SetMaximizedBounds {
public static void main(String[] args) throws Exception {
- //Supported platforms are Windows and OS X.
- String os = System.getProperty("os.name").toLowerCase();
- if (!os.contains("windows") && !os.contains("os x")) {
- return;
- }
-
if (!Toolkit.getDefaultToolkit().
isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
return;
}
- GraphicsEnvironment ge = GraphicsEnvironment.
- getLocalGraphicsEnvironment();
+ GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice().getDefaultConfiguration();
- if (ge.isHeadlessInstance()) {
- return;
- }
-
- for (GraphicsDevice gd : ge.getScreenDevices()) {
- for (GraphicsConfiguration gc : gd.getConfigurations()) {
testMaximizedBounds(gc, false);
testMaximizedBounds(gc, true);
}
- }
- }
static void testMaximizedBounds(GraphicsConfiguration gc, boolean undecorated)
throws Exception {
Frame frame = null;
try {
-
Rectangle maxArea = getMaximizedScreenArea(gc);
Robot robot = new Robot();
robot.setAutoDelay(50);
@@ -90,13 +77,14 @@
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
robot.waitForIdle();
robot.delay(1000);
Rectangle bounds = frame.getBounds();
- if (!bounds.equals(maximizedBounds)) {
+ applyScale(bounds, gc.getDefaultTransform().getScaleX(), gc.getDefaultTransform().getScaleY());
+ if (!compare(bounds, maximizedBounds)) {
throw new RuntimeException("The bounds of the Frame do not equal to what"
- + " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
+ + " is specified when the frame is in Frame.MAXIMIZED_BOTH");
}
frame.setExtendedState(Frame.NORMAL);
robot.waitForIdle();
robot.delay(1000);
@@ -110,13 +98,14 @@
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
robot.waitForIdle();
robot.delay(1000);
bounds = frame.getBounds();
- if (!bounds.equals(maximizedBounds)) {
+ applyScale(bounds, gc.getDefaultTransform().getScaleX(), gc.getDefaultTransform().getScaleY());
+ if (!compare(bounds, maximizedBounds)) {
throw new RuntimeException("The bounds of the Frame do not equal to what"
- + " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
+ + " is specified when the frame is in Frame.MAXIMIZED_BOTH");
}
} finally {
if (frame != null) {
frame.dispose();
}
@@ -130,6 +119,20 @@
bounds.x + insets.left,
bounds.y + insets.top,
bounds.width - insets.left - insets.right,
bounds.height - insets.top - insets.bottom);
}
+
+ static void applyScale(Rectangle rect, double scaleX, double scaleY) {
+ rect.x = (int)Math.ceil(((double)rect.x * scaleX));
+ rect.y = (int)Math.ceil(((double)rect.y * scaleY));
+ rect.width = (int)Math.ceil(((double)rect.width * scaleX));
+ rect.height = (int)Math.ceil(((double)rect.height * scaleY));
+ }
+
+ static boolean compare(Rectangle r1, Rectangle r2) {
+ return (Math.abs(r1.x - r2.x) <= 2 &&
+ Math.abs(r1.y - r2.y) <= 2 &&
+ Math.abs(r1.width - r2.width) <= 2 &&
+ Math.abs(r1.height - r2.height) <= 2);
+ }
}
< prev index next >