Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComponent/7154030/bug7154030.java
41153 views
1
/*
2
* Copyright (c) 2012, 2021, 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
* Portions Copyright (c) 2012 IBM Corporation
26
*/
27
28
import javax.swing.JButton;
29
import javax.swing.JDesktopPane;
30
import javax.swing.JFrame;
31
import javax.swing.SwingUtilities;
32
33
import java.awt.Color;
34
import java.awt.Dimension;
35
import java.awt.Graphics;
36
import java.awt.Insets;
37
import java.awt.Rectangle;
38
import java.awt.Toolkit;
39
import java.awt.image.BufferedImage;
40
import javax.imageio.ImageIO;
41
import java.io.File;
42
43
/*
44
* @test
45
* @key headful
46
* @bug 7154030
47
* @summary Swing components fail to hide after calling hide()
48
* @author Jonathan Lu
49
* @library ../../regtesthelpers/
50
* @library /lib/client/
51
* @build Util
52
* @build ExtendedRobot
53
* @run main bug7154030
54
*/
55
56
public class bug7154030 {
57
58
private static JButton button = null;
59
private static JFrame frame;
60
private static int locx, locy, frw, frh;
61
62
public static void main(String[] args) throws Exception {
63
try {
64
BufferedImage imageInit = null;
65
66
BufferedImage imageShow = null;
67
68
BufferedImage imageHide = null;
69
70
ExtendedRobot robot = new ExtendedRobot();
71
72
SwingUtilities.invokeAndWait(new Runnable() {
73
74
@Override
75
public void run() {
76
JDesktopPane desktop = new JDesktopPane();
77
button = new JButton("button");
78
frame = new JFrame();
79
80
button.setSize(200, 200);
81
button.setLocation(100, 100);
82
button.setForeground(Color.RED);
83
button.setBackground(Color.RED);
84
button.setOpaque(true);
85
button.setVisible(false);
86
desktop.add(button);
87
desktop.setMinimumSize(new Dimension(300, 300));
88
desktop.setMaximumSize(new Dimension(300, 300));
89
90
frame.setContentPane(desktop);
91
frame.setMinimumSize(new Dimension(350, 350));
92
frame.setMaximumSize(new Dimension(350, 350));
93
frame.pack();
94
frame.setLocationRelativeTo(null);
95
frame.setVisible(true);
96
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
97
}
98
});
99
100
robot.waitForIdle(1000);
101
robot.delay(1000);
102
103
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
104
Rectangle screen = new Rectangle(0, 0, (int) screenSize.getWidth(), (int) screenSize.getHeight());
105
Rectangle bounds = frame.getBounds();
106
Insets insets = frame.getInsets();
107
locx = bounds.x + insets.left;
108
locy = bounds.y + insets.top;
109
frw = bounds.width - insets.left - insets.right;
110
frh = bounds.height - insets.top - insets.bottom;
111
112
BufferedImage fullScreen = robot.createScreenCapture(screen);
113
Graphics g = fullScreen.getGraphics();
114
g.setColor(Color.RED);
115
g.drawRect(locx - 1, locy - 1, frw + 1, frh + 1);
116
imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
117
118
SwingUtilities.invokeAndWait(new Runnable() {
119
120
@Override
121
public void run() {
122
button.show();
123
}
124
});
125
126
robot.waitForIdle(500);
127
imageShow = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
128
if (Util.compareBufferedImages(imageInit, imageShow)) {
129
ImageIO.write(imageInit, "png", new File("imageInit.png"));
130
ImageIO.write(imageShow, "png", new File("imageShow.png"));
131
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
132
throw new Exception("Failed to show opaque button");
133
}
134
135
robot.waitForIdle();
136
137
SwingUtilities.invokeAndWait(new Runnable() {
138
@Override
139
public void run() {
140
button.hide();
141
}
142
});
143
144
robot.waitForIdle(500);
145
imageHide = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
146
147
if (!Util.compareBufferedImages(imageInit, imageHide)) {
148
ImageIO.write(imageInit, "png", new File("imageInit.png"));
149
ImageIO.write(imageHide, "png", new File("imageHide.png"));
150
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
151
throw new Exception("Failed to hide opaque button");
152
}
153
154
SwingUtilities.invokeAndWait(new Runnable() {
155
156
@Override
157
public void run() {
158
button.setOpaque(false);
159
button.setBackground(new Color(128, 128, 0));
160
button.setVisible(false);
161
}
162
});
163
164
robot.waitForIdle(500);
165
imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
166
167
SwingUtilities.invokeAndWait(new Runnable() {
168
169
@Override
170
public void run() {
171
button.show();
172
}
173
});
174
175
robot.waitForIdle(500);
176
imageShow = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
177
178
if (Util.compareBufferedImages(imageInit, imageShow)) {
179
ImageIO.write(imageInit, "png", new File("imageInit.png"));
180
ImageIO.write(imageShow, "png", new File("imageShow.png"));
181
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
182
throw new Exception("Failed to show non-opaque button");
183
}
184
185
SwingUtilities.invokeAndWait(new Runnable() {
186
187
@Override
188
public void run() {
189
button.hide();
190
}
191
});
192
193
robot.waitForIdle(500);
194
imageHide = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
195
196
if (!Util.compareBufferedImages(imageInit, imageHide)) {
197
ImageIO.write(imageInit, "png", new File("imageInit.png"));
198
ImageIO.write(imageHide, "png", new File("imageHide.png"));
199
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
200
throw new Exception("Failed to hide non-opaque button");
201
}
202
} finally {
203
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
204
}
205
}
206
}
207
208