Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JInternalFrame/6647340/bug6647340.java
41153 views
1
/*
2
* Copyright (c) 2008, 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
/* @test
25
* @key headful
26
* @bug 6647340
27
* @summary Checks that iconified internal frame follows
28
* the main frame borders properly.
29
* @run main bug6647340
30
*/
31
32
import javax.swing.*;
33
import java.awt.*;
34
import java.beans.PropertyVetoException;
35
36
public class bug6647340 {
37
private JFrame frame;
38
private volatile Point location;
39
private volatile Point iconloc;
40
private JInternalFrame jif;
41
private static Robot robot;
42
43
public static void main(String[] args) throws Exception {
44
robot = new Robot();
45
final bug6647340 test = new bug6647340();
46
try {
47
SwingUtilities.invokeAndWait(() -> test.setupUI());
48
robot.waitForIdle();
49
robot.delay(1000);
50
test.test();
51
} finally {
52
if (test.frame != null) {
53
SwingUtilities.invokeAndWait(() -> test.frame.dispose());
54
}
55
}
56
}
57
58
private void setupUI() {
59
frame = new JFrame();
60
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61
62
JDesktopPane desktop = new JDesktopPane();
63
frame.add(desktop);
64
65
jif = new JInternalFrame("Internal Frame", true, true, true, true);
66
jif.setBounds(20, 20, 200, 100);
67
desktop.add(jif);
68
jif.setVisible(true);
69
70
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
71
frame.setBounds((screen.width - 400) / 2, (screen.height - 400) / 2, 400, 400);
72
frame.setLocationRelativeTo(null);
73
frame.setVisible(true);
74
}
75
76
private void test() throws Exception {
77
test1();
78
79
robot.waitForIdle();
80
robot.delay(500);
81
check1();
82
robot.waitForIdle();
83
84
test2();
85
robot.waitForIdle();
86
robot.delay(500);
87
check2();
88
}
89
90
private void test1() throws Exception {
91
SwingUtilities.invokeAndWait(() -> {
92
setIcon(true);
93
location = jif.getDesktopIcon().getLocation();
94
Dimension size = frame.getSize();
95
frame.setSize(size.width + 100, size.height + 100);
96
});
97
}
98
99
private void test2() throws Exception {
100
SwingUtilities.invokeAndWait(() -> {
101
setIcon(false);
102
});
103
robot.waitForIdle();
104
robot.delay(500);
105
106
SwingUtilities.invokeAndWait(() -> {
107
Dimension size = frame.getSize();
108
frame.setSize(size.width - 100, size.height - 100);
109
});
110
robot.waitForIdle();
111
robot.delay(500);
112
113
SwingUtilities.invokeAndWait(() -> {
114
setIcon(true);
115
});
116
}
117
118
private void check1() throws Exception {
119
SwingUtilities.invokeAndWait(() -> {
120
iconloc = jif.getDesktopIcon().getLocation();
121
});
122
if (!iconloc.equals(location)) {
123
System.out.println("First test passed");
124
} else {
125
throw new RuntimeException("Icon isn't shifted with the frame bounds");
126
}
127
}
128
129
private void check2() throws Exception {
130
SwingUtilities.invokeAndWait(() -> {
131
iconloc = jif.getDesktopIcon().getLocation();
132
});
133
if (iconloc.equals(location)) {
134
System.out.println("Second test passed");
135
} else {
136
throw new RuntimeException("Icon isn't located near the frame bottom");
137
}
138
}
139
140
private void setIcon(boolean b) {
141
try {
142
jif.setIcon(b);
143
} catch (PropertyVetoException e) {
144
e.printStackTrace();
145
}
146
}
147
}
148
149