author | goetz |
Tue, 14 Jun 2016 10:44:59 +0200 | |
changeset 39056 | d99e63b6d962 |
parent 32282 | 9c9ff2c42e0d |
permissions | -rw-r--r-- |
21596 | 1 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
2 |
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. |
21596 | 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 |
||
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
24 |
/* |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
25 |
* @test |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
26 |
* @key headful |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
27 |
* @bug 6683775 6794764 |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
28 |
* @summary Painting artifacts is seen when panel is made setOpaque(false) for a translucent window |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
29 |
* @author Alexander Potochkin |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
30 |
* @modules java.desktop/com.sun.awt |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
31 |
* java.desktop/sun.awt |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
32 |
* @run main bug6683775 |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
32282
diff
changeset
|
33 |
*/ |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
34 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
35 |
import com.sun.awt.AWTUtilities; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
36 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
37 |
import javax.swing.*; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
38 |
import java.awt.*; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
39 |
import java.awt.image.BufferedImage; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
40 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
41 |
public class bug6683775 { |
32282 | 42 |
static final int LOC = 100, |
43 |
SIZE = 200; |
|
44 |
||
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
46 |
GraphicsConfiguration gc = getGC(); |
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
23010
diff
changeset
|
47 |
if (!AWTUtilities.isTranslucencySupported( |
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
23010
diff
changeset
|
48 |
AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT) |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
49 |
|| gc == null) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
50 |
return; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
51 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
52 |
Robot robot = new Robot(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
53 |
final JFrame testFrame = new JFrame(gc); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
54 |
|
32282 | 55 |
SwingUtilities.invokeAndWait(() -> { |
56 |
JFrame backgroundFrame = new JFrame("Background frame"); |
|
57 |
backgroundFrame.setUndecorated(true); |
|
58 |
JPanel panel = new JPanel(); |
|
59 |
panel.setBackground(Color.RED); |
|
60 |
backgroundFrame.add(panel); |
|
61 |
backgroundFrame.setBounds(LOC, LOC, SIZE, SIZE); |
|
62 |
backgroundFrame.setVisible(true); |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
63 |
|
32282 | 64 |
testFrame.setUndecorated(true); |
65 |
JPanel p = new JPanel(); |
|
66 |
p.setOpaque(false); |
|
67 |
testFrame.add(p); |
|
68 |
AWTUtilities.setWindowOpaque(testFrame, false); |
|
69 |
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
70 |
testFrame.setBounds(LOC, LOC, SIZE, SIZE); |
|
71 |
testFrame.setVisible(true); |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
72 |
}); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
73 |
|
32282 | 74 |
robot.waitForIdle(); |
75 |
Thread.sleep(1500); |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
76 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
77 |
//robot.getPixelColor() didn't work right for some reason |
32282 | 78 |
BufferedImage capture = |
79 |
robot.createScreenCapture(new Rectangle(LOC, LOC, SIZE, SIZE)); |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
80 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
81 |
int redRGB = Color.RED.getRGB(); |
32282 | 82 |
if (redRGB != capture.getRGB(SIZE/2, SIZE/2)) { |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
83 |
throw new RuntimeException("Transparent frame is not transparent!"); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
84 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
85 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
86 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
87 |
private static GraphicsConfiguration getGC() { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
88 |
GraphicsConfiguration transparencyCapableGC = |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
89 |
GraphicsEnvironment.getLocalGraphicsEnvironment() |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
90 |
.getDefaultScreenDevice().getDefaultConfiguration(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
91 |
if (!AWTUtilities.isTranslucencyCapable(transparencyCapableGC)) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
92 |
transparencyCapableGC = null; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
93 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
94 |
GraphicsEnvironment env = |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
95 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
96 |
GraphicsDevice[] devices = env.getScreenDevices(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
97 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
98 |
for (int i = 0; i < devices.length && transparencyCapableGC == null; i++) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
99 |
GraphicsConfiguration[] configs = devices[i].getConfigurations(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
100 |
for (int j = 0; j < configs.length && transparencyCapableGC == null; j++) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
101 |
if (AWTUtilities.isTranslucencyCapable(configs[j])) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
102 |
transparencyCapableGC = configs[j]; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
103 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
104 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
105 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
106 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
107 |
return transparencyCapableGC; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
108 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
109 |
} |