jdk/src/java.desktop/share/classes/com/sun/awt/AWTUtilities.java
author prr
Fri, 03 Feb 2017 09:28:34 -0800
changeset 43724 a272f9475e44
parent 41004 01e8aabf5e7c
child 44655 06871a50a4b5
permissions -rw-r--r--
8173409: make setMixingCutoutShape public and remove jdk.desktop Reviewed-by: serb, mchung, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
     2
 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
     4
 *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    10
 *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    15
 * accompanied this code).
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    16
 *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3237
diff changeset
    23
 * questions.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    24
 */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    25
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    26
package com.sun.awt;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    27
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    28
import java.awt.*;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    29
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    30
import sun.awt.AWTAccessor;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    31
import sun.awt.SunToolkit;
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    32
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    33
/**
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    34
 * A collection of utility methods for AWT.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    35
 *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    36
 * The functionality provided by the static methods of the class includes:
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    37
 * <ul>
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    38
 * <li>Setting shapes on top-level windows
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    39
 * <li>Setting a constant alpha value for each pixel of a top-level window
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    40
 * <li>Making a window non-opaque, after that it paints only explicitly
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    41
 * painted pixels on the screen, with arbitrary alpha values for every pixel.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    42
 * <li>Setting a 'mixing-cutout' shape for a component.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    43
 * </ul>
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    44
 * <p>
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    45
 * A "top-level window" is an instance of the {@code Window} class (or its
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    46
 * descendant, such as {@code JFrame}).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    47
 * <p>
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    48
 * Some of the mentioned features may not be supported by the native platform.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    49
 * To determine whether a particular feature is supported, the user must use
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    50
 * the {@code isTranslucencySupported()} method of the class passing a desired
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    51
 * translucency kind (a member of the {@code Translucency} enum) as an
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    52
 * argument.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    53
 * <p>
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    54
 * The per-pixel alpha feature also requires the user to create her/his
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    55
 * windows using a translucency-capable graphics configuration.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    56
 * The {@code isTranslucencyCapable()} method must
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    57
 * be used to verify whether any given GraphicsConfiguration supports
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
    58
 * the translucency effects.
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    59
 * <p>
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    60
 * <b>WARNING</b>: This class is an implementation detail and only meant
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    61
 * for limited use outside of the core platform. This API may change
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    62
 * drastically between update release, and it may even be
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    63
 * removed or be moved in some other package(s)/class(es).
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    64
 */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    65
