8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API

Reviewed-by: azvegint, prr
This commit is contained in:
Sergey Bylokhov 2017-10-27 14:15:02 -07:00
parent a569f5293b
commit 66812b5f48
17 changed files with 507 additions and 652 deletions
src/java.desktop
macosx/classes
share/classes
unix/classes/sun/awt/X11
windows/classes/sun/awt/windows
test/jdk
com/sun/awt/Translucency
java/awt/Window/ShapedAndTranslucentWindows
javax/swing
JComponent/6683775
JInternalFrame/6726866
JPopupMenu/7156657

@ -25,19 +25,19 @@
package com.apple.eawt;
import java.awt.*;
import java.awt.Component;
import java.awt.Window;
import javax.swing.RootPaneContainer;
import sun.lwawt.macosx.*;
import com.apple.eawt.event.GestureUtilities;
import sun.lwawt.macosx.CPlatformWindow;
/**
* Utility class perform animated full screen actions to top-level {@link Window}s.
*
* This class manages the relationship between {@link Window}s and the {@link FullScreenListener}s
* attached to them. It's design is similar to the Java SE 6u10 {@link com.sun.awt.AWTUtilities}
* attached to them. It's design is similar to the Java SE 6u10 {@code com.sun.awt.AWTUtilities}
* class which adds additional functionality to AWT Windows, without adding new API to the
* {@link java.awt.Window} class.
*
@ -45,7 +45,6 @@ import com.apple.eawt.event.GestureUtilities;
*
* @see FullScreenAdapter
* @see GestureUtilities
* @see com.sun.awt.AWTUtilities
*
* @since Java for Mac OS X 10.7 Update 1
*/

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,13 +25,15 @@
package com.apple.eawt.event;
import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JRootPane;
/**
* Registration utility class to add {@link GestureListener}s to Swing components.
*
* This class manages the relationship between {@link JComponent}s and the {@link GestureListener}s
* attached to them. It's design is similar to the Java SE 6u10 {@link com.sun.awt.AWTUtilities}
* attached to them. It's design is similar to the Java SE 6u10 {@code com.sun.awt.AWTUtilities}
* class which adds additional functionality to AWT Windows, without adding new API to the
* {@link java.awt.Window} class.
*
@ -40,7 +42,6 @@ import javax.swing.*;
*
* @see GestureAdapter
* @see JFrame#getRootPane()
* @see com.sun.awt.AWTUtilities
*
* @since Java for Mac OS X 10.5 Update 7, Java for Mac OS X 10.6 Update 2
*/

@ -25,13 +25,25 @@
package sun.lwawt.macosx;
import com.apple.eawt.FullScreenAdapter;
import com.apple.eawt.FullScreenUtilities;
import com.apple.eawt.event.FullScreenEvent;
import java.awt.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.Dialog;
import java.awt.Dialog.ModalityType;
import java.awt.event.*;
import java.beans.*;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.Insets;
import java.awt.MenuBar;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
@ -39,20 +51,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import javax.swing.*;
import javax.swing.JRootPane;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
import sun.awt.*;
import com.apple.laf.ClientPropertyApplicator;
import com.apple.laf.ClientPropertyApplicator.Property;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.ComponentAccessor;
import sun.awt.AWTAccessor.WindowAccessor;
import sun.java2d.SurfaceData;
import sun.java2d.opengl.CGLSurfaceData;
import sun.lwawt.*;
import sun.util.logging.PlatformLogger;
import com.apple.laf.*;
import com.apple.laf.ClientPropertyApplicator.Property;
import com.sun.awt.AWTUtilities;
import sun.lwawt.LWToolkit;
import sun.lwawt.LWWindowPeer;
import sun.lwawt.LWWindowPeer.PeerType;
import sun.lwawt.PlatformWindow;
import sun.util.logging.PlatformLogger;
public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
@ -172,7 +186,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
}},
new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
AWTUtilities.setWindowOpacity(c.target, value == null ? 1.0f : Float.parseFloat(value.toString()));
c.target.setOpacity(value == null ? 1.0f : Float.parseFloat(value.toString()));
}},
new Property<CPlatformWindow>(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));

