Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JDialog/Transparency/TransparencyTest.java
41152 views
1
/*
2
* Copyright (c) 2016, 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 8062946 8159906
28
@summary Verify Transparency upon iconify/deiconify sequence
29
@run main TransparencyTest
30
*/
31
import java.awt.GraphicsEnvironment;
32
import java.awt.GraphicsDevice;
33
import java.awt.Color;
34
import java.awt.Point;
35
import java.awt.Robot;
36
import javax.swing.JDialog;
37
import javax.swing.JFrame;
38
import javax.swing.SwingUtilities;
39
40
public class TransparencyTest {
41
42
private static JFrame frame;
43
private static JDialog dialog;
44
private static JDialog backgroundDialog;
45
private static final int WIDTH = 250;
46
private static final int HEIGHT = 250;
47
private static final float OPACITY = 0.60f;
48
private static volatile Point dlgPos;
49
50
public static void createAndShowGUI() {
51
frame = new JFrame("JFrame");
52
frame.setSize(WIDTH, HEIGHT);
53
frame.setLocation(100, 300);
54
55
dialog = new JDialog(frame, false);
56
dialog.setSize(250, 250);
57
dialog.setUndecorated(true);
58
dialog.setLocation(400, 300);
59
dlgPos = dialog.getLocation();
60
backgroundDialog = new JDialog(frame, false);
61
backgroundDialog.setSize(250, 250);
62
backgroundDialog.setUndecorated(true);
63
backgroundDialog.getContentPane().setBackground(Color.red);
64
backgroundDialog.setLocation(dlgPos.x, dlgPos.y);
65
66
frame.setVisible(true);
67
backgroundDialog.setVisible(true);
68
dialog.setVisible(true);
69
}
70
71
public static void main(String[] args) throws Exception {
72
73
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
74
GraphicsDevice gd = ge.getDefaultScreenDevice();
75
GraphicsDevice.WindowTranslucency mode = GraphicsDevice.WindowTranslucency.TRANSLUCENT;
76
boolean translucencyCheck = gd.isWindowTranslucencySupported(mode);
77
if(!translucencyCheck) {
78
return;
79
}
80
81
Robot robot = new Robot();
82
// create a GUI
83
SwingUtilities.invokeAndWait(new Runnable() {
84
85
@Override
86
public void run() {
87
createAndShowGUI();
88
}
89
});
90
robot.waitForIdle();
91
robot.delay(200);
92
93
int x = dlgPos.x + 100;
94
int y = dlgPos.y + 100;
95
Color opaque = robot.getPixelColor(x, y);
96
97
// set Dialog Opacity
98
SwingUtilities.invokeAndWait(new Runnable() {
99
100
@Override
101
public void run() {
102
dialog.setOpacity(OPACITY);
103
}
104
});
105
robot.waitForIdle();
106
robot.delay(200);
107
108
// iconify frame
109
SwingUtilities.invokeAndWait(new Runnable() {
110
111
@Override
112
public void run() {
113
frame.setExtendedState(JFrame.ICONIFIED);
114
}
115
});
116
robot.waitForIdle();
117
robot.delay(500);
118
119
// deiconify frame
120
SwingUtilities.invokeAndWait(new Runnable() {
121
122
@Override
123
public void run() {
124
frame.setExtendedState(JFrame.NORMAL);
125
}
126
});
127
robot.waitForIdle();
128
robot.delay(500);
129
130
Color transparent = robot.getPixelColor(x, y);
131
if (transparent.equals(opaque)) {
132
frame.dispose();
133
throw new RuntimeException("JDialog transparency lost "
134
+ "upon iconify/deiconify sequence");
135
}
136
frame.dispose();
137
}
138
}
139
140