--- old/src/java.desktop/macosx/classes/com/apple/eawt/FullScreenUtilities.java 2017-08-22 12:28:31.000000000 -0700 +++ new/src/java.desktop/macosx/classes/com/apple/eawt/FullScreenUtilities.java 2017-08-22 12:28:31.000000000 -0700 @@ -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 @@ * * @see FullScreenAdapter * @see GestureUtilities - * @see com.sun.awt.AWTUtilities * * @since Java for Mac OS X 10.7 Update 1 */ --- old/src/java.desktop/macosx/classes/com/apple/eawt/event/GestureUtilities.java 2017-08-22 12:28:32.000000000 -0700 +++ new/src/java.desktop/macosx/classes/com/apple/eawt/event/GestureUtilities.java 2017-08-22 12:28:32.000000000 -0700 @@ -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 @@ * * @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 */ --- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2017-08-22 12:28:33.000000000 -0700 +++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2017-08-22 12:28:33.000000000 -0700 @@ -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.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 @@ c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString())); }}, new Property(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(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) { c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString())); --- old/src/java.desktop/share/classes/java/awt/Component.java 2017-08-22 12:28:34.000000000 -0700 +++ new/src/java.desktop/share/classes/java/awt/Component.java 2017-08-22 12:28:34.000000000 -0700 @@ -843,10 +843,6 @@ 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) { --- old/src/java.desktop/share/classes/java/awt/GraphicsDevice.java 2017-08-22 12:28:35.000000000 -0700 +++ new/src/java.desktop/share/classes/java/awt/GraphicsDevice.java 2017-08-22 12:28:35.000000000 -0700 @@ -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; --- old/src/java.desktop/share/classes/java/awt/Window.java 2017-08-22 12:28:36.000000000 -0700 +++ new/src/java.desktop/share/classes/java/awt/Window.java 2017-08-22 12:28:36.000000000 -0700 @@ -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.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 @@ 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(); } --- old/src/java.desktop/share/classes/javax/swing/DefaultDesktopManager.java 2017-08-22 12:28:37.000000000 -0700 +++ new/src/java.desktop/share/classes/javax/swing/DefaultDesktopManager.java 2017-08-22 12:28:37.000000000 -0700 @@ -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 DesktopManager. * It currently implements the basic behaviors for managing * JInternalFrames in an arbitrary parent. @@ -315,7 +321,7 @@ 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; --- old/src/java.desktop/share/classes/sun/awt/AWTAccessor.java 2017-08-22 12:28:38.000000000 -0700 +++ new/src/java.desktop/share/classes/sun/awt/AWTAccessor.java 2017-08-22 12:28:37.000000000 -0700 @@ -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 @@ -25,31 +25,59 @@ package sun.awt; -import jdk.internal.misc.Unsafe; - -import javax.accessibility.AccessibleContext; -import java.awt.*; -import java.awt.event.FocusEvent.Cause; +import java.awt.AWTEvent; +import java.awt.AWTException; +import java.awt.BufferCapabilities; +import java.awt.CheckboxMenuItem; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.DefaultKeyboardFocusManager; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FileDialog; +import java.awt.Font; +import java.awt.Frame; +import java.awt.GraphicsConfiguration; +import java.awt.KeyboardFocusManager; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuComponent; +import java.awt.MenuContainer; +import java.awt.MenuItem; +import java.awt.MenuShortcut; +import java.awt.Point; +import java.awt.PopupMenu; +import java.awt.Rectangle; +import java.awt.ScrollPaneAdjustable; +import java.awt.SystemColor; +import java.awt.SystemTray; +import java.awt.Toolkit; +import java.awt.TrayIcon; +import java.awt.Window; import java.awt.dnd.DragSourceContext; import java.awt.dnd.DropTargetContext; import java.awt.dnd.peer.DragSourceContextPeer; import java.awt.dnd.peer.DropTargetContextPeer; -import java.awt.event.AWTEventListener; +import java.awt.event.FocusEvent.Cause; import java.awt.event.InputEvent; import java.awt.event.InvocationEvent; import java.awt.event.KeyEvent; import java.awt.geom.Point2D; import java.awt.image.BufferStrategy; import java.awt.peer.ComponentPeer; - import java.awt.peer.MenuComponentPeer; +import java.io.File; import java.lang.reflect.InvocationTargetException; import java.security.AccessControlContext; - -import java.io.File; import java.util.ResourceBundle; import java.util.Vector; + import javax.accessibility.AccessibleBundle; +import javax.accessibility.AccessibleContext; + +import jdk.internal.misc.Unsafe; /** * The AWTAccessor utility class. @@ -290,26 +318,6 @@ */ 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. */ void updateWindow(Window window); --- old/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java 2017-08-22 12:28:38.000000000 -0700 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java 2017-08-22 12:28:38.000000000 -0700 @@ -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 { @@ -2598,7 +2692,7 @@ @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; } --- old/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java 2017-08-22 12:28:39.000000000 -0700 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java 2017-08-22 12:28:39.000000000 -0700 @@ -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.*; +package sun.awt.X11; +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 @@ } 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 @@ 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); } --- old/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java 2017-08-22 12:28:40.000000000 -0700 +++ new/src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java 2017-08-22 12:28:40.000000000 -0700 @@ -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.*; +package sun.awt.windows; -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 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); } --- old/test/javax/swing/JComponent/6683775/bug6683775.java 2017-08-22 12:28:41.000000000 -0700 +++ new/test/javax/swing/JComponent/6683775/bug6683775.java 2017-08-22 12:28:41.000000000 -0700 @@ -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 @@ 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 @@ 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 @@ 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]; } } --- old/test/javax/swing/JInternalFrame/6726866/bug6726866.java 2017-08-22 12:28:42.000000000 -0700 +++ new/test/javax/swing/JInternalFrame/6726866/bug6726866.java 2017-08-22 12:28:42.000000000 -0700 @@ -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 @@ 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)); } } --- old/test/javax/swing/JPopupMenu/7156657/bug7156657.java 2017-08-22 12:28:43.000000000 -0700 +++ new/test/javax/swing/JPopupMenu/7156657/bug7156657.java 2017-08-22 12:28:42.000000000 -0700 @@ -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 @@ @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 @@ 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 @@ 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(); --- old/test/com/sun/awt/Translucency/WindowOpacity.java 2017-08-22 12:28:43.000000000 -0700 +++ /dev/null 2017-08-22 12:28:43.000000000 -0700 @@ -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 --- /dev/null 2017-08-22 12:28:43.000000000 -0700 +++ new/test/java/awt/Window/ShapedAndTranslucentWindows/WindowOpacity.java 2017-08-22 12:28:43.000000000 -0700 @@ -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); + } + } +} --- old/src/java.desktop/share/classes/com/sun/awt/AWTUtilities.java 2017-08-22 12:28:44.000000000 -0700 +++ /dev/null 2017-08-22 12:28:44.000000000 -0700 @@ -1,464 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -package com.sun.awt; - -import java.awt.*; - -import javax.swing.JRootPane; - -import sun.awt.AWTAccessor; -import sun.awt.SunToolkit; - -/** - * A collection of utility methods for AWT. - * - * The functionality provided by the static methods of the class includes: - * - *

- * A "top-level window" is an instance of the {@code Window} class (or its - * descendant, such as {@code JFrame}). - *

- * Some of the mentioned features may not be supported by the native platform. - * To determine whether a particular feature is supported, the user must use - * the {@code isTranslucencySupported()} method of the class passing a desired - * translucency kind (a member of the {@code Translucency} enum) as an - * argument. - *

- * The per-pixel alpha feature also requires the user to create her/his - * windows using a translucency-capable graphics configuration. - * The {@code isTranslucencyCapable()} method must - * be used to verify whether any given GraphicsConfiguration supports - * the translucency effects. - *

- * WARNING: This class is an implementation detail and only meant - * for limited use outside of the core platform. This API may change - * drastically between update release, and it may even be - * removed or be moved in some other package(s)/class(es). - */ -public final class AWTUtilities { - - /** - * The AWTUtilities class should not be instantiated - */ - private AWTUtilities() { - } - - /** Kinds of translucency supported by the underlying system. - * @see #isTranslucencySupported - */ - public static enum Translucency { - /** - * Represents support in the underlying system for windows each pixel - * of which is guaranteed to be either completely opaque, with - * an alpha value of 1.0, or completely transparent, with an alpha - * value of 0.0. - */ - PERPIXEL_TRANSPARENT, - - /** - * Represents support in the underlying system for windows all of - * the pixels of which have the same alpha value between or including - * 0.0 and 1.0. - */ - TRANSLUCENT, - - /** - * Represents support in the underlying system for windows that - * contain or might contain pixels with arbitrary alpha values - * between and including 0.0 and 1.0. - */ - PERPIXEL_TRANSLUCENT; - } - - - /** - * Returns whether the given level of translucency is supported by - * the underlying system. - * - * Note that this method may sometimes return the value - * indicating that the particular level is supported, but - * the native windowing system may still not support the - * given level of translucency (due to the bugs in - * the windowing system). - * - * @param translucencyKind a kind of translucency support - * (either PERPIXEL_TRANSPARENT, - * TRANSLUCENT, or PERPIXEL_TRANSLUCENT) - * @return whether the given translucency kind is supported - */ - public static boolean isTranslucencySupported(Translucency translucencyKind) { - switch (translucencyKind) { - case PERPIXEL_TRANSPARENT: - return isWindowShapingSupported(); - case TRANSLUCENT: - return isWindowOpacitySupported(); - case PERPIXEL_TRANSLUCENT: - return isWindowTranslucencySupported(); - } - return false; - } - - - /** - * Returns whether the windowing system supports changing the opacity - * value of top-level windows. - * Note that this method may sometimes return true, but the native - * windowing system may still not support the concept of - * translucency (due to the bugs in the windowing system). - */ - private static boolean isWindowOpacitySupported() { - Toolkit curToolkit = Toolkit.getDefaultToolkit(); - if (!(curToolkit instanceof SunToolkit)) { - return false; - } - return ((SunToolkit)curToolkit).isWindowOpacitySupported(); - } - - /** - * Set the opacity of the window. The opacity is at 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 isTranslucencySupported() method should indicate that the - * TRANSLUCENT level of 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 IllegalArgumentException is thrown. - * - * @param window the window to set the opacity level to - * @param opacity the opacity level to set to the window - * @throws NullPointerException if the window argument is null - * @throws IllegalArgumentException if the opacity is out of - * the range [0..1] - * @throws IllegalArgumentException if the window is in full screen mode, - * and the opacity is less than 1.0f - * @throws UnsupportedOperationException if the TRANSLUCENT translucency - * kind is not supported - */ - 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); - } - - /** - * Get the opacity of the window. If the opacity has not - * yet being set, this method returns 1.0. - * - * @param window the window to get the opacity level from - * @throws NullPointerException if the window argument is null - */ - public static float getWindowOpacity(Window window) { - if (window == null) { - throw new NullPointerException( - "The window argument should not be null."); - } - - return AWTAccessor.getWindowAccessor().getOpacity(window); - } - - /** - * Returns whether the windowing system supports changing the shape - * of top-level windows. - * 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). - */ - public static boolean isWindowShapingSupported() { - Toolkit curToolkit = Toolkit.getDefaultToolkit(); - if (!(curToolkit instanceof SunToolkit)) { - return false; - } - return ((SunToolkit)curToolkit).isWindowShapingSupported(); - } - - /** - * Returns an object that implements the Shape interface and represents - * the shape previously set with the call to the setWindowShape() method. - * If no shape has been set yet, or the shape has been reset to null, - * this method returns null. - * - * @param window the window to get the shape from - * @return the current shape of the window - * @throws NullPointerException if the window argument is null - */ - public static Shape getWindowShape(Window window) { - if (window == null) { - throw new NullPointerException( - "The window argument should not be null."); - } - return AWTAccessor.getWindowAccessor().getShape(window); - } - - /** - * Sets a shape for the given window. - * If the shape argument is null, this methods restores - * the default shape making the window rectangular. - *

Note that in order to set a shape, the window must be undecorated. - * If the window is decorated, this method ignores the {@code shape} - * argument and resets the shape to null. - *

Also note that the window must not be in the full-screen mode - * when setting a non-null shape. Otherwise the IllegalArgumentException - * is thrown. - *

Depending on the platform, the method may return without - * effecting the shape of the window if the window has a non-null warning - * string ({@link Window#getWarningString()}). In this case the passed - * shape object is ignored. - * - * @param window the window to set the shape to - * @param shape the shape to set to the window - * @throws NullPointerException if the window argument is null - * @throws IllegalArgumentException if the window is in full screen mode, - * and the shape is not null - * @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT - * translucency kind is not supported - */ - 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); - } - - private static boolean isWindowTranslucencySupported() { - /* - * Per-pixel alpha is supported if all the conditions are TRUE: - * 1. The toolkit is a sort of SunToolkit - * 2. The toolkit supports translucency in general - * (isWindowTranslucencySupported()) - * 3. There's at least one translucency-capable - * GraphicsConfiguration - */ - - Toolkit curToolkit = Toolkit.getDefaultToolkit(); - if (!(curToolkit instanceof SunToolkit)) { - return false; - } - - if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) { - return false; - } - - GraphicsEnvironment env = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - - // If the default GC supports translucency return true. - // It is important to optimize the verification this way, - // see CR 6661196 for more details. - if (isTranslucencyCapable(env.getDefaultScreenDevice() - .getDefaultConfiguration())) - { - return true; - } - - // ... otherwise iterate through all the GCs. - GraphicsDevice[] devices = env.getScreenDevices(); - - for (int i = 0; i < devices.length; i++) { - GraphicsConfiguration[] configs = devices[i].getConfigurations(); - for (int j = 0; j < configs.length; j++) { - if (isTranslucencyCapable(configs[j])) { - return true; - } - } - } - - return false; - } - - /** - * Enables the per-pixel alpha support for the given window. - * Once the window becomes non-opaque (the isOpaque is set to false), - * the drawing sub-system is starting to respect the alpha value of each - * separate pixel. If a pixel gets painted with alpha color component - * equal to zero, it becomes visually transparent, if the alpha of the - * pixel is equal to 255, the pixel is fully opaque. Interim values - * of the alpha color component make the pixel semi-transparent (i.e. - * translucent). - *

