# HG changeset patch # User prr # Date 1529428355 25200 # Node ID 0e9d1d4ab69233c42be9d887d4071c1068217e0a # Parent 681b118332d731747e0a225d6d86b21314f350cf# Parent c82ed0f373bb3e99c0fad02caea49a5d636bb39b Merge diff -r c82ed0f373bb -r 0e9d1d4ab692 make/scripts/compare_exceptions.sh.incl --- a/make/scripts/compare_exceptions.sh.incl Tue Jun 19 07:15:00 2018 -0400 +++ b/make/scripts/compare_exceptions.sh.incl Tue Jun 19 10:12:35 2018 -0700 @@ -179,7 +179,6 @@ ./lib/libsplashscreen.so ./lib/libsunec.so ./lib/libsunwjdga.so - ./lib/libt2k.so ./lib/libunpack.so ./lib/libverify.so ./lib/libzip.so @@ -290,7 +289,6 @@ ./lib/libsplashscreen.so ./lib/libsunec.so ./lib/libsunwjdga.so - ./lib/libt2k.so ./lib/libunpack.so ./lib/libverify.so ./lib/libzip.so diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java Tue Jun 19 10:12:35 2018 -0700 @@ -74,10 +74,17 @@ // This is used to create a CImage from a Image public static CImage createFromImage(final Image image) { - return getCreator().createFromImage(image); + return getCreator().createFromImage(image, null); + } + + // This is used to create a CImage from a Image + public static CImage createFromImage(final Image image, CTrayIcon.IconObserver observer) { + return getCreator().createFromImage(image, observer); } public static class Creator { + CTrayIcon.IconObserver observer; + Creator() { } // This is used to create a CImage with an NSImage pointer. It MUST be a CFRetained @@ -124,7 +131,7 @@ return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name)); } - private static int[] imageToArray(Image image, boolean prepareImage) { + private static int[] imageToArray(Image image, boolean prepareImage, CTrayIcon.IconObserver observer) { if (image == null) return null; if (prepareImage && !(image instanceof BufferedImage)) { @@ -153,14 +160,14 @@ BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D g2 = bimg.createGraphics(); g2.setComposite(AlphaComposite.Src); - g2.drawImage(image, 0, 0, null); + g2.drawImage(image, 0, 0, observer); g2.dispose(); return ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData(); } public byte[] getPlatformImageBytes(final Image image) { - int[] buffer = imageToArray(image, false); + int[] buffer = imageToArray(image, false, null); if (buffer == null) { return null; @@ -178,22 +185,27 @@ // This is used to create a CImage from a Image public CImage createFromImage(final Image image) { - return createFromImage(image, true); + return createFromImage(image, true, null); + } + + // This is used to create a CImage from a Image + public CImage createFromImage(final Image image, CTrayIcon.IconObserver observer) { + return createFromImage(image, true, observer); } public CImage createFromImageImmediately(final Image image) { - return createFromImage(image, false); + return createFromImage(image, false, null); } // This is used to create a CImage from a Image - private CImage createFromImage(final Image image, final boolean prepareImage) { + private CImage createFromImage(final Image image, final boolean prepareImage, CTrayIcon.IconObserver observer) { if (image instanceof MultiResolutionImage) { List resolutionVariants = ((MultiResolutionImage) image).getResolutionVariants(); return createFromImages(resolutionVariants, prepareImage); } - int[] buffer = imageToArray(image, prepareImage); + int[] buffer = imageToArray(image, prepareImage, observer); if (buffer == null) { return null; } @@ -218,7 +230,7 @@ num = 0; for (final Image img : images) { - buffers[num] = imageToArray(img, prepareImage); + buffers[num] = imageToArray(img, prepareImage, null); if (buffers[num] == null) { // Unable to process the image continue; diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CTrayIcon.java Tue Jun 19 10:12:35 2018 -0700 @@ -43,6 +43,7 @@ import java.awt.event.MouseEvent; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; import java.awt.peer.TrayIconPeer; import javax.swing.Icon; @@ -61,6 +62,7 @@ // Component target. Because TrayIcon isn't Component's subclass, // we use this dummy frame instead private final Frame dummyFrame; + IconObserver observer = new IconObserver(); // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events // on MOUSE_RELEASE. Click events are only generated if there were no drag @@ -143,7 +145,7 @@ CImage cimage = null; if (icon != null) { BufferedImage image = scaleIcon(icon, 0.75); - cimage = CImage.getCreator().createFromImage(image); + cimage = CImage.getCreator().createFromImage(image, null); } if (cimage != null) { cimage.execute(imagePtr -> { @@ -184,9 +186,14 @@ @Override public void updateImage() { + Image image = target.getImage(); - if (image == null) return; + if (image != null) { + updateNativeImage(image); + } + } + void updateNativeImage(Image image) { MediaTracker tracker = new MediaTracker(new Button("")); tracker.addImage(image, 0); try { @@ -199,7 +206,7 @@ return; } - CImage cimage = CImage.getCreator().createFromImage(image); + CImage cimage = CImage.getCreator().createFromImage(image, observer); boolean imageAutoSize = target.isImageAutoSize(); cimage.execute(imagePtr -> { execute(ptr -> { @@ -346,5 +353,25 @@ return UIManager.getIcon("OptionPane.informationIcon"); } } + + class IconObserver implements ImageObserver { + @Override + public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) { + if (image != target.getImage()) // if the image has been changed + { + return false; + } + if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS | + ImageObserver.WIDTH | ImageObserver.HEIGHT)) != 0) + { + SunToolkit.executeOnEventHandlerThread(target, new Runnable() { + public void run() { + updateNativeImage(image); + } + }); + } + return (flags & ImageObserver.ALLBITS) == 0; + } + } } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2018, 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 @@ -325,15 +325,15 @@ } JavaComponentAccessibility *child = [self createWithParent:parent accessible:jchild role:childJavaRole index:childIndex withEnv:env withView:parent->fView]; - + (*env)->DeleteLocalRef(env, jchild); (*env)->DeleteLocalRef(env, jchildJavaRole); - + [children addObject:child]; childIndex++; } (*env)->DeleteLocalRef(env, jchildrenAndRoles); - + return children; } @@ -646,6 +646,9 @@ } // The above set of attributes is immutable per role, but some objects, if // they are the child of a list, need to add the selected and index attributes. + if ([self accessibilityIsIgnored]) { + return names; + } id myParent = [self accessibilityParentAttribute]; if ([myParent isKindOfClass:[JavaComponentAccessibility class]]) { NSString *parentRole = [(JavaComponentAccessibility *)myParent javaRole]; @@ -1060,7 +1063,7 @@ sjc_CAccessibility, "requestSelection", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V" ); - + if ([(NSNumber*)value boolValue]) { JNIEnv* env = [ThreadUtilities getJNIEnv]; JNFCallStaticVoidMethod(env, jm_requestSelection, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) @@ -1167,7 +1170,7 @@ // Need to handle popupmenus differently. // // At least for now don't handle combo box menus. - // This may change when later fixing issues which currently + // This may change when later fixing issues which currently // exist for combo boxes, but for now the following is only // for JPopupMenus, not for combobox menus. id parent = [self parent]; @@ -1349,7 +1352,7 @@ NSWindow* hostWindow = [[self->fView window] retain]; jobject focused = JNFCallStaticObjectMethod(env, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop) [hostWindow release]; - + if (focused != NULL) { if (JNFIsInstanceOf(env, focused, &sjc_Accessible)) { value = [JavaComponentAccessibility createWithAccessible:focused withEnv:env withView:fView]; diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/com/sun/media/sound/JavaSoundAudioClip.java --- a/src/java.desktop/share/classes/com/sun/media/sound/JavaSoundAudioClip.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/com/sun/media/sound/JavaSoundAudioClip.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, 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 @@ -30,6 +30,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaEventListener; @@ -76,6 +78,7 @@ private Sequencer sequencer = null; private Sequence sequence = null; private boolean sequencerloop = false; + private volatile boolean success; /** * used for determining how many samples is the @@ -91,12 +94,31 @@ //private final static long CLIP_THRESHOLD = 1; private static final int STREAM_BUFFER_SIZE = 1024; - public JavaSoundAudioClip(InputStream in) throws IOException { + public static JavaSoundAudioClip create(final URLConnection uc) { + JavaSoundAudioClip clip = new JavaSoundAudioClip(); + try { + clip.init(uc.getInputStream()); + } catch (final Exception ignored) { + // AudioClip will be no-op if some exception will occurred + } + return clip; + } + + public static JavaSoundAudioClip create(final URL url) { + JavaSoundAudioClip clip = new JavaSoundAudioClip(); + try { + clip.init(url.openStream()); + } catch (final Exception ignored) { + // AudioClip will be no-op if some exception will occurred + } + return clip; + } + + private void init(InputStream in) throws IOException { if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip."); BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE); bis.mark(STREAM_BUFFER_SIZE); - boolean success = false; try { AudioInputStream as = AudioSystem.getAudioInputStream(bis); // load the stream data into memory @@ -120,18 +142,21 @@ success = false; } } - if (!success) { - throw new IOException("Unable to create AudioClip from input stream"); - } } @Override public synchronized void play() { + if (!success) { + return; + } startImpl(false); } @Override public synchronized void loop() { + if (!success) { + return; + } startImpl(true); } @@ -206,6 +231,9 @@ @Override public synchronized void stop() { + if (!success) { + return; + } if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->stop()"); lastPlayCall = 0; diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/java/applet/Applet.java --- a/src/java.desktop/share/classes/java/applet/Applet.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/java/applet/Applet.java Tue Jun 19 10:12:35 2018 -0700 @@ -42,6 +42,8 @@ import javax.accessibility.AccessibleState; import javax.accessibility.AccessibleStateSet; +import com.sun.media.sound.JavaSoundAudioClip; + /** * An applet is a small program that is intended not to be run on * its own, but rather to be embedded inside another application. @@ -322,7 +324,7 @@ * @since 1.2 */ public static final AudioClip newAudioClip(URL url) { - return new sun.applet.AppletAudioClip(url); + return JavaSoundAudioClip.create(url); } /** diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/javax/swing/SwingWorker.java --- a/src/java.desktop/share/classes/javax/swing/SwingWorker.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/javax/swing/SwingWorker.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, 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,21 +22,30 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + package javax.swing; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.lang.ref.WeakReference; import java.security.AccessController; import java.security.PrivilegedAction; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.beans.PropertyChangeEvent; import java.util.List; -import java.util.concurrent.*; -import java.util.concurrent.locks.*; - -import java.awt.event.*; - -import javax.swing.SwingUtilities; +import java.util.concurrent.Callable; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.FutureTask; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RunnableFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import sun.awt.AppContext; import sun.swing.AccumulativeRunnable; @@ -597,6 +606,8 @@ * //the dialog will be visible until the SwingWorker is done * dialog.setVisible(true); * + * + * @throws CancellationException {@inheritDoc} */ public final T get() throws InterruptedException, ExecutionException { return future.get(); @@ -606,6 +617,8 @@ * {@inheritDoc} *

