--- a/jdk/test/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java Wed May 20 17:10:15 2015 +0300
+++ b/jdk/test/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java Fri May 22 15:19:05 2015 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, 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
@@ -22,67 +22,108 @@
*/
import java.awt.*;
-
/*
* @test
* @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.
*
- * @library ../../../../lib/testlibrary
- * @build ExtendedRobot
* @run main SetMaximizedBounds
*/
public class SetMaximizedBounds {
- Frame frame;
- Rectangle bound;
- boolean supported;
- ExtendedRobot robot;
- static Rectangle max = new Rectangle(100,100,400,400);
+ 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;
+ }
- public void doTest() throws Exception {
- robot = new ExtendedRobot();
+ GraphicsEnvironment ge = GraphicsEnvironment.
+ getLocalGraphicsEnvironment();
+
+ if (ge.isHeadlessInstance()) {
+ return;
+ }
+
+ for (GraphicsDevice gd : ge.getScreenDevices()) {
+ for (GraphicsConfiguration gc : gd.getConfigurations()) {
+ testMaximizedBounds(gc);
+ }
+ }
+ }
- EventQueue.invokeAndWait( () -> {
- frame = new Frame( "TestFrame ");
- frame.setLayout(new FlowLayout());
+ static void testMaximizedBounds(GraphicsConfiguration gc) throws Exception {
+
+ Frame frame = null;
+ try {
+
+ Rectangle maxArea = getMaximizedScreenArea(gc);
+
+ Robot robot = new Robot();
+ robot.setAutoDelay(50);
- if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
- supported = true;
- frame.setMaximizedBounds(max);
- } else {
- supported = false;
+ frame = new Frame();
+ Rectangle maximizedBounds = new Rectangle(
+ maxArea.x + maxArea.width / 6,
+ maxArea.y + maxArea.height / 6,
+ maxArea.width / 3,
+ maxArea.height / 3);
+ frame.setMaximizedBounds(maximizedBounds);
+ frame.setSize(maxArea.width / 8, maxArea.height / 8);
+ frame.setVisible(true);
+ robot.waitForIdle();
+
+ frame.setExtendedState(Frame.MAXIMIZED_BOTH);
+ robot.waitForIdle();
+ robot.delay(1000);
+
+ Rectangle bounds = frame.getBounds();
+ if (!bounds.equals(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");
}
- frame.setSize(200, 200);
- frame.setVisible(true);
- });
+ frame.setExtendedState(Frame.NORMAL);
+ robot.waitForIdle();
+ robot.delay(1000);
- robot.waitForIdle(2000);
- if (supported) {
- EventQueue.invokeAndWait( () -> {
- frame.setExtendedState(Frame.MAXIMIZED_BOTH);
- });
- robot.waitForIdle(2000);
- bound = frame.getBounds();
- if(!bound.equals(max))
+ maximizedBounds = new Rectangle(
+ maxArea.x + maxArea.width / 10,
+ maxArea.y + maxArea.height / 10,
+ maxArea.width / 5,
+ maxArea.height / 5);
+ frame.setMaximizedBounds(maximizedBounds);
+ frame.setExtendedState(Frame.MAXIMIZED_BOTH);
+ robot.waitForIdle();
+ robot.delay(1000);
+
+ bounds = frame.getBounds();
+ if (!bounds.equals(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");
- } else {
- System.out.println("Frame.MAXIMIZED_BOTH not supported");
+ + " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
+ }
+ } finally {
+ if (frame != null) {
+ frame.dispose();
+ }
}
-
- frame.dispose();
}
- public static void main(String[] args) throws Exception {
- String os = System.getProperty("os.name").toLowerCase();
- System.out.println(os);
- if (os.contains("windows") || os.contains("os x"))
- new SetMaximizedBounds().doTest();
- else
- System.out.println("Platform "+os+" is not supported. Supported platforms are Windows and OS X.");
+ static Rectangle getMaximizedScreenArea(GraphicsConfiguration gc) {
+ Rectangle bounds = gc.getBounds();
+ Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
+ return new Rectangle(
+ bounds.x + insets.left,
+ bounds.y + insets.top,
+ bounds.width - insets.left - insets.right,
+ bounds.height - insets.top - insets.bottom);
}
}