20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import java.awt.*; |
24 import java.awt.*; |
25 |
|
26 /* |
25 /* |
27 * @test |
26 * @test |
28 * @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH) |
27 * @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH) |
29 * is called for a Frame after been called setMaximizedBounds() with |
28 * is called for a Frame after been called setMaximizedBounds() with |
30 * certain value, Frame bounds must equal to this value. |
29 * certain value, Frame bounds must equal to this value. |
31 * |
30 * |
32 * @library ../../../../lib/testlibrary |
|
33 * @build ExtendedRobot |
|
34 * @run main SetMaximizedBounds |
31 * @run main SetMaximizedBounds |
35 */ |
32 */ |
36 |
33 |
37 public class SetMaximizedBounds { |
34 public class SetMaximizedBounds { |
38 |
35 |
39 Frame frame; |
36 public static void main(String[] args) throws Exception { |
40 Rectangle bound; |
|
41 boolean supported; |
|
42 ExtendedRobot robot; |
|
43 static Rectangle max = new Rectangle(100,100,400,400); |
|
44 |
37 |
45 public void doTest() throws Exception { |
38 //Supported platforms are Windows and OS X. |
46 robot = new ExtendedRobot(); |
39 String os = System.getProperty("os.name").toLowerCase(); |
|
40 if (!os.contains("windows") && !os.contains("os x")) { |
|
41 return; |
|
42 } |
47 |
43 |
48 EventQueue.invokeAndWait( () -> { |
44 if (!Toolkit.getDefaultToolkit(). |
49 frame = new Frame( "TestFrame "); |
45 isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { |
50 frame.setLayout(new FlowLayout()); |
46 return; |
|
47 } |
51 |
48 |
52 if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { |
49 GraphicsEnvironment ge = GraphicsEnvironment. |
53 supported = true; |
50 getLocalGraphicsEnvironment(); |
54 frame.setMaximizedBounds(max); |
51 |
55 } else { |
52 if (ge.isHeadlessInstance()) { |
56 supported = false; |
53 return; |
|
54 } |
|
55 |
|
56 for (GraphicsDevice gd : ge.getScreenDevices()) { |
|
57 for (GraphicsConfiguration gc : gd.getConfigurations()) { |
|
58 testMaximizedBounds(gc); |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 static void testMaximizedBounds(GraphicsConfiguration gc) throws Exception { |
|
64 |
|
65 Frame frame = null; |
|
66 try { |
|
67 |
|
68 Rectangle maxArea = getMaximizedScreenArea(gc); |
|
69 |
|
70 Robot robot = new Robot(); |
|
71 robot.setAutoDelay(50); |
|
72 |
|
73 frame = new Frame(); |
|
74 Rectangle maximizedBounds = new Rectangle( |
|
75 maxArea.x + maxArea.width / 6, |
|
76 maxArea.y + maxArea.height / 6, |
|
77 maxArea.width / 3, |
|
78 maxArea.height / 3); |
|
79 frame.setMaximizedBounds(maximizedBounds); |
|
80 frame.setSize(maxArea.width / 8, maxArea.height / 8); |
|
81 frame.setVisible(true); |
|
82 robot.waitForIdle(); |
|
83 |
|
84 frame.setExtendedState(Frame.MAXIMIZED_BOTH); |
|
85 robot.waitForIdle(); |
|
86 robot.delay(1000); |
|
87 |
|
88 Rectangle bounds = frame.getBounds(); |
|
89 if (!bounds.equals(maximizedBounds)) { |
|
90 throw new RuntimeException("The bounds of the Frame do not equal to what" |
|
91 + " is specified when the frame is in Frame.MAXIMIZED_BOTH state"); |
57 } |
92 } |
58 |
93 |
59 frame.setSize(200, 200); |
94 frame.setExtendedState(Frame.NORMAL); |
60 frame.setVisible(true); |
95 robot.waitForIdle(); |
61 }); |
96 robot.delay(1000); |
62 |
97 |
63 robot.waitForIdle(2000); |
98 maximizedBounds = new Rectangle( |
64 if (supported) { |
99 maxArea.x + maxArea.width / 10, |
65 EventQueue.invokeAndWait( () -> { |
100 maxArea.y + maxArea.height / 10, |
66 frame.setExtendedState(Frame.MAXIMIZED_BOTH); |
101 maxArea.width / 5, |
67 }); |
102 maxArea.height / 5); |
68 robot.waitForIdle(2000); |
103 frame.setMaximizedBounds(maximizedBounds); |
69 bound = frame.getBounds(); |
104 frame.setExtendedState(Frame.MAXIMIZED_BOTH); |
70 if(!bound.equals(max)) |
105 robot.waitForIdle(); |
|
106 robot.delay(1000); |
|
107 |
|
108 bounds = frame.getBounds(); |
|
109 if (!bounds.equals(maximizedBounds)) { |
71 throw new RuntimeException("The bounds of the Frame do not equal to what" |
110 throw new RuntimeException("The bounds of the Frame do not equal to what" |
72 + " is specified when the frame is in Frame.MAXIMIZED_BOTH state"); |
111 + " is specified when the frame is in Frame.MAXIMIZED_BOTH state"); |
73 } else { |
112 } |
74 System.out.println("Frame.MAXIMIZED_BOTH not supported"); |
113 } finally { |
|
114 if (frame != null) { |
|
115 frame.dispose(); |
|
116 } |
75 } |
117 } |
76 |
|
77 frame.dispose(); |
|
78 } |
118 } |
79 |
119 |
80 public static void main(String[] args) throws Exception { |
120 static Rectangle getMaximizedScreenArea(GraphicsConfiguration gc) { |
81 String os = System.getProperty("os.name").toLowerCase(); |
121 Rectangle bounds = gc.getBounds(); |
82 System.out.println(os); |
122 Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); |
83 if (os.contains("windows") || os.contains("os x")) |
123 return new Rectangle( |
84 new SetMaximizedBounds().doTest(); |
124 bounds.x + insets.left, |
85 else |
125 bounds.y + insets.top, |
86 System.out.println("Platform "+os+" is not supported. Supported platforms are Windows and OS X."); |
126 bounds.width - insets.left - insets.right, |
|
127 bounds.height - insets.top - insets.bottom); |
87 } |
128 } |
88 } |
129 } |