3330
3331 /**
3332 * Determines whether this component will be displayed on the screen.
3333 * @return <code>true</code> if the component and all of its ancestors
3334 * until a toplevel window are visible, <code>false</code> otherwise
3335 */
3336 boolean isRecursivelyVisible() {
3337 // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible.
3338 // We're overriding isRecursivelyVisible to implement this policy.
3339 return visible;
3340 }
3341
3342
3343 // ******************** SHAPES & TRANSPARENCY CODE ********************
3344
3345 /**
3346 * Returns the opacity of the window.
3347 *
3348 * @return the opacity of the window
3349 *
3350 * @see Window#setOpacity
3351 * @see GraphicsDevice.WindowTranslucency
3352 *
3353 * @since 1.7
3354 */
3355 public float getOpacity() {
3356 synchronized (getTreeLock()) {
3357 return opacity;
3358 }
3359 }
3360
3361 /**
3362 * Sets the opacity of the window.
3363 * <p>
3364 * The opacity value is in the range [0..1]. Note that setting the opacity
3365 * level of 0 may or may not disable the mouse event handling on this
3366 * window. This is a platform-dependent behavior.
3367 * <p>
3368 * In order for this method to enable the translucency effect, the {@link
3369 * GraphicsDevice#isWindowTranslucencySupported()} method must indicate that
3370 * the {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3371 * translucency is supported.
3372 * <p>
3373 * Also note that the window must not be in the full-screen mode when
3374 * setting the opacity value < 1.0f. Otherwise the {@code
3375 * IllegalComponentStateException} is thrown.
3376 * <p>
3377 * The translucency levels of individual pixels may also be effected by the
3378 * alpha component of their color (see {@link setBackground()}) and the
3379 * current shape of this window (see {@link setShape()}).
3380 *
3381 * @param opacity the opacity level to set to the window
3382 *
3383 * @throws IllegalArgumentException if the opacity is out of the range
3384 * [0..1]
3385 * @throws IllegalComponentStateException if the window is in full screen
3386 * mode, and the opacity is less than 1.0f
3387 * @throws UnsupportedOperationException if the {@code
3388 * GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3389 * translucency kind is not supported and the opacity is less than 1.0f
3390 *
3391 * @see Window#getOpacity
3392 * @see Window#setBackground()
3393 * @see Window#setShape()
3394 * @see GraphicsDevice.WindowTranslucency
3395 * @see GraphicsDevice#isWindowTranslucencySupported()
3396 *
3397 * @since 1.7
3398 */
3399 public void setOpacity(float opacity) {
3400 synchronized (getTreeLock()) {
3401 if (opacity < 0.0f || opacity > 1.0f) {
3402 throw new IllegalArgumentException(
3403 "The value of opacity should be in the range [0.0f .. 1.0f].");
3404 }
3405 if (opacity < 1.0f) {
3406 GraphicsConfiguration gc = getGraphicsConfiguration();
3407 GraphicsDevice gd = gc.getDevice();
3408 if (gc.getDevice().getFullScreenWindow() == this) {
3409 throw new IllegalComponentStateException(
3410 "Setting opacity for full-screen window is not supported.");
3411 }
3412 if (!gd.isWindowTranslucencySupported(
3413 GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3414 {
3415 throw new UnsupportedOperationException(
3417 }
3418 }
3419 this.opacity = opacity;
3420 WindowPeer peer = (WindowPeer)getPeer();
3421 if (peer != null) {
3422 peer.setOpacity(opacity);
3423 }
3424 }
3425 }
3426
3427 /**
3428 * Returns the shape of the window.
3429 *
3430 * The value returned by this method may not be the same as
3431 * previously set with {@code setShape(shape)}, but it is guaranteed
3432 * to represent the same shape.
3433 *
3434 * @return the shape of the window or {@code null} if no
3435 * shape is specified for the window
3436 *
3437 * @see Window#setShape
3438 * @see GraphicsDevice.WindowTranslucency
3439 *
3440 * @since 1.7
3441 */
3442 public Shape getShape() {
3443 synchronized (getTreeLock()) {
3444 return shape == null ? null : new Path2D.Float(shape);
3445 }
3446 }
3447
3448 /**
3449 * Sets the shape of the window.
3450 * <p>
3451 * Setting a shape enables cutting off some parts of the window, leaving
3452 * visible and clickable only those parts belonging to the given shape
3453 * (see {@link Shape}). If the shape argument is null, this methods
3454 * restores the default shape (making the window rectangular on most
3455 * platforms.)
3456 * <p>
3457 * The following conditions must be met in order to set a non-null shape:
3458 * <ul>
3459 * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3460 * PERPIXEL_TRANSPARENT} translucency kind must be supported by the
3461 * underlying system (see {@link })
3462 * <i>and</i>
3463 * <li>The window must not be in the full-screen mode (see
3464 * {@link GraphicsDevice#setFullScreenWindow()})
3465 * </ul>
3466 * If a certain condition is not met, either the {@code
3467 * UnsupportedOperationException} or {@code IllegalComponentStateException}
3468 * is thrown.
3469 * <p>
3470 * The tranlucency levels of individual pixels may also be effected by the
3471 * alpha component of their color (see {@link setBackground()}) and the
3472 * opacity value (see {@link setOpacity()}). See {@link
3473 * GraphicsDevice#WindowTranslucency} for more details.
3474 *
3475 * @param shape the shape to set to the window
3476 *
3477 * @throws IllegalComponentStateException if the shape is not {@code
3478 * null} and the window is in full-screen mode
3479 * @throws UnsupportedOperationException if the shape is not {@code
3480 * null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3481 * PERPIXEL_TRANSPARENT} translucency is not supported
3482 *
3483 * @see Window#getShape()
3484 * @see Window#setBackgound()
3485 * @see Window#setOpacity()
3486 * @see GraphicsDevice.WindowTranslucency
3487 * @see GraphicsDevice#isWindowTranslucencySupported()
3488 *
3489 * @since 1.7
3490 */
3491 public void setShape(Shape shape) {
3492 synchronized (getTreeLock()) {
3493 if (shape != null) {
3494 GraphicsConfiguration gc = getGraphicsConfiguration();
3495 GraphicsDevice gd = gc.getDevice();
3496 if (gc.getDevice().getFullScreenWindow() == this) {
3497 throw new IllegalComponentStateException(
3498 "Setting shape for full-screen window is not supported.");
3499 }
3500 if (!gd.isWindowTranslucencySupported(
3501 GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3502 {
3503 throw new UnsupportedOperationException(
3504 "PERPIXEL_TRANSPARENT translucency is not supported.");
3505 }
3506 }
3507 this.shape = (shape == null) ? null : new Path2D.Float(shape);
3508 WindowPeer peer = (WindowPeer)getPeer();
3509 if (peer != null) {
3510 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3511 }
3512 }
3513 }
3514
3515 /**
3516 * Gets the background color of this window.
3517 * <p>
3518 * Note that the alpha component of the returned color indicates whether
3519 * the window is in the non-opaque (per-pixel translucent) mode.
3520 *
3521 * @return this component's background color
3522 *
3523 * @see Window#setBackground
3524 * @see Window#isOpaque
3525 * @see GraphicsDevice.WindowTranslucency
3526 */
3527 @Override
3528 public Color getBackground() {
3529 return super.getBackground();
3530 }
3531
3532 /**
3533 * Sets the background color of this window.
3534 * <p>
3535 * If the windowing system supports the {@link
3536 * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
3537 * tranclucency, the alpha component of the given background color
3538 * may effect the mode of operation for this window: it indicates whether
3539 * this window must be opaque (alpha == 1.0f) or per-pixel translucent
3540 * (alpha < 1.0f). All the following conditions must be met in order
3541 * to be able to enable the per-pixel transparency mode for this window:
3542 * <ul>
3543 * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3544 * PERPIXEL_TRANSLUCENT} translucency must be supported
3545 * by the graphics device where this window is located <i>and</i>
3546 * <li>The window must not be in the full-screen mode (see {@link
3547 * GraphicsDevice#setFullScreenWindow()})
3548 * </ul>
3549 * If a certain condition is not met at the time of calling this method,
3550 * the alpha component of the given background color will not effect the
3551 * mode of operation for this window.
3552 * <p>
3553 * When the window is per-pixel translucent, the drawing sub-system
3554 * respects the alpha value of each individual pixel. If a pixel gets
3555 * painted with the alpha color component equal to zero, it becomes
3556 * visually transparent, if the alpha of the pixel is equal to 1.0f, the
3557 * pixel is fully opaque. Interim values of the alpha color component make
3558 * the pixel semi-transparent. In this mode the background of the window
3559 * gets painted with the alpha value of the given background color (meaning
3560 * that it is not painted at all if the alpha value of the argument of this
3561 * method is equal to zero.)
3562 * <p>
3563 * The actual level of translucency of a given pixel also depends on window
3564 * opacity (see {@link setOpacity()}), as well as the current shape of
3565 * this window (see {@link setShape()}).
3566 * <p>
3567 * Note that painting a pixel with the alpha value of 0 may or may not
3568 * disable the mouse event handling on this pixel. This is a
3569 * platform-dependent behavior. To make sure the mouse clicks do not get
3570 * dispatched to a particular pixel, the pixel must be excluded from the
3571 * shape of the window.
3572 * <p>
3573 * Enabling the per-pixel translucency mode may change the graphics
3574 * configuration of this window due to the native platform requirements.
3575 *
3576 * @param bgColor the color to become this window's background color.
3577 *
3578 * @throws IllegalComponentStateException if the alpha value of the given
3579 * background color is less than 1.0f and the window is in
3580 * full-screen mode
3581 * @throws UnsupportedOperationException if the alpha value of the given
3582 * background color is less than 1.0f and
3583 * {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3584 * PERPIXEL_TRANSLUCENT} translucency is not supported
3585 *
3586 * @see Window#getBackground
3587 * @see Window#isOpaque
3588 * @see Window#setOpacity()
3589 * @see Window#setShape()
3590 * @see GraphicsDevice.WindowTranslucency
3591 * @see GraphicsDevice#isWindowTranslucencySupported()
3592 * @see GraphicsConfiguration#isTranslucencyCapable()
3593 */
3594 @Override
3595 public void setBackground(Color bgColor) {
3596 Color oldBg = getBackground();
3597 super.setBackground(bgColor);
3598 if (oldBg != null && oldBg.equals(bgColor)) {
3599 return;
3600 }
3601 int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
3602 int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3603 if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3604 GraphicsConfiguration gc = getGraphicsConfiguration();
3605 GraphicsDevice gd = gc.getDevice();
3606 if (gc.getDevice().getFullScreenWindow() == this) {
3607 throw new IllegalComponentStateException(
3608 "Making full-screen window non opaque is not supported.");
3609 }
3610 if (!gc.isTranslucencyCapable()) {
3611 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3618 setLayersOpaque(this, false);
3619 } else if ((oldAlpha < 255) && (alpha == 255)) {
3620 setLayersOpaque(this, true);
3621 }
3622 WindowPeer peer = (WindowPeer)getPeer();
3623 if (peer != null) {
3624 peer.setOpaque(alpha == 255);
3625 }
3626 }
3627
3628 /**
3629 * Indicates if the window is currently opaque.
3630 * <p>
3631 * The method returns {@code false} if the background color of the window
3632 * is not {@code null} and the alpha component of the color is less than
3633 * 1.0f. The method returns {@code true} otherwise.
3634 *
3635 * @return {@code true} if the window is opaque, {@code false} otherwise
3636 *
3637 * @see Window#getBackground
3638 * @see Window#setBackground
3639 * @since 1.7
3640 */
3641 @Override
3642 public boolean isOpaque() {
3643 Color bg = getBackground();
3644 return bg != null ? bg.getAlpha() == 255 : true;
3645 }
3646
3647 private void updateWindow() {
3648 synchronized (getTreeLock()) {
3649 WindowPeer peer = (WindowPeer)getPeer();
3650 if (peer != null) {
3651 peer.updateWindow();
3652 }
3653 }
3654 }
3655
3656 /**
3657 * {@inheritDoc}
3658 *
|
3330
3331 /**
3332 * Determines whether this component will be displayed on the screen.
3333 * @return <code>true</code> if the component and all of its ancestors
3334 * until a toplevel window are visible, <code>false</code> otherwise
3335 */
3336 boolean isRecursivelyVisible() {
3337 // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible.
3338 // We're overriding isRecursivelyVisible to implement this policy.
3339 return visible;
3340 }
3341
3342
3343 // ******************** SHAPES & TRANSPARENCY CODE ********************
3344
3345 /**
3346 * Returns the opacity of the window.
3347 *
3348 * @return the opacity of the window
3349 *
3350 * @see Window#setOpacity(float)
3351 * @see GraphicsDevice.WindowTranslucency
3352 *
3353 * @since 1.7
3354 */
3355 public float getOpacity() {
3356 synchronized (getTreeLock()) {
3357 return opacity;
3358 }
3359 }
3360
3361 /**
3362 * Sets the opacity of the window.
3363 * <p>
3364 * The opacity value is in the range [0..1]. Note that setting the opacity
3365 * level of 0 may or may not disable the mouse event handling on this
3366 * window. This is a platform-dependent behavior.
3367 * <p>
3368 * In order for this method to enable the translucency effect, the {@link
3369 * GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)} method must indicate that
3370 * the {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3371 * translucency is supported.
3372 * <p>
3373 * Also note that the window must not be in the full-screen mode when
3374 * setting the opacity value < 1.0f. Otherwise the {@code
3375 * IllegalComponentStateException} is thrown.
3376 * <p>
3377 * The translucency levels of individual pixels may also be effected by the
3378 * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3379 * current shape of this window (see {@link #setShape(Shape)}).
3380 *
3381 * @param opacity the opacity level to set to the window
3382 *
3383 * @throws IllegalArgumentException if the opacity is out of the range
3384 * [0..1]
3385 * @throws IllegalComponentStateException if the window is in full screen
3386 * mode, and the opacity is less than 1.0f
3387 * @throws UnsupportedOperationException if the {@code
3388 * GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3389 * translucency kind is not supported and the opacity is less than 1.0f
3390 *
3391 * @see Window#getOpacity
3392 * @see Window#setBackground(Color)
3393 * @see Window#setShape(Shape)
3394 * @see GraphicsDevice.WindowTranslucency
3395 * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3396 *
3397 * @since 1.7
3398 */
3399 public void setOpacity(float opacity) {
3400 synchronized (getTreeLock()) {
3401 if (opacity < 0.0f || opacity > 1.0f) {
3402 throw new IllegalArgumentException(
3403 "The value of opacity should be in the range [0.0f .. 1.0f].");
3404 }
3405 if (opacity < 1.0f) {
3406 GraphicsConfiguration gc = getGraphicsConfiguration();
3407 GraphicsDevice gd = gc.getDevice();
3408 if (gc.getDevice().getFullScreenWindow() == this) {
3409 throw new IllegalComponentStateException(
3410 "Setting opacity for full-screen window is not supported.");
3411 }
3412 if (!gd.isWindowTranslucencySupported(
3413 GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3414 {
3415 throw new UnsupportedOperationException(
3417 }
3418 }
3419 this.opacity = opacity;
3420 WindowPeer peer = (WindowPeer)getPeer();
3421 if (peer != null) {
3422 peer.setOpacity(opacity);
3423 }
3424 }
3425 }
3426
3427 /**
3428 * Returns the shape of the window.
3429 *
3430 * The value returned by this method may not be the same as
3431 * previously set with {@code setShape(shape)}, but it is guaranteed
3432 * to represent the same shape.
3433 *
3434 * @return the shape of the window or {@code null} if no
3435 * shape is specified for the window
3436 *
3437 * @see Window#setShape(Shape)
3438 * @see GraphicsDevice.WindowTranslucency
3439 *
3440 * @since 1.7
3441 */
3442 public Shape getShape() {
3443 synchronized (getTreeLock()) {
3444 return shape == null ? null : new Path2D.Float(shape);
3445 }
3446 }
3447
3448 /**
3449 * Sets the shape of the window.
3450 * <p>
3451 * Setting a shape enables cutting off some parts of the window, leaving
3452 * visible and clickable only those parts belonging to the given shape
3453 * (see {@link Shape}). If the shape argument is null, this methods
3454 * restores the default shape (making the window rectangular on most
3455 * platforms.)
3456 * <p>
3457 * The following conditions must be met in order to set a non-null shape:
3458 * <ul>
3459 * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3460 * PERPIXEL_TRANSPARENT} translucency kind must be supported by the
3461 * underlying system
3462 * <i>and</i>
3463 * <li>The window must not be in the full-screen mode (see
3464 * {@link GraphicsDevice#setFullScreenWindow(Window)})
3465 * </ul>
3466 * If a certain condition is not met, either the {@code
3467 * UnsupportedOperationException} or {@code IllegalComponentStateException}
3468 * is thrown.
3469 * <p>
3470 * The tranlucency levels of individual pixels may also be effected by the
3471 * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3472 * opacity value (see {@link #setOpacity(float)}). See {@link
3473 * GraphicsDevice.WindowTranslucency} for more details.
3474 *
3475 * @param shape the shape to set to the window
3476 *
3477 * @throws IllegalComponentStateException if the shape is not {@code
3478 * null} and the window is in full-screen mode
3479 * @throws UnsupportedOperationException if the shape is not {@code
3480 * null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3481 * PERPIXEL_TRANSPARENT} translucency is not supported
3482 *
3483 * @see Window#getShape()
3484 * @see Window#setBackground(Color)
3485 * @see Window#setOpacity(float)
3486 * @see GraphicsDevice.WindowTranslucency
3487 * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3488 *
3489 * @since 1.7
3490 */
3491 public void setShape(Shape shape) {
3492 synchronized (getTreeLock()) {
3493 if (shape != null) {
3494 GraphicsConfiguration gc = getGraphicsConfiguration();
3495 GraphicsDevice gd = gc.getDevice();
3496 if (gc.getDevice().getFullScreenWindow() == this) {
3497 throw new IllegalComponentStateException(
3498 "Setting shape for full-screen window is not supported.");
3499 }
3500 if (!gd.isWindowTranslucencySupported(
3501 GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3502 {
3503 throw new UnsupportedOperationException(
3504 "PERPIXEL_TRANSPARENT translucency is not supported.");
3505 }
3506 }
3507 this.shape = (shape == null) ? null : new Path2D.Float(shape);
3508 WindowPeer peer = (WindowPeer)getPeer();
3509 if (peer != null) {
3510 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3511 }
3512 }
3513 }
3514
3515 /**
3516 * Gets the background color of this window.
3517 * <p>
3518 * Note that the alpha component of the returned color indicates whether
3519 * the window is in the non-opaque (per-pixel translucent) mode.
3520 *
3521 * @return this component's background color
3522 *
3523 * @see Window#setBackground(Color)
3524 * @see Window#isOpaque
3525 * @see GraphicsDevice.WindowTranslucency
3526 */
3527 @Override
3528 public Color getBackground() {
3529 return super.getBackground();
3530 }
3531
3532 /**
3533 * Sets the background color of this window.
3534 * <p>
3535 * If the windowing system supports the {@link
3536 * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
3537 * tranclucency, the alpha component of the given background color
3538 * may effect the mode of operation for this window: it indicates whether
3539 * this window must be opaque (alpha == 1.0f) or per-pixel translucent
3540 * (alpha < 1.0f). All the following conditions must be met in order
3541 * to be able to enable the per-pixel transparency mode for this window:
3542 * <ul>
3543 * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3544 * PERPIXEL_TRANSLUCENT} translucency must be supported
3545 * by the graphics device where this window is located <i>and</i>
3546 * <li>The window must not be in the full-screen mode (see {@link
3547 * GraphicsDevice#setFullScreenWindow(Window)})
3548 * </ul>
3549 * If a certain condition is not met at the time of calling this method,
3550 * the alpha component of the given background color will not effect the
3551 * mode of operation for this window.
3552 * <p>
3553 * When the window is per-pixel translucent, the drawing sub-system
3554 * respects the alpha value of each individual pixel. If a pixel gets
3555 * painted with the alpha color component equal to zero, it becomes
3556 * visually transparent, if the alpha of the pixel is equal to 1.0f, the
3557 * pixel is fully opaque. Interim values of the alpha color component make
3558 * the pixel semi-transparent. In this mode the background of the window
3559 * gets painted with the alpha value of the given background color (meaning
3560 * that it is not painted at all if the alpha value of the argument of this
3561 * method is equal to zero.)
3562 * <p>
3563 * The actual level of translucency of a given pixel also depends on window
3564 * opacity (see {@link #setOpacity(float)}), as well as the current shape of
3565 * this window (see {@link #setShape(Shape)}).
3566 * <p>
3567 * Note that painting a pixel with the alpha value of 0 may or may not
3568 * disable the mouse event handling on this pixel. This is a
3569 * platform-dependent behavior. To make sure the mouse clicks do not get
3570 * dispatched to a particular pixel, the pixel must be excluded from the
3571 * shape of the window.
3572 * <p>
3573 * Enabling the per-pixel translucency mode may change the graphics
3574 * configuration of this window due to the native platform requirements.
3575 *
3576 * @param bgColor the color to become this window's background color.
3577 *
3578 * @throws IllegalComponentStateException if the alpha value of the given
3579 * background color is less than 1.0f and the window is in
3580 * full-screen mode
3581 * @throws UnsupportedOperationException if the alpha value of the given
3582 * background color is less than 1.0f and
3583 * {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3584 * PERPIXEL_TRANSLUCENT} translucency is not supported
3585 *
3586 * @see Window#getBackground
3587 * @see Window#isOpaque
3588 * @see Window#setOpacity(float)
3589 * @see Window#setShape(Shape)
3590 * @see GraphicsDevice.WindowTranslucency
3591 * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3592 * @see GraphicsConfiguration#isTranslucencyCapable()
3593 */
3594 @Override
3595 public void setBackground(Color bgColor) {
3596 Color oldBg = getBackground();
3597 super.setBackground(bgColor);
3598 if (oldBg != null && oldBg.equals(bgColor)) {
3599 return;
3600 }
3601 int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
3602 int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3603 if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3604 GraphicsConfiguration gc = getGraphicsConfiguration();
3605 GraphicsDevice gd = gc.getDevice();
3606 if (gc.getDevice().getFullScreenWindow() == this) {
3607 throw new IllegalComponentStateException(
3608 "Making full-screen window non opaque is not supported.");
3609 }
3610 if (!gc.isTranslucencyCapable()) {
3611 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3618 setLayersOpaque(this, false);
3619 } else if ((oldAlpha < 255) && (alpha == 255)) {
3620 setLayersOpaque(this, true);
3621 }
3622 WindowPeer peer = (WindowPeer)getPeer();
3623 if (peer != null) {
3624 peer.setOpaque(alpha == 255);
3625 }
3626 }
3627
3628 /**
3629 * Indicates if the window is currently opaque.
3630 * <p>
3631 * The method returns {@code false} if the background color of the window
3632 * is not {@code null} and the alpha component of the color is less than
3633 * 1.0f. The method returns {@code true} otherwise.
3634 *
3635 * @return {@code true} if the window is opaque, {@code false} otherwise
3636 *
3637 * @see Window#getBackground
3638 * @see Window#setBackground(Color)
3639 * @since 1.7
3640 */
3641 @Override
3642 public boolean isOpaque() {
3643 Color bg = getBackground();
3644 return bg != null ? bg.getAlpha() == 255 : true;
3645 }
3646
3647 private void updateWindow() {
3648 synchronized (getTreeLock()) {
3649 WindowPeer peer = (WindowPeer)getPeer();
3650 if (peer != null) {
3651 peer.updateWindow();
3652 }
3653 }
3654 }
3655
3656 /**
3657 * {@inheritDoc}
3658 *
|