* Please refer to {@link #get} for more details. + * + * @throws CancellationException {@inheritDoc} */ public final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/javax/swing/text/WrappedPlainView.java --- a/src/java.desktop/share/classes/javax/swing/text/WrappedPlainView.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/javax/swing/text/WrappedPlainView.java Tue Jun 19 10:12:35 2018 -0700 @@ -364,8 +364,9 @@ this, p0); } else { p = p0 + Utilities.getTabbedTextOffset(segment, metrics, - tabBase, tabBase + currentWidth, - this, p0, false); + (float)tabBase, + (float)(tabBase + currentWidth), + this, p0, false); } SegmentCache.releaseSharedSegment(segment); return p; @@ -847,8 +848,8 @@ Segment segment = SegmentCache.getSharedSegment(); loadText(segment, p0, p1); int n = Utilities.getTabbedTextOffset(segment, metrics, - alloc.x, x, - WrappedPlainView.this, p0); + (float)alloc.x, (float)x, + WrappedPlainView.this, p0, false); SegmentCache.releaseSharedSegment(segment); return Math.min(p0 + n, p1 - 1); } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/module-info.java --- a/src/java.desktop/share/classes/module-info.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/module-info.java Tue Jun 19 10:12:35 2018 -0700 @@ -108,7 +108,12 @@ // qualified exports may be inserted at build time // see make/GensrcModuleInfo.gmk exports sun.awt to - jdk.accessibility; + jdk.accessibility, + jdk.unsupported.desktop; + + exports java.awt.dnd.peer to jdk.unsupported.desktop; + exports sun.awt.dnd to jdk.unsupported.desktop; + exports sun.swing to jdk.unsupported.desktop; opens javax.swing.plaf.basic to jdk.jconsole; @@ -131,6 +136,8 @@ uses javax.sound.sampled.spi.FormatConversionProvider; uses javax.sound.sampled.spi.MixerProvider; + uses sun.swing.InteropProvider; + provides sun.datatransfer.DesktopDatatransferService with sun.awt.datatransfer.DesktopDatatransferServiceImpl; diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/applet/AppletAudioClip.java --- a/src/java.desktop/share/classes/sun/applet/AppletAudioClip.java Tue Jun 19 07:15:00 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -/* - * Copyright (c) 1995, 2003, 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 sun.applet; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ByteArrayInputStream; -import java.net.URL; -import java.net.URLConnection; -import java.applet.AudioClip; - -import com.sun.media.sound.JavaSoundAudioClip; - - -/** - * Applet audio clip; - * - * @author Arthur van Hoff, Kara Kytle - */ - -@SuppressWarnings("deprecation") -public class AppletAudioClip implements AudioClip { - - // url that this AudioClip is based on - private URL url = null; - - // the audio clip implementation - private AudioClip audioClip = null; - - boolean DEBUG = false /*true*/; - - /** - * Constructs an AppletAudioClip from an URL. - */ - public AppletAudioClip(URL url) { - - // store the url - this.url = url; - - try { - // create a stream from the url, and use it - // in the clip. - InputStream in = url.openStream(); - createAppletAudioClip(in); - - } catch (IOException e) { - /* just quell it */ - if (DEBUG) { - System.err.println("IOException creating AppletAudioClip" + e); - } - } - } - - /** - * Constructs an AppletAudioClip from a URLConnection. - */ - public AppletAudioClip(URLConnection uc) { - - try { - // create a stream from the url, and use it - // in the clip. - createAppletAudioClip(uc.getInputStream()); - - } catch (IOException e) { - /* just quell it */ - if (DEBUG) { - System.err.println("IOException creating AppletAudioClip" + e); - } - } - } - - - /** - * For constructing directly from Jar entries, or any other - * raw Audio data. Note that the data provided must include the format - * header. - */ - public AppletAudioClip(byte [] data) { - - try { - - // construct a stream from the byte array - InputStream in = new ByteArrayInputStream(data); - - createAppletAudioClip(in); - - } catch (IOException e) { - /* just quell it */ - if (DEBUG) { - System.err.println("IOException creating AppletAudioClip " + e); - } - } - } - - - /* - * Does the real work of creating an AppletAudioClip from an InputStream. - * This function is used by both constructors. - */ - void createAppletAudioClip(InputStream in) throws IOException { - - try { - audioClip = new JavaSoundAudioClip(in); - } catch (Exception e3) { - // no matter what happened, we throw an IOException to avoid changing the interfaces.... - throw new IOException("Failed to construct the AudioClip: " + e3); - } - } - - - public synchronized void play() { - - if (audioClip != null) - audioClip.play(); - } - - - public synchronized void loop() { - - if (audioClip != null) - audioClip.loop(); - } - - public synchronized void stop() { - - if (audioClip != null) - audioClip.stop(); - } -} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/awt/www/content/audio/aiff.java --- a/src/java.desktop/share/classes/sun/awt/www/content/audio/aiff.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/awt/www/content/audio/aiff.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, 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,21 +23,21 @@ * questions. */ -/** - * Basic .aiff audio handler. - * @author Jeff Nisewanger - */ package sun.awt.www.content.audio; -import java.net.*; import java.io.IOException; -import sun.applet.AppletAudioClip; +import java.net.ContentHandler; +import java.net.URLConnection; + +import com.sun.media.sound.JavaSoundAudioClip; /** - * Returns an AppletAudioClip object. + * Basic .aiff audio handler returns an JavaSoundAudioClip object. + * + * @author Jeff Nisewanger */ public class aiff extends ContentHandler { public Object getContent(URLConnection uc) throws IOException { - return new AppletAudioClip(uc); + return JavaSoundAudioClip.create(uc); } } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/awt/www/content/audio/basic.java --- a/src/java.desktop/share/classes/sun/awt/www/content/audio/basic.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/awt/www/content/audio/basic.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, 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,23 +23,24 @@ * questions. */ -/** - * Basic .au and .snd audio handler. - * @author Jeff Nisewanger - */ package sun.awt.www.content.audio; -import java.net.*; import java.io.IOException; -import sun.applet.AppletAudioClip; +import java.net.ContentHandler; +import java.net.URLConnection; + +import com.sun.media.sound.JavaSoundAudioClip; /** - * Returns an AppletAudioClip object. + * Basic .au and .snd audio handler returns an JavaSoundAudioClip object. + *

* This provides backwards compatibility with the behavior * of ClassLoader.getResource().getContent() on JDK1.1. + * + * @author Jeff Nisewanger */ public class basic extends ContentHandler { public Object getContent(URLConnection uc) throws IOException { - return new AppletAudioClip(uc); + return JavaSoundAudioClip.create(uc); } } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/awt/www/content/audio/wav.java --- a/src/java.desktop/share/classes/sun/awt/www/content/audio/wav.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/awt/www/content/audio/wav.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, 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,21 +23,21 @@ * questions. */ -/** - * Basic .wav audio handler. - * @author Jeff Nisewanger - */ package sun.awt.www.content.audio; -import java.net.*; import java.io.IOException; -import sun.applet.AppletAudioClip; +import java.net.ContentHandler; +import java.net.URLConnection; + +import com.sun.media.sound.JavaSoundAudioClip; /** - * Returns an AppletAudioClip object. + * Basic .wav audio handler returns an JavaSoundAudioClip object. + * + * @author Jeff Nisewanger */ public class wav extends ContentHandler { public Object getContent(URLConnection uc) throws IOException { - return new AppletAudioClip(uc); + return JavaSoundAudioClip.create(uc); } } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/awt/www/content/audio/x_aiff.java --- a/src/java.desktop/share/classes/sun/awt/www/content/audio/x_aiff.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/awt/www/content/audio/x_aiff.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, 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,21 +23,21 @@ * questions. */ -/** - * Basic .aiff audio handler. - * @author Jeff Nisewanger - */ package sun.awt.www.content.audio; -import java.net.*; import java.io.IOException; -import sun.applet.AppletAudioClip; +import java.net.ContentHandler; +import java.net.URLConnection; + +import com.sun.media.sound.JavaSoundAudioClip; /** - * Returns an AppletAudioClip object. + * Basic .aiff audio handler returns an JavaSoundAudioClip object. + * + * @author Jeff Nisewanger */ public class x_aiff extends ContentHandler { public Object getContent(URLConnection uc) throws IOException { - return new AppletAudioClip(uc); + return JavaSoundAudioClip.create(uc); } } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/awt/www/content/audio/x_wav.java --- a/src/java.desktop/share/classes/sun/awt/www/content/audio/x_wav.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/awt/www/content/audio/x_wav.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, 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,21 +23,21 @@ * questions. */ -/** - * Basic .wav audio handler. - * @author Jeff Nisewanger - */ package sun.awt.www.content.audio; -import java.net.*; import java.io.IOException; -import sun.applet.AppletAudioClip; +import java.net.ContentHandler; +import java.net.URLConnection; + +import com.sun.media.sound.JavaSoundAudioClip; /** - * Returns an AppletAudioClip object. + * Basic .wav audio handler returns an JavaSoundAudioClip object. + * + * @author Jeff Nisewanger */ public class x_wav extends ContentHandler { public Object getContent(URLConnection uc) throws IOException { - return new AppletAudioClip(uc); + return JavaSoundAudioClip.create(uc); } } diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java --- a/src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/font/CompositeGlyphMapper.java Tue Jun 19 10:12:35 2018 -0700 @@ -28,7 +28,7 @@ /* remember that the API requires a Font use a * consistent glyph id. for a code point, and this is a * problem if a particular strike uses native scaler sometimes - * and T2K others. That needs to be dealt with somewhere, but + * and the JDK scaler others. That needs to be dealt with somewhere, but * here we can just always get the same glyph code without * needing a strike. * diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/font/FontManagerNativeLibrary.java --- a/src/java.desktop/share/classes/sun/font/FontManagerNativeLibrary.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/font/FontManagerNativeLibrary.java Tue Jun 19 10:12:35 2018 -0700 @@ -50,9 +50,6 @@ To avoid link error we have to load freetype explicitly before we load fontmanager. - Note that we do not need to do this for T2K because - fontmanager.dll does not depend on t2k.dll. - NB: consider moving freetype wrapper part to separate shared library in order to avoid dependency. */ System.loadLibrary("freetype"); diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/font/FontScaler.java --- a/src/java.desktop/share/classes/sun/font/FontScaler.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/font/FontScaler.java Tue Jun 19 10:12:35 2018 -0700 @@ -29,7 +29,6 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.lang.ref.WeakReference; -import java.lang.reflect.Constructor; import sun.java2d.Disposer; import sun.java2d.DisposerRecord; @@ -82,51 +81,16 @@ public abstract class FontScaler implements DisposerRecord { private static FontScaler nullScaler = null; - private static Constructor scalerConstructor = null; //Find preferred font scaler // //NB: we can allow property based preferences // (theoretically logic can be font type specific) - static { - Class scalerClass = null; - Class[] arglst = new Class[] {Font2D.class, int.class, - boolean.class, int.class}; - - try { - @SuppressWarnings("unchecked") - Class tmp = (Class) - ((!FontUtilities.useT2K && !FontUtilities.useLegacy) ? - Class.forName("sun.font.FreetypeFontScaler") : - Class.forName("sun.font.T2KFontScaler")); - scalerClass = tmp; - } catch (ClassNotFoundException e) { - try { - @SuppressWarnings("unchecked") - Class tmp = (Class) - Class.forName("sun.font.FreetypeFontScaler"); - scalerClass = tmp; - } catch (ClassNotFoundException e1) { - scalerClass = NullFontScaler.class; - } - } finally { - if (FontUtilities.debugFonts()) { - System.out.println("Scaler class="+scalerClass); - } - } - - //NB: rewrite using factory? constructor is ugly way - try { - scalerConstructor = scalerClass.getConstructor(arglst); - } catch (NoSuchMethodException e) { - //should not happen - } - } /* This is the only place to instantiate new FontScaler. * Therefore this is very convinient place to register - * scaler with Disposer as well as trigger deregistring bad font - * in case when scaler reports this. + * scaler with Disposer as well as trigger deregistering a bad font + * when the scaler reports this. */ public static FontScaler getScaler(Font2D font, int indexInCollection, @@ -135,14 +99,13 @@ FontScaler scaler = null; try { - Object args[] = new Object[] {font, indexInCollection, - supportsCJK, filesize}; - scaler = scalerConstructor.newInstance(args); + scaler = new FreetypeFontScaler(font, indexInCollection, + supportsCJK, filesize); Disposer.addObjectRecord(font, scaler); } catch (Throwable e) { - scaler = nullScaler; + scaler = getNullScaler(); - //if we can not instantiate scaler assume bad font + //if we can not instantiate scaler assume a bad font //NB: technically it could be also because of internal scaler // error but here we are assuming scaler is ok. FontManager fm = FontManagerFactory.getInstance(); diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/font/FontUtilities.java --- a/src/java.desktop/share/classes/sun/font/FontUtilities.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/font/FontUtilities.java Tue Jun 19 10:12:35 2018 -0700 @@ -52,10 +52,6 @@ public static boolean useJDKScaler; - public static boolean useT2K; - // useLegacy is a short-term debugging transition aid. - public static boolean useLegacy; - public static boolean isWindows; private static boolean debugFonts = false; @@ -76,33 +72,16 @@ isMacOSX = osName.contains("OS X"); // TODO: MacOSX - /* Support a value of "t2k" as meaning use the JDK internal - * scaler over the platform scaler whether or not t2k is - * actually available. - * This can be considered transitional support for some - * level of compatibility, as in it avoids the native scaler - * as before but cannot guarantee rendering equivalence - * with T2K. - * It will also use t2k instead of freetype if t2k is - * available - this is the same as before. - * The new value of "jdk" means even if t2k is available, - * the decision as to whether to use that or freetype is - * not affected by this setting. + /* If set to "jdk", use the JDK's scaler rather than + * the platform one. This may be a no-op on platforms where + * JDK has been configured so that it always relies on the + * platform scaler. The principal case where it has an + * effect is that on Windows, 2D will never use GDI. */ String scalerStr = System.getProperty("sun.java2d.font.scaler"); if (scalerStr != null) { - useT2K = "t2k".equals(scalerStr); - if (useT2K) { - System.out.println("WARNING: t2k will be removed in JDK 11."); - } - useLegacy = "legacy".equals(scalerStr); - if (useLegacy) { - System.out.println("WARNING: legacy behavior will be removed in JDK 11."); - } - useJDKScaler = useT2K || "jdk".equals(scalerStr); + useJDKScaler = "jdk".equals(scalerStr); } else { - useT2K = false; - useLegacy = false; useJDKScaler = false; } isWindows = osName.startsWith("Windows"); diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/font/SunFontManager.java --- a/src/java.desktop/share/classes/sun/font/SunFontManager.java Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/classes/sun/font/SunFontManager.java Tue Jun 19 10:12:35 2018 -0700 @@ -132,10 +132,9 @@ public static final int FONTFORMAT_NONE = -1; public static final int FONTFORMAT_TRUETYPE = 0; public static final int FONTFORMAT_TYPE1 = 1; - public static final int FONTFORMAT_T2K = 2; - public static final int FONTFORMAT_TTC = 3; - public static final int FONTFORMAT_COMPOSITE = 4; - public static final int FONTFORMAT_NATIVE = 5; + public static final int FONTFORMAT_TTC = 2; + public static final int FONTFORMAT_COMPOSITE = 3; + public static final int FONTFORMAT_NATIVE = 4; /* Pool of 20 font file channels chosen because some UTF-8 locale * composite fonts can use up to 16 platform fonts (including the @@ -353,7 +352,7 @@ * handle two fonts of the same name, so the JRE one * must be the first one registered. Pass "true" to * registerFonts method as on-screen these JRE fonts - * always go through the T2K rasteriser. + * always go through the JDK rasteriser. */ if (FontUtilities.isLinux) { /* Linux font configuration uses these fonts */ diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/classes/sun/swing/InteropProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/sun/swing/InteropProvider.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018, 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 sun.swing; + +public interface InteropProvider { +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/native/common/font/fontscalerdefs.h --- a/src/java.desktop/share/native/common/font/fontscalerdefs.h Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/native/common/font/fontscalerdefs.h Tue Jun 19 10:12:35 2018 -0700 @@ -32,13 +32,6 @@ extern "C" { #endif -#define kPosInfinity16 (32767) -#define kNegInfinity16 (-32768) - -#define kPosInfinity32 (0x7fffffff) -#define kNegInfinity32 (0x80000000) - - #ifdef _LP64 typedef unsigned int UInt32; typedef int Int32; @@ -65,27 +58,6 @@ #endif #endif -#define kPosInfinity32 (0x7fffffff) -#define kNegInfinity32 (0x80000000) - -#define F26Dot6ToFixed(n) ((n) << 10) -#define F26Dot6ToScalar(n) (((t2kScalar)(n)) / (t2kScalar)64) - - /* t2kFixed is the same as F16Dot16 format although T2K also uses 26.6 */ -typedef Int32 t2kFixed; -typedef float t2kScalar; - -#define t2kIntToFixed(x) ((t2kFixed)(x) << 16) -#define t2kFixedToInt(x) ((x) >> 16) - -#define t2kFixedRound(x) (((x) + 0x8000) >> 16) -#define t2kFixed1 t2kIntToFixed(1) - -#define t2kFloatToFixed(f) (t2kFixed)((f) * (float)(t2kFixed1)) -#define t2kFixedToFloat(x) ((x) / (float)(65536)) - -#define t2kScalarAverage(a, b) (((a) + (b)) / (t2kScalar)(2)) - /* managed: 1 means the glyph has a hardware cached * copy, and its freeing is managed by the usual * 2D disposer code. diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/native/libfontmanager/freetypeScaler.c --- a/src/java.desktop/share/native/libfontmanager/freetypeScaler.c Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/native/libfontmanager/freetypeScaler.c Tue Jun 19 10:12:35 2018 -0700 @@ -364,6 +364,19 @@ context->doBold = (boldness != 1.0); context->doItalize = (italic != 0); + /* freetype is very keen to use embedded bitmaps, even if it knows + * there is a rotation or you asked for antialiasing. + * In the rendering path we will check useSBits and disable + * bitmaps unless it is set. And here we set it only if none + * of the conditions invalidate using it. + * Note that we allow embedded bitmaps for the LCD case. + */ + if ((aa != TEXT_AA_ON) && (fm != TEXT_FM_ON) && + !context->doBold && !context->doItalize && + (context->transform.yx == 0) && (context->transform.xy == 0)) + { + context->useSbits = 1; + } return ptr_to_jlong(context); } @@ -685,9 +698,8 @@ return ptr_to_jlong(getNullGlyphImage()); } - /* if algorithmic styling is required then we do not request bitmap */ - if (context->doBold || context->doItalize) { - renderFlags = FT_LOAD_DEFAULT; + if (!context->useSbits) { + renderFlags |= FT_LOAD_NO_BITMAP; } /* NB: in case of non identity transform diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/native/libfontmanager/harfbuzz/hb-face.cc --- a/src/java.desktop/share/native/libfontmanager/harfbuzz/hb-face.cc Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/native/libfontmanager/harfbuzz/hb-face.cc Tue Jun 19 10:12:35 2018 -0700 @@ -117,9 +117,6 @@ return closure; } -#ifdef __SUNPRO_CC -extern "C" { -#endif static void _hb_face_for_data_closure_destroy (void *data) { @@ -128,9 +125,6 @@ hb_blob_destroy (closure->blob); free (closure); } -#ifdef __SUNPRO_CC -} -#endif static hb_blob_t * _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) @@ -496,7 +490,7 @@ unsigned int *table_count, /* IN/OUT */ hb_tag_t *table_tags /* OUT */) { - if (face->destroy != _hb_face_for_data_closure_destroy) + if (face->destroy != (hb_destroy_func_t) _hb_face_for_data_closure_destroy) { if (table_count) *table_count = 0; diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/share/native/libfontmanager/harfbuzz/hb-private.hh --- a/src/java.desktop/share/native/libfontmanager/harfbuzz/hb-private.hh Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/share/native/libfontmanager/harfbuzz/hb-private.hh Tue Jun 19 10:12:35 2018 -0700 @@ -139,7 +139,7 @@ #define HB_FUNC __func__ #endif -#ifdef __SUNPRO_CC +#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140) /* https://github.com/harfbuzz/harfbuzz/issues/630 */ #define __restrict #endif diff -r c82ed0f373bb -r 0e9d1d4ab692 src/java.desktop/windows/native/libawt/windows/awt_Component.cpp --- a/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp Tue Jun 19 07:15:00 2018 -0400 +++ b/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp Tue Jun 19 10:12:35 2018 -0700 @@ -3853,6 +3853,8 @@ MsgRouting AwtComponent::WmForwardChar(WCHAR character, LPARAM lParam, BOOL synthetic) { + deadKeyActive = FALSE; + // just post WM_CHAR with unicode key value DefWindowProc(WM_CHAR, (WPARAM)character, lParam); return mrConsume; diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/DispatcherWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/DispatcherWrapper.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop; + +import java.awt.SecondaryLoop; +import java.awt.EventQueue; +import sun.awt.FwDispatcher; +import sun.awt.AWTAccessor; + +/** + * This class provides a wrapper over inner class DispatcherProxy + * which implements jdk internal sun.awt.FwDispatcher interface + * and provides APIs to be used by FX swing interop to access and use + * FwDispatcher APIs. + * + * @since 11 + */ +public abstract class DispatcherWrapper { + private DispatcherProxy fwd; + + public DispatcherWrapper() { + fwd = new DispatcherProxy(); + } + + public abstract boolean isDispatchThread(); + + public abstract void scheduleDispatch(Runnable r); + + public abstract SecondaryLoop createSecondaryLoop(); + + public static void setFwDispatcher(EventQueue eventQueue, DispatcherWrapper dispatcher) { + AWTAccessor.getEventQueueAccessor().setFwDispatcher(eventQueue, dispatcher.fwd); + } + + private class DispatcherProxy implements FwDispatcher { + + @Override + public boolean isDispatchThread() { + return DispatcherWrapper.this.isDispatchThread(); + } + + @Override + public void scheduleDispatch(Runnable r) { + DispatcherWrapper.this.scheduleDispatch(r); + } + + @Override + public SecondaryLoop createSecondaryLoop() { + return DispatcherWrapper.this.createSecondaryLoop(); + } + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/DragSourceContextWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/DragSourceContextWrapper.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop; + +import java.awt.Cursor; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.DragSourceContext; +import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.DataFlavor; +import java.util.Map; +import sun.awt.dnd.SunDragSourceContextPeer; + +/** + * This class provides a wrapper over inner DragSourceContextPeerProxy class + * which extends jdk internal sun.awt.dnd.SunDragSourceContextPeer class + * and provides APIs to be used by FX swing interop to access and use + * DragSourceContextPeer APIs. + * + * @since 11 + */ +public abstract class DragSourceContextWrapper { + private DragSourceContextPeerProxy dsp; + + public DragSourceContextWrapper(DragGestureEvent e) { + dsp = new DragSourceContextPeerProxy(e); + } + + DragSourceContextPeer getPeer() { + return dsp; + } + + public static int convertModifiersToDropAction(int modifiers, + int supportedActions) { + return DragSourceContextPeerProxy. + convertModifiersToDropAction(modifiers, supportedActions); + } + + protected abstract void setNativeCursor(Cursor c, int cType); + + protected abstract void startDrag(Transferable trans, long[] formats, + Map formatMap); + + public abstract void startSecondaryEventLoop(); + + public abstract void quitSecondaryEventLoop(); + + public void dragDropFinished(final boolean success, + final int operations, + final int x, final int y) { + dsp.dragDropFinishedCall(success, operations, x, y); + } + + public DragSourceContext getDragSourceContext() { + return dsp.getDragSourceContextCall(); + } + + private class DragSourceContextPeerProxy extends SunDragSourceContextPeer { + + public DragSourceContextPeerProxy(DragGestureEvent e) { + super(e); + } + + protected void startDrag(Transferable trans, long[] formats, + Map formatMap) { + DragSourceContextWrapper.this.startDrag(trans, formats, formatMap); + } + + protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) { + DragSourceContextWrapper.this.setNativeCursor(c, cType); + } + + public void startSecondaryEventLoop() { + DragSourceContextWrapper.this.startSecondaryEventLoop(); + } + + public void quitSecondaryEventLoop() { + DragSourceContextWrapper.this.quitSecondaryEventLoop(); + } + + protected void dragDropFinishedCall(final boolean success, + final int operations, + final int x, final int y) { + dragDropFinished(success, operations, x, y); + } + + protected DragSourceContext getDragSourceContextCall() { + return getDragSourceContext(); + } + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/DropTargetContextWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/DropTargetContextWrapper.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop; + +import java.awt.dnd.peer.DropTargetContextPeer; +import java.awt.dnd.DropTarget; +import java.awt.dnd.InvalidDnDOperationException; +import java.awt.dnd.DropTargetContext; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import sun.awt.AWTAccessor; + +/** + * This class provides a wrapper over inner class DropTargetContextPeerProxy + * which implements jdk internal java.awt.dnd.peer.DropTargetContextPeer interface + * and provides APIs to be used by FX swing interop to access and use + * DropTargetContextPeer APIs. + * + * @since 11 + */ +public abstract class DropTargetContextWrapper { + + private DropTargetContextPeerProxy dcp; + public DropTargetContextWrapper() { + dcp = new DropTargetContextPeerProxy(); + } + + public void setDropTargetContext(DropTargetContext dtc, + DropTargetContextWrapper dtcpw) { + AWTAccessor.getDropTargetContextAccessor(). + setDropTargetContextPeer(dtc, dtcpw.dcp); + } + + public void reset(DropTargetContext dtc) { + AWTAccessor.getDropTargetContextAccessor().reset(dtc); + } + + public abstract void setTargetActions(int actions); + + public abstract int getTargetActions(); + + public abstract DropTarget getDropTarget(); + + public abstract DataFlavor[] getTransferDataFlavors(); + + public abstract Transferable getTransferable() throws InvalidDnDOperationException; + + public abstract boolean isTransferableJVMLocal(); + + public abstract void acceptDrag(int dragAction); + + public abstract void rejectDrag(); + + public abstract void acceptDrop(int dropAction); + + public abstract void rejectDrop(); + + public abstract void dropComplete(boolean success); + + private class DropTargetContextPeerProxy implements DropTargetContextPeer { + + public void setTargetActions(int actions) { + DropTargetContextWrapper.this.setTargetActions(actions); + } + + public int getTargetActions() { + return DropTargetContextWrapper.this.getTargetActions(); + } + + public DropTarget getDropTarget() { + return DropTargetContextWrapper.this.getDropTarget(); + } + + public DataFlavor[] getTransferDataFlavors() { + return DropTargetContextWrapper.this.getTransferDataFlavors(); + } + + public Transferable getTransferable() + throws InvalidDnDOperationException { + return DropTargetContextWrapper.this.getTransferable(); + } + + public boolean isTransferableJVMLocal() { + return DropTargetContextWrapper.this.isTransferableJVMLocal(); + } + + public void acceptDrag(int dragAction) { + DropTargetContextWrapper.this.acceptDrag(dragAction); + } + + public void rejectDrag() { + DropTargetContextWrapper.this.rejectDrag(); + } + + public void acceptDrop(int dropAction) { + DropTargetContextWrapper.this.acceptDrop(dropAction); + } + + public void rejectDrop() { + DropTargetContextWrapper.this.rejectDrop(); + } + + public void dropComplete(boolean success) { + DropTargetContextWrapper.this.dropComplete(success); + } + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/LightweightContentWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/LightweightContentWrapper.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop; + +import java.awt.Component; +import java.awt.dnd.DragGestureRecognizer; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragSource; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.InvalidDnDOperationException; +import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.dnd.DropTarget; +import javax.swing.JComponent; +import sun.swing.LightweightContent; + +/** + * This class provides a wrapper over inner LightweightContentProxy class + * which implements jdk internal sun.swing.LightweightContent interface + * and provides APIs to be used by FX swing interop to access and use + * LightweightContent APIs. + * + * @since 11 + */ +public abstract class LightweightContentWrapper { + private LightweightContentProxy lwCnt; + + public LightweightContentWrapper() { + lwCnt = new LightweightContentProxy(); + } + + LightweightContentProxy getContent() { + return lwCnt; + } + + public abstract void imageBufferReset(int[] data, int x, int y, int width, + int height, int linestride); + + public abstract void imageBufferReset(int[] data, int x, int y, int width, + int height, + int linestride, double scaleX, + double scaleY); + + public abstract JComponent getComponent(); + + public abstract void paintLock(); + + public abstract void paintUnlock(); + + public abstract void imageReshaped(int x, int y, int width, int height); + + public abstract void imageUpdated(int dirtyX, int dirtyY,int dirtyWidth, + int dirtyHeight); + + public abstract void focusGrabbed(); + + public abstract void focusUngrabbed(); + + public abstract void preferredSizeChanged(int width, int height); + + public abstract void maximumSizeChanged(int width, int height); + + public abstract void minimumSizeChanged(int width, int height); + + public abstract T createDragGestureRecognizer( + Class abstractRecognizerClass, + DragSource ds, Component c, int srcActions, + DragGestureListener dgl); + + public abstract DragSourceContextWrapper createDragSourceContext(DragGestureEvent dge) + throws InvalidDnDOperationException; + + public abstract void addDropTarget(DropTarget dt); + + public abstract void removeDropTarget(DropTarget dt); + + private class LightweightContentProxy implements LightweightContent { + + public JComponent getComponent() { + return LightweightContentWrapper.this.getComponent(); + } + + public void paintLock() { + LightweightContentWrapper.this.paintLock(); + } + + public void paintUnlock() { + LightweightContentWrapper.this.paintUnlock(); + } + + public void imageBufferReset(int[] data, int x, int y, int width, + int height, int linestride) { + LightweightContentWrapper.this.imageBufferReset(data, x, y, width, + height, linestride); + } + + public void imageBufferReset(int[] data, int x, int y, int width, + int height, int linestride, double scaleX, + double scaleY) { + LightweightContentWrapper.this.imageBufferReset(data, x, y, width, + height, linestride, scaleX, scaleY); + } + + public void imageReshaped(int x, int y, int width, int height) { + LightweightContentWrapper.this.imageReshaped(x, y, width, height); + } + + public void imageUpdated(int dirtyX, int dirtyY,int dirtyWidth, int dirtyHeight) { + LightweightContentWrapper.this.imageUpdated(dirtyX, dirtyY, dirtyWidth, dirtyHeight); + } + + public void focusGrabbed() { + LightweightContentWrapper.this.focusGrabbed(); + } + + public void focusUngrabbed() { + LightweightContentWrapper.this.focusUngrabbed(); + } + + public void preferredSizeChanged(int width, int height) { + LightweightContentWrapper.this.preferredSizeChanged(width, height); + } + + public void maximumSizeChanged(int width, int height) { + LightweightContentWrapper.this.maximumSizeChanged(width, height); + } + + public void minimumSizeChanged(int width, int height) { + LightweightContentWrapper.this.minimumSizeChanged(width, height); + } + + public T createDragGestureRecognizer( + Class abstractRecognizerClass, + DragSource ds, Component c, int srcActions, + DragGestureListener dgl) { + return LightweightContentWrapper.this.createDragGestureRecognizer( + abstractRecognizerClass, ds, c, srcActions, dgl); + } + + public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) + throws InvalidDnDOperationException { + DragSourceContextWrapper peerWrapper = + LightweightContentWrapper.this.createDragSourceContext(dge); + return peerWrapper.getPeer(); + } + + public void addDropTarget(DropTarget dt) { + LightweightContentWrapper.this.addDropTarget(dt); + } + + public void removeDropTarget(DropTarget dt) { + LightweightContentWrapper.this.removeDropTarget(dt); + } + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/LightweightFrameWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/LightweightFrameWrapper.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop; + +import java.awt.AWTEvent; +import java.awt.Container; +import java.awt.Component; +import java.awt.event.WindowFocusListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.event.KeyEvent; +import sun.awt.LightweightFrame; +import sun.awt.UngrabEvent; +import sun.awt.AWTAccessor; +import sun.swing.JLightweightFrame; + +/** + * This class wraps sun.swing.JLightweightFrame and implements + * APIs to be used by FX swing interop to access and use JLightweightFrame APIs. + * + * @since 11 + */ +public class LightweightFrameWrapper { + + JLightweightFrame lwFrame; + + public LightweightFrameWrapper() { + lwFrame = new JLightweightFrame(); + } + + private JLightweightFrame getLightweightFrame() { + return lwFrame; + } + + public void notifyDisplayChanged(final int scaleFactor) { + if (lwFrame != null) { + lwFrame.notifyDisplayChanged(scaleFactor, scaleFactor); + } + } + + /** + * {@code overrideNativeWindowHandle()} is package private but + * part of the interface of this class. It supports providing a + * foreign native window handle (i.e. an FX window handle) to AWT, + * and as such is intended to be called via JNI code, + * not by Java code, so it is not public. + */ + void overrideNativeWindowHandle(long handle, Runnable closeWindow) { + if (lwFrame != null) { + lwFrame.overrideNativeWindowHandle(handle, closeWindow); + } + } + + public void setHostBounds(int x, int y, int w, int h) { + if (lwFrame != null) { + lwFrame.setHostBounds(x, y, w, h); + } + } + + public void dispose() { + if (lwFrame != null) { + lwFrame.dispose(); + } + } + + public void addWindowFocusListener(WindowFocusListener listener) { + if (lwFrame != null) { + lwFrame.addWindowFocusListener(listener); + } + } + + public void setVisible(boolean visible) { + if (lwFrame != null) { + lwFrame.setVisible(visible); + } + } + + public void setBounds(int x, int y, int w, int h) { + if (lwFrame != null) { + lwFrame.setBounds(x, y, w, h); + } + } + + public void setContent(final LightweightContentWrapper lwCntWrapper) { + if (lwFrame != null) { + lwFrame.setContent(lwCntWrapper.getContent()); + } + } + + public void emulateActivation(boolean activate) { + if (lwFrame != null) { + lwFrame.emulateActivation(activate); + } + } + + public MouseEvent createMouseEvent(LightweightFrameWrapper lwFrame, + int swingID, long swingWhen, int swingModifiers, + int relX, int relY, int absX, int absY, + int clickCount, boolean swingPopupTrigger, + int swingButton) { + return new java.awt.event.MouseEvent(lwFrame.getLightweightFrame(), + swingID, swingWhen, + swingModifiers, + relX, relY, absX, absY, clickCount, + swingPopupTrigger, swingButton); + } + + public MouseWheelEvent createMouseWheelEvent(LightweightFrameWrapper lwFrame, + int swingModifiers, int x, int y, int wheelRotation) { + return new MouseWheelEvent(lwFrame.getLightweightFrame(), + java.awt.event.MouseEvent.MOUSE_WHEEL, + System.currentTimeMillis(), + swingModifiers, x, y, 0, 0, 0, false, + MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, + wheelRotation); + } + + public KeyEvent createKeyEvent(LightweightFrameWrapper lwFrame, + int swingID, long swingWhen, + int swingModifiers, + int swingKeyCode, char swingChar) { + return new java.awt.event.KeyEvent(lwFrame.getLightweightFrame(), + swingID, swingWhen, swingModifiers, swingKeyCode, + swingChar); + } + + public AWTEvent createUngrabEvent(LightweightFrameWrapper lwFrame) { + return new UngrabEvent(lwFrame.getLightweightFrame()); + } + + public Component findComponentAt(LightweightFrameWrapper cont, int x, int y, boolean ignoreEnabled) { + Container lwframe = cont.getLightweightFrame(); + return AWTAccessor.getContainerAccessor().findComponentAt(lwframe, x, y, ignoreEnabled); + } + + public boolean isCompEqual(Component c, LightweightFrameWrapper lwFrame) { + return c != lwFrame.getLightweightFrame(); + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/SwingInterOpUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/SwingInterOpUtils.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop; + +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.AWTEvent; +import sun.awt.SunToolkit; +import sun.awt.AppContext; +import sun.awt.UngrabEvent; + +/** + * This class provides static utility methods to be used by FX swing interop + * to access and use jdk internal classes like SunToolkit, AppContext + * and UngrabEvent. + * + * @since 11 + */ +public class SwingInterOpUtils { + + public static void postEvent(Object target, java.awt.AWTEvent e) { + AppContext context = SunToolkit.targetToAppContext(target); + if (context != null) { + SunToolkit.postEvent(context, e); + } + } + + public static void grab(Toolkit toolkit, Window window) { + if (toolkit instanceof SunToolkit) { + ((SunToolkit)toolkit).grab(window); + } + } + + public static void ungrab(Toolkit toolkit, Window window) { + if (toolkit instanceof SunToolkit) { + ((SunToolkit)toolkit).ungrab(window); + } + } + + public static boolean isUngrabEvent(AWTEvent e) { + return e instanceof UngrabEvent; + } + + public static final int GRAB_EVENT_MASK = SunToolkit.GRAB_EVENT_MASK; + +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/internal/InteropProviderImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/jdk/swing/interop/internal/InteropProviderImpl.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, 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 jdk.swing.interop.internal; + +import sun.swing.InteropProvider; + +/** + * @since 11 + */ +public class InteropProviderImpl implements InteropProvider { +} diff -r c82ed0f373bb -r 0e9d1d4ab692 src/jdk.unsupported.desktop/share/classes/module-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.unsupported.desktop/share/classes/module-info.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, 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. + */ +/** + * This module is intended for use only by the javafx.swing module + * for the purpose of FX/Swing interop + * + * @since 11 + */ +module jdk.unsupported.desktop { + + requires transitive java.desktop; + + exports jdk.swing.interop; + + provides sun.swing.InteropProvider + with jdk.swing.interop.internal.InteropProviderImpl; + +} + diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/ProblemList.txt --- a/test/jdk/ProblemList.txt Tue Jun 19 07:15:00 2018 -0400 +++ b/test/jdk/ProblemList.txt Tue Jun 19 10:12:35 2018 -0700 @@ -804,7 +804,6 @@ javax/swing/text/Utilities/8142966/SwingFontMetricsTest.java 8202663 windows-all javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java 202880 linux-all javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all -javax/swing/plaf/nimbus/8057791/bug8057791.java 8202877 macosx-all javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all java/awt/im/memoryleak/InputContextMemoryLeakTest.java 8023814 linux-all,solaris-all diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/java/awt/FontClass/GlyphRotationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/java/awt/FontClass/GlyphRotationTest.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018, 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 + * @bug 8204929 + * @summary test rotation of font with embedded bitmaps + * @run main GlyphRotationTest + */ + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import javax.imageio.ImageIO; + +public class GlyphRotationTest { + + public static final String fontName = "MS UI Gothic"; + public static Font font; + public static final int SZ = 50; + + public static void main(String[] args) { + font = new Font(fontName, Font.PLAIN, 15); + if (!font.getFamily(java.util.Locale.ENGLISH).equals(fontName)) { + return; + } + BufferedImage bi = new BufferedImage(SZ,SZ,BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = bi.createGraphics(); + g2d.setColor(Color.white); + g2d.fillRect(0, 0, SZ, SZ); + g2d.setColor(Color.black); + g2d.setFont(font); + g2d.drawString("1", SZ/2, SZ/2); + int pixCnt1 = countPixels(bi); + AffineTransform at = AffineTransform.getRotateInstance(Math.PI/2); + font = font.deriveFont(Font.PLAIN, at); + g2d.setFont(font); + g2d.drawString("1", SZ/2, SZ/2); + int pixCnt2 = countPixels(bi); + if (args.length > 0) { + try { + ImageIO.write(bi, "png", new java.io.File("im.png")); + } catch (Exception e) {} + } + if (pixCnt1 == pixCnt2) { + String msg = "cnt 1 = " + pixCnt1 + " cnt 2 = " + pixCnt2; + throw new RuntimeException(msg); + } + } + + static int countPixels(BufferedImage bi) { + int cnt = 0; + int w = bi.getWidth(null); + int h = bi.getHeight(null); + for (int i=0; i formats = new ArrayList<>(); + + private static final AudioFormat.Encoding[] encodings = + {AudioFormat.Encoding.ALAW, AudioFormat.Encoding.ULAW, + AudioFormat.Encoding.PCM_SIGNED, + AudioFormat.Encoding.PCM_UNSIGNED, + AudioFormat.Encoding.PCM_FLOAT}; + + private static final AudioFileFormat.Type[] types = + {WAVE, AU, AIFF, AIFC, SND}; + + static { + for (final AudioFormat.Encoding enc : encodings) { + formats.add(new AudioFormat(enc, 44100, 8, 1, 1, 44100, true)); + formats.add(new AudioFormat(enc, 44100, 8, 1, 1, 44100, false)); + } + } + + public static void main(final String[] args) throws Exception { + for (final AudioFileFormat.Type type : types) { + for (final AudioFormat format : formats) { + File file = new File("audio." + type.getExtension()); + try { + AudioSystem.write(getStream(format), type, file); + } catch (IOException | IllegalArgumentException ignored) { + continue; + } + AudioClip content; + try { + content = (AudioClip) file.toURL().getContent(); + // We need to generate OOM because the stream in AudioClip + // will be closed in finalize(). + generateOOME(); + } finally { + Files.delete(file.toPath()); + } + if (content == null) { + throw new RuntimeException("Content is null"); + } + } + } + } + + private static AudioInputStream getStream(final AudioFormat format) { + final InputStream in = new ByteArrayInputStream(new byte[100]); + return new AudioInputStream(in, format, 10); + } + + private static void generateOOME() throws Exception { + List leak = new LinkedList<>(); + try { + while (true) { + leak.add(new byte[1024 * 1024]); + } + } catch (OutOfMemoryError ignored) { + } + // Give the GC a chance at that weakref in case of slow systems + Thread.sleep(2000); + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/javax/swing/SwingWorker/6608234/CheckCancellationException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/javax/swing/SwingWorker/6608234/CheckCancellationException.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018, 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. + */ + +import java.util.concurrent.CancellationException; +import java.util.concurrent.CountDownLatch; + +import javax.swing.SwingWorker; + +/** + * @test + * @bug 6608234 + */ +public final class CheckCancellationException { + + private static final CountDownLatch go = new CountDownLatch(1); + + public static void main(final String[] args) throws Exception { + SwingWorker worker = new SwingWorker() { + protected Void doInBackground() { + go.countDown(); + while (!Thread.interrupted()) ; + return null; + } + }; + worker.execute(); + go.await(); + worker.cancel(true); + try { + worker.get(); + } catch (final CancellationException expected) { + // expected exception + return; + } + throw new RuntimeException("CancellationException was not thrown"); + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/javax/swing/text/Caret/TestCaretPosition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/javax/swing/text/Caret/TestCaretPosition.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2018, 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 + * @bug 8199441 + * @key headful + * @summary Verifies caret position in multiline line-wrapped text component + * in hidpi mode should be in sync with mouse press position. + * @run main/othervm -Dsun.java2d.uiScale=1.5 TestCaretPosition + */ + +import javax.swing.JTextArea; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; +import java.awt.Font; +import java.awt.BorderLayout; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.geom.Rectangle2D; + +public class TestCaretPosition { + private static JTextArea jTextArea1; + private static JFrame f; + + private static void createUI() { + jTextArea1 = new JTextArea(5, 80); + f = new JFrame(); + jTextArea1.setFont(new java.awt.Font("Arial", Font.PLAIN, 12)); + + fillTextArea(jTextArea1); + jTextArea1.setLineWrap(true); + jTextArea1.addMouseListener(new MouseListener() { + @Override + public void mouseClicked(MouseEvent e) {} + + @Override + public void mousePressed(MouseEvent e) { + try { + Caret caret = jTextArea1.getCaret(); + Rectangle2D rect = jTextArea1.modelToView2D(caret.getDot()); + + if (Math.abs(e.getPoint().x - rect.getX()) > 5) { + System.out.println("mouse point " + e.getPoint()); + System.out.println("caret position " + rect); + throw new RuntimeException(" Wrong caret position"); + } + } catch (BadLocationException ex) {} + } + + @Override + public void mouseReleased(MouseEvent e) {} + + @Override + public void mouseEntered(MouseEvent e) {} + + @Override + public void mouseExited(MouseEvent e) {} + }); + f.add(new JScrollPane(jTextArea1), BorderLayout.CENTER); + f.pack(); + f.setVisible(true); + } + + public static void main(String args[]) throws Exception { + try { + + SwingUtilities.invokeAndWait(() -> createUI()); + + Point p = jTextArea1.getLocationOnScreen(); + Robot robot = new Robot(); + robot.setAutoDelay(200); + robot.mouseMove(p.x+ 480, p.y+6); + robot.waitForIdle(); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + } finally { + SwingUtilities.invokeAndWait(() -> f.dispose()); + } + } + + private static void fillTextArea(JTextArea area) { + StringBuilder buf = new StringBuilder(); + + for (int i = 0; i < 3; i++) { + StringBuilder row = new StringBuilder(); + for (int j = 0; j < 50; j++) { + row.append(j); + if (j % 5 == 0) { + row.append(" "); + } + } + buf.append(row).append(System.lineSeparator()); + } + area.setText(buf.toString()); + area.setCaretPosition(0); + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/sanity/client/SwingSet/src/GridBagLayoutDemoTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/sanity/client/SwingSet/src/GridBagLayoutDemoTest.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2018, 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. + */ +import org.jtregext.GuiTestListener; +import com.sun.swingset3.demos.gridbaglayout.GridBagLayoutDemo; +import static com.sun.swingset3.demos.gridbaglayout.GridBagLayoutDemo.*; +import static com.sun.swingset3.demos.gridbaglayout.Calculator.*; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Point; +import javax.swing.JButton; +import javax.swing.UIManager; +import org.testng.annotations.Test; +import org.netbeans.jemmy.ClassReference; +import org.netbeans.jemmy.operators.JFrameOperator; +import org.netbeans.jemmy.operators.JButtonOperator; +import org.netbeans.jemmy.operators.JTextFieldOperator; +import org.testng.annotations.Listeners; +import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR; +import static org.jemmy2ext.JemmyExt.getUIValue; +/* + * @test + * @key headful + * @summary Verifies SwingSet3 GridBagLayoutDemo by checking the relative + * location of all the components before and after resizing the frame, + * interacting with all the controls and checking this interaction on the + * text field display. + * + * @library /sanity/client/lib/jemmy/src + * @library /sanity/client/lib/Extensions/src + * @library /sanity/client/lib/SwingSet3/src + * @modules java.desktop + * java.logging + * @build com.sun.swingset3.demos.gridbaglayout.GridBagLayoutDemo + * @run testng GridBagLayoutDemoTest + */ + +@Listeners(GuiTestListener.class) +public class GridBagLayoutDemoTest { + + private JTextFieldOperator tfScreen; + private JButtonOperator buttonZero; + private JButtonOperator buttonOne; + private JButtonOperator buttonTwo; + private JButtonOperator buttonThree; + private JButtonOperator buttonFour; + private JButtonOperator buttonFive; + private JButtonOperator buttonSix; + private JButtonOperator buttonSeven; + private JButtonOperator buttonEight; + private JButtonOperator buttonNine; + private JButtonOperator buttonPlus; + private JButtonOperator buttonMinus; + private JButtonOperator buttonMultiply; + private JButtonOperator buttonDivide; + private JButtonOperator buttonComma; + private JButtonOperator buttonSqrt; + private JButtonOperator buttonReciprocal; + private JButtonOperator buttonToggleSign; + private JButtonOperator buttonEquals; + private JButtonOperator backspaceButton; + private JButtonOperator resetButton; + private JFrameOperator mainFrame; + + @Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class) + public void test(String lookAndFeel) throws Exception { + initializeUIComponents(lookAndFeel); + // Check that the relative location of buttons is as expected. + checkRelativeLocations(); + // Interact with buttons and check the result on the display. + checkInteractionOnDisplay(); + // Change the location and check that the relative location of buttons is same as before. + checkChangeLocation(); + // Change the size and check that the relative location of buttons is same as before. + checkChangeSize(); + } + + private double x(Component component) { + return component.getLocation().getX(); + } + + private double y(Component component) { + return component.getLocation().getY(); + } + + private void checkRight(JButtonOperator currentButton, JButtonOperator rightButton) { + // Check that x coordinate of right button is greater than that of right + // end of current button + currentButton.waitStateOnQueue(button -> x(button) + button.getWidth() < x(rightButton.getSource())); + // Check that the y coordinate of the button is same as the button to + // the right + currentButton.waitStateOnQueue(button -> y(button) == y(rightButton.getSource())); + // Check that the height of the button is same as the button to the + // right + currentButton.waitStateOnQueue(button -> button.getHeight() == rightButton.getHeight()); + } + + private void checkBelow(JButtonOperator currentButton, JButtonOperator buttonBelow) { + // Check that y coordinate of button below is greater than that of + // bottom end of current button + currentButton.waitStateOnQueue(button -> y(button) + button.getHeight() < y(buttonBelow.getSource())); + // Check that the x coordinate of the button is same as the button below + currentButton.waitStateOnQueue(button -> x(button) == x(buttonBelow.getSource())); + // Check that the width of the button is same as the button below + currentButton.waitStateOnQueue(button -> button.getWidth() == buttonBelow.getWidth()); + } + + private void checkRelativeLocations() { + // Check relative location of button 7 + checkRight(buttonSeven, buttonEight); + checkBelow(buttonSeven, buttonFour); + + // Check relative location of button 8 + checkRight(buttonEight, buttonNine); + checkBelow(buttonEight, buttonFive); + + // Check relative location of button 9 + checkRight(buttonNine, buttonDivide); + checkBelow(buttonNine, buttonSix); + + // Check relative location of Division button + checkRight(buttonDivide, buttonReciprocal); + checkBelow(buttonDivide, buttonMultiply); + + // Check relative location of Reciprocal and Sqrt buttons + checkBelow(buttonReciprocal, buttonSqrt); + + // Check relative location of button 4 + checkRight(buttonFour, buttonFive); + checkBelow(buttonFour, buttonOne); + + // Check relative location of button 5 + checkRight(buttonFive, buttonSix); + checkBelow(buttonFive, buttonTwo); + + // Check relative location of button 6 + checkRight(buttonSix, buttonMultiply); + checkBelow(buttonSix, buttonThree); + + // Check relative location of Multiply button + checkRight(buttonMultiply, buttonSqrt); + checkBelow(buttonMultiply, buttonMinus); + + // Check relative location of button 1 + checkRight(buttonOne, buttonTwo); + checkBelow(buttonOne, buttonZero); + + // Check relative location of button 2 + checkRight(buttonTwo, buttonThree); + checkBelow(buttonTwo, buttonToggleSign); + + // Check relative location of button 3 + checkRight(buttonThree, buttonMinus); + checkBelow(buttonThree, buttonComma); + + // Check relative location of Minus button + checkBelow(buttonMinus, buttonPlus); + + // Check relative location of button 0 + checkRight(buttonZero, buttonToggleSign); + + // Check relative location of Sign Toggle Button + checkRight(buttonToggleSign, buttonComma); + + // Check relative location of Comma button + checkRight(buttonComma, buttonPlus); + + // Check relative location of plus and Equals buttons + checkRight(buttonPlus, buttonEquals); + + // Check relative location of JPanel containing Backspace and Reset + // buttons + Point parentLocation = getUIValue(backspaceButton, (JButton button) -> button.getParent().getLocation()); + // Check that the y coordinate of bottom of the screen is + // less than that of parent of backspace button + tfScreen.waitStateOnQueue(screen -> y(screen) + screen.getHeight() < parentLocation.getY()); + // Check that the y coordinate of the button 7 is greater + // than that of parent of backspace + buttonSeven.waitStateOnQueue(button -> parentLocation.getY() < y(button)); + // Check that the y coordinate of reciprocal button is greater + // than that of parent of backspace + buttonReciprocal.waitStateOnQueue(button -> parentLocation.getY() < y(button)); + // Check that x coordinate of screen is same as that of parent of + // backspace + tfScreen.waitStateOnQueue(screen -> x(screen) == parentLocation.getX()); + // Check that x coordinate of button 7 is same as that of parent of + // backspace + buttonSeven.waitStateOnQueue(button -> x(button) == parentLocation.getX()); + + // Check relative location of Backspace button + // Check that the x coordinate of right of backspace button + // is less than that of reset button + backspaceButton.waitStateOnQueue(button -> x(button) + button.getWidth() < x(resetButton.getSource())); + // Check that the height of backspace button is same as that of reset + // button + backspaceButton.waitStateOnQueue(button -> button.getHeight() == resetButton.getHeight()); + // Check that the y coordinate bottom of backspace button is less that + // that of button 7 + backspaceButton.waitStateOnQueue( + button -> parentLocation.getY() + button.getParent().getHeight() < y(buttonSeven.getSource())); + + // Check that the x coordinate of reset button is greater than that + // of right of backspace button + resetButton.waitStateOnQueue(button -> x(backspaceButton.getSource()) + backspaceButton.getWidth() < x(button)); + + // Check that the height of reset button is same as that of backspace + // button + resetButton.waitStateOnQueue(button -> backspaceButton.getHeight() == button.getHeight()); + + // Check that the y coordinate of bottom of reset button is less + // than that of divide button. + resetButton.waitStateOnQueue( + button -> parentLocation.getY() + button.getParent().getHeight() < y(buttonDivide.getSource())); + + // Check that the y coordinate of top of screen is lower + // than that of parent of backspace button + tfScreen.waitStateOnQueue(screen -> y(screen) + screen.getHeight() < parentLocation.getY()); + } + + private void checkInteractionOnDisplay() { + // Check buttons: 1,2,+,=,C + buttonOne.push(); + tfScreen.waitText("1"); + buttonPlus.push(); + tfScreen.waitText("1"); + buttonTwo.push(); + tfScreen.waitText("2"); + buttonEquals.push(); + tfScreen.waitText("3"); + resetButton.push(); + tfScreen.waitText("0"); + + // Check buttons: 3,4,- + buttonFour.push(); + tfScreen.waitText("4"); + buttonMinus.push(); + tfScreen.waitText("4"); + buttonThree.push(); + tfScreen.waitText("3"); + buttonEquals.push(); + tfScreen.waitText("1"); + reset(); + + // Check buttons: 5,6,* + buttonFive.push(); + tfScreen.waitText("5"); + buttonMultiply.push(); + tfScreen.waitText("5"); + buttonSix.push(); + tfScreen.waitText("6"); + buttonEquals.push(); + tfScreen.waitText("30"); + reset(); + + // Check buttons: 8,9,/ + buttonNine.push(); + buttonNine.push(); + tfScreen.waitText("99"); + buttonDivide.push(); + tfScreen.waitText("99"); + buttonEight.push(); + tfScreen.waitText("8"); + buttonEquals.push(); + tfScreen.waitText("12.375"); + reset(); + + // Check buttons: 7,0,[+/-],Backspace + buttonSeven.push(); + tfScreen.waitText("7"); + buttonZero.push(); + tfScreen.waitText("70"); + buttonToggleSign.push(); + tfScreen.waitText("-70"); + buttonToggleSign.push(); + tfScreen.waitText("70"); + backspaceButton.push(); + tfScreen.waitText("7"); + reset(); + + // Check Sqrt Button + buttonFour.push(); + buttonNine.push(); + tfScreen.waitText("49"); + buttonSqrt.push(); + tfScreen.waitText("7"); + reset(); + + // Check Reciprocal Button + buttonFour.push(); + tfScreen.waitText("4"); + buttonReciprocal.push(); + tfScreen.waitText("0.25"); + reset(); + + // Check Comma button + buttonFour.push(); + buttonComma.push(); + tfScreen.waitText("4,"); + } + + private void reset() { + resetButton.push(); + tfScreen.waitText("0"); + } + + private void initializeUIComponents(String lookAndFeel) throws Exception { + UIManager.setLookAndFeel(lookAndFeel); + new ClassReference(GridBagLayoutDemo.class.getCanonicalName()).startApplication(); + mainFrame = new JFrameOperator(GRID_BAG_LAYOUT_DEMO_TITLE); + mainFrame.setComparator(EXACT_STRING_COMPARATOR); + buttonZero = new JButtonOperator(mainFrame, ZERO_BUTTON_TITLE); + buttonOne = new JButtonOperator(mainFrame, ONE_BUTTON_TITLE); + buttonTwo = new JButtonOperator(mainFrame, TWO_BUTTON_TITLE); + buttonThree = new JButtonOperator(mainFrame, THREE_BUTTON_TITLE); + buttonFour = new JButtonOperator(mainFrame, FOUR_BUTTON_TITLE); + buttonFive = new JButtonOperator(mainFrame, FIVE_BUTTON_TITLE); + buttonSix = new JButtonOperator(mainFrame, SIX_BUTTON_TITLE); + buttonSeven = new JButtonOperator(mainFrame, SEVEN_BUTTON_TITLE); + buttonEight = new JButtonOperator(mainFrame, EIGHT_BUTTON_TITLE); + buttonNine = new JButtonOperator(mainFrame, NINE_BUTTON_TITLE); + buttonPlus = new JButtonOperator(mainFrame, PLUS_BUTTON_TITLE); + buttonMinus = new JButtonOperator(mainFrame, MINUS_BUTTON_TITLE); + buttonMultiply = new JButtonOperator(mainFrame, MULTIPLY_BUTTON_TITLE); + buttonDivide = new JButtonOperator(mainFrame, DIVIDE_BUTTON_TITLE); + buttonComma = new JButtonOperator(mainFrame, ","); + buttonSqrt = new JButtonOperator(mainFrame, SQRT_BUTTON_TITLE); + buttonReciprocal = new JButtonOperator(mainFrame, INVERSE_BUTTON_TITLE); + buttonToggleSign = new JButtonOperator(mainFrame, SWAPSIGN_BUTTON_TITLE); + buttonEquals = new JButtonOperator(mainFrame, EQUALS_BUTTON_TITLE); + resetButton = new JButtonOperator(mainFrame, C_BUTTON_TITLE); + backspaceButton = new JButtonOperator(mainFrame, BACKSPACE_BUTTON_TITLE); + tfScreen = new JTextFieldOperator(mainFrame, 0); + } + + private void checkChangeLocation() { + Point startingPoint = new Point(100, 100); + mainFrame.setLocation(startingPoint); + mainFrame.waitComponentLocation(startingPoint); + checkRelativeLocations(); + } + + private void checkChangeSize() { + Dimension newSize = new Dimension((int) mainFrame.getToolkit().getScreenSize().getWidth() / 2, + (int) mainFrame.getToolkit().getScreenSize().getHeight() / 2); + mainFrame.setSize(newSize); + mainFrame.waitComponentSize(newSize); + checkRelativeLocations(); + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/sanity/client/SwingSet/src/TestHelpers.java --- a/test/jdk/sanity/client/SwingSet/src/TestHelpers.java Tue Jun 19 07:15:00 2018 -0400 +++ b/test/jdk/sanity/client/SwingSet/src/TestHelpers.java Tue Jun 19 10:12:35 2018 -0700 @@ -1,17 +1,40 @@ - import java.awt.Dimension; import java.awt.Point; - +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.nio.file.Path; +import javax.swing.UIManager; import org.netbeans.jemmy.operators.ComponentOperator; +import org.testng.annotations.DataProvider; public class TestHelpers { + /** + * A DataProvider having the class name of all the available look and feels + * + * @return a 2d Object array containing the class name of all the available + * look and feels + */ + @DataProvider(name = "availableLookAndFeels") + public static Object[][] provideAvailableLookAndFeels() { + UIManager.LookAndFeelInfo LookAndFeelInfos[] + = UIManager.getInstalledLookAndFeels(); + Object[][] lookAndFeels = new Object[LookAndFeelInfos.length][1]; + for (int i = 0; i < LookAndFeelInfos.length; i++) { + lookAndFeels[i][0] = LookAndFeelInfos[i].getClassName(); + } + return lookAndFeels; + } + public static void checkChangeLocation(ComponentOperator component, Point finalLocation) { Point initialLocation = component.getLocation(); component.setLocation(finalLocation); component.waitComponentLocation(finalLocation); component.setLocation(initialLocation); + component.waitComponentLocation(initialLocation); } public static void checkChangeSize(ComponentOperator component, @@ -20,5 +43,7 @@ component.setSize(dimensionFinal); component.waitComponentSize(dimensionFinal); component.setSize(dimensionInitial); + component.waitComponentSize(dimensionInitial); } + } diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/Calculator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/Calculator.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,469 @@ +/* + * Copyright (c) 2007, 2018, 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. + */ +package com.sun.swingset3.demos.gridbaglayout; + +import java.awt.*; +import java.awt.event.*; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import javax.swing.*; + +/** + * Calculator + * + * @author Pavel Porvatov + */ +public class Calculator extends JComponent { + + private static final String ZERO = "0"; + + private static final char DECIMAL_SEPARATOR = ','; + + private final JTextField tfScreen = new JTextField(); + + private enum State { + + INPUT_X, + INPUT_X_FINISHED, + INPUT_Y, + INPUT_Y_FINISHED + } + + private enum Operator { + + ADDITION, + SUBTRACTION, + MULTIPLICATION, + DIVISION, + SQRT, + INVERSE, + EQUALS + } + + private final Map keyMapping = new HashMap(); + + private String operand_x; + + private Operator operator; + + private State state; + + public static final String ZERO_BUTTON_TITLE = "0"; + public static final String ONE_BUTTON_TITLE = "1"; + public static final String TWO_BUTTON_TITLE = "2"; + public static final String THREE_BUTTON_TITLE = "3"; + public static final String FOUR_BUTTON_TITLE = "4"; + public static final String FIVE_BUTTON_TITLE = "5"; + public static final String SIX_BUTTON_TITLE = "6"; + public static final String SEVEN_BUTTON_TITLE = "7"; + public static final String EIGHT_BUTTON_TITLE = "8"; + public static final String NINE_BUTTON_TITLE = "9"; + public static final String PLUS_BUTTON_TITLE = "+"; + public static final String MINUS_BUTTON_TITLE = "-"; + public static final String DIVIDE_BUTTON_TITLE = "/"; + public static final String MULTIPLY_BUTTON_TITLE = "*"; + public static final String BACKSPACE_BUTTON_TITLE = "Backspace"; + public static final String C_BUTTON_TITLE = "C"; + public static final String EQUALS_BUTTON_TITLE = "="; + public static final String SWAPSIGN_BUTTON_TITLE = "+/-"; + public static final String INVERSE_BUTTON_TITLE = "1/x"; + public static final String SQRT_BUTTON_TITLE = "sqrt"; + public static final String COMMA_BUTTON_TITLE = ","; + + private static DecimalFormatSymbols decimalFormatSymbols; + private static DecimalFormat decimalFormat; + + public Calculator() { + keyMapping.put('/', Operator.DIVISION); + keyMapping.put('*', Operator.MULTIPLICATION); + keyMapping.put('+', Operator.ADDITION); + keyMapping.put('-', Operator.SUBTRACTION); + keyMapping.put('\n', Operator.EQUALS); + + decimalFormatSymbols = new DecimalFormatSymbols(Locale.US); + decimalFormatSymbols.setDecimalSeparator('.'); + decimalFormat = new DecimalFormat("##0.###", decimalFormatSymbols); + + initUI(); + + addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + char c = e.getKeyChar(); + + if (Character.isDigit(c)) { + doProcessChar(c); + } else if (c == '.' || c == ',') { + doProcessChar(DECIMAL_SEPARATOR); + } else { + Operator operator = keyMapping.get(c); + + if (operator != null) { + doProcessOperator(operator); + } + } + } + + public void keyPressed(KeyEvent e) { + switch (e.getKeyCode()) { + case KeyEvent.VK_BACK_SPACE: + doProcessBackspace(); + + break; + + case KeyEvent.VK_DELETE: + doReset(); + } + } + }); + + doReset(); + } + + private void initUI() { + tfScreen.setHorizontalAlignment(JTextField.RIGHT); + + JButton btnBackspace = new JButton(BACKSPACE_BUTTON_TITLE); + + btnBackspace.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doProcessBackspace(); + } + }); + + JButton btnReset = new JButton(C_BUTTON_TITLE); + + btnReset.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doReset(); + } + }); + + JPanel pnGridPanel = new JPanel(new GridLayout(1, 2, 8, 8)); + + pnGridPanel.add(btnBackspace); + pnGridPanel.add(btnReset); + + setLayout(new GridBagLayout()); + + JButton btnSwapSign = new SquareButton(SWAPSIGN_BUTTON_TITLE); + + btnSwapSign.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doSwapSign(); + } + }); + + addComp(tfScreen, 0, 0, 5, 1); + addComp(pnGridPanel, 0, 1, 5, 1); + + addComp(new CharButton(SEVEN_BUTTON_TITLE.charAt(0)), 0, 2, 1, 1); + addComp(new CharButton(EIGHT_BUTTON_TITLE.charAt(0)), 1, 2, 1, 1); + addComp(new CharButton(NINE_BUTTON_TITLE.charAt(0)), 2, 2, 1, 1); + addComp(new OperatorButton(Operator.DIVISION, DIVIDE_BUTTON_TITLE), 3, 2, 1, 1); + addComp(new OperatorButton(Operator.INVERSE, INVERSE_BUTTON_TITLE), 4, 2, 1, 1); + + addComp(new CharButton(FOUR_BUTTON_TITLE.charAt(0)), 0, 3, 1, 1); + addComp(new CharButton(FIVE_BUTTON_TITLE.charAt(0)), 1, 3, 1, 1); + addComp(new CharButton(SIX_BUTTON_TITLE.charAt(0)), 2, 3, 1, 1); + addComp(new OperatorButton(Operator.MULTIPLICATION, MULTIPLY_BUTTON_TITLE), 3, 3, 1, 1); + addComp(new OperatorButton(Operator.SQRT, SQRT_BUTTON_TITLE), 4, 3, 1, 1); + + addComp(new CharButton(ONE_BUTTON_TITLE.charAt(0)), 0, 4, 1, 1); + addComp(new CharButton(TWO_BUTTON_TITLE.charAt(0)), 1, 4, 1, 1); + addComp(new CharButton(THREE_BUTTON_TITLE.charAt(0)), 2, 4, 1, 1); + addComp(new OperatorButton(Operator.SUBTRACTION, MINUS_BUTTON_TITLE), 3, 4, 1, 1); + + addComp(new CharButton(ZERO_BUTTON_TITLE.charAt(0)), 0, 5, 1, 1); + addComp(btnSwapSign, 1, 5, 1, 1); + addComp(new CharButton(COMMA_BUTTON_TITLE.charAt(0)), 2, 5, 1, 1); + addComp(new OperatorButton(Operator.ADDITION, PLUS_BUTTON_TITLE), 3, 5, 1, 1); + addComp(new OperatorButton(Operator.EQUALS, EQUALS_BUTTON_TITLE), 4, 5, 1, 1); + + // Set focusable false + resetFocusable(this); + + setFocusable(true); + } + + private static void resetFocusable(Component component) { + component.setFocusable(false); + + if (component instanceof Container) { + for (Component c : ((Container) component).getComponents()) { + resetFocusable(c); + } + } + } + + private void doReset() { + synchronized (this) { + operand_x = null; + operator = null; + state = State.INPUT_X; + } + tfScreen.setText(ZERO); + } + + private void doProcessChar(char c) { + String text = tfScreen.getText(); + + String newValue; + + synchronized (this) { + if (state == State.INPUT_X || state == State.INPUT_Y) { + newValue = attachChar(text, c); + + if (stringToValue(newValue) == null) { + return; + } + } else { + newValue = attachChar("0", c); + + if (stringToValue(newValue) == null) { + return; + } + + if (operator == null) { + operand_x = null; + state = State.INPUT_X; + } else { + operand_x = text; + state = State.INPUT_Y; + } + } + } + tfScreen.setText(newValue); + } + + private static String attachChar(String s, char c) { + if (Character.isDigit(c)) { + if (s.equals(ZERO)) { + return Character.toString(c); + } + + if (s.equals("-" + ZERO)) { + return "-" + Character.toString(c); + } + + return s + Character.toString(c); + } else { + return s + Character.toString(c); + } + } + + private void doSwapSign() { + String text = tfScreen.getText(); + + tfScreen.setText(text.startsWith("-") ? text.substring(1) : "-" + text); + } + + private void doProcessBackspace() { + String text = tfScreen.getText(); + + if (text.length() > 0) { + text = text.substring(0, text.length() - 1); + } + + if (text.length() == 0 || text.equals("-")) { + text = ZERO; + } + + if (stringToValue(text) != null) { + tfScreen.setText(text); + } + } + + private void doProcessOperator(Operator operator) { + double y = stringToValue(tfScreen.getText()); + + // Process unary operators + boolean isUnary; + + switch (operator) { + case SQRT: + tfScreen.setText(valueToString(Math.sqrt(y))); + + isUnary = true; + + break; + + case INVERSE: + tfScreen.setText(valueToString(1 / y)); + + isUnary = true; + + break; + + default: + isUnary = false; + } + + synchronized (this) { + if (isUnary) { + if (state == State.INPUT_X) { + state = State.INPUT_X_FINISHED; + } + + if (state == State.INPUT_Y) { + state = State.INPUT_Y_FINISHED; + } + + return; + } + + // Process binary operators + if (state == State.INPUT_Y || state == State.INPUT_Y_FINISHED) { + double x = stringToValue(operand_x); + double result; + + switch (this.operator) { + case ADDITION: + result = x + y; + + break; + + case SUBTRACTION: + result = x - y; + + break; + + case MULTIPLICATION: + result = x * y; + + break; + + case DIVISION: + result = x / y; + + break; + + default: + throw new IllegalStateException("Unsupported operation " + operator); + } + + tfScreen.setText(valueToString(result)); + } + + this.operator = operator == Operator.EQUALS ? null : operator; + operand_x = null; + + state = State.INPUT_X_FINISHED; + } + } + + private static Double stringToValue(String value) { + try { + return new Double(value.replace(DECIMAL_SEPARATOR, '.')); + } catch (NumberFormatException e) { + // Continue convertion + } + + if (value.endsWith(String.valueOf(DECIMAL_SEPARATOR))) { + try { + // Try convert uncompleted value + return new Double(value.substring(0, value.length() - 1)); + } catch (NumberFormatException e) { + // Continue convertion + } + } + + return null; + } + + private static String valueToString(Double value) { + if (value == null) { + return ZERO; + } else { + String result = decimalFormat.format(value); + + if (result.endsWith(".0")) { + result = result.substring(0, result.length() - 2); + } + + if (result.equals("-0")) { + result = ZERO; + } + + return result; + } + } + + private void addComp(Component comp, int gridx, int gridy, + int gridwidth, int gridheight) { + add(comp, new GridBagConstraints(gridx, gridy, gridwidth, gridheight, + 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(4, 4, 4, 4), 0, 0)); + } + + private static class SquareButton extends JButton { + + private SquareButton(String text) { + super(text); + + setMargin(new Insets(2, 0, 2, 0)); + } + + public Dimension getMinimumSize() { + Dimension result = super.getMinimumSize(); + + if (result.width < result.height) { + result.width = result.height; + } + + return result; + } + + public Dimension getPreferredSize() { + return getMinimumSize(); + } + } + + private class CharButton extends SquareButton { + + private CharButton(final char c) { + super(String.valueOf(c)); + + addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doProcessChar(c); + } + }); + } + } + + private class OperatorButton extends SquareButton { + + private OperatorButton(final Operator operator, String text) { + super(text); + + addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doProcessOperator(operator); + } + }); + } + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/GridBagLayoutDemo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/GridBagLayoutDemo.java Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2007, 2018, 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. + */ +package com.sun.swingset3.demos.gridbaglayout; + +import java.awt.*; +import javax.swing.*; + +import com.sun.swingset3.demos.JGridPanel; +import com.sun.swingset3.demos.ResourceManager; +import com.sun.swingset3.DemoProperties; + +/** + * GridBagLayout Demo + * + * @author Pavel Porvatov + */ +@DemoProperties( + value = "GridBagLayout Demo", + category = "Containers", + description = "Demonstrates GridBagLayout, a layout which allows to arrange components in containers.", + sourceFiles = { + "com/sun/swingset3/demos/gridbaglayout/GridBagLayoutDemo.java", + "com/sun/swingset3/demos/gridbaglayout/Calculator.java", + "com/sun/swingset3/demos/JGridPanel.java", + "com/sun/swingset3/demos/ResourceManager.java", + "com/sun/swingset3/demos/gridbaglayout/resources/GridBagLayoutDemo.properties", + "com/sun/swingset3/demos/gridbaglayout/resources/images/GridBagLayoutDemo.gif" + } +) +public class GridBagLayoutDemo extends JPanel { + + private final ResourceManager resourceManager = new ResourceManager(this.getClass()); + + private final JLabel lbCaption = new JLabel("" + + resourceManager.getString("GridBagLayoutDemo.caption.text") + ""); + + private final Calculator calculator = new Calculator(); + + public static final String GRID_BAG_LAYOUT_DEMO_TITLE = GridBagLayoutDemo.class + .getAnnotation(DemoProperties.class).value(); + + /** + * main method allows us to run as a standalone demo. + */ + public static void main(String[] args) { + JFrame frame = new JFrame(GRID_BAG_LAYOUT_DEMO_TITLE); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().add(new GridBagLayoutDemo()); + frame.setPreferredSize(new Dimension(800, 600)); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + public GridBagLayoutDemo() { + setLayout(new BorderLayout()); + + initUI(); + } + + private void initUI() { + JGridPanel pnContent = new JGridPanel(1, 0, 2); + + pnContent.setBorderEqual(10); + + pnContent.cell(lbCaption, JGridPanel.Layout.FILL). + cell(). + cell(calculator, JGridPanel.Layout.CENTER, JGridPanel.Layout.FIRST). + cell(); + + add(pnContent); + } +} diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/resources/GridBagLayoutDemo.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/resources/GridBagLayoutDemo.properties Tue Jun 19 10:12:35 2018 -0700 @@ -0,0 +1,4 @@ +### GridBagLayout Demo ### + +GridBagLayoutDemo.caption.text = This calculator uses the GridBagLayout layout manager to arrange components. \ + GridBagLayout is very useful when you need to place components in a grid of rows and columns. diff -r c82ed0f373bb -r 0e9d1d4ab692 test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/resources/images/GridBagLayoutDemo.gif Binary file test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/gridbaglayout/resources/images/GridBagLayoutDemo.gif has changed