jdk/test/javax/swing/JComponent/6683775/bug6683775.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 32282 9c9ff2c42e0d
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     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
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     4
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     7
 * published by the Free Software Foundation.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     8
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    13
 * accompanied this code).
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    14
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    18
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    21
 * questions.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    22
 */
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2808
diff changeset
    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
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    42
    static final int LOC = 100,
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    43
            SIZE = 200;
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    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
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    55
        SwingUtilities.invokeAndWait(() -> {
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    56
            JFrame backgroundFrame = new JFrame("Background frame");
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    57
            backgroundFrame.setUndecorated(true);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    58
            JPanel panel = new JPanel();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    59
            panel.setBackground(Color.RED);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    60
            backgroundFrame.add(panel);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    61
            backgroundFrame.setBounds(LOC, LOC, SIZE, SIZE);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    62
            backgroundFrame.setVisible(true);
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
diff changeset
    63
32282
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    64
            testFrame.setUndecorated(true);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    65
            JPanel p = new JPanel();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    66
            p.setOpaque(false);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    67
            testFrame.add(p);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    68
            AWTUtilities.setWindowOpaque(testFrame, false);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    69
            testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    70
            testFrame.setBounds(LOC, LOC, SIZE, SIZE);
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    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
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    74
        robot.waitForIdle();
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    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
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    78
        BufferedImage capture =
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    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
9c9ff2c42e0d 8014212: Robot captures black screen
azvegint
parents: 31448
diff changeset
    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
}