Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Frame/SetMaximizedBounds/SetMaximizedBounds.java
41153 views
1
/*
2
* Copyright (c) 2007, 2020, 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
import java.awt.Frame;
25
import java.awt.GraphicsConfiguration;
26
import java.awt.GraphicsDevice;
27
import java.awt.GraphicsEnvironment;
28
import java.awt.Insets;
29
import java.awt.Rectangle;
30
import java.awt.Robot;
31
import java.awt.Toolkit;
32
33
/**
34
* @test
35
* @key headful
36
* @bug 8065739 8131339 8231564
37
* @requires (os.family == "windows" | os.family == "mac")
38
* @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH)
39
* is called for a Frame after been called setMaximizedBounds() with
40
* certain value, Frame bounds must equal to this value.
41
*/
42
public class SetMaximizedBounds {
43
44
public static void main(String[] args) throws Exception {
45
//Supported platforms are Windows and OS X.
46
String os = System.getProperty("os.name").toLowerCase();
47
if (!os.contains("windows") && !os.contains("os x")) {
48
return;
49
}
50
51
if (!Toolkit.getDefaultToolkit().
52
isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
53
return;
54
}
55
56
GraphicsEnvironment ge = GraphicsEnvironment.
57
getLocalGraphicsEnvironment();
58
59
for (GraphicsDevice gd : ge.getScreenDevices()) {
60
for (GraphicsConfiguration gc : gd.getConfigurations()) {
61
testMaximizedBounds(gc, false);
62
testMaximizedBounds(gc, true);
63
}
64
}
65
}
66
67
static void testMaximizedBounds(GraphicsConfiguration gc, boolean undecorated)
68
throws Exception {
69
70
Frame frame = null;
71
try {
72
73
Rectangle maxArea = getMaximizedScreenArea(gc);
74
75
Robot robot = new Robot();
76
robot.setAutoDelay(50);
77
78
frame = new Frame();
79
frame.setUndecorated(undecorated);
80
Rectangle maximizedBounds = new Rectangle(
81
maxArea.x + maxArea.width / 5,
82
maxArea.y + maxArea.height / 5,
83
maxArea.width / 2,
84
maxArea.height / 2);
85
frame.setMaximizedBounds(maximizedBounds);
86
frame.setSize(maxArea.width / 8, maxArea.height / 8);
87
frame.setVisible(true);
88
robot.waitForIdle();
89
90
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
91
robot.waitForIdle();
92
robot.delay(1000);
93
94
Rectangle bounds = frame.getBounds();
95
if (!bounds.equals(maximizedBounds)) {
96
System.err.println("Expected: " + maximizedBounds);
97
System.err.println("Actual: " + bounds);
98
throw new RuntimeException("The bounds of the Frame do not equal to what"
99
+ " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
100
}
101
102
frame.setExtendedState(Frame.NORMAL);
103
robot.waitForIdle();
104
robot.delay(1000);
105
106
maximizedBounds = new Rectangle(
107
maxArea.x + maxArea.width / 6,
108
maxArea.y + maxArea.height / 6,
109
maxArea.width / 3,
110
maxArea.height / 3);
111
frame.setMaximizedBounds(maximizedBounds);
112
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
113
robot.waitForIdle();
114
robot.delay(1000);
115
116
bounds = frame.getBounds();
117
if (!bounds.equals(maximizedBounds)) {
118
System.err.println("Expected: " + maximizedBounds);
119
System.err.println("Actual: " + bounds);
120
throw new RuntimeException("The bounds of the Frame do not equal to what"
121
+ " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
122
}
123
} finally {
124
if (frame != null) {
125
frame.dispose();
126
}
127
}
128
}
129
130
static Rectangle getMaximizedScreenArea(GraphicsConfiguration gc) {
131
Rectangle bounds = gc.getBounds();
132
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
133
return new Rectangle(
134
bounds.x + insets.left,
135
bounds.y + insets.top,
136
bounds.width - insets.left - insets.right,
137
bounds.height - insets.top - insets.bottom);
138
}
139
}
140
141