jdk/test/javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentWindowClickSwing.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 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
import java.awt.event.MouseAdapter;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    27
import java.awt.event.MouseEvent;
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
/*
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    30
 * @test
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    31
 * @summary Check if swing components present in a window set with opacity less
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    32
 *          than 1.0 appears translucent
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    33
 * Test Description: Check if TRANSLUCENT Translucency type is supported for the
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    34
 *      current platform. Proceed if supported. Show a window containing some swing
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    35
 *      components and set it with opacity less than 1.0. Check if the swing components
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    36
 *      appear translucent and check if events trigger correctly for the components
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    37
 * Expected Result: If TRANSLUCENT Translucency type is supported, the components
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    38
 *      should appear translucent showing the background. They should trigger events
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    39
 *      correctly
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    40
 * @author mrkam
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    41
 * @library ../../../../lib/testlibrary
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    42
 * @build Common ExtendedRobot
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    43
 * @run main TranslucentWindowClickSwing
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
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    46
public class TranslucentWindowClickSwing extends Common {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    47
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    48
    private Component south;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    49
    private Component center;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    50
    private Component north;
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 static void main(String[] args) throws Exception{
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    53
        if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    54
            new TranslucentWindowClickSwing(JWindow.class).doTest();
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
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    57
    public TranslucentWindowClickSwing(Class windowClass) throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    58
        super(windowClass, 0.2f, 1.0f, false);
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
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    61
    @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    62
    public void createSwingComponents() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    63
        south = new JButton("South");
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    64
        south.addMouseListener(new MouseAdapter() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    65
            @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    66
            public void mouseClicked(MouseEvent e) { clicked |= 1 << 2; }
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
        window.add(south, BorderLayout.SOUTH);
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
        center = new JList();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    71
        center.addMouseListener(new MouseAdapter() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    72
            @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    73
            public void mouseClicked(MouseEvent e) { clicked |= 1 << 1; }
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.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
        north = new JTextField("North");
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    78
        north.addMouseListener(new MouseAdapter() {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    79
            @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    80
            public void mouseClicked(MouseEvent e) { clicked |= 1 << 0; }
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    81
        });
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    82
        window.add(north, BorderLayout.NORTH);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    83
    }
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
    @Override
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    86
    public void doTest() throws Exception {
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    87
        Point ls;
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    88
        robot.waitForIdle();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    89
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    90
        ls = north.getLocationOnScreen();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    91
        checkClick(ls.x + north.getWidth() / 3, ls.y + north.getHeight() / 2, 0);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    92
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    93
        ls = center.getLocationOnScreen();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    94
        checkClick(ls.x + center.getWidth() / 4, ls.y + center.getHeight() / 4, 1);
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
        ls = center.getLocationOnScreen();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
    97
        checkClick(ls.x + center.getWidth() * 3 / 4, ls.y + center.getHeight() * 3 / 4, 1);
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
        ls = south.getLocationOnScreen();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   100
        checkClick(ls.x + south.getWidth() * 2 / 3, ls.y + south.getHeight() / 2, 2);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   101
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   102
        EventQueue.invokeAndWait(this::dispose);
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   103
        robot.waitForIdle();
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   104
    }
2713482c0fd3 8055360: Move the rest part of AWT ShapedAndTranslucent tests to OpenJDK
dermashov
parents:
diff changeset
   105
}