author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 39056 | d99e63b6d962 |
permissions | -rw-r--r-- |
26601
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
1 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
26601
diff
changeset
|
2 |
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
26601
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
4 |
* |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
8 |
* |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
13 |
* accompanied this code). |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
14 |
* |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
18 |
* |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
21 |
* questions. |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
22 |
*/ |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
23 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
24 |
import javax.swing.*; |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
25 |
import java.awt.*; |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
26 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
27 |
/* |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
28 |
* @test |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
26601
diff
changeset
|
29 |
* @key headful |
26601
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
30 |
* @summary Check if a per-pixel translucent window shows only the area having |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
31 |
* opaque pixels |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
32 |
* Test Description: Check if PERPIXEL_TRANSLUCENT Translucency type is supported |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
33 |
* on the current platform. Proceed if it is supported. Create a swing window |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
34 |
* with some swing components in it and a transparent background (alpha 0.0). |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
35 |
* Bring this window on top of a known background. Do this test for JFrame, |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
36 |
* JWindow and JDialog |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
37 |
* Expected Result: Only the components present in the window must be shown. Other |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
38 |
* areas of the window must be transparent so that the background shows |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
39 |
* @author mrkam |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
40 |
* @library ../../../../lib/testlibrary |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
41 |
* @build Common ExtendedRobot |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
42 |
* @run main PerPixelTranslucentSwing |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
43 |
*/ |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
44 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
45 |
public class PerPixelTranslucentSwing extends Common { |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
46 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
47 |
JButton north; |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
48 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
49 |
public static void main(String[] ignored) throws Exception { |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
50 |
FG_COLOR = new Color(200, 0, 0, 0); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
51 |
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT)) |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
52 |
for (Class<Window> windowClass: WINDOWS_TO_TEST) |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
53 |
new PerPixelTranslucentSwing(windowClass).doTest(); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
54 |
} |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
55 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
56 |
public PerPixelTranslucentSwing(Class windowClass) throws Exception { |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
57 |
super(windowClass); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
58 |
} |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
59 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
60 |
@Override |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
61 |
public void createSwingComponents() { |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
62 |
Container contentPane = RootPaneContainer.class.cast(window).getContentPane(); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
63 |
BorderLayout bl = new BorderLayout(10, 5); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
64 |
contentPane.setLayout(bl); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
65 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
66 |
north = new JButton("North"); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
67 |
contentPane.add(north, BorderLayout.NORTH); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
68 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
69 |
JList center = new JList(new String[] {"Center"}); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
70 |
contentPane.add(center, BorderLayout.CENTER); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
71 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
72 |
JTextField south = new JTextField("South"); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
73 |
contentPane.add(south, BorderLayout.SOUTH); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
74 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
75 |
window.pack(); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
76 |
window.setVisible(true); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
77 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
78 |
north.requestFocus(); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
79 |
} |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
80 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
81 |
@Override |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
82 |
public void doTest() throws Exception { |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
83 |
robot.waitForIdle(delay); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
84 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
85 |
// Check for background translucency |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
86 |
Rectangle bounds = north.getBounds(); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
87 |
Point loc = north.getLocationOnScreen(); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
88 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
89 |
Color color = robot.getPixelColor(loc.x + bounds.width / 2, loc.y + bounds.height + 3); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
90 |
System.out.println(color); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
91 |
if (FG_COLOR.getRGB() == color.getRGB()) |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
92 |
throw new RuntimeException("Background is not translucent (" + color + ")"); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
93 |
|
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
94 |
EventQueue.invokeAndWait(this::dispose); |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
95 |
} |
2713482c0fd3
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff
changeset
|
96 |
} |