test/jdk/javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentCanvas.java
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 52739 7199c4da1a6f
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26601
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
     1
/*
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
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 java.awt.*;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    25
import javax.swing.*;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    26
import java.awt.image.BufferedImage;
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
/*
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    29
 * @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 26601
diff changeset
    30
 * @key headful
26601
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    31
 * @summary Check if a per-pixel translucent window shows up with correct translucency
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    32
 * @author mrkam
52739
7199c4da1a6f 8186549: move ExtendedRobot closer to tests
shurailine
parents: 47968
diff changeset
    33
 * @library /lib/client
26601
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    34
 * @build Common ExtendedRobot
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    35
 * @run main PerPixelTranslucentCanvas
47968
a42e805414e4 8190348: [TESTBUG] Test javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentCanvas.java fails
pbansal
parents: 47216
diff changeset
    36
 * @run main/othervm -Dsun.java2d.uiScale=1.5 PerPixelTranslucentCanvas
26601
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    37
 */
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    38
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    39
public class PerPixelTranslucentCanvas extends Common {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    40
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    41
    JPanel center;
47968
a42e805414e4 8190348: [TESTBUG] Test javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentCanvas.java fails
pbansal
parents: 47216
diff changeset
    42
    static Color OVAL_COLOR = Color.BLUE;
26601
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
    public static void main(String[] ignored) throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    45
        FG_COLOR = new Color(200, 0, 0, 100);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    46
        BG_COLOR = Color.GREEN;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    47
        for (Class<Window> windowClass: WINDOWS_TO_TEST)
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    48
            new PerPixelTranslucentCanvas(windowClass).doTest();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    49
    }
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    50
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    51
    public PerPixelTranslucentCanvas(Class windowClass) throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    52
        super(windowClass);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    53
    }
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
    @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    56
    public void createSwingComponents() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    57
        Container contentPane = RootPaneContainer.class.cast(window).getContentPane();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    58
        BorderLayout bl = new BorderLayout(10, 10);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    59
        contentPane.setLayout(bl);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    60
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    61
        JLabel label = new JLabel("North", new ImageIcon(
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    62
                new BufferedImage(30, 30, BufferedImage.TYPE_INT_RGB)), SwingConstants.CENTER);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    63
        contentPane.add(label, BorderLayout.NORTH);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    64
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    65
        JButton button = new JButton("West");
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    66
        contentPane.add(button, BorderLayout.WEST);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    67
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    68
        center = new JPanel() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    69
            @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    70
            public void paint(Graphics g) {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    71
                g.setColor(OVAL_COLOR);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    72
                g.fillOval(0, 0, getWidth(), getHeight());
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    73
            }
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
        contentPane.add(center, BorderLayout.CENTER);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    76
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    77
        JTextField jTextField = new JTextField("South");
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    78
        contentPane.add(jTextField, BorderLayout.SOUTH);
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
        Rectangle bounds = center.getBounds();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    86
        Point loc = center.getLocationOnScreen();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    87
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    88
        final int x = loc.x + bounds.width / 2;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    89
        final int y = loc.y + bounds.height / 2;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    90
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    91
        Color color = robot.getPixelColor(x, y);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    92
        if (OVAL_COLOR.getRGB() != color.getRGB())
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    93
            throw new RuntimeException("bounds = " + bounds + "\n" +
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    94
                    "loc = " + loc + "\n" +
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    95
                    "background loc = " + background.getX() + ", " + background.getY() + "\n" +
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    96
                    "so middle point over background is " + (x - background.getX()) + ", " + (y - background.getY()) + "\n" +
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    97
                    "Oval is not opaque in the middle point (" + x + ", " + y + ", " + color + ")");
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    98
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    99
        color = robot.getPixelColor(loc.x - 5, loc.y - 5);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   100
        if (FG_COLOR.getRGB() == color.getRGB())
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   101
            throw new RuntimeException("Background is not translucent (" + color + ")");
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   102
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   103
        EventQueue.invokeAndWait(this::dispose);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   104
        robot.waitForIdle();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   105
    }
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   106
}