From 176a41f92e65f66b0b675d4e2908c4b5faafba53 Mon Sep 17 00:00:00 2001 From: Anthony Petrov Date: Tue, 21 Apr 2009 11:35:52 +0400 Subject: [PATCH] 6802853: API: shaped & translucent windows A public API for the feature forward-ported from 6u10. Reviewed-by: yan --- .../java/awt/GraphicsConfiguration.java | 7 +- .../classes/java/awt/GraphicsDevice.java | 44 ++- jdk/src/share/classes/java/awt/Window.java | 333 ++++++++++++------ .../share/classes/sun/awt/EmbeddedFrame.java | 4 +- jdk/src/share/classes/sun/awt/SunToolkit.java | 17 +- .../classes/sun/awt/X11GraphicsConfig.java | 2 - .../classes/sun/awt/Win32GraphicsConfig.java | 2 - .../sun/awt/windows/WComponentPeer.java | 5 +- .../classes/sun/awt/windows/WWindowPeer.java | 27 +- .../TranslucentJAppletTest.java | 2 +- .../TranslucentShapedFrameTest/TSFrame.java | 51 ++- .../TranslucentShapedFrameTest.form | 0 .../TranslucentShapedFrameTest.java | 46 +-- 13 files changed, 320 insertions(+), 220 deletions(-) rename jdk/test/{com/sun/awt/Translucency => java/awt/Window}/TranslucentJAppletTest/TranslucentJAppletTest.java (98%) rename jdk/test/{com/sun/awt/Translucency => java/awt/Window}/TranslucentShapedFrameTest/TSFrame.java (86%) rename jdk/test/{com/sun/awt/Translucency => java/awt/Window}/TranslucentShapedFrameTest/TranslucentShapedFrameTest.form (100%) rename jdk/test/{com/sun/awt/Translucency => java/awt/Window}/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java (92%) diff --git a/jdk/src/share/classes/java/awt/GraphicsConfiguration.java b/jdk/src/share/classes/java/awt/GraphicsConfiguration.java index c520d310bbe..23afe8b8674 100644 --- a/jdk/src/share/classes/java/awt/GraphicsConfiguration.java +++ b/jdk/src/share/classes/java/awt/GraphicsConfiguration.java @@ -440,13 +440,14 @@ public abstract class GraphicsConfiguration { * the {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT * PERPIXEL_TRANSLUCENT} kind of translucency. * - * @param gc GraphicsConfiguration - * @throws NullPointerException if the gc argument is null * @return whether the given GraphicsConfiguration supports * the translucency effects. + * * @see Window#setBackground(Color) + * + * @since 1.7 */ - /*public */boolean isTranslucencyCapable() { + public boolean isTranslucencyCapable() { // Overridden in subclasses return false; } diff --git a/jdk/src/share/classes/java/awt/GraphicsDevice.java b/jdk/src/share/classes/java/awt/GraphicsDevice.java index 920687150d9..c7d9b13fba6 100644 --- a/jdk/src/share/classes/java/awt/GraphicsDevice.java +++ b/jdk/src/share/classes/java/awt/GraphicsDevice.java @@ -112,10 +112,14 @@ public abstract class GraphicsDevice { */ public final static int TYPE_IMAGE_BUFFER = 2; - /** Kinds of translucency supported by the underlying system. - * @see #isTranslucencySupported + /** + * Kinds of translucency supported by the underlying system. + * + * @see #isWindowTranslucencySupported + * + * @since 1.7 */ - /*public */static enum WindowTranslucency { + public static enum WindowTranslucency { /** * Represents support in the underlying system for windows each pixel * of which is guaranteed to be either completely opaque, with @@ -246,38 +250,44 @@ public abstract class GraphicsDevice { * full-screen window is not visible, this method will make it visible. * It will remain visible when returning to windowed mode. *

- * When returning to windowed mode from an exclusive full-screen window, any - * display changes made by calling setDisplayMode are + * When entering full-screen mode, all the translucency effects are reset for + * the window. Its shape is set to {@code null}, the opacity value is set to + * 1.0f, and the background color alpha is set to 255 (completely opaque). + * These values are not restored when returning to windowed mode. + *

+ * When returning to windowed mode from an exclusive full-screen window, + * any display changes made by calling {@code setDisplayMode} are * automatically restored to their original state. * - * @param w a window to use as the full-screen window; null + * @param w a window to use as the full-screen window; {@code null} * if returning to windowed mode. Some platforms expect the * fullscreen window to be a top-level component (i.e., a Frame); * therefore it is preferable to use a Frame here rather than a * Window. + * * @see #isFullScreenSupported * @see #getFullScreenWindow * @see #setDisplayMode * @see Component#enableInputMethods * @see Component#setVisible + * * @since 1.4 */ public void setFullScreenWindow(Window w) { if (w != null) { - //XXX: The actions should be documented in some non-update release. - /* if (w.getShape() != null) { - w.setShape(w, null); - } - if (!w.isOpaque()) { - w.setOpaque(false); + w.setShape(null); } if (w.getOpacity() < 1.0f) { w.setOpacity(1.0f); } - */ + Color bgColor = w.getBackground(); + if (bgColor.getAlpha() < 255) { + bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), + bgColor.getBlue(), 255); + w.setBackground(bgColor); + } } - if (fullScreenWindow != null && windowedModeBounds != null) { // if the window went into fs mode before it was realized it may // have (0,0) dimensions @@ -469,13 +479,15 @@ public abstract class GraphicsDevice { } /** - * Returns whether the given level of translucency is supported + * Returns whether the given level of translucency is supported by * this graphics device. * * @param translucencyKind a kind of translucency support * @return whether the given translucency kind is supported + * + * @since 1.7 */ - /*public */boolean isWindowTranslucencySupported(WindowTranslucency translucencyKind) { + public boolean isWindowTranslucencySupported(WindowTranslucency translucencyKind) { switch (translucencyKind) { case PERPIXEL_TRANSPARENT: return isWindowShapingSupported(); diff --git a/jdk/src/share/classes/java/awt/Window.java b/jdk/src/share/classes/java/awt/Window.java index a95edb901d1..d991647c646 100644 --- a/jdk/src/share/classes/java/awt/Window.java +++ b/jdk/src/share/classes/java/awt/Window.java @@ -25,6 +25,7 @@ package java.awt; import java.awt.event.*; +import java.awt.geom.Path2D; import java.awt.geom.Point2D; import java.awt.im.InputContext; import java.awt.image.BufferStrategy; @@ -297,6 +298,7 @@ public class Window extends Container implements Accessible { /* * Opacity level of the window * + * @serial * @see #setOpacity(float) * @see #getOpacity() * @since 1.7 @@ -307,6 +309,7 @@ public class Window extends Container implements Accessible { * The shape assigned to this window. This field is set to null if * no shape is set (rectangular window). * + * @serial * @see #getShape() * @see #setShape(Shape) * @since 1.7 @@ -3340,32 +3343,78 @@ public class Window extends Container implements Accessible { // ******************** SHAPES & TRANSPARENCY CODE ******************** /** - * JavaDoc + * Returns the opacity of the window. + * + * @return the opacity of the window + * + * @see Window#setOpacity + * @see GraphicsDevice.WindowTranslucency + * + * @since 1.7 */ - /*public */float getOpacity() { + public float getOpacity() { synchronized (getTreeLock()) { return opacity; } } /** - * JavaDoc + * Sets the opacity of the window. + *

+ * The opacity value is in the range [0..1]. Note that setting the opacity + * level of 0 may or may not disable the mouse event handling on this + * window. This is a platform-dependent behavior. + *

+ * In order for this method to enable the translucency effect, the {@link + * GraphicsDevice#isWindowTranslucencySupported()} method must indicate that + * the {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT} + * translucency is supported. + *

+ * Also note that the window must not be in the full-screen mode when + * setting the opacity value < 1.0f. Otherwise the {@code + * IllegalComponentStateException} is thrown. + *

+ * The translucency levels of individual pixels may also be effected by the + * alpha component of their color (see {@link setBackground()}) and the + * current shape of this window (see {@link setShape()}). + * + * @param opacity the opacity level to set to the window + * + * @throws IllegalArgumentException if the opacity is out of the range + * [0..1] + * @throws IllegalComponentStateException if the window is in full screen + * mode, and the opacity is less than 1.0f + * @throws UnsupportedOperationException if the {@code + * GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT} + * translucency kind is not supported and the opacity is less than 1.0f + * + * @see Window#getOpacity + * @see Window#setBackground() + * @see Window#setShape() + * @see GraphicsDevice.WindowTranslucency + * @see GraphicsDevice#isWindowTranslucencySupported() + * + * @since 1.7 */ - /*public */void setOpacity(float opacity) { + public void setOpacity(float opacity) { synchronized (getTreeLock()) { if (opacity < 0.0f || opacity > 1.0f) { throw new IllegalArgumentException( "The value of opacity should be in the range [0.0f .. 1.0f]."); } - GraphicsConfiguration gc = getGraphicsConfiguration(); - GraphicsDevice gd = gc.getDevice(); - if (!gd.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) { - throw new UnsupportedOperationException( + if (opacity < 1.0f) { + GraphicsConfiguration gc = getGraphicsConfiguration(); + GraphicsDevice gd = gc.getDevice(); + if (gc.getDevice().getFullScreenWindow() == this) { + throw new IllegalComponentStateException( + "Setting opacity for full-screen window is not supported."); + } + if (!gd.isWindowTranslucencySupported( + GraphicsDevice.WindowTranslucency.TRANSLUCENT)) + { + throw new UnsupportedOperationException( "TRANSLUCENT translucency is not supported."); - } - if ((gc.getDevice().getFullScreenWindow() == this) && (opacity < 1.0f)) { - throw new IllegalArgumentException( - "Setting opacity for full-screen window is not supported."); + } } this.opacity = opacity; WindowPeer peer = (WindowPeer)getPeer(); @@ -3376,37 +3425,86 @@ public class Window extends Container implements Accessible { } /** - * JavaDoc + * Returns the shape of the window. + * + * The value returned by this method may not be the same as + * previously set with {@code setShape(shape)}, but it is guaranteed + * to represent the same shape. + * + * @return the shape of the window or {@code null} if no + * shape is specified for the window + * + * @see Window#setShape + * @see GraphicsDevice.WindowTranslucency + * + * @since 1.7 */ - /*public */Shape getShape() { + public Shape getShape() { synchronized (getTreeLock()) { - return shape; + return shape == null ? null : new Path2D.Float(shape); } } /** - * JavaDoc + * Sets the shape of the window. + *

+ * Setting a shape enables cutting off some parts of the window, leaving + * visible and clickable only those parts belonging to the given shape + * (see {@link Shape}). If the shape argument is null, this methods + * restores the default shape (making the window rectangular on most + * platforms.) + *

+ * The following conditions must be met in order to set a non-null shape: + *

+ * If a certain condition is not met, either the {@code + * UnsupportedOperationException} or {@code IllegalComponentStateException} + * is thrown. + *

+ * The tranlucency levels of individual pixels may also be effected by the + * alpha component of their color (see {@link setBackground()}) and the + * opacity value (see {@link setOpacity()}). See {@link + * GraphicsDevice#WindowTranslucency} for more details. * - * @param window the window to set the shape to * @param shape the shape to set to the window - * @throws IllegalArgumentException if the window is in full screen mode, - * and the shape is not null + * + * @throws IllegalComponentStateException if the shape is not {@code + * null} and the window is in full-screen mode + * @throws UnsupportedOperationException if the shape is not {@code + * null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT + * PERPIXEL_TRANSPARENT} translucency is not supported + * + * @see Window#getShape() + * @see Window#setBackgound() + * @see Window#setOpacity() + * @see GraphicsDevice.WindowTranslucency + * @see GraphicsDevice#isWindowTranslucencySupported() + * + * @since 1.7 */ - /*public */void setShape(Shape shape) { + public void setShape(Shape shape) { synchronized (getTreeLock()) { - GraphicsConfiguration gc = getGraphicsConfiguration(); - GraphicsDevice gd = gc.getDevice(); - if (!gd.isWindowTranslucencySupported( - GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT)) - { - throw new UnsupportedOperationException( + if (shape != null) { + GraphicsConfiguration gc = getGraphicsConfiguration(); + GraphicsDevice gd = gc.getDevice(); + if (gc.getDevice().getFullScreenWindow() == this) { + throw new IllegalComponentStateException( + "Setting shape for full-screen window is not supported."); + } + if (!gd.isWindowTranslucencySupported( + GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT)) + { + throw new UnsupportedOperationException( "PERPIXEL_TRANSPARENT translucency is not supported."); + } } - if ((gc.getDevice().getFullScreenWindow() == this) && (shape != null)) { - throw new IllegalArgumentException( - "Setting shape for full-screen window is not supported."); - } - this.shape = shape; + this.shape = (shape == null) ? null : new Path2D.Float(shape); WindowPeer peer = (WindowPeer)getPeer(); if (peer != null) { peer.applyShape(shape == null ? null : Region.getInstance(shape, null)); @@ -3415,66 +3513,115 @@ public class Window extends Container implements Accessible { } /** - * JavaDoc + * Gets the background color of this window. + *

+ * Note that the alpha component of the returned color indicates whether + * the window is in the non-opaque (per-pixel translucent) mode. + * + * @return this component's background color + * + * @see Window#setBackground + * @see GraphicsDevice.WindowTranslucency + */ + @Override + public Color getBackground() { + return super.getBackground(); + } + + /** + * Sets the background color of this window. + *

+ * If the windowing system supports the {@link + * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT} + * tranclucency, the alpha component of the given background color + * may effect the mode of operation for this window: it indicates whether + * this window must be opaque (alpha == 1.0f) or per-pixel translucent + * (alpha < 1.0f). All the following conditions must be met in order + * to be able to enable the per-pixel transparency mode for this window: + *

+ * If a certain condition is not met at the time of calling this method, + * the alpha component of the given background color will not effect the + * mode of operation for this window. + *

+ * When the window is per-pixel translucent, the drawing sub-system + * respects the alpha value of each individual pixel. If a pixel gets + * painted with the alpha color component equal to zero, it becomes + * visually transparent, if the alpha of the pixel is equal to 1.0f, the + * pixel is fully opaque. Interim values of the alpha color component make + * the pixel semi-transparent. In this mode the background of the window + * gets painted with the alpha value of the given background color (meaning + * that it is not painted at all if the alpha value of the argument of this + * method is equal to zero.) + *

+ * The actual level of translucency of a given pixel also depends on window + * opacity (see {@link setOpacity()}), as well as the current shape of + * this window (see {@link setShape()}). + *

+ * Note that painting a pixel with the alpha value of 0 may or may not + * disable the mouse event handling on this pixel. This is a + * platform-dependent behavior. To make sure the mouse clicks do not get + * dispatched to a particular pixel, the pixel must be excluded from the + * shape of the window. + *

+ * Enabling the per-pixel translucency mode may change the graphics + * configuration of this window due to the native platform requirements. + * + * @param bgColor the color to become this window's background color. + * + * @throws IllegalComponentStateException if the alpha value of the given + * background color is less than 1.0f and the window is in + * full-screen mode + * @throws UnsupportedOperationException if the alpha value of the given + * background color is less than 1.0f and + * {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT + * PERPIXEL_TRANSLUCENT} translucency is not supported + * + * @see Window#getBackground + * @see Window#setOpacity() + * @see Window#setShape() + * @see GraphicsDevice.WindowTranslucency + * @see GraphicsDevice#isWindowTranslucencySupported() + * @see GraphicsConfiguration#isTranslucencyCapable() */ -/* @Override public void setBackground(Color bgColor) { + Color oldBg = getBackground(); + if (oldBg != null && oldBg.equals(bgColor)) { + return; + } + super.setBackground(bgColor); + int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255; int alpha = bgColor.getAlpha(); - if (alpha < 255) { // non-opaque window + if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window GraphicsConfiguration gc = getGraphicsConfiguration(); GraphicsDevice gd = gc.getDevice(); if (gc.getDevice().getFullScreenWindow() == this) { - throw new IllegalArgumentException( + throw new IllegalComponentStateException( "Making full-screen window non opaque is not supported."); } if (!gc.isTranslucencyCapable()) { GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC(); if (capableGC == null) { - throw new IllegalArgumentException( + throw new UnsupportedOperationException( "PERPIXEL_TRANSLUCENT translucency is not supported"); } - // TODO: change GC + setGraphicsConfiguration(capableGC); } setLayersOpaque(this, false); + } else if ((oldAlpha < 255) && (alpha == 255)) { + setLayersOpaque(this, true); } - - super.setBackground(bgColor); - WindowPeer peer = (WindowPeer)getPeer(); if (peer != null) { peer.setOpaque(alpha == 255); } } -*/ - - private transient boolean opaque = true; - - void setOpaque(boolean opaque) { - synchronized (getTreeLock()) { - GraphicsConfiguration gc = getGraphicsConfiguration(); - if (!opaque && !com.sun.awt.AWTUtilities.isTranslucencyCapable(gc)) { - throw new IllegalArgumentException( - "The window must use a translucency-compatible graphics configuration"); - } - if (!com.sun.awt.AWTUtilities.isTranslucencySupported( - com.sun.awt.AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT)) - { - throw new UnsupportedOperationException( - "PERPIXEL_TRANSLUCENT translucency is not supported."); - } - if ((gc.getDevice().getFullScreenWindow() == this) && !opaque) { - throw new IllegalArgumentException( - "Making full-screen window non opaque is not supported."); - } - setLayersOpaque(this, opaque); - this.opaque = opaque; - WindowPeer peer = (WindowPeer)getPeer(); - if (peer != null) { - peer.setOpaque(opaque); - } - } - } private void updateWindow(BufferedImage backBuffer) { synchronized (getTreeLock()) { @@ -3505,10 +3652,10 @@ public class Window extends Container implements Accessible { } lp.setOpaque(isOpaque); root.setOpaque(isOpaque); - root.setDoubleBuffered(isOpaque); //XXX: the "white rect" workaround + root.setDoubleBuffered(isOpaque); if (content != null) { content.setOpaque(isOpaque); - content.setDoubleBuffered(isOpaque); //XXX: the "white rect" workaround + content.setDoubleBuffered(isOpaque); // Iterate down one level to see whether we have a JApplet // (which is also a RootPaneContainer) which requires processing @@ -3523,36 +3670,6 @@ public class Window extends Container implements Accessible { } } } - - Color bg = component.getBackground(); - boolean hasTransparentBg = TRANSPARENT_BACKGROUND_COLOR.equals(bg); - - Container container = null; - if (component instanceof Container) { - container = (Container) component; - } - - if (isOpaque) { - if (hasTransparentBg) { - // Note: we use the SystemColor.window color as the default. - // This color is used in the WindowPeer implementations to - // initialize the background color of the window if it is null. - // (This might not be the right thing to do for other - // RootPaneContainers we might be invoked with) - Color newColor = null; - if (container != null && container.preserveBackgroundColor != null) { - newColor = container.preserveBackgroundColor; - } else { - newColor = SystemColor.window; - } - component.setBackground(newColor); - } - } else { - if (!hasTransparentBg && container != null) { - container.preserveBackgroundColor = bg; - } - component.setBackground(TRANSPARENT_BACKGROUND_COLOR); - } } @@ -3620,20 +3737,16 @@ public class Window extends Container implements Accessible { window.setShape(shape); } public boolean isOpaque(Window window) { - /* - return window.getBackground().getAlpha() < 255; - */ - synchronized (window.getTreeLock()) { - return window.opaque; - } + Color bg = window.getBackground(); + return (bg != null) ? bg.getAlpha() == 255 : true; } public void setOpaque(Window window, boolean opaque) { - /* Color bg = window.getBackground(); + if (bg == null) { + bg = new Color(0, 0, 0, 0); + } window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), opaque ? 255 : 0)); - */ - window.setOpaque(opaque); } public void updateWindow(Window window, BufferedImage backBuffer) { window.updateWindow(backBuffer); diff --git a/jdk/src/share/classes/sun/awt/EmbeddedFrame.java b/jdk/src/share/classes/sun/awt/EmbeddedFrame.java index 7b77862d5f7..ee9a1e77d3d 100644 --- a/jdk/src/share/classes/sun/awt/EmbeddedFrame.java +++ b/jdk/src/share/classes/sun/awt/EmbeddedFrame.java @@ -588,9 +588,11 @@ public abstract class EmbeddedFrame extends Frame public void setOpacity(float opacity) { } + public void setOpaque(boolean isOpaque) { } - public void updateWindow(BufferedImage backBuffer) { + + public void updateWindow(BufferedImage bi) { } public void repositionSecurityWarning() { } diff --git a/jdk/src/share/classes/sun/awt/SunToolkit.java b/jdk/src/share/classes/sun/awt/SunToolkit.java index ac99f4bab5a..a6e1cb1247b 100644 --- a/jdk/src/share/classes/sun/awt/SunToolkit.java +++ b/jdk/src/share/classes/sun/awt/SunToolkit.java @@ -2038,37 +2038,34 @@ public abstract class SunToolkit extends Toolkit /** * Returns whether or not a containing top level window for the passed * component is - * {@link com.sun.awt.AWTUtilities.Translucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}. + * {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}. * * @param c a Component which toplevel's to check * @return {@code true} if the passed component is not null and has a * containing toplevel window which is opaque (so per-pixel translucency * is not enabled), {@code false} otherwise - * @see com.sun.awt.AWTUtilities.Translucency#PERPIXEL_TRANSLUCENT - * @see com.sun.awt.AWTUtilities#isWindowOpaque(Window) + * @see GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT */ public static boolean isContainingTopLevelOpaque(Component c) { Window w = getContainingWindow(c); - // return w != null && (w).isOpaque(); - return w != null && com.sun.awt.AWTUtilities.isWindowOpaque(w); + return w != null && ((Window)w).getBackground() != null && + ((Window)w).getBackground().getAlpha() == 255; } /** * Returns whether or not a containing top level window for the passed * component is - * {@link com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT TRANSLUCENT}. + * {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}. * * @param c a Component which toplevel's to check * @return {@code true} if the passed component is not null and has a * containing toplevel window which has opacity less than * 1.0f (which means that it is translucent), {@code false} otherwise - * @see com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT - * @see com.sun.awt.AWTUtilities#getWindowOpacity(Window) + * @see GraphicsDevice.WindowTranslucency#TRANSLUCENT */ public static boolean isContainingTopLevelTranslucent(Component c) { Window w = getContainingWindow(c); - // return w != null && (w).getOpacity() < 1.0f; - return w != null && com.sun.awt.AWTUtilities.getWindowOpacity((Window)w) < 1.0f; + return w != null && ((Window)w).getOpacity() < 1.0f; } /** diff --git a/jdk/src/solaris/classes/sun/awt/X11GraphicsConfig.java b/jdk/src/solaris/classes/sun/awt/X11GraphicsConfig.java index aa4b527208b..7cfa8b08393 100644 --- a/jdk/src/solaris/classes/sun/awt/X11GraphicsConfig.java +++ b/jdk/src/solaris/classes/sun/awt/X11GraphicsConfig.java @@ -451,9 +451,7 @@ public class X11GraphicsConfig extends GraphicsConfiguration } } - /* @Override - */ public boolean isTranslucencyCapable() { return isTranslucencyCapable(getAData()); } diff --git a/jdk/src/windows/classes/sun/awt/Win32GraphicsConfig.java b/jdk/src/windows/classes/sun/awt/Win32GraphicsConfig.java index 2eefb33f1ce..92bd3b8aff8 100644 --- a/jdk/src/windows/classes/sun/awt/Win32GraphicsConfig.java +++ b/jdk/src/windows/classes/sun/awt/Win32GraphicsConfig.java @@ -332,9 +332,7 @@ public class Win32GraphicsConfig extends GraphicsConfiguration // the rest of the flip actions are not supported } - /* @Override - */ public boolean isTranslucencyCapable() { //XXX: worth checking if 8-bit? Anyway, it doesn't hurt. return true; diff --git a/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java b/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java index 6ad608452a1..d5e451903ae 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java @@ -970,11 +970,12 @@ public abstract class WComponentPeer extends WObjectPeer * * Conditions which could prevent hw acceleration include the toplevel * window containing this component being - * {@link com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT TRANSLUCENT}. + * {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT + * PERPIXEL_TRANSLUCENT}. * * @return {@code true} if this component is capable of being hw * accelerated, {@code false} otherwise - * @see com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT + * @see GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT */ public boolean isAccelCapable() { boolean isTranslucent = diff --git a/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java b/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java index 4a23b779d62..8de4390f83c 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java @@ -335,16 +335,14 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer, } private void updateShape() { - // Shape shape = ((Window)target).getShape(); - Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target); + Shape shape = ((Window)target).getShape(); if (shape != null) { applyShape(Region.getInstance(shape, null)); } } private void updateOpacity() { - // float opacity = ((Window)target).getOpacity(); - float opacity = AWTAccessor.getWindowAccessor().getOpacity((Window)target); + float opacity = ((Window)target).getOpacity(); if (opacity < 1.0f) { setOpacity(opacity); } @@ -610,11 +608,13 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer, public void setOpaque(boolean isOpaque) { Window target = (Window)getTarget(); - SunToolkit sunToolkit = (SunToolkit)target.getToolkit(); - if (!sunToolkit.isWindowTranslucencySupported() || - !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration())) - { - return; + if (!isOpaque) { + SunToolkit sunToolkit = (SunToolkit)target.getToolkit(); + if (!sunToolkit.isWindowTranslucencySupported() || + !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration())) + { + return; + } } boolean opaqueChanged = this.isOpaque != isOpaque; @@ -648,9 +648,9 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer, // its shape only. To restore the correct visual appearance // of the window (i.e. w/ the correct shape) we have to reset // the shape. - Shape shape = AWTAccessor.getWindowAccessor().getShape(target); + Shape shape = ((Window)target).getShape(); if (shape != null) { - AWTAccessor.getWindowAccessor().setShape(target, shape); + ((Window)target).setShape(shape); } } @@ -664,6 +664,11 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer, return; } + Component target = (Component)this.target; + if (target.getWidth() <= 0 || target.getHeight() <= 0) { + return; + } + TranslucentWindowPainter currentPainter = painter; if (currentPainter != null) { currentPainter.updateWindow(backBuffer); diff --git a/jdk/test/com/sun/awt/Translucency/TranslucentJAppletTest/TranslucentJAppletTest.java b/jdk/test/java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java similarity index 98% rename from jdk/test/com/sun/awt/Translucency/TranslucentJAppletTest/TranslucentJAppletTest.java rename to jdk/test/java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java index 08cbe4069a3..69995055ef2 100644 --- a/jdk/test/com/sun/awt/Translucency/TranslucentJAppletTest/TranslucentJAppletTest.java +++ b/jdk/test/java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java @@ -56,7 +56,7 @@ public class TranslucentJAppletTest { frame.add(applet); frame.setBounds(100, 100, 200, 200); frame.setUndecorated(true); - com.sun.awt.AWTUtilities.setWindowOpaque(frame, false); + frame.setBackground(new Color(0, 0, 0, 0)); frame.setVisible(true); } diff --git a/jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TSFrame.java b/jdk/test/java/awt/Window/TranslucentShapedFrameTest/TSFrame.java similarity index 86% rename from jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TSFrame.java rename to jdk/test/java/awt/Window/TranslucentShapedFrameTest/TSFrame.java index 1e9cf74658e..fd86d9abf46 100644 --- a/jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TSFrame.java +++ b/jdk/test/java/awt/Window/TranslucentShapedFrameTest/TSFrame.java @@ -23,14 +23,14 @@ * have any questions. */ -import com.sun.awt.AWTUtilities; -import static com.sun.awt.AWTUtilities.Translucency.*; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsDevice.WindowTranslucency; import java.awt.GraphicsEnvironment; import java.awt.RenderingHints; import java.awt.event.MouseAdapter; @@ -93,8 +93,8 @@ public class TSFrame { } } private static class NonOpaqueJFrame extends JFrame { - NonOpaqueJFrame(GraphicsConfiguration gc) { - super("NonOpaque Swing JFrame", gc); + NonOpaqueJFrame() { + super("NonOpaque Swing JFrame"); JPanel p = new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); @@ -111,8 +111,8 @@ public class TSFrame { } private static class NonOpaqueJAppletFrame extends JFrame { JPanel p; - NonOpaqueJAppletFrame(GraphicsConfiguration gc) { - super("NonOpaque Swing JAppletFrame", gc); + NonOpaqueJAppletFrame() { + super("NonOpaque Swing JAppletFrame"); JApplet ja = new JApplet() { public void paint(Graphics g) { super.paint(g); @@ -135,8 +135,8 @@ public class TSFrame { } } private static class NonOpaqueFrame extends Frame { - NonOpaqueFrame(GraphicsConfiguration gc) { - super("NonOpaque AWT Frame", gc); + NonOpaqueFrame() { + super("NonOpaque AWT Frame"); // uncomment to test with hw child // setLayout(null); // Component c = new Panel() { @@ -166,7 +166,7 @@ public class TSFrame { } } - public static Frame createGui(GraphicsConfiguration gc, + public static Frame createGui( final boolean useSwing, final boolean useShape, final boolean useTransl, @@ -176,21 +176,16 @@ public class TSFrame { Frame frame; done = false; - if (gc == null) { - gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). - getDefaultScreenDevice().getDefaultConfiguration(); - } - if (useNonOpaque) { if (useSwing) { - frame = new NonOpaqueJFrame(gc); + frame = new NonOpaqueJFrame(); // frame = new NonOpaqueJAppletFrame(gc); } else { - frame = new NonOpaqueFrame(gc); + frame = new NonOpaqueFrame(); } animateComponent(frame); } else if (useSwing) { - frame = new JFrame("Swing Frame", gc); + frame = new JFrame("Swing Frame"); JComponent p = new JButton("Swing!"); p.setPreferredSize(new Dimension(200, 100)); frame.add("North", p); @@ -198,7 +193,7 @@ public class TSFrame { animateComponent(p); frame.add("Center", p); } else { - frame = new Frame("AWT Frame", gc) { + frame = new Frame("AWT Frame") { public void paint(Graphics g) { g.setColor(Color.red); g.fillRect(0, 0, 100, 100); @@ -239,32 +234,30 @@ public class TSFrame { frame.setLocation(450, 10); frame.pack(); + GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice(); if (useShape) { - if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSPARENT)) { + if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) { System.out.println("applying PERPIXEL_TRANSPARENT"); - AWTUtilities.setWindowShape(frame, - new Ellipse2D.Double(0, 0, frame.getWidth(), - frame.getHeight()/3)); + frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), + frame.getHeight()/3)); frame.setTitle("PERPIXEL_TRANSPARENT"); } else { System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported"); } } if (useTransl) { - if (AWTUtilities.isTranslucencySupported(TRANSLUCENT)) { + if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) { System.out.println("applying TRANSLUCENT"); - AWTUtilities.setWindowOpacity(frame, factor); + frame.setOpacity(factor); frame.setTitle("TRANSLUCENT"); } else { System.out.println("Passed: TRANSLUCENT unsupported"); } } if (useNonOpaque) { - if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSLUCENT) && - AWTUtilities.isTranslucencyCapable(gc)) - { + if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) { System.out.println("applying PERPIXEL_TRANSLUCENT"); - AWTUtilities.setWindowOpaque(frame, false); + frame.setBackground(new Color(0, 0, 0, 0)); frame.setTitle("PERPIXEL_TRANSLUCENT"); } else { System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported"); @@ -295,7 +288,7 @@ public class TSFrame { public static void main(String[] args) throws Exception { SwingUtilities.invokeLater(new Runnable() { public void run() { - TSFrame.createGui(null, useSwing, + TSFrame.createGui(useSwing, useShape, useTransl, useNonOpaque, diff --git a/jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TranslucentShapedFrameTest.form b/jdk/test/java/awt/Window/TranslucentShapedFrameTest/TranslucentShapedFrameTest.form similarity index 100% rename from jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TranslucentShapedFrameTest.form rename to jdk/test/java/awt/Window/TranslucentShapedFrameTest/TranslucentShapedFrameTest.form diff --git a/jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java b/jdk/test/java/awt/Window/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java similarity index 92% rename from jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java rename to jdk/test/java/awt/Window/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java index edb58ff67b8..bf58ba2173c 100644 --- a/jdk/test/com/sun/awt/Translucency/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java +++ b/jdk/test/java/awt/Window/TranslucentShapedFrameTest/TranslucentShapedFrameTest.java @@ -34,11 +34,11 @@ * @run main/manual/othervm -Dsun.java2d.noddraw=true TranslucentShapedFrameTest * @run main/manual/othervm -Dsun.java2d.opengl=True TranslucentShapedFrameTest */ -import com.sun.awt.AWTUtilities; -import static com.sun.awt.AWTUtilities.Translucency.*; +import java.awt.Color; import java.awt.Frame; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import java.awt.GraphicsDevice.WindowTranslucency; import java.awt.GraphicsEnvironment; import java.awt.Shape; import java.awt.geom.Ellipse2D; @@ -130,7 +130,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { jLabel2.setText("Instructions:"); - passedBtn.setBackground(new java.awt.Color(129, 255, 100)); + passedBtn.setBackground(new Color(129, 255, 100)); passedBtn.setText("Passed"); passedBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -138,7 +138,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { } }); - failedBtn.setBackground(java.awt.Color.red); + failedBtn.setBackground(Color.red); failedBtn.setText("Failed"); failedBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -234,7 +234,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { private void nonOpaqueChbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nonOpaqueChbActionPerformed if (testFrame != null) { // REMIND: this path in the test doesn't work well (test bug) -// AWTUtilities.setWindowOpaque(testFrame, !nonOpaqueChb.isSelected()); + testFrame.setBackground(new Color(0, 0, 0, nonOpaqueChb.isSelected() ? 0 : 255)); } }//GEN-LAST:event_nonOpaqueChbActionPerformed @@ -246,7 +246,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { testFrame.getWidth(), testFrame.getHeight()); } - AWTUtilities.setWindowShape(testFrame, s); + testFrame.setShape(s); } }//GEN-LAST:event_shapedCbActionPerformed @@ -254,7 +254,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { JSlider source = (JSlider)evt.getSource(); int transl = transparencySld.getValue(); if (testFrame != null) { - AWTUtilities.setWindowOpacity(testFrame, (float)transl/100f); + testFrame.setOpacity((float)transl/100f); } }//GEN-LAST:event_transparencySldStateChanged @@ -276,7 +276,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { private void createFrameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createFrameBtnActionPerformed disposeFrameBtnActionPerformed(evt); int transl = transparencySld.getValue(); - testFrame = TSFrame.createGui(gcToUse, + testFrame = TSFrame.createGui( useSwingCb.isSelected(), shapedCb.isSelected(), (transl < 100), nonOpaqueChb.isSelected(), (float)transl/100f); @@ -308,36 +308,16 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame { } private void checkEffects() { - if (!AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSPARENT)) { + GraphicsDevice gd = getGraphicsConfiguration().getDevice(); + if (!gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) { shapedCb.setEnabled(false); } - - if (!AWTUtilities.isTranslucencySupported(TRANSLUCENT)) { + if (!gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) { transparencySld.setEnabled(false); } - - GraphicsConfiguration gc = null; - if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSLUCENT)) { - gc = findGraphicsConfig(); - if (gc == null) { - nonOpaqueChb.setEnabled(false); - } + if (!gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) { + nonOpaqueChb.setEnabled(false); } - - gcToUse = gc; - } - - private GraphicsConfiguration findGraphicsConfig() { - GraphicsDevice gd = - GraphicsEnvironment.getLocalGraphicsEnvironment(). - getDefaultScreenDevice(); - GraphicsConfiguration gcs[] = gd.getConfigurations(); - for (GraphicsConfiguration gc : gcs) { - if (AWTUtilities.isTranslucencyCapable(gc)) { - return gc; - } - } - return null; } // Variables declaration - do not modify//GEN-BEGIN:variables