author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 21596 | 0e3a39f29dbc |
child 28071 | 3acb75b8df45 |
permissions | -rw-r--r-- |
21596 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21596
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, 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 |
||
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
24 |
/* @test |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
25 |
@bug 6683775 6794764 |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
26 |
@summary Painting artifacts is seen when panel is made setOpaque(false) for a translucent window |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
27 |
@author Alexander Potochkin |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
28 |
@run main bug6683775 |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
29 |
*/ |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
30 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
31 |
import com.sun.awt.AWTUtilities; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
32 |
import sun.awt.SunToolkit; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
33 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
34 |
import javax.swing.*; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
35 |
import java.awt.*; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
36 |
import java.awt.image.BufferedImage; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
37 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
38 |
public class bug6683775 { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
39 |
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
|
40 |
GraphicsConfiguration gc = getGC(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
41 |
if (!AWTUtilities.isTranslucencySupported( |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
42 |
AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT) |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
43 |
|| gc == null) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
44 |
return; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
45 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
46 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
47 |
Robot robot = new Robot(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
48 |
final JFrame testFrame = new JFrame(gc); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
49 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
50 |
SwingUtilities.invokeLater(new Runnable() { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
51 |
public void run() { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
52 |
JFrame backgroundFrame = new JFrame("Background frame"); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
53 |
backgroundFrame.setUndecorated(true); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
54 |
JPanel panel = new JPanel(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
55 |
panel.setBackground(Color.RED); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
56 |
backgroundFrame.add(panel); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
57 |
backgroundFrame.setSize(200, 200); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
58 |
backgroundFrame.setVisible(true); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
59 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
60 |
testFrame.setUndecorated(true); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
61 |
JPanel p = new JPanel(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
62 |
p.setOpaque(false); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
63 |
testFrame.add(p); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
64 |
AWTUtilities.setWindowOpaque(testFrame, false); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
65 |
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
66 |
testFrame.setSize(400, 400); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
67 |
testFrame.setLocation(0, 0); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
68 |
testFrame.setVisible(true); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
69 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
70 |
}); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
71 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
72 |
toolkit.realSync(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
73 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
74 |
//robot.getPixelColor() didn't work right for some reason |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
75 |
BufferedImage capture = robot.createScreenCapture(new Rectangle(100, 100)); |
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 |
int redRGB = Color.RED.getRGB(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
78 |
if (redRGB != capture.getRGB(10, 10)) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
79 |
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
|
80 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
81 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
82 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
83 |
private static GraphicsConfiguration getGC() { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
84 |
GraphicsConfiguration transparencyCapableGC = |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
85 |
GraphicsEnvironment.getLocalGraphicsEnvironment() |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
86 |
.getDefaultScreenDevice().getDefaultConfiguration(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
87 |
if (!AWTUtilities.isTranslucencyCapable(transparencyCapableGC)) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
88 |
transparencyCapableGC = null; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
89 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
90 |
GraphicsEnvironment env = |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
91 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
92 |
GraphicsDevice[] devices = env.getScreenDevices(); |
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 |
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
|
95 |
GraphicsConfiguration[] configs = devices[i].getConfigurations(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
96 |
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
|
97 |
if (AWTUtilities.isTranslucencyCapable(configs[j])) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
98 |
transparencyCapableGC = configs[j]; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
99 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
100 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
101 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
102 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff
changeset
|
103 |
return transparencyCapableGC; |
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 |
} |