@ -25,7 +25,16 @@
package com.sun.awt;
import java.awt.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.Window;
import javax.swing.JRootPane;
@ -64,6 +73,7 @@ import sun.awt.SunToolkit;
* drastically between update release, and it may even be
* removed or be moved in some other package(s)/class(es).
*/
@Deprecated(forRemoval = true, since = "10")
public final class AWTUtilities {
/**
@ -114,7 +124,10 @@ public final class AWTUtilities {
* (either PERPIXEL_TRANSPARENT,
* TRANSLUCENT, or PERPIXEL_TRANSLUCENT)
* @return whether the given translucency kind is supported
* @deprecated use {@link GraphicsDevice#isWindowTranslucencySupported}
* instead
*/
@Deprecated(forRemoval = true, since = "10")
public static boolean isTranslucencySupported(Translucency translucencyKind) {
switch (translucencyKind) {
case PERPIXEL_TRANSPARENT:
@ -166,14 +179,15 @@ public final class AWTUtilities {
* and the opacity is less than 1.0f
* @throws UnsupportedOperationException if the TRANSLUCENT translucency
* kind is not supported
* @deprecated use {@link Window#setOpacity} instead
*/
@Deprecated(forRemoval = true, since = "10")
public static void setWindowOpacity(Window window, float opacity) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
AWTAccessor.getWindowAccessor().setOpacity(window, opacity);
window.setOpacity(opacity);
}
/**
@ -182,14 +196,16 @@ public final class AWTUtilities {
*
* @param window the window to get the opacity level from
* @throws NullPointerException if the window argument is null
* @deprecated use {@link Window#getOpacity} instead
*/
@Deprecated(forRemoval = true, since = "10")
public static float getWindowOpacity(Window window) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
return AWTAccessor.getWindowAccessor().getOpacity(window);
return window.getOpacity();
}
/**
@ -198,7 +214,10 @@ public final class AWTUtilities {
* Note that this method may sometimes return true, but the native
* windowing system may still not support the concept of
* shaping (due to the bugs in the windowing system).
* @deprecated use {@link GraphicsDevice#isWindowTranslucencySupported}
* instead
*/
@Deprecated(forRemoval = true, since = "10")
public static boolean isWindowShapingSupported() {
Toolkit curToolkit = Toolkit.getDefaultToolkit();
if (!(curToolkit instanceof SunToolkit)) {
@ -216,13 +235,15 @@ public final class AWTUtilities {
* @param window the window to get the shape from
* @return the current shape of the window
* @throws NullPointerException if the window argument is null
* @deprecated use {@link Window#getShape} instead
*/
@Deprecated(forRemoval = true, since = "10")
public static Shape getWindowShape(Window window) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
return AWTAccessor.getWindowAccessor().getShape(window);
return window.getShape();
}
/**
@ -247,13 +268,15 @@ public final class AWTUtilities {
* and the shape is not null
* @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT
* translucency kind is not supported
* @deprecated use {@link Window#setShape} instead
*/
@Deprecated(forRemoval = true, since = "10")
public static void setWindowShape(Window window, Shape shape) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
AWTAccessor.getWindowAccessor().setShape(window, shape);
window.setShape(shape);
}
private static boolean isWindowTranslucencySupported() {
@ -349,7 +372,9 @@ public final class AWTUtilities {
* isOpaque argument is {@code false}.
* @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT
* translucency kind is not supported
* @deprecated use {@link Window#setBackground} instead
*/
@Deprecated(forRemoval = true, since = "10")
public static void setWindowOpaque(Window window, boolean isOpaque) {
if (window == null) {
throw new NullPointerException(
@ -359,7 +384,12 @@ public final class AWTUtilities {
throw new UnsupportedOperationException(
"The PERPIXEL_TRANSLUCENT translucency kind is not supported");
}
AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque);
Color bg = window.getBackground();
if (bg == null) {
bg = new Color(0, 0, 0, 0);
}
window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(),
isOpaque ? 255 : 0));
}
/**
@ -369,7 +399,9 @@ public final class AWTUtilities {
* @return whether the window is currently opaque (true)
* or translucent (false)
* @throws NullPointerException if the window argument is null
* @deprecated use {@link Window#isOpaque} instead
*/
@Deprecated(forRemoval = true, since = "10")
public static boolean isWindowOpaque(Window window) {
if (window == null) {
throw new NullPointerException(
@ -395,7 +427,10 @@ public final class AWTUtilities {
* @throws NullPointerException if the gc argument is null
* @return whether the given GraphicsConfiguration supports
* the translucency effects.
* @deprecated use {@link GraphicsConfiguration#isTranslucencyCapable}
* instead
*/
@Deprecated(forRemoval = true, since = "10")
public static boolean isTranslucencyCapable(GraphicsConfiguration gc) {
if (gc == null) {
throw new NullPointerException("The gc argument should not be null");
@ -448,8 +483,9 @@ public final class AWTUtilities {
* 'mixing-cutout' shape
* @param shape the new 'mixing-cutout' shape
* @throws NullPointerException if the component argument is {@code null}
* @deprecated use {@link Component#setMixingCutoutShape} instead
*/
@Deprecated(since = "9")
@Deprecated(forRemoval = true, since = "9")
public static void setComponentMixingCutoutShape(Component component,
Shape shape)
{

@ -843,10 +843,6 @@ public abstract class Component implements ImageObserver, MenuContainer,
public Rectangle getBounds(Component comp) {
return new Rectangle(comp.x, comp.y, comp.width, comp.height);
}
public void setMixingCutoutShape(Component comp, Shape shape) {
comp.setMixingCutoutShape(shape);
}
public void setGraphicsConfiguration(Component comp,
GraphicsConfiguration gc)
{

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,12 +23,10 @@
* questions.
*/
package java.awt;
import java.awt.image.ColorModel;
import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.SunToolkit;

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,9 +22,17 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt;
import java.awt.event.*;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.im.InputContext;
@ -48,7 +56,13 @@ import java.util.ResourceBundle;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.accessibility.*;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleState;
import javax.accessibility.AccessibleStateSet;
import sun.awt.AWTAccessor;
import sun.awt.AWTPermissions;
import sun.awt.AppContext;
@ -4050,26 +4064,6 @@ public class Window extends Container implements Accessible {
static {
AWTAccessor.setWindowAccessor(new AWTAccessor.WindowAccessor() {
public float getOpacity(Window window) {
return window.opacity;
}
public void setOpacity(Window window, float opacity) {
window.setOpacity(opacity);
}
public Shape getShape(Window window) {
return window.getShape();
}
public void setShape(Window window, Shape shape) {
window.setShape(shape);
}
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));
}
public void updateWindow(Window window) {
window.updateWindow();
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,16 +23,22 @@
* questions.
*/
package javax.swing;
import com.sun.awt.AWTUtilities;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.beans.PropertyVetoException;
import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
import java.awt.*;
import java.beans.PropertyVetoException;
/** This is an implementation of the <code>DesktopManager</code>.
* It currently implements the basic behaviors for managing
* <code>JInternalFrame</code>s in an arbitrary parent.
@ -315,7 +321,7 @@ public class DefaultDesktopManager implements DesktopManager, java.io.Serializab
if (p != null) {
String mode = (String)p.getClientProperty("JDesktopPane.dragMode");
Window window = SwingUtilities.getWindowAncestor(f);
if (window != null && !AWTUtilities.isWindowOpaque(window)) {
if (window != null && !window.isOpaque()) {
dragMode = DEFAULT_DRAG_MODE;
} else if (mode != null && mode.equals("outline")) {
dragMode = OUTLINE_DRAG_MODE;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -290,26 +290,6 @@ public final class AWTAccessor {
* An interface of accessor for java.awt.Window class.
*/
public interface WindowAccessor {
/*
* Get opacity level of the given window.
*/
float getOpacity(Window window);
/*
* Set opacity level to the given window.
*/
void setOpacity(Window window, float opacity);
/*
* Get a shape assigned to the given window.
*/
Shape getShape(Window window);
/*
* Set a shape to the given window.
*/
void setShape(Window window, Shape shape);
/*
* Set the opaque preoperty to the given window.
*/
void setOpaque(Window window, boolean isOpaque);
/*
* Update the image of a non-opaque (translucent) window.
*/

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,41 +22,135 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt.X11;
import java.awt.peer.TaskbarPeer;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.AWTError;
import java.awt.AWTException;
import java.awt.Button;
import java.awt.Canvas;
import java.awt.Checkbox;
import java.awt.CheckboxMenuItem;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Insets;
import java.awt.JobAttributes;
import java.awt.Label;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.PageAttributes;
import java.awt.Panel;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.PrintJob;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.ScrollPane;
import java.awt.Scrollbar;
import java.awt.SystemColor;
import java.awt.SystemTray;
import java.awt.Taskbar;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Window;
import java.awt.datatransfer.Clipboard;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.awt.im.InputMethodHighlight;
import java.awt.im.spi.InputMethodDescriptor;
import java.awt.peer.*;
import java.awt.peer.ButtonPeer;
import java.awt.peer.CanvasPeer;
import java.awt.peer.CheckboxMenuItemPeer;
import java.awt.peer.CheckboxPeer;
import java.awt.peer.ChoicePeer;
import java.awt.peer.DesktopPeer;
import java.awt.peer.DialogPeer;
import java.awt.peer.FileDialogPeer;
import java.awt.peer.FontPeer;
import java.awt.peer.FramePeer;
import java.awt.peer.KeyboardFocusManagerPeer;
import java.awt.peer.LabelPeer;
import java.awt.peer.ListPeer;
import java.awt.peer.MenuBarPeer;
import java.awt.peer.MenuItemPeer;
import java.awt.peer.MenuPeer;
import java.awt.peer.MouseInfoPeer;
import java.awt.peer.PanelPeer;
import java.awt.peer.PopupMenuPeer;
import java.awt.peer.RobotPeer;
import java.awt.peer.ScrollPanePeer;
import java.awt.peer.ScrollbarPeer;
import java.awt.peer.SystemTrayPeer;
import java.awt.peer.TaskbarPeer;
import java.awt.peer.TextAreaPeer;
import java.awt.peer.TextFieldPeer;
import java.awt.peer.TrayIconPeer;
import java.awt.peer.WindowPeer;
import java.beans.PropertyChangeListener;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
import sun.awt.*;
import sun.awt.AWTAccessor;
import sun.awt.AWTPermissions;
import sun.awt.AppContext;
import sun.awt.DisplayChangedListener;
import sun.awt.LightweightFrame;
import sun.awt.SunToolkit;
import sun.awt.UNIXToolkit;
import sun.awt.X11GraphicsConfig;
import sun.awt.X11GraphicsDevice;
import sun.awt.X11GraphicsEnvironment;
import sun.awt.XSettings;
import sun.awt.datatransfer.DataTransferer;
import sun.font.FontConfigManager;
import sun.java2d.SunGraphicsEnvironment;
import sun.awt.util.PerformanceLogger;
import sun.awt.util.ThreadGroupUtils;
import sun.font.FontConfigManager;
import sun.java2d.SunGraphicsEnvironment;
import sun.print.PrintJob2D;
import sun.security.action.GetPropertyAction;
import sun.security.action.GetBooleanAction;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger;
import static sun.awt.X11.XlibUtil.scaleDown;
public final class XToolkit extends UNIXToolkit implements Runnable {
@ -2587,7 +2681,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
@Override
public boolean isWindowTranslucencySupported() {
//NOTE: it may not be supported. The actual check is being performed
// at com.sun.awt.AWTUtilities(). In X11 we need to check
// at java.awt.GraphicsDevice. In X11 we need to check
// whether there's any translucency-capable GC available.
return true;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,42 +22,50 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt.X11;
import java.awt.*;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.SystemColor;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.peer.ComponentPeer;
import java.awt.peer.WindowPeer;
import java.io.UnsupportedEncodingException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
import sun.awt.AWTAccessor.ComponentAccessor;
import sun.util.logging.PlatformLogger;
import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.ComponentAccessor;
import sun.awt.DisplayChangedListener;
import sun.awt.IconInfo;
import sun.awt.SunToolkit;
import sun.awt.X11GraphicsDevice;
import sun.awt.X11GraphicsEnvironment;
import sun.awt.IconInfo;
import sun.java2d.pipe.Region;
import sun.util.logging.PlatformLogger;
class XWindowPeer extends XPanelPeer implements WindowPeer,
DisplayChangedListener {
@ -446,16 +454,14 @@ class XWindowPeer extends XPanelPeer 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);
}
@ -2375,7 +2381,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
public void print(Graphics g) {
// We assume we print the whole frame,
// so we expect no clip was set previously
Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
Shape shape = ((Window)target).getShape();
if (shape != null) {
g.setClip(shape);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,23 +22,48 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt.windows;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.peer.*;
import java.beans.*;
import java.util.*;
import java.util.List;
import sun.util.logging.PlatformLogger;
import java.awt.AWTEvent;
import java.awt.AWTEventMulticaster;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.SystemColor;
import java.awt.Window;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.geom.AffineTransform;
import sun.awt.*;
import java.awt.image.DataBufferInt;
import java.awt.peer.WindowPeer;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.LinkedList;
import java.util.List;
import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.DisplayChangedListener;
import sun.awt.SunToolkit;
import sun.awt.Win32GraphicsConfig;
import sun.awt.Win32GraphicsDevice;
import sun.awt.Win32GraphicsEnvironment;
import sun.java2d.pipe.Region;
import sun.swing.SwingUtilities2;
import sun.util.logging.PlatformLogger;
public class WWindowPeer extends WPanelPeer implements WindowPeer,
DisplayChangedListener
@ -671,7 +696,7 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
public void print(Graphics g) {
// We assume we print the whole frame,
// so we expect no clip was set previously
Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
Shape shape = ((Window)target).getShape();
if (shape != null) {
g.setClip(shape);
}

@ -1,467 +0,0 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test %W% %E%
@key headful
@bug 6594131
@summary Tests the AWTUtilities.get/setWindowOpacity() methods
@author anthony.petrov@...: area=awt.toplevel
@modules java.desktop/com.sun.awt
@run main WindowOpacity
*/
import java.awt.*;
import java.awt.event.*;
import com.sun.awt.AWTUtilities;
public class WindowOpacity
{
//*** test-writer defined static variables go here ***
private static Robot robot;
private static void init()
{
//*** Create instructions for the user here ***
String[] instructions =
{
"This is an AUTOMATIC test, simply wait until it is done.",
"The result (passed or failed) will be shown in the",
"message window below."
};
Sysout.createDialog( );
Sysout.printInstructions( instructions );
if (!AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.TRANSLUCENT)) {
System.out.println("Either the Toolkit or the native system does not support controlling the window opacity level.");
pass();
}
try {
robot = new Robot();
}catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException ("Unexpected failure");
}
boolean passed;
Frame f = new Frame("Opacity test");
f.setUndecorated(true);
passed = false;
try {
AWTUtilities.getWindowOpacity(null);
} catch (NullPointerException e) {
passed = true;
}
if (!passed) {
fail("getWindowOpacity() allows passing null.");
}
passed = false;
try {
AWTUtilities.setWindowOpacity(null, 0.5f);
} catch (NullPointerException e) {
passed = true;
}
if (!passed) {
fail("setWindowOpacity() allows passing null.");
}
float curOpacity = AWTUtilities.getWindowOpacity(f);
if (curOpacity < 1.0f || curOpacity > 1.0f) {
fail("getWindowOpacity() reports the initial opacity level other than 1.0: " + curOpacity);
}
passed = false;
try {
AWTUtilities.setWindowOpacity(f, -0.5f);
} catch (IllegalArgumentException e) {
passed = true;
}
if (!passed) {
fail("setWindowOpacity() allows passing negative opacity level.");
}
passed = false;
try {
AWTUtilities.setWindowOpacity(f, 1.5f);
} catch (IllegalArgumentException e) {
passed = true;
}
if (!passed) {
fail("setWindowOpacity() allows passing opacity level greater than 1.0.");
}
AWTUtilities.setWindowOpacity(f, 0.5f);
curOpacity = AWTUtilities.getWindowOpacity(f);
if (curOpacity < 0.5f || curOpacity > 0.5f) {
fail("getWindowOpacity() reports the opacity level that differs from the value set with setWindowOpacity: " + curOpacity);
}
AWTUtilities.setWindowOpacity(f, 0.75f);
curOpacity = AWTUtilities.getWindowOpacity(f);
if (curOpacity < 0.75f || curOpacity > 0.75f) {
fail("getWindowOpacity() reports the opacity level that differs from the value set with setWindowOpacity the second time: " + curOpacity);
}
f.setBounds(100, 100, 300, 200);
f.setVisible(true);
robot.waitForIdle();
curOpacity = AWTUtilities.getWindowOpacity(f);
if (curOpacity < 0.75f || curOpacity > 0.75f) {
fail("getWindowOpacity() reports the opacity level that differs from the value set with setWindowOpacity before showing the frame: " + curOpacity);
}
AWTUtilities.setWindowOpacity(f, 0.5f);
robot.waitForIdle();
curOpacity = AWTUtilities.getWindowOpacity(f);
if (curOpacity < 0.5f || curOpacity > 0.5f) {
fail("getWindowOpacity() reports the opacity level that differs from the value set with setWindowOpacity after showing the frame: " + curOpacity);
}
WindowOpacity.pass();
}//End init()
/*****************************************************
* Standard Test Machinery Section
* DO NOT modify anything in this section -- it's a
* standard chunk of code which has all of the
* synchronisation necessary for the test harness.
* By keeping it the same in all tests, it is easier
* to read and understand someone else's test, as
* well as insuring that all tests behave correctly
* with the test harness.
* There is a section following this for test-
* classes
******************************************************/
private static boolean theTestPassed = false;
private static boolean testGeneratedInterrupt = false;
private static String failureMessage = "";
private static Thread mainThread = null;
private static int sleepTime = 300000;
// Not sure about what happens if multiple of this test are
// instantiated in the same VM. Being static (and using
// static vars), it aint gonna work. Not worrying about
// it for now.
public static void main( String args[] ) throws InterruptedException
{
mainThread = Thread.currentThread();
try
{
init();
}
catch( TestPassedException e )
{
//The test passed, so just return from main and harness will
// interepret this return as a pass
return;
}
//At this point, neither test pass nor test fail has been
// called -- either would have thrown an exception and ended the
// test, so we know we have multiple threads.
//Test involves other threads, so sleep and wait for them to
// called pass() or fail()
try
{
Thread.sleep( sleepTime );
//Timed out, so fail the test
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
}
catch (InterruptedException e)
{
//The test harness may have interrupted the test. If so, rethrow the exception
// so that the harness gets it and deals with it.
if( ! testGeneratedInterrupt ) throw e;
//reset flag in case hit this code more than once for some reason (just safety)
testGeneratedInterrupt = false;
if ( theTestPassed == false )
{
throw new RuntimeException( failureMessage );
}
}
}//main
public static synchronized void setTimeoutTo( int seconds )
{
sleepTime = seconds * 1000;
}
public static synchronized void pass()
{
Sysout.println( "The test passed." );
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
//first check if this is executing in main thread
if ( mainThread == Thread.currentThread() )
{
//Still in the main thread, so set the flag just for kicks,
// and throw a test passed exception which will be caught
// and end the test.
theTestPassed = true;
throw new TestPassedException();
}
theTestPassed = true;
testGeneratedInterrupt = true;
mainThread.interrupt();
}//pass()
public static synchronized void fail()
{
//test writer didn't specify why test failed, so give generic
fail( "it just plain failed! :-)" );
}
public static synchronized void fail( String whyFailed )
{
Sysout.println( "The test failed: " + whyFailed );
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
//check if this called from main thread
if ( mainThread == Thread.currentThread() )
{
//If main thread, fail now 'cause not sleeping
throw new RuntimeException( whyFailed );
}
theTestPassed = false;
testGeneratedInterrupt = true;
failureMessage = whyFailed;
mainThread.interrupt();
}//fail()
}// class WindowOpacity
//This exception is used to exit from any level of call nesting
// when it's determined that the test has passed, and immediately
// end the test.
class TestPassedException extends RuntimeException
{
}
//*********** End Standard Test Machinery Section **********
//************ Begin classes defined for the test ****************
// if want to make listeners, here is the recommended place for them, then instantiate
// them in init()
/* Example of a class which may be written as part of a test
class NewClass implements anInterface
{
static int newVar = 0;
public void eventDispatched(AWTEvent e)
{
//Counting events to see if we get enough
eventCount++;
if( eventCount == 20 )
{
//got enough events, so pass
WindowOpacity.pass();
}
else if( tries == 20 )
{
//tried too many times without getting enough events so fail
WindowOpacity.fail();
}
}// eventDispatched()
}// NewClass class
*/
//************** End classes defined for the test *******************
/****************************************************
Standard Test Machinery
DO NOT modify anything below -- it's a standard
chunk of code whose purpose is to make user
interaction uniform, and thereby make it simpler
to read and understand someone else's test.
****************************************************/
/**
This is part of the standard test machinery.
It creates a dialog (with the instructions), and is the interface
for sending text messages to the user.
To print the instructions, send an array of strings to Sysout.createDialog
WithInstructions method. Put one line of instructions per array entry.
To display a message for the tester to see, simply call Sysout.println
with the string to be displayed.
This mimics System.out.println but works within the test harness as well
as standalone.
*/
class Sysout
{
private static TestDialog dialog;
public static void createDialogWithInstructions( String[] instructions )
{
dialog = new TestDialog( new Frame(), "Instructions" );
dialog.printInstructions( instructions );
dialog.setVisible(true);
println( "Any messages for the tester will display here." );
}
public static void createDialog( )
{
dialog = new TestDialog( new Frame(), "Instructions" );
String[] defInstr = { "Instructions will appear here. ", "" } ;
dialog.printInstructions( defInstr );
dialog.setVisible(true);
println( "Any messages for the tester will display here." );
}
public static void printInstructions( String[] instructions )
{
dialog.printInstructions( instructions );
}
public static void println( String messageIn )
{
dialog.displayMessage( messageIn );
System.out.println(messageIn);
}
}// Sysout class
/**
This is part of the standard test machinery. It provides a place for the
test instructions to be displayed, and a place for interactive messages
to the user to be displayed.
To have the test instructions displayed, see Sysout.
To have a message to the user be displayed, see Sysout.
Do not call anything in this dialog directly.
*/
class TestDialog extends Dialog
{
TextArea instructionsText;
TextArea messageText;
int maxStringLength = 80;
//DO NOT call this directly, go through Sysout
public TestDialog( Frame frame, String name )
{
super( frame, name );
int scrollBoth = TextArea.SCROLLBARS_BOTH;
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
add( "North", instructionsText );
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
add("Center", messageText);
pack();
setVisible(true);
}// TestDialog()
//DO NOT call this directly, go through Sysout
public void printInstructions( String[] instructions )
{
//Clear out any current instructions
instructionsText.setText( "" );
//Go down array of instruction strings
String printStr, remainingStr;
for( int i=0; i < instructions.length; i++ )
{
//chop up each into pieces maxSringLength long
remainingStr = instructions[ i ];
while( remainingStr.length() > 0 )
{
//if longer than max then chop off first max chars to print
if( remainingStr.length() >= maxStringLength )
{
//Try to chop on a word boundary
int posOfSpace = remainingStr.
lastIndexOf( ' ', maxStringLength - 1 );
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
printStr = remainingStr.substring( 0, posOfSpace + 1 );
remainingStr = remainingStr.substring( posOfSpace + 1 );
}
//else just print
else
{
printStr = remainingStr;
remainingStr = "";
}
instructionsText.append( printStr + "\n" );
}// while
}// for
}//printInstructions()
//DO NOT call this directly, go through Sysout
public void displayMessage( String messageIn )
{
messageText.append( messageIn + "\n" );
System.out.println(messageIn);
}
}// TestDialog class

@ -0,0 +1,139 @@
/*
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@key headful
@bug 6594131 8186617
@summary Tests the Window.get/setOpacity() methods
*/
import java.awt.AWTException;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;
public class WindowOpacity {
public static void main(String[] args) throws Exception {
GraphicsDevice gd =
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
if (!gd.isWindowTranslucencySupported(
GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {
System.out.println(
"Either the Toolkit or the native system does not support"
+ " controlling the window opacity level.");
return;
}
Frame f = new Frame("Opacity test");
try {
test(f);
} finally {
f.dispose();
}
}
private static void test(final Frame f) throws AWTException {
boolean passed;
f.setUndecorated(true);
float curOpacity = f.getOpacity();
if (curOpacity < 1.0f || curOpacity > 1.0f) {
throw new RuntimeException(
"getOpacity() reports the initial opacity level "
+ "other than 1.0: " + curOpacity);
}
passed = false;
try {
f.setOpacity(-0.5f);
} catch (IllegalArgumentException e) {
passed = true;
}
if (!passed) {
throw new RuntimeException(
"setOpacity() allows passing negative opacity level.");
}
passed = false;
try {
f.setOpacity(1.5f);
} catch (IllegalArgumentException e) {
passed = true;
}
if (!passed) {
throw new RuntimeException(
"setOpacity() allows passing opacity level greater than 1.0.");
}
f.setOpacity(0.5f);
curOpacity = f.getOpacity();
if (curOpacity < 0.5f || curOpacity > 0.5f) {
throw new RuntimeException(
"setOpacity() reports the opacity level that "
+ "differs from the value set with "
+ "setWindowOpacity: " + curOpacity);
}
f.setOpacity(0.75f);
curOpacity = f.getOpacity();
if (curOpacity < 0.75f || curOpacity > 0.75f) {
throw new RuntimeException(
"getOpacity() reports the opacity level that "
+ "differs from the value set with "
+ "setWindowOpacity the second time: "
+ curOpacity);
}
f.setBounds(100, 100, 300, 200);
f.setVisible(true);
Robot robot = new Robot();
robot.waitForIdle();
curOpacity = f.getOpacity();
if (curOpacity < 0.75f || curOpacity > 0.75f) {
throw new RuntimeException(
"getOpacity() reports the opacity level that "
+ "differs from the value set with "
+ "setWindowOpacity before showing the frame: "
+ curOpacity);
}
f.setOpacity(0.5f);
robot.waitForIdle();
curOpacity = f.getOpacity();
if (curOpacity < 0.5f || curOpacity > 0.5f) {
throw new RuntimeException(
"getOpacity() reports the opacity level that "
+ "differs from the value set with "
+ "setWindowOpacity after showing the frame: "
+ curOpacity);
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,29 +24,32 @@
/*
* @test
* @key headful
* @bug 6683775 6794764
* @summary Painting artifacts is seen when panel is made setOpaque(false) for a translucent window
* @author Alexander Potochkin
* @modules java.desktop/com.sun.awt
* java.desktop/sun.awt
* @run main bug6683775
* @bug 6683775 6794764 8186617
* @summary Painting artifacts is seen when panel is made setOpaque(false) for a
* translucent window
*/
import com.sun.awt.AWTUtilities;
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Window;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class bug6683775 {
static final int LOC = 100,
SIZE = 200;
public static void main(String[] args) throws Exception {
GraphicsConfiguration gc = getGC();
if (!AWTUtilities.isTranslucencySupported(
AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT)
|| gc == null) {
if (gc == null || !gc.getDevice().isWindowTranslucencySupported(
GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
return;
}
Robot robot = new Robot();
@ -65,7 +68,7 @@ public class bug6683775 {
JPanel p = new JPanel();
p.setOpaque(false);
testFrame.add(p);
AWTUtilities.setWindowOpaque(testFrame, false);
setOpaque(testFrame, false);
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testFrame.setBounds(LOC, LOC, SIZE, SIZE);
testFrame.setVisible(true);
@ -78,17 +81,28 @@ public class bug6683775 {
BufferedImage capture =
robot.createScreenCapture(new Rectangle(LOC, LOC, SIZE, SIZE));
SwingUtilities.invokeAndWait(testFrame::dispose);
int redRGB = Color.RED.getRGB();
if (redRGB != capture.getRGB(SIZE/2, SIZE/2)) {
throw new RuntimeException("Transparent frame is not transparent!");
}
}
public static 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));
}
private static GraphicsConfiguration getGC() {
GraphicsConfiguration transparencyCapableGC =
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
if (!AWTUtilities.isTranslucencyCapable(transparencyCapableGC)) {
if (!transparencyCapableGC.isTranslucencyCapable()) {
transparencyCapableGC = null;
GraphicsEnvironment env =
@ -98,7 +112,7 @@ public class bug6683775 {
for (int i = 0; i < devices.length && transparencyCapableGC == null; i++) {
GraphicsConfiguration[] configs = devices[i].getConfigurations();
for (int j = 0; j < configs.length && transparencyCapableGC == null; j++) {
if (AWTUtilities.isTranslucencyCapable(configs[j])) {
if (configs[j].isTranslucencyCapable()) {
transparencyCapableGC = configs[j];
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,15 +22,20 @@
*/
/* @test
@bug 6726866
@summary Repainting artifacts when resizing or dragging JInternalFrames in non-opaque toplevel
@author Alexander Potochkin
@bug 6726866 8186617
@summary Repainting artifacts when resizing or dragging JInternalFrames in
non-opaque toplevel
@run applet/manual=yesno bug6726866.html
*/
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Method;
import java.awt.Color;
import java.awt.Window;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
public class bug6726866 extends JApplet {
@ -54,14 +59,12 @@ public class bug6726866 extends JApplet {
frame.toFront();
}
private void setWindowNonOpaque(Window w) {
try {
Class<?> c = Class.forName("com.sun.awt.AWTUtilities");
Method m = c.getMethod("setWindowOpaque", Window.class, boolean.class);
m.invoke(null, w, false);
}
catch (Exception e) {
e.printStackTrace();
public static void setWindowNonOpaque(Window window) {
Color bg = window.getBackground();
if (bg == null) {
bg = new Color(0, 0, 0, 0);
}
window.setBackground(
new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), 0));
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,23 +21,33 @@
* questions.
*/
import com.sun.awt.AWTUtilities;
import sun.awt.SunToolkit;
import javax.swing.*;
import java.awt.*;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.util.concurrent.Callable;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import sun.awt.SunToolkit;
/*
@test
@key headful
@bug 7156657
@summary Version 7 doesn't support translucent popup menus against a translucent window
@key headful
@bug 7156657 8186617
@summary Version 7 doesn't support translucent popup menus against a
translucent window
@library ../../regtesthelpers
@author Pavel Porvatov
@modules java.desktop/com.sun.awt
java.desktop/sun.awt
@modules java.desktop/sun.awt
*/
public class bug7156657 {
private static JFrame lowerFrame;
@ -54,8 +64,7 @@ public class bug7156657 {
@Override
public Boolean call() throws Exception {
frame = createFrame();
if (!AWTUtilities.isTranslucencyCapable(frame.getGraphicsConfiguration())) {
if (!frame.getGraphicsConfiguration().isTranslucencyCapable()) {
System.out.println("Translucency is not supported, the test skipped");
return true;
@ -71,7 +80,7 @@ public class bug7156657 {
popupMenu.add(new TransparentMenuItem("2222"));
popupMenu.add(new TransparentMenuItem("3333"));
AWTUtilities.setWindowOpaque(frame, false);
setOpaque(frame, false);
JPanel pnContent = new JPanel();
pnContent.setBackground(new Color(255, 255, 255, 128));
frame.add(pnContent);
@ -132,6 +141,14 @@ public class bug7156657 {
System.out.println("The test passed");
}
public static 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));
}
private static JFrame createFrame() {
JFrame result = new JFrame();