< prev index next >

src/java.desktop/share/classes/com/sun/awt/AWTUtilities.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.awt;
  27 
  28 import java.awt.*;








  29 
  30 import javax.swing.JRootPane;
  31 
  32 import sun.awt.AWTAccessor;
  33 import sun.awt.SunToolkit;
  34 
  35 /**
  36  * A collection of utility methods for AWT.
  37  *
  38  * The functionality provided by the static methods of the class includes:
  39  * <ul>
  40  * <li>Setting shapes on top-level windows
  41  * <li>Setting a constant alpha value for each pixel of a top-level window
  42  * <li>Making a window non-opaque, after that it paints only explicitly
  43  * painted pixels on the screen, with arbitrary alpha values for every pixel.
  44  * <li>Setting a 'mixing-cutout' shape for a component.
  45  * </ul>
  46  * <p>
  47  * A "top-level window" is an instance of the {@code Window} class (or its
  48  * descendant, such as {@code JFrame}).
  49  * <p>
  50  * Some of the mentioned features may not be supported by the native platform.
  51  * To determine whether a particular feature is supported, the user must use
  52  * the {@code isTranslucencySupported()} method of the class passing a desired
  53  * translucency kind (a member of the {@code Translucency} enum) as an
  54  * argument.
  55  * <p>
  56  * The per-pixel alpha feature also requires the user to create her/his
  57  * windows using a translucency-capable graphics configuration.
  58  * The {@code isTranslucencyCapable()} method must
  59  * be used to verify whether any given GraphicsConfiguration supports
  60  * the translucency effects.
  61  * <p>
  62  * <b>WARNING</b>: This class is an implementation detail and only meant
  63  * for limited use outside of the core platform. This API may change
  64  * drastically between update release, and it may even be
  65  * removed or be moved in some other package(s)/class(es).
  66  */

  67 public final class AWTUtilities {
  68 
  69     /**
  70      * The AWTUtilities class should not be instantiated
  71      */
  72     private AWTUtilities() {
  73     }
  74 
  75     /** Kinds of translucency supported by the underlying system.
  76      *  @see #isTranslucencySupported
  77      */
  78     public static enum Translucency {
  79         /**
  80          * Represents support in the underlying system for windows each pixel
  81          * of which is guaranteed to be either completely opaque, with
  82          * an alpha value of 1.0, or completely transparent, with an alpha
  83          * value of 0.0.
  84          */
  85         PERPIXEL_TRANSPARENT,
  86 


  97          * between and including 0.0 and 1.0.
  98          */
  99         PERPIXEL_TRANSLUCENT;
 100     }
 101 
 102 
 103     /**
 104      * Returns whether the given level of translucency is supported by
 105      * the underlying system.
 106      *
 107      * Note that this method may sometimes return the value
 108      * indicating that the particular level is supported, but
 109      * the native windowing system may still not support the
 110      * given level of translucency (due to the bugs in
 111      * the windowing system).
 112      *
 113      * @param translucencyKind a kind of translucency support
 114      *                         (either PERPIXEL_TRANSPARENT,
 115      *                         TRANSLUCENT, or PERPIXEL_TRANSLUCENT)
 116      * @return whether the given translucency kind is supported


 117      */

 118     public static boolean isTranslucencySupported(Translucency translucencyKind) {
 119         switch (translucencyKind) {
 120             case PERPIXEL_TRANSPARENT:
 121                 return isWindowShapingSupported();
 122             case TRANSLUCENT:
 123                 return isWindowOpacitySupported();
 124             case PERPIXEL_TRANSLUCENT:
 125                 return isWindowTranslucencySupported();
 126         }
 127         return false;
 128     }
 129 
 130 
 131     /**
 132      * Returns whether the windowing system supports changing the opacity
 133      * value of top-level windows.
 134      * Note that this method may sometimes return true, but the native
 135      * windowing system may still not support the concept of
 136      * translucency (due to the bugs in the windowing system).
 137      */


 149      * the mouse event handling on this window. This is
 150      * a platform-dependent behavior.
 151      *
 152      * In order for this method to enable the translucency effect,
 153      * the isTranslucencySupported() method should indicate that the
 154      * TRANSLUCENT level of translucency is supported.
 155      *
 156      * <p>Also note that the window must not be in the full-screen mode
 157      * when setting the opacity value &lt; 1.0f. Otherwise
 158      * the IllegalArgumentException is thrown.
 159      *
 160      * @param window the window to set the opacity level to
 161      * @param opacity the opacity level to set to the window
 162      * @throws NullPointerException if the window argument is null
 163      * @throws IllegalArgumentException if the opacity is out of
 164      *                                  the range [0..1]
 165      * @throws IllegalArgumentException if the window is in full screen mode,
 166      *                                  and the opacity is less than 1.0f
 167      * @throws UnsupportedOperationException if the TRANSLUCENT translucency
 168      *                                       kind is not supported

 169      */

 170     public static void setWindowOpacity(Window window, float opacity) {
 171         if (window == null) {
 172             throw new NullPointerException(
 173                     "The window argument should not be null.");
 174         }
 175 
 176         AWTAccessor.getWindowAccessor().setOpacity(window, opacity);
 177     }
 178 
 179     /**
 180      * Get the opacity of the window. If the opacity has not
 181      * yet being set, this method returns 1.0.
 182      *
 183      * @param window the window to get the opacity level from
 184      * @throws NullPointerException if the window argument is null

 185      */

 186     public static float getWindowOpacity(Window window) {
 187         if (window == null) {
 188             throw new NullPointerException(
 189                     "The window argument should not be null.");
 190         }
 191 
 192         return AWTAccessor.getWindowAccessor().getOpacity(window);
 193     }
 194 
 195     /**
 196      * Returns whether the windowing system supports changing the shape
 197      * of top-level windows.
 198      * Note that this method may sometimes return true, but the native
 199      * windowing system may still not support the concept of
 200      * shaping (due to the bugs in the windowing system).


 201      */

 202     public static boolean isWindowShapingSupported() {
 203         Toolkit curToolkit = Toolkit.getDefaultToolkit();
 204         if (!(curToolkit instanceof SunToolkit)) {
 205             return false;
 206         }
 207         return ((SunToolkit)curToolkit).isWindowShapingSupported();
 208     }
 209 
 210     /**
 211      * Returns an object that implements the Shape interface and represents
 212      * the shape previously set with the call to the setWindowShape() method.
 213      * If no shape has been set yet, or the shape has been reset to null,
 214      * this method returns null.
 215      *
 216      * @param window the window to get the shape from
 217      * @return the current shape of the window
 218      * @throws NullPointerException if the window argument is null

 219      */

 220     public static Shape getWindowShape(Window window) {
 221         if (window == null) {
 222             throw new NullPointerException(
 223                     "The window argument should not be null.");
 224         }
 225         return AWTAccessor.getWindowAccessor().getShape(window);
 226     }
 227 
 228     /**
 229      * Sets a shape for the given window.
 230      * If the shape argument is null, this methods restores
 231      * the default shape making the window rectangular.
 232      * <p>Note that in order to set a shape, the window must be undecorated.
 233      * If the window is decorated, this method ignores the {@code shape}
 234      * argument and resets the shape to null.
 235      * <p>Also note that the window must not be in the full-screen mode
 236      * when setting a non-null shape. Otherwise the IllegalArgumentException
 237      * is thrown.
 238      * <p>Depending on the platform, the method may return without
 239      * effecting the shape of the window if the window has a non-null warning
 240      * string ({@link Window#getWarningString()}). In this case the passed
 241      * shape object is ignored.
 242      *
 243      * @param window the window to set the shape to
 244      * @param shape the shape to set to the window
 245      * @throws NullPointerException if the window argument is null
 246      * @throws IllegalArgumentException if the window is in full screen mode,
 247      *                                  and the shape is not null
 248      * @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT
 249      *                                       translucency kind is not supported

 250      */

 251     public static void setWindowShape(Window window, Shape shape) {
 252         if (window == null) {
 253             throw new NullPointerException(
 254                     "The window argument should not be null.");
 255         }
 256         AWTAccessor.getWindowAccessor().setShape(window, shape);
 257     }
 258 
 259     private static boolean isWindowTranslucencySupported() {
 260         /*
 261          * Per-pixel alpha is supported if all the conditions are TRUE:
 262          *    1. The toolkit is a sort of SunToolkit
 263          *    2. The toolkit supports translucency in general
 264          *        (isWindowTranslucencySupported())
 265          *    3. There's at least one translucency-capable
 266          *        GraphicsConfiguration
 267          */
 268 
 269         Toolkit curToolkit = Toolkit.getDefaultToolkit();
 270         if (!(curToolkit instanceof SunToolkit)) {


 332      * {@code true}.
 333      * <p>Depending on the platform, the method may return without
 334      * effecting the opaque property of the window if the window has a non-null
 335      * warning string ({@link Window#getWarningString()}). In this case
 336      * the passed 'isOpaque' value is ignored.
 337      *
 338      * @param window the window to set the shape to
 339      * @param isOpaque whether the window must be opaque (true),
 340      *                 or translucent (false)
 341      * @throws NullPointerException if the window argument is null
 342      * @throws IllegalArgumentException if the window uses
 343      *                                  a GraphicsConfiguration for which the
 344      *                                  {@code isTranslucencyCapable()}
 345      *                                  method returns false
 346      * @throws IllegalArgumentException if the window is in full screen mode,
 347      *                                  and the isOpaque is false
 348      * @throws IllegalArgumentException if the window is decorated and the
 349      * isOpaque argument is {@code false}.
 350      * @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT
 351      *                                       translucency kind is not supported

 352      */

 353     public static void setWindowOpaque(Window window, boolean isOpaque) {
 354         if (window == null) {
 355             throw new NullPointerException(
 356                     "The window argument should not be null.");
 357         }
 358         if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) {
 359             throw new UnsupportedOperationException(
 360                     "The PERPIXEL_TRANSLUCENT translucency kind is not supported");
 361         }
 362         AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque);
 363     }
 364 
 365     /**
 366      * Returns whether the window is opaque or translucent.
 367      *
 368      * @param window the window to set the shape to
 369      * @return whether the window is currently opaque (true)
 370      *         or translucent (false)
 371      * @throws NullPointerException if the window argument is null

 372      */

 373     public static boolean isWindowOpaque(Window window) {
 374         if (window == null) {
 375             throw new NullPointerException(
 376                     "The window argument should not be null.");
 377         }
 378 
 379         return window.isOpaque();
 380     }
 381 
 382     /**
 383      * Verifies whether a given GraphicsConfiguration supports
 384      * the PERPIXEL_TRANSLUCENT kind of translucency.
 385      * All windows that are intended to be used with the {@link #setWindowOpaque}
 386      * method must be created using a GraphicsConfiguration for which this method
 387      * returns true.
 388      * <p>Note that some native systems enable the per-pixel translucency
 389      * mode for any window created using a translucency-capable
 390      * graphics configuration. However, it is highly recommended to always
 391      * invoke the setWindowOpaque() method for these windows, at least
 392      * for the sake of cross-platform compatibility reasons.
 393      *
 394      * @param gc GraphicsConfiguration
 395      * @throws NullPointerException if the gc argument is null
 396      * @return whether the given GraphicsConfiguration supports
 397      *         the translucency effects.


 398      */

 399     public static boolean isTranslucencyCapable(GraphicsConfiguration gc) {
 400         if (gc == null) {
 401             throw new NullPointerException("The gc argument should not be null");
 402         }
 403         /*
 404         return gc.isTranslucencyCapable();
 405         */
 406         Toolkit curToolkit = Toolkit.getDefaultToolkit();
 407         if (!(curToolkit instanceof SunToolkit)) {
 408             return false;
 409         }
 410         return ((SunToolkit)curToolkit).isTranslucencyCapable(gc);
 411     }
 412 
 413     /**
 414      * Sets a 'mixing-cutout' shape for the given component.
 415      *
 416      * By default a lightweight component is treated as an opaque rectangle for
 417      * the purposes of the Heavyweight/Lightweight Components Mixing feature.
 418      * This method enables developers to set an arbitrary shape to be cut out


 431      * <li><i>non-empty-shape</i> - the given shape will be cut out from
 432      * heavyweight components.
 433      * </ul>
 434      * <p>
 435      * The most common example when the 'mixing-cutout' shape is needed is a
 436      * glass pane component. The {@link JRootPane#setGlassPane} method
 437      * automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape
 438      * for the given glass pane component.  If a developer needs some other
 439      * 'mixing-cutout' shape for the glass pane (which is rare), this must be
 440      * changed manually after installing the glass pane to the root pane.
 441      * <p>
 442      * Note that the 'mixing-cutout' shape neither affects painting, nor the
 443      * mouse events handling for the given component. It is used exclusively
 444      * for the purposes of the Heavyweight/Lightweight Components Mixing
 445      * feature.
 446      *
 447      * @param component the component that needs non-default
 448      * 'mixing-cutout' shape
 449      * @param shape the new 'mixing-cutout' shape
 450      * @throws NullPointerException if the component argument is {@code null}

 451      */
 452     @Deprecated(since = "9")
 453     public static void setComponentMixingCutoutShape(Component component,
 454             Shape shape)
 455     {
 456         if (component == null) {
 457             throw new NullPointerException(
 458                     "The component argument should not be null.");
 459         }
 460 
 461         component.setMixingCutoutShape(shape);
 462     }
 463 }
 464 


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.awt;
  27 
  28 import java.awt.Component;
  29 import java.awt.Dialog;
  30 import java.awt.Frame;
  31 import java.awt.GraphicsConfiguration;
  32 import java.awt.GraphicsDevice;
  33 import java.awt.GraphicsEnvironment;
  34 import java.awt.Shape;
  35 import java.awt.Toolkit;
  36 import java.awt.Window;
  37 
  38 import javax.swing.JRootPane;
  39 
  40 import sun.awt.AWTAccessor;
  41 import sun.awt.SunToolkit;
  42 
  43 /**
  44  * A collection of utility methods for AWT.
  45  *
  46  * The functionality provided by the static methods of the class includes:
  47  * <ul>
  48  * <li>Setting shapes on top-level windows
  49  * <li>Setting a constant alpha value for each pixel of a top-level window
  50  * <li>Making a window non-opaque, after that it paints only explicitly
  51  * painted pixels on the screen, with arbitrary alpha values for every pixel.
  52  * <li>Setting a 'mixing-cutout' shape for a component.
  53  * </ul>
  54  * <p>
  55  * A "top-level window" is an instance of the {@code Window} class (or its
  56  * descendant, such as {@code JFrame}).
  57  * <p>
  58  * Some of the mentioned features may not be supported by the native platform.
  59  * To determine whether a particular feature is supported, the user must use
  60  * the {@code isTranslucencySupported()} method of the class passing a desired
  61  * translucency kind (a member of the {@code Translucency} enum) as an
  62  * argument.
  63  * <p>
  64  * The per-pixel alpha feature also requires the user to create her/his
  65  * windows using a translucency-capable graphics configuration.
  66  * The {@code isTranslucencyCapable()} method must
  67  * be used to verify whether any given GraphicsConfiguration supports
  68  * the translucency effects.
  69  * <p>
  70  * <b>WARNING</b>: This class is an implementation detail and only meant
  71  * for limited use outside of the core platform. This API may change
  72  * drastically between update release, and it may even be
  73  * removed or be moved in some other package(s)/class(es).
  74  */
  75 @Deprecated(forRemoval = true, since = "10")
  76 public final class AWTUtilities {
  77 
  78     /**
  79      * The AWTUtilities class should not be instantiated
  80      */
  81     private AWTUtilities() {
  82     }
  83 
  84     /** Kinds of translucency supported by the underlying system.
  85      *  @see #isTranslucencySupported
  86      */
  87     public static enum Translucency {
  88         /**
  89          * Represents support in the underlying system for windows each pixel
  90          * of which is guaranteed to be either completely opaque, with
  91          * an alpha value of 1.0, or completely transparent, with an alpha
  92          * value of 0.0.
  93          */
  94         PERPIXEL_TRANSPARENT,
  95 


 106          * between and including 0.0 and 1.0.
 107          */
 108         PERPIXEL_TRANSLUCENT;
 109     }
 110 
 111 
 112     /**
 113      * Returns whether the given level of translucency is supported by
 114      * the underlying system.
 115      *
 116      * Note that this method may sometimes return the value
 117      * indicating that the particular level is supported, but
 118      * the native windowing system may still not support the
 119      * given level of translucency (due to the bugs in
 120      * the windowing system).
 121      *
 122      * @param translucencyKind a kind of translucency support
 123      *                         (either PERPIXEL_TRANSPARENT,
 124      *                         TRANSLUCENT, or PERPIXEL_TRANSLUCENT)
 125      * @return whether the given translucency kind is supported
 126      * @deprecated use {@link GraphicsDevice#isWindowTranslucencySupported}
 127      *             instead
 128      */
 129     @Deprecated(forRemoval = true, since = "10")
 130     public static boolean isTranslucencySupported(Translucency translucencyKind) {
 131         switch (translucencyKind) {
 132             case PERPIXEL_TRANSPARENT:
 133                 return isWindowShapingSupported();
 134             case TRANSLUCENT:
 135                 return isWindowOpacitySupported();
 136             case PERPIXEL_TRANSLUCENT:
 137                 return isWindowTranslucencySupported();
 138         }
 139         return false;
 140     }
 141 
 142 
 143     /**
 144      * Returns whether the windowing system supports changing the opacity
 145      * value of top-level windows.
 146      * Note that this method may sometimes return true, but the native
 147      * windowing system may still not support the concept of
 148      * translucency (due to the bugs in the windowing system).
 149      */


 161      * the mouse event handling on this window. This is
 162      * a platform-dependent behavior.
 163      *
 164      * In order for this method to enable the translucency effect,
 165      * the isTranslucencySupported() method should indicate that the
 166      * TRANSLUCENT level of translucency is supported.
 167      *
 168      * <p>Also note that the window must not be in the full-screen mode
 169      * when setting the opacity value &lt; 1.0f. Otherwise
 170      * the IllegalArgumentException is thrown.
 171      *
 172      * @param window the window to set the opacity level to
 173      * @param opacity the opacity level to set to the window
 174      * @throws NullPointerException if the window argument is null
 175      * @throws IllegalArgumentException if the opacity is out of
 176      *                                  the range [0..1]
 177      * @throws IllegalArgumentException if the window is in full screen mode,
 178      *                                  and the opacity is less than 1.0f
 179      * @throws UnsupportedOperationException if the TRANSLUCENT translucency
 180      *                                       kind is not supported
 181      * @deprecated use {@link Window#setOpacity} instead
 182      */
 183     @Deprecated(forRemoval = true, since = "10")
 184     public static void setWindowOpacity(Window window, float opacity) {
 185         if (window == null) {
 186             throw new NullPointerException(
 187                     "The window argument should not be null.");
 188         }
 189 
 190         AWTAccessor.getWindowAccessor().setOpacity(window, opacity);
 191     }
 192 
 193     /**
 194      * Get the opacity of the window. If the opacity has not
 195      * yet being set, this method returns 1.0.
 196      *
 197      * @param window the window to get the opacity level from
 198      * @throws NullPointerException if the window argument is null
 199      * @deprecated use {@link Window#getOpacity} instead
 200      */
 201     @Deprecated(forRemoval = true, since = "10")
 202     public static float getWindowOpacity(Window window) {
 203         if (window == null) {
 204             throw new NullPointerException(
 205                     "The window argument should not be null.");
 206         }
 207 
 208         return AWTAccessor.getWindowAccessor().getOpacity(window);
 209     }
 210 
 211     /**
 212      * Returns whether the windowing system supports changing the shape
 213      * of top-level windows.
 214      * Note that this method may sometimes return true, but the native
 215      * windowing system may still not support the concept of
 216      * shaping (due to the bugs in the windowing system).
 217      * @deprecated use {@link GraphicsDevice#isWindowTranslucencySupported}
 218      *             instead
 219      */
 220     @Deprecated(forRemoval = true, since = "10")
 221     public static boolean isWindowShapingSupported() {
 222         Toolkit curToolkit = Toolkit.getDefaultToolkit();
 223         if (!(curToolkit instanceof SunToolkit)) {
 224             return false;
 225         }
 226         return ((SunToolkit)curToolkit).isWindowShapingSupported();
 227     }
 228 
 229     /**
 230      * Returns an object that implements the Shape interface and represents
 231      * the shape previously set with the call to the setWindowShape() method.
 232      * If no shape has been set yet, or the shape has been reset to null,
 233      * this method returns null.
 234      *
 235      * @param window the window to get the shape from
 236      * @return the current shape of the window
 237      * @throws NullPointerException if the window argument is null
 238      * @deprecated use {@link Window#getShape} instead
 239      */
 240     @Deprecated(forRemoval = true, since = "10")
 241     public static Shape getWindowShape(Window window) {
 242         if (window == null) {
 243             throw new NullPointerException(
 244                     "The window argument should not be null.");
 245         }
 246         return AWTAccessor.getWindowAccessor().getShape(window);
 247     }
 248 
 249     /**
 250      * Sets a shape for the given window.
 251      * If the shape argument is null, this methods restores
 252      * the default shape making the window rectangular.
 253      * <p>Note that in order to set a shape, the window must be undecorated.
 254      * If the window is decorated, this method ignores the {@code shape}
 255      * argument and resets the shape to null.
 256      * <p>Also note that the window must not be in the full-screen mode
 257      * when setting a non-null shape. Otherwise the IllegalArgumentException
 258      * is thrown.
 259      * <p>Depending on the platform, the method may return without
 260      * effecting the shape of the window if the window has a non-null warning
 261      * string ({@link Window#getWarningString()}). In this case the passed
 262      * shape object is ignored.
 263      *
 264      * @param window the window to set the shape to
 265      * @param shape the shape to set to the window
 266      * @throws NullPointerException if the window argument is null
 267      * @throws IllegalArgumentException if the window is in full screen mode,
 268      *                                  and the shape is not null
 269      * @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT
 270      *                                       translucency kind is not supported
 271      * @deprecated use {@link Window#setShape} instead
 272      */
 273     @Deprecated(forRemoval = true, since = "10")
 274     public static void setWindowShape(Window window, Shape shape) {
 275         if (window == null) {
 276             throw new NullPointerException(
 277                     "The window argument should not be null.");
 278         }
 279         AWTAccessor.getWindowAccessor().setShape(window, shape);
 280     }
 281 
 282     private static boolean isWindowTranslucencySupported() {
 283         /*
 284          * Per-pixel alpha is supported if all the conditions are TRUE:
 285          *    1. The toolkit is a sort of SunToolkit
 286          *    2. The toolkit supports translucency in general
 287          *        (isWindowTranslucencySupported())
 288          *    3. There's at least one translucency-capable
 289          *        GraphicsConfiguration
 290          */
 291 
 292         Toolkit curToolkit = Toolkit.getDefaultToolkit();
 293         if (!(curToolkit instanceof SunToolkit)) {


 355      * {@code true}.
 356      * <p>Depending on the platform, the method may return without
 357      * effecting the opaque property of the window if the window has a non-null
 358      * warning string ({@link Window#getWarningString()}). In this case
 359      * the passed 'isOpaque' value is ignored.
 360      *
 361      * @param window the window to set the shape to
 362      * @param isOpaque whether the window must be opaque (true),
 363      *                 or translucent (false)
 364      * @throws NullPointerException if the window argument is null
 365      * @throws IllegalArgumentException if the window uses
 366      *                                  a GraphicsConfiguration for which the
 367      *                                  {@code isTranslucencyCapable()}
 368      *                                  method returns false
 369      * @throws IllegalArgumentException if the window is in full screen mode,
 370      *                                  and the isOpaque is false
 371      * @throws IllegalArgumentException if the window is decorated and the
 372      * isOpaque argument is {@code false}.
 373      * @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT
 374      *                                       translucency kind is not supported
 375      * @deprecated use {@link Window#setBackground} instead
 376      */
 377     @Deprecated(forRemoval = true, since = "10")
 378     public static void setWindowOpaque(Window window, boolean isOpaque) {
 379         if (window == null) {
 380             throw new NullPointerException(
 381                     "The window argument should not be null.");
 382         }
 383         if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) {
 384             throw new UnsupportedOperationException(
 385                     "The PERPIXEL_TRANSLUCENT translucency kind is not supported");
 386         }
 387         AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque);
 388     }
 389 
 390     /**
 391      * Returns whether the window is opaque or translucent.
 392      *
 393      * @param window the window to set the shape to
 394      * @return whether the window is currently opaque (true)
 395      *         or translucent (false)
 396      * @throws NullPointerException if the window argument is null
 397      * @deprecated use {@link Window#isOpaque} instead
 398      */
 399     @Deprecated(forRemoval = true, since = "10")
 400     public static boolean isWindowOpaque(Window window) {
 401         if (window == null) {
 402             throw new NullPointerException(
 403                     "The window argument should not be null.");
 404         }
 405 
 406         return window.isOpaque();
 407     }
 408 
 409     /**
 410      * Verifies whether a given GraphicsConfiguration supports
 411      * the PERPIXEL_TRANSLUCENT kind of translucency.
 412      * All windows that are intended to be used with the {@link #setWindowOpaque}
 413      * method must be created using a GraphicsConfiguration for which this method
 414      * returns true.
 415      * <p>Note that some native systems enable the per-pixel translucency
 416      * mode for any window created using a translucency-capable
 417      * graphics configuration. However, it is highly recommended to always
 418      * invoke the setWindowOpaque() method for these windows, at least
 419      * for the sake of cross-platform compatibility reasons.
 420      *
 421      * @param gc GraphicsConfiguration
 422      * @throws NullPointerException if the gc argument is null
 423      * @return whether the given GraphicsConfiguration supports
 424      *         the translucency effects.
 425      * @deprecated use {@link GraphicsConfiguration#isTranslucencyCapable}
 426      *             instead
 427      */
 428     @Deprecated(forRemoval = true, since = "10")
 429     public static boolean isTranslucencyCapable(GraphicsConfiguration gc) {
 430         if (gc == null) {
 431             throw new NullPointerException("The gc argument should not be null");
 432         }
 433         /*
 434         return gc.isTranslucencyCapable();
 435         */
 436         Toolkit curToolkit = Toolkit.getDefaultToolkit();
 437         if (!(curToolkit instanceof SunToolkit)) {
 438             return false;
 439         }
 440         return ((SunToolkit)curToolkit).isTranslucencyCapable(gc);
 441     }
 442 
 443     /**
 444      * Sets a 'mixing-cutout' shape for the given component.
 445      *
 446      * By default a lightweight component is treated as an opaque rectangle for
 447      * the purposes of the Heavyweight/Lightweight Components Mixing feature.
 448      * This method enables developers to set an arbitrary shape to be cut out


 461      * <li><i>non-empty-shape</i> - the given shape will be cut out from
 462      * heavyweight components.
 463      * </ul>
 464      * <p>
 465      * The most common example when the 'mixing-cutout' shape is needed is a
 466      * glass pane component. The {@link JRootPane#setGlassPane} method
 467      * automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape
 468      * for the given glass pane component.  If a developer needs some other
 469      * 'mixing-cutout' shape for the glass pane (which is rare), this must be
 470      * changed manually after installing the glass pane to the root pane.
 471      * <p>
 472      * Note that the 'mixing-cutout' shape neither affects painting, nor the
 473      * mouse events handling for the given component. It is used exclusively
 474      * for the purposes of the Heavyweight/Lightweight Components Mixing
 475      * feature.
 476      *
 477      * @param component the component that needs non-default
 478      * 'mixing-cutout' shape
 479      * @param shape the new 'mixing-cutout' shape
 480      * @throws NullPointerException if the component argument is {@code null}
 481      * @deprecated use {@link Component#setMixingCutoutShape} instead
 482      */
 483     @Deprecated(forRemoval = true, since = "9")
 484     public static void setComponentMixingCutoutShape(Component component,
 485             Shape shape)
 486     {
 487         if (component == null) {
 488             throw new NullPointerException(
 489                     "The component argument should not be null.");
 490         }
 491 
 492         component.setMixingCutoutShape(shape);
 493     }
 494 }
 495 
< prev index next >