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 import java.awt.Frame;
25 import java.awt.GraphicsDevice;
26 import java.awt.GraphicsEnvironment;
27 import java.awt.Rectangle;
28 import java.awt.Robot;
29 import java.awt.Toolkit;
30
31 /**
32 * @test
33 * @bug 8176359 8231564
34 * @key headful
35 * @requires (os.family == "windows" | os.family == "mac")
36 * @summary setMaximizedBounds() should work if set to the screen other than
37 * current screen of the Frame, the size of the frame is intentionally
38 * small
39 */
40 public final class MaximizedToOppositeScreenSmall {
41
42 public static void main(String[] args) throws Exception {
43 //Supported platforms are Windows and OS X.
44 String os = System.getProperty("os.name").toLowerCase();
45 if (!os.contains("windows") && !os.contains("os x")) {
46 return;
47 }
48
49 if (!Toolkit.getDefaultToolkit().
50 isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
51 return;
52 }
53
54 var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
55 GraphicsDevice[] gds = ge.getScreenDevices();
56 Robot robot = new Robot();
57 for (GraphicsDevice gd1 : gds) {
58 Rectangle framAt = gd1.getDefaultConfiguration().getBounds();
59 framAt.grow(-framAt.width / 2 + 100, -framAt.height / 2 + 100);
60 for (GraphicsDevice gd2 : gds) {
61 Rectangle maxTo = gd2.getDefaultConfiguration().getBounds();
62 maxTo.grow(-maxTo.width / 2 + 120, -maxTo.height / 2 + 120);
63 Frame frame = new Frame(gd1.getDefaultConfiguration());
64 try {
65 frame.setBounds(framAt);
66 frame.setVisible(true);
67 robot.waitForIdle();
68 robot.delay(1000);
69
70 frame.setMaximizedBounds(maxTo);
71 frame.setExtendedState(Frame.MAXIMIZED_BOTH);
72 robot.waitForIdle();
73 robot.delay(1000);
74
75 Rectangle actual = frame.getBounds();
76 if (!actual.equals(maxTo)) {
77 System.err.println("Actual: " + actual);
78 System.err.println("Expected: " + maxTo);
79 throw new RuntimeException("Wrong bounds");
80 }
81 } finally {
82 frame.dispose();
83 }
84 }
85 }
86 }
87 }
88
|
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 import java.awt.Dimension;
25 import java.awt.Frame;
26 import java.awt.GraphicsDevice;
27 import java.awt.GraphicsEnvironment;
28 import java.awt.Rectangle;
29 import java.awt.Robot;
30 import java.awt.Toolkit;
31
32 /**
33 * @test
34 * @bug 8176359 8231564 8211999
35 * @key headful
36 * @requires (os.family == "windows" | os.family == "mac")
37 * @summary setMaximizedBounds() should work if set to the screen other than
38 * current screen of the Frame, the size of the frame is intentionally
39 * small
40 */
41 public final class MaximizedToOppositeScreenSmall {
42
43 public static void main(String[] args) throws Exception {
44 //Supported platforms are Windows and OS X.
45 String os = System.getProperty("os.name").toLowerCase();
46 if (!os.contains("windows") && !os.contains("os x")) {
47 return;
48 }
49
50 if (!Toolkit.getDefaultToolkit().
51 isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
52 return;
53 }
54
55 var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
56 GraphicsDevice[] gds = ge.getScreenDevices();
57 Robot robot = new Robot();
58 for (GraphicsDevice gd1 : gds) {
59 Rectangle framAt = gd1.getDefaultConfiguration().getBounds();
60 framAt.grow(-framAt.width / 2 + 100, -framAt.height / 2 + 100);
61 for (GraphicsDevice gd2 : gds) {
62 Frame frame = new Frame(gd1.getDefaultConfiguration());
63 try {
64 frame.setLayout(null); // trigger use the minimum size of
65 // the peer
66 frame.setBounds(framAt);
67
68 frame.setVisible(true);
69 robot.waitForIdle();
70 robot.delay(1000);
71
72 Dimension minimumSize = frame.getMinimumSize();
73 minimumSize.width = Math.max(minimumSize.width, 120);
74 minimumSize.height = Math.max(minimumSize.height, 120);
75 Rectangle maxTo = gd2.getDefaultConfiguration().getBounds();
76 maxTo.grow(-maxTo.width / 2 + minimumSize.width,
77 -maxTo.height / 2 + minimumSize.height);
78
79 frame.setMaximizedBounds(maxTo);
80 frame.setExtendedState(Frame.MAXIMIZED_BOTH);
81 robot.waitForIdle();
82 robot.delay(1000);
83
84 Rectangle actual = frame.getBounds();
85 if (!actual.equals(maxTo)) {
86 System.err.println("Actual: " + actual);
87 System.err.println("Expected: " + maxTo);
88 throw new RuntimeException("Wrong bounds");
89 }
90 } finally {
91 frame.dispose();
92 }
93 }
94 }
95 }
96 }
97
|