Note that in order for the window to support the per-pixel alpha - * mode, the window must be created using the GraphicsConfiguration - * for which the {@link #isTranslucencyCapable} - * method returns true. - *

Also note that some native systems enable the per-pixel translucency - * mode for any window created using the translucency-compatible - * graphics configuration. However, it is highly recommended to always - * invoke the setWindowOpaque() method for these windows, at least for - * the sake of cross-platform compatibility reasons. - *

Also note that the window must not be in the full-screen mode - * when making it non-opaque. Otherwise the IllegalArgumentException - * is thrown. - *

If the window is a {@code Frame} or a {@code Dialog}, the window must - * be undecorated prior to enabling the per-pixel translucency effect (see - * {@link Frame#setUndecorated} and/or {@link Dialog#setUndecorated}). - * If the window becomes decorated through a subsequent call to the - * corresponding {@code setUndecorated()} method, the per-pixel - * translucency effect will be disabled and the opaque property reset to - * {@code true}. - *

Depending on the platform, the method may return without - * effecting the opaque property of the window if the window has a non-null - * warning string ({@link Window#getWarningString()}). In this case - * the passed 'isOpaque' value is ignored. - * - * @param window the window to set the shape to - * @param isOpaque whether the window must be opaque (true), - * or translucent (false) - * @throws NullPointerException if the window argument is null - * @throws IllegalArgumentException if the window uses - * a GraphicsConfiguration for which the - * {@code isTranslucencyCapable()} - * method returns false - * @throws IllegalArgumentException if the window is in full screen mode, - * and the isOpaque is false - * @throws IllegalArgumentException if the window is decorated and the - * isOpaque argument is {@code false}. - * @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT - * translucency kind is not supported - */ - public static void setWindowOpaque(Window window, boolean isOpaque) { - if (window == null) { - throw new NullPointerException( - "The window argument should not be null."); - } - if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) { - throw new UnsupportedOperationException( - "The PERPIXEL_TRANSLUCENT translucency kind is not supported"); - } - AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque); - } - - /** - * Returns whether the window is opaque or translucent. - * - * @param window the window to set the shape to - * @return whether the window is currently opaque (true) - * or translucent (false) - * @throws NullPointerException if the window argument is null - */ - public static boolean isWindowOpaque(Window window) { - if (window == null) { - throw new NullPointerException( - "The window argument should not be null."); - } - - return window.isOpaque(); - } - - /** - * Verifies whether a given GraphicsConfiguration supports - * the PERPIXEL_TRANSLUCENT kind of translucency. - * All windows that are intended to be used with the {@link #setWindowOpaque} - * method must be created using a GraphicsConfiguration for which this method - * returns true. - *

Note that some native systems enable the per-pixel translucency - * mode for any window created using a translucency-capable - * graphics configuration. However, it is highly recommended to always - * invoke the setWindowOpaque() method for these windows, at least - * for the sake of cross-platform compatibility reasons. - * - * @param gc GraphicsConfiguration - * @throws NullPointerException if the gc argument is null - * @return whether the given GraphicsConfiguration supports - * the translucency effects. - */ - public static boolean isTranslucencyCapable(GraphicsConfiguration gc) { - if (gc == null) { - throw new NullPointerException("The gc argument should not be null"); - } - /* - return gc.isTranslucencyCapable(); - */ - Toolkit curToolkit = Toolkit.getDefaultToolkit(); - if (!(curToolkit instanceof SunToolkit)) { - return false; - } - return ((SunToolkit)curToolkit).isTranslucencyCapable(gc); - } - - /** - * Sets a 'mixing-cutout' shape for the given component. - * - * By default a lightweight component is treated as an opaque rectangle for - * the purposes of the Heavyweight/Lightweight Components Mixing feature. - * This method enables developers to set an arbitrary shape to be cut out - * from heavyweight components positioned underneath the lightweight - * component in the z-order. - *

- * The {@code shape} argument may have the following values: - *

- *

- * The most common example when the 'mixing-cutout' shape is needed is a - * glass pane component. The {@link JRootPane#setGlassPane} method - * automatically sets the empty-shape as the 'mixing-cutout' shape - * for the given glass pane component. If a developer needs some other - * 'mixing-cutout' shape for the glass pane (which is rare), this must be - * changed manually after installing the glass pane to the root pane. - *

- * Note that the 'mixing-cutout' shape neither affects painting, nor the - * mouse events handling for the given component. It is used exclusively - * for the purposes of the Heavyweight/Lightweight Components Mixing - * feature. - * - * @param component the component that needs non-default - * 'mixing-cutout' shape - * @param shape the new 'mixing-cutout' shape - * @throws NullPointerException if the component argument is {@code null} - */ - @Deprecated(since = "9") - public static void setComponentMixingCutoutShape(Component component, - Shape shape) - { - if (component == null) { - throw new NullPointerException( - "The component argument should not be null."); - } - - component.setMixingCutoutShape(shape); - } -} -