Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/swing/JComponent/7154030/bug7154030.java
66646 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 volatile 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
frame.setUndecorated(true);
80
81
button.setSize(200, 200);
82
button.setLocation(100, 100);
83
button.setForeground(Color.RED);
84
button.setBackground(Color.RED);
85
button.setOpaque(true);
86
button.setVisible(false);
87
desktop.add(button);
88
desktop.setMinimumSize(new Dimension(300, 300));
89
desktop.setMaximumSize(new Dimension(300, 300));
90
91
frame.setContentPane(desktop);
92
frame.setMinimumSize(new Dimension(350, 350));
93
frame.setMaximumSize(new Dimension(350, 350));
94
frame.pack();
95
frame.setLocationRelativeTo(null);
96
frame.setVisible(true);
97
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
98
}
99
});
100
101
robot.waitForIdle(1000);
102
robot.delay(1000);
103
104
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
105
Rectangle screen = new Rectangle(0, 0, (int) screenSize.getWidth(), (int) screenSize.getHeight());
106
SwingUtilities.invokeAndWait(() -> {
107
Rectangle bounds = frame.getBounds();
108
Insets insets = frame.getInsets();
109
locx = bounds.x + insets.left;
110
locy = bounds.y + insets.top;
111
frw = bounds.width - insets.left - insets.right;
112
frh = bounds.height - insets.top - insets.bottom;
113
});
114
115
BufferedImage fullScreen = robot.createScreenCapture(screen);
116
Graphics g = fullScreen.getGraphics();
117
g.setColor(Color.RED);
118
g.drawRect(locx - 1, locy - 1, frw + 1, frh + 1);
119
imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
120
121
SwingUtilities.invokeAndWait(new Runnable() {
122
123
@Override
124
public void run() {
125
button.show();
126
}
127
});
128
129
robot.waitForIdle(500);
130
imageShow = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
131
if (Util.compareBufferedImages(imageInit, imageShow)) {
132
ImageIO.write(imageInit, "png", new File("imageInit.png"));
133
ImageIO.write(imageShow, "png", new File("imageShow.png"));
134
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
135
throw new Exception("Failed to show opaque button");
136
}
137
138
robot.waitForIdle();
139
140
SwingUtilities.invokeAndWait(new Runnable() {
141
@Override
142
public void run() {
143
button.hide();
144
}
145
});
146
147
robot.waitForIdle(500);
148
imageHide = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
149
150
if (!Util.compareBufferedImages(imageInit, imageHide)) {
151
ImageIO.write(imageInit, "png", new File("imageInit.png"));
152
ImageIO.write(imageHide, "png", new File("imageHide.png"));
153
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
154
throw new Exception("Failed to hide opaque button");
155
}
156
157
SwingUtilities.invokeAndWait(new Runnable() {
158
159
@Override
160
public void run() {
161
button.setOpaque(false);
162
button.setBackground(new Color(128, 128, 0));
163
button.setVisible(false);
164
}
165
});
166
167
robot.waitForIdle(500);
168
imageInit = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
169
170
SwingUtilities.invokeAndWait(new Runnable() {
171
172
@Override
173
public void run() {
174
button.show();
175
}
176
});
177
178
robot.waitForIdle(500);
179
imageShow = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
180
181
if (Util.compareBufferedImages(imageInit, imageShow)) {
182
ImageIO.write(imageInit, "png", new File("imageInit.png"));
183
ImageIO.write(imageShow, "png", new File("imageShow.png"));
184
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
185
throw new Exception("Failed to show non-opaque button");
186
}
187
188
SwingUtilities.invokeAndWait(new Runnable() {
189
190
@Override
191
public void run() {
192
button.hide();
193
}
194
});
195
196
robot.waitForIdle(500);
197
imageHide = robot.createScreenCapture(new Rectangle(locx, locy, frw, frh));
198
199
if (!Util.compareBufferedImages(imageInit, imageHide)) {
200
ImageIO.write(imageInit, "png", new File("imageInit.png"));
201
ImageIO.write(imageHide, "png", new File("imageHide.png"));
202
ImageIO.write(fullScreen, "png", new File("fullScreenInit.png"));
203
throw new Exception("Failed to hide non-opaque button");
204
}
205
} finally {
206
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
207
}
208
}
209
}
210
211