public final class AWTUtilities {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    66
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    67
    /**
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    68
     * The AWTUtilities class should not be instantiated
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    69
     */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    70
    private AWTUtilities() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    71
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
    72
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    73
    /** Kinds of translucency supported by the underlying system.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    74
     *  @see #isTranslucencySupported
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    75
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    76
    public static enum Translucency {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    77
        /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    78
         * Represents support in the underlying system for windows each pixel
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    79
         * of which is guaranteed to be either completely opaque, with
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    80
         * an alpha value of 1.0, or completely transparent, with an alpha
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    81
         * value of 0.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    82
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    83
        PERPIXEL_TRANSPARENT,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    84
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    85
        /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    86
         * Represents support in the underlying system for windows all of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    87
         * the pixels of which have the same alpha value between or including
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    88
         * 0.0 and 1.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    89
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    90
        TRANSLUCENT,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    91
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    92
        /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    93
         * Represents support in the underlying system for windows that
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    94
         * contain or might contain pixels with arbitrary alpha values
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    95
         * between and including 0.0 and 1.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    96
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    97
        PERPIXEL_TRANSLUCENT;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    98
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
    99
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   100
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   101
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   102
     * Returns whether the given level of translucency is supported by
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   103
     * the underlying system.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   104
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   105
     * Note that this method may sometimes return the value
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   106
     * indicating that the particular level is supported, but
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   107
     * the native windowing system may still not support the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   108
     * given level of translucency (due to the bugs in
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   109
     * the windowing system).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   110
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   111
     * @param translucencyKind a kind of translucency support
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   112
     *                         (either PERPIXEL_TRANSPARENT,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   113
     *                         TRANSLUCENT, or PERPIXEL_TRANSLUCENT)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   114
     * @return whether the given translucency kind is supported
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   115
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   116
    public static boolean isTranslucencySupported(Translucency translucencyKind) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   117
        switch (translucencyKind) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   118
            case PERPIXEL_TRANSPARENT:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   119
                return isWindowShapingSupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   120
            case TRANSLUCENT:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   121
                return isWindowOpacitySupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   122
            case PERPIXEL_TRANSLUCENT:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   123
                return isWindowTranslucencySupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   124
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   125
        return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   126
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   127
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   128
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   129
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   130
     * Returns whether the windowing system supports changing the opacity
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   131
     * value of top-level windows.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   132
     * Note that this method may sometimes return true, but the native
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   133
     * windowing system may still not support the concept of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   134
     * translucency (due to the bugs in the windowing system).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   135
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   136
    private static boolean isWindowOpacitySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   137
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   138
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   139
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   140
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   141
        return ((SunToolkit)curToolkit).isWindowOpacitySupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   142
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   143
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   144
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   145
     * Set the opacity of the window. The opacity is at the range [0..1].
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   146
     * Note that setting the opacity level of 0 may or may not disable
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   147
     * the mouse event handling on this window. This is
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   148
     * a platform-dependent behavior.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   149
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   150
     * In order for this method to enable the translucency effect,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   151
     * the isTranslucencySupported() method should indicate that the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   152
     * TRANSLUCENT level of translucency is supported.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   153
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   154
     * <p>Also note that the window must not be in the full-screen mode
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   155
     * when setting the opacity value &lt; 1.0f. Otherwise
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   156
     * the IllegalArgumentException is thrown.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   157
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   158
     * @param window the window to set the opacity level to
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   159
     * @param opacity the opacity level to set to the window
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   160
     * @throws NullPointerException if the window argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   161
     * @throws IllegalArgumentException if the opacity is out of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   162
     *                                  the range [0..1]
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   163
     * @throws IllegalArgumentException if the window is in full screen mode,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   164
     *                                  and the opacity is less than 1.0f
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   165
     * @throws UnsupportedOperationException if the TRANSLUCENT translucency
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   166
     *                                       kind is not supported
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   167
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   168
    public static void setWindowOpacity(Window window, float opacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   169
        if (window == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   170
            throw new NullPointerException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   171
                    "The window argument should not be null.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   172
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   173
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   174
        AWTAccessor.getWindowAccessor().setOpacity(window, opacity);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   175
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   176
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   177
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   178
     * Get the opacity of the window. If the opacity has not
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   179
     * yet being set, this method returns 1.0.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   180
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   181
     * @param window the window to get the opacity level from
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   182
     * @throws NullPointerException if the window argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   183
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   184
    public static float getWindowOpacity(Window window) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   185
        if (window == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   186
            throw new NullPointerException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   187
                    "The window argument should not be null.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   188
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   189
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   190
        return AWTAccessor.getWindowAccessor().getOpacity(window);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   191
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   192
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   193
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   194
     * Returns whether the windowing system supports changing the shape
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   195
     * of top-level windows.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   196
     * Note that this method may sometimes return true, but the native
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   197
     * windowing system may still not support the concept of
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   198
     * shaping (due to the bugs in the windowing system).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   199
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   200
    public static boolean isWindowShapingSupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   201
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   202
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   203
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   204
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   205
        return ((SunToolkit)curToolkit).isWindowShapingSupported();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   206
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   207
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   208
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   209
     * Returns an object that implements the Shape interface and represents
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   210
     * the shape previously set with the call to the setWindowShape() method.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   211
     * If no shape has been set yet, or the shape has been reset to null,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   212
     * this method returns null.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   213
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   214
     * @param window the window to get the shape from
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   215
     * @return the current shape of the window
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   216
     * @throws NullPointerException if the window argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   217
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   218
    public static Shape getWindowShape(Window window) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   219
        if (window == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   220
            throw new NullPointerException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   221
                    "The window argument should not be null.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   222
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   223
        return AWTAccessor.getWindowAccessor().getShape(window);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   224
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   225
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   226
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   227
     * Sets a shape for the given window.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   228
     * If the shape argument is null, this methods restores
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   229
     * the default shape making the window rectangular.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   230
     * <p>Note that in order to set a shape, the window must be undecorated.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   231
     * If the window is decorated, this method ignores the {@code shape}
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   232
     * argument and resets the shape to null.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   233
     * <p>Also note that the window must not be in the full-screen mode
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   234
     * when setting a non-null shape. Otherwise the IllegalArgumentException
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   235
     * is thrown.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   236
     * <p>Depending on the platform, the method may return without
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   237
     * effecting the shape of the window if the window has a non-null warning
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   238
     * string ({@link Window#getWarningString()}). In this case the passed
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   239
     * shape object is ignored.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   240
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   241
     * @param window the window to set the shape to
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   242
     * @param shape the shape to set to the window
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   243
     * @throws NullPointerException if the window argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   244
     * @throws IllegalArgumentException if the window is in full screen mode,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   245
     *                                  and the shape is not null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   246
     * @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   247
     *                                       translucency kind is not supported
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   248
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   249
    public static void setWindowShape(Window window, Shape shape) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   250
        if (window == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   251
            throw new NullPointerException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   252
                    "The window argument should not be null.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   253
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   254
        AWTAccessor.getWindowAccessor().setShape(window, shape);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   255
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   256
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   257
    private static boolean isWindowTranslucencySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   258
        /*
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   259
         * Per-pixel alpha is supported if all the conditions are TRUE:
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   260
         *    1. The toolkit is a sort of SunToolkit
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   261
         *    2. The toolkit supports translucency in general
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   262
         *        (isWindowTranslucencySupported())
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   263
         *    3. There's at least one translucency-capable
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   264
         *        GraphicsConfiguration
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   265
         */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   266
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   267
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   268
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   269
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   270
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   271
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   272
        if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   273
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   274
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   275
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   276
        GraphicsEnvironment env =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   277
            GraphicsEnvironment.getLocalGraphicsEnvironment();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   278
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   279
        // If the default GC supports translucency return true.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   280
        // It is important to optimize the verification this way,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   281
        // see CR 6661196 for more details.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   282
        if (isTranslucencyCapable(env.getDefaultScreenDevice()
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   283
                    .getDefaultConfiguration()))
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   284
        {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   285
            return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   286
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   287
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   288
        // ... otherwise iterate through all the GCs.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   289
        GraphicsDevice[] devices = env.getScreenDevices();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   290
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   291
        for (int i = 0; i < devices.length; i++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   292
            GraphicsConfiguration[] configs = devices[i].getConfigurations();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   293
            for (int j = 0; j < configs.length; j++) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   294
                if (isTranslucencyCapable(configs[j])) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   295
                    return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   296
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   297
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   298
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   299
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   300
        return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   301
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   302
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   303
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   304
     * Enables the per-pixel alpha support for the given window.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   305
     * Once the window becomes non-opaque (the isOpaque is set to false),
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   306
     * the drawing sub-system is starting to respect the alpha value of each
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   307
     * separate pixel. If a pixel gets painted with alpha color component
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   308
     * equal to zero, it becomes visually transparent, if the alpha of the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   309
     * pixel is equal to 255, the pixel is fully opaque. Interim values
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   310
     * of the alpha color component make the pixel semi-transparent (i.e.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   311
     * translucent).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   312
     * <p>Note that in order for the window to support the per-pixel alpha
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   313
     * mode, the window must be created using the GraphicsConfiguration
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   314
     * for which the {@link #isTranslucencyCapable}
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   315
     * method returns true.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   316
     * <p>Also note that some native systems enable the per-pixel translucency
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   317
     * mode for any window created using the translucency-compatible
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   318
     * graphics configuration. However, it is highly recommended to always
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   319
     * invoke the setWindowOpaque() method for these windows, at least for
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   320
     * the sake of cross-platform compatibility reasons.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   321
     * <p>Also note that the window must not be in the full-screen mode
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   322
     * when making it non-opaque. Otherwise the IllegalArgumentException
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   323
     * is thrown.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   324
     * <p>If the window is a {@code Frame} or a {@code Dialog}, the window must
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   325
     * be undecorated prior to enabling the per-pixel translucency effect (see
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   326
     * {@link Frame#setUndecorated()} and/or {@link Dialog#setUndecorated()}).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   327
     * If the window becomes decorated through a subsequent call to the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   328
     * corresponding {@code setUndecorated()} method, the per-pixel
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   329
     * translucency effect will be disabled and the opaque property reset to
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   330
     * {@code true}.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   331
     * <p>Depending on the platform, the method may return without
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   332
     * effecting the opaque property of the window if the window has a non-null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   333
     * warning string ({@link Window#getWarningString()}). In this case
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   334
     * the passed 'isOpaque' value is ignored.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   335
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   336
     * @param window the window to set the shape to
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   337
     * @param isOpaque whether the window must be opaque (true),
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   338
     *                 or translucent (false)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   339
     * @throws NullPointerException if the window argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   340
     * @throws IllegalArgumentException if the window uses
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   341
     *                                  a GraphicsConfiguration for which the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   342
     *                                  {@code isTranslucencyCapable()}
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   343
     *                                  method returns false
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   344
     * @throws IllegalArgumentException if the window is in full screen mode,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   345
     *                                  and the isOpaque is false
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   346
     * @throws IllegalArgumentException if the window is decorated and the
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   347
     * isOpaque argument is {@code false}.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   348
     * @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   349
     *                                       translucency kind is not supported
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   350
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   351
    public static void setWindowOpaque(Window window, boolean isOpaque) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   352
        if (window == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   353
            throw new NullPointerException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   354
                    "The window argument should not be null.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   355
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   356
        if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   357
            throw new UnsupportedOperationException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   358
                    "The PERPIXEL_TRANSLUCENT translucency kind is not supported");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   359
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   360
        AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   361
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   362
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   363
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   364
     * Returns whether the window is opaque or translucent.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   365
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   366
     * @param window the window to set the shape to
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   367
     * @return whether the window is currently opaque (true)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   368
     *         or translucent (false)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   369
     * @throws NullPointerException if the window argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   370
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   371
    public static boolean isWindowOpaque(Window window) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   372
        if (window == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   373
            throw new NullPointerException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   374
                    "The window argument should not be null.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   375
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   376
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2451
diff changeset
   377
        return window.isOpaque();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   378
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   379
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   380
    /**
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   381
     * Verifies whether a given GraphicsConfiguration supports
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   382
     * the PERPIXEL_TRANSLUCENT kind of translucency.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   383
     * All windows that are intended to be used with the {@link #setWindowOpaque}
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   384
     * method must be created using a GraphicsConfiguration for which this method
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   385
     * returns true.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   386
     * <p>Note that some native systems enable the per-pixel translucency
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   387
     * mode for any window created using a translucency-capable
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   388
     * graphics configuration. However, it is highly recommended to always
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   389
     * invoke the setWindowOpaque() method for these windows, at least
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   390
     * for the sake of cross-platform compatibility reasons.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   391
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   392
     * @param gc GraphicsConfiguration
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   393
     * @throws NullPointerException if the gc argument is null
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   394
     * @return whether the given GraphicsConfiguration supports
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   395
     *         the translucency effects.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   396
     */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   397
    public static boolean isTranslucencyCapable(GraphicsConfiguration gc) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   398
        if (gc == null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   399
            throw new NullPointerException("The gc argument should not be null");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   400
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   401
        /*
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   402
        return gc.isTranslucencyCapable();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   403
        */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   404
        Toolkit curToolkit = Toolkit.getDefaultToolkit();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   405
        if (!(curToolkit instanceof SunToolkit)) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   406
            return false;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   407
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   408
        return ((SunToolkit)curToolkit).isTranslucencyCapable(gc);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   409
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   410
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   411
    /**
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   412
     * Sets a 'mixing-cutout' shape for the given component.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   413
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   414
     * By default a lightweight component is treated as an opaque rectangle for
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   415
     * the purposes of the Heavyweight/Lightweight Components Mixing feature.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   416
     * This method enables developers to set an arbitrary shape to be cut out
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   417
     * from heavyweight components positioned underneath the lightweight
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   418
     * component in the z-order.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   419
     * <p>
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   420
     * The {@code shape} argument may have the following values:
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   421
     * <ul>
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   422
     * <li>{@code null} - reverts the default cutout shape (the rectangle equal
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   423
     * to the component's {@code getBounds()})
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   424
     * <li><i>empty-shape</i> - does not cut out anything from heavyweight
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   425
     * components. This makes the given lightweight component effectively
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   426
     * transparent. Note that descendants of the lightweight component still
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   427
     * affect the shapes of heavyweight components.  An example of an
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   428
     * <i>empty-shape</i> is {@code new Rectangle()}.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   429
     * <li><i>non-empty-shape</i> - the given shape will be cut out from
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   430
     * heavyweight components.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   431
     * </ul>
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   432
     * <p>
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   433
     * The most common example when the 'mixing-cutout' shape is needed is a
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   434
     * glass pane component. The {@link JRootPane#setGlassPane()} method
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   435
     * automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   436
     * for the given glass pane component.  If a developer needs some other
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   437
     * 'mixing-cutout' shape for the glass pane (which is rare), this must be
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   438
     * changed manually after installing the glass pane to the root pane.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   439
     * <p>
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   440
     * Note that the 'mixing-cutout' shape neither affects painting, nor the
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   441
     * mouse events handling for the given component. It is used exclusively
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   442
     * for the purposes of the Heavyweight/Lightweight Components Mixing
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   443
     * feature.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   444
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   445
     * @param component the component that needs non-default
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   446
     * 'mixing-cutout' shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   447
     * @param shape the new 'mixing-cutout' shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   448
     * @throws NullPointerException if the component argument is {@code null}
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   449
     */
41004
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 26749
diff changeset
   450
    @Deprecated(since = "9")
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   451
    public static void setComponentMixingCutoutShape(Component component,
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   452
            Shape shape)
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   453
    {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   454
        if (component == null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   455
            throw new NullPointerException(
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   456
                    "The component argument should not be null.");
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   457
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   458
43724
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 41004
diff changeset
   459
        component.setMixingCutoutShape(shape);
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   460
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   461
}
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
diff changeset
   462