Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java
47626 views
1
/*
2
* Copyright (c) 2014, 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
import com.sun.awt.AWTUtilities;
26
import java.awt.Frame;
27
import java.awt.Panel;
28
import java.awt.Point;
29
import java.awt.Rectangle;
30
import java.awt.Robot;
31
import java.awt.event.InputEvent;
32
import java.awt.event.MouseAdapter;
33
import java.awt.event.MouseEvent;
34
import javax.swing.JButton;
35
import javax.swing.SwingUtilities;
36
import test.java.awt.regtesthelpers.Util;
37
38
/**
39
* AWT/Swing overlapping test for opaque Swing components.
40
* <p>This test verify if AWT components are drawn correctly under opaque components.
41
* <p>See <a href="https://bugs.openjdk.java.net/browse/JDK-6776743">JDK-6776743</a> for details
42
* <p>See base class for test info.
43
*/
44
/*
45
@test
46
@bug 6776743
47
@summary Opaque overlapping test for each AWT component
48
@library ../../regtesthelpers
49
@build Util
50
@run main OpaqueOverlapping
51
*/
52
public class OpaqueOverlapping extends OverlappingTestBase {
53
54
{
55
useClickValidation = false;
56
failMessage = "Opacity test mismatchs";
57
58
// CR 6994264 (Choice autohides dropdown on Solaris 10)
59
skipClassNames = new String[] { "Choice" };
60
}
61
private String testSeq;
62
private final static String checkSeq = "010000101";
63
private Point heavyLoc;
64
private JButton light;
65
private Frame frame = null;
66
67
protected void prepareControls() {
68
testSeq = "";
69
// Create components
70
if(frame != null) {
71
frame.setVisible(false);
72
}
73
frame = new Frame("OpaqueOverlapping mixing test");
74
final Panel panel = new Panel();
75
panel.setLayout(null);
76
77
propagateAWTControls(panel);
78
79
// Overlap the buttons
80
currentAwtControl.setBounds(30, 30, 200, 200);
81
82
light = new JButton(" LW Button ");
83
light.setBounds(10, 10, 50, 50);
84
85
// Put the components into the frame
86
panel.add(light);
87
frame.add(panel);
88
frame.setBounds(50, 50, 400, 400);
89
frame.setVisible(true);
90
91
currentAwtControl.addMouseListener(new MouseAdapter() {
92
@Override
93
public void mouseClicked(MouseEvent e) {
94
panel.setComponentZOrder(light, 0);
95
frame.validate();
96
testSeq = testSeq + "0";
97
}
98
});
99
light.addActionListener(new java.awt.event.ActionListener() {
100
public void actionPerformed(java.awt.event.ActionEvent e) {
101
panel.setComponentZOrder(currentAwtControl, 0);
102
frame.validate();
103
testSeq = testSeq + "1";
104
}
105
});
106
}
107
108
@Override
109
protected boolean performTest() {
110
try {
111
SwingUtilities.invokeAndWait(new Runnable() {
112
public void run() {
113
heavyLoc = currentAwtControl.getLocationOnScreen();
114
}
115
});
116
} catch (Exception e) {
117
}
118
Robot robot = Util.createRobot();
119
robot.setAutoDelay(ROBOT_DELAY);
120
121
Util.waitForIdle(robot);
122
123
// Move the mouse pointer to the position where both
124
// components overlap
125
robot.mouseMove(heavyLoc.x + 5, heavyLoc.y + 5);
126
127
// Now perform the click at this point for 9 times
128
// In the middle of the process toggle the opaque
129
// flag value.
130
for (int i = 0; i < 9; ++i) {
131
if (i == 3) {
132
AWTUtilities.setComponentMixingCutoutShape(light,
133
new Rectangle());
134
}
135
if (i == 6) {
136
AWTUtilities.setComponentMixingCutoutShape(light,
137
null);
138
}
139
140
robot.mousePress(InputEvent.BUTTON1_MASK);
141
robot.mouseRelease(InputEvent.BUTTON1_MASK);
142
Util.waitForIdle(robot);
143
144
if (currentAwtControl.getClass() == java.awt.Choice.class && i != 1 && i != 6 && i != 8) {
145
// due to the fact that Choice doesn't get mouseClicked event if its dropdown is shown
146
robot.mousePress(InputEvent.BUTTON1_MASK);
147
robot.mouseRelease(InputEvent.BUTTON1_MASK);
148
Util.waitForIdle(robot);
149
}
150
}
151
152
Util.waitForIdle(robot);
153
154
boolean result = testSeq.equals(checkSeq);
155
if (!result) {
156
System.err.println("Expected: " + checkSeq);
157
System.err.println("Observed: " + testSeq);
158
}
159
return result;
160
}
161
162
// this strange plumbing stuff is required due to "Standard Test Machinery" in base class
163
public static void main(String args[]) throws InterruptedException {
164
instance = new OpaqueOverlapping();
165
OverlappingTestBase.doMain(args);
166
}
167
}
168
169