jdk/test/javax/swing/JWindow/ShapedAndTranslucentWindows/ShapedTranslucentPerPixelTranslucentGradient.java
author dermashov
Tue, 26 Aug 2014 15:04:49 +0400
changeset 26601 2713482c0fd3
child 39056 d99e63b6d962
permissions -rw-r--r--
8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK Reviewed-by: alexsch
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
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
 * @test
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    28
 * @summary Check if shaped, translucent and per-pixel translucent window is
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    29
 *          dragged and resized by mouse correctly.
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    30
 * Test Description: Check if PERPIXEL_TRANSLUCENT, TRANSLUCENT and
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    31
 *      PERPIXEL_TRANSPARENT translucency types are supported on the current
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    32
 *      platform. Proceed if they are supported. Create a window with some
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    33
 *      components in it, make window undecorated, apply shape in componentResized
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    34
 *      listener. The shape should match the window size; apply opacity of 0.7,
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    35
 *      apply translucent background of 0 and have a gradient painted as
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    36
 *      background from fully-transparent to fully-opaque in componentResized
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    37
 *      listener. Drag and resize the window using AWT Robot and verify that
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    38
 *      shape and translucency are correctly applied with pixels checking. Make
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    39
 *      the window appear on top of a known background. Repeat this for JWindow,
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    40
 *      JDialog, JFrame.
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    41
 * Expected Result: If PERPIXEL_TRANSLUCENT, TRANSLUCENT and PERPIXEL_TRANSPARENT
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    42
 *      translucency types are supported, the window should appear as specified
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    43
 *      with the expected shape and translucency. Window background should have
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    44
 *      translucent gradient in parts that are not clipped by shape, all the
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    45
 *      controls should be equally translucent.
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    46
 * @author mrkam
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    47
 * @library ../../../../lib/testlibrary
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    48
 * @build Common ExtendedRobot
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    49
 * @run main ShapedTranslucentPerPixelTranslucentGradient
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
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    52
public class ShapedTranslucentPerPixelTranslucentGradient extends Common {
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
    public static void main(String[] ignored) throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    55
        if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT)
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    56
            && checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT)
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    57
            && checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    58
            for (Class<Window> windowClass: WINDOWS_TO_TEST)
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    59
                new ShapedTranslucentPerPixelTranslucentGradient(windowClass).doTest();
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
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    62
    public ShapedTranslucentPerPixelTranslucentGradient(Class windowClass) throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    63
        super(windowClass, 0.7f, 0f, true);
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
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    66
    public void doTest() throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    67
        robot.waitForIdle(delay);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    68
        checkDynamic();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    69
    }
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    70
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    71
    @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    72
    public void applyShape() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    73
        applyDynamicShape();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    74
        gradientWidth = window.getWidth();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    75
        gradientHeight = window.getHeight();
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
}