Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Frame/UnfocusableMaximizedFrameResizablity/UnfocusableMaximizedFrameResizablity.java
41153 views
1
/*
2
* Copyright (c) 2007, 2019, 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
/*
25
@test
26
@key headful
27
@bug 4980161 7158623 8204860 8208125 8215280
28
@summary Setting focusable window state to false makes the maximized frame resizable
29
@compile UnfocusableMaximizedFrameResizablity.java
30
@run main UnfocusableMaximizedFrameResizablity
31
*/
32
33
import java.awt.Toolkit;
34
import java.awt.Frame;
35
import java.awt.Rectangle;
36
import java.awt.AWTException;
37
import java.awt.event.InputEvent;
38
import java.awt.Robot;
39
40
public class UnfocusableMaximizedFrameResizablity {
41
42
private static Frame frame;
43
private static Robot robot;
44
private static boolean isProgInterruption = false;
45
private static Thread mainThread = null;
46
private static int sleepTime = 300000;
47
48
private static void createAndShowFrame() throws Exception {
49
50
//MAXIMIZED_BOTH frame is resizable on Mac OS by default. Nothing to test.
51
if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {
52
cleanup();
53
return;
54
}
55
56
//The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test.
57
if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
58
cleanup();
59
return;
60
}
61
62
frame = new Frame("Unfocusable frame");
63
frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300));
64
frame.setSize(200, 200);
65
frame.setVisible(true);
66
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
67
frame.setFocusableWindowState(false);
68
69
try {
70
robot = new Robot();
71
} catch (AWTException e) {
72
throw new RuntimeException("Robot creation failed");
73
}
74
robot.delay(2000);
75
76
// The initial bounds of the frame
77
final Rectangle bounds = frame.getBounds();
78
79
// Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip")
80
robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2);
81
robot.waitForIdle();
82
83
// ... and start resizing
84
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
85
robot.waitForIdle();
86
robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15);
87
robot.waitForIdle();
88
89
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
90
robot.waitForIdle();
91
92
// The bounds of the frame after the attempt of resizing is made
93
final Rectangle finalBounds = frame.getBounds();
94
95
if (!finalBounds.equals(bounds)) {
96
cleanup();
97
throw new RuntimeException("The maximized unfocusable frame can be resized.");
98
}
99
cleanup();
100
}
101
102
private static void cleanup() {
103
if (frame != null) {
104
frame.dispose();
105
}
106
isProgInterruption = true;
107
mainThread.interrupt();
108
}
109
110
public static void main(String args[]) throws Exception {
111
112
mainThread = Thread.currentThread();
113
114
try {
115
createAndShowFrame();
116
mainThread.sleep(sleepTime);
117
} catch (InterruptedException e) {
118
if (!isProgInterruption) {
119
throw e;
120
}
121
}
122
123
if (!isProgInterruption) {
124
throw new RuntimeException("Timed out after " + sleepTime / 1000
125
+ " seconds");
126
}
127
}
128
}
129
130
131