Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Frame/RestoreToOppositeScreen/RestoreToOppositeScreen.java
41153 views
1
/*
2
* Copyright (c) 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.GraphicsDevice;
26
import java.awt.GraphicsEnvironment;
27
import java.awt.Rectangle;
28
import java.awt.Toolkit;
29
30
/**
31
* @test
32
* @bug 8256373
33
* @key headful
34
* @summary setBounds() should work if the frame is minimized
35
*/
36
public final class RestoreToOppositeScreen {
37
38
public static void main(String[] args) throws Exception {
39
Toolkit toolkit = Toolkit.getDefaultToolkit();
40
if (!toolkit.isFrameStateSupported(Frame.ICONIFIED)) {
41
return;
42
}
43
44
var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
45
GraphicsDevice[] gds = ge.getScreenDevices();
46
for (GraphicsDevice gd1 : gds) {
47
Rectangle screen1 = gd1.getDefaultConfiguration().getBounds();
48
int x1 = (int) screen1.getCenterX();
49
int y1 = (int) screen1.getCenterY();
50
for (GraphicsDevice gd2 : gds) {
51
Rectangle screen2 = gd2.getDefaultConfiguration().getBounds();
52
// tweak the (x2, y2) point so even if the screen1 and screen2
53
// are the same, we will use different bounds, otherwise
54
// setBounds() will be ignored
55
int x2 = (int) screen2.getCenterX() - 50;
56
int y2 = (int) screen2.getCenterY() - 50;
57
Frame frame = new Frame();
58
try {
59
// show the frame on one monitor, and then move it to
60
// another while the frame minimized
61
frame.setBounds(x1, y1, 400, 400);
62
frame.setVisible(true);
63
Thread.sleep(2000);
64
frame.setExtendedState(Frame.ICONIFIED);
65
Thread.sleep(2000);
66
Rectangle before = new Rectangle(x2, y2, 380, 380);
67
frame.setBounds(before);
68
Thread.sleep(2000);
69
frame.setExtendedState(Frame.NORMAL);
70
Thread.sleep(2000);
71
Rectangle after = frame.getBounds();
72
checkSize(after.x, before.x, "x");
73
checkSize(after.y, before.y, "y");
74
checkSize(after.width, before.width, "width");
75
checkSize(after.height, before.height, "height");
76
} finally {
77
frame.dispose();
78
}
79
}
80
}
81
}
82
83
private static void checkSize(int actual, int expected, String prop) {
84
if (Math.abs(actual - expected) > 10) { // let's allow size variation,
85
// the bug is reproduced anyway
86
System.err.println("Expected: " + expected);
87
System.err.println("Actual: " + actual);
88
throw new RuntimeException(prop + " is wrong");
89
}
90
}
91
}
92
93