--- old/./build.gradle 2018-05-05 14:08:30.327019000 +0530 +++ new/./build.gradle 2018-05-05 14:08:29.453417500 +0530 @@ -1586,12 +1586,6 @@ // Qualified exports needed by javafx.swing def qualExportsSwing = [ - "--add-exports=java.desktop/java.awt.dnd.peer=javafx.swing", - "--add-exports=java.desktop/sun.awt=javafx.swing", - "--add-exports=java.desktop/sun.awt.dnd=javafx.swing", - "--add-exports=java.desktop/sun.awt.image=javafx.swing", - "--add-exports=java.desktop/sun.java2d=javafx.swing", - "--add-exports=java.desktop/sun.swing=javafx.swing", ] // These strings define the module-source-path to be used in compilation. --- old/dependencies/java.desktop/module-info.java.extra 2018-05-05 14:08:34.432826400 +0530 +++ new/dependencies/java.desktop/module-info.java.extra 2018-05-05 14:08:33.699625100 +0530 @@ -23,10 +23,4 @@ * questions. */ -exports java.awt.dnd.peer to javafx.swing; -exports sun.awt to javafx.swing; -exports sun.awt.dnd to javafx.swing; -exports sun.awt.image to javafx.swing; -exports sun.java2d to javafx.swing; -exports sun.swing to javafx.swing; exports sun.print to javafx.graphics; --- old/modules/javafx.swing/src/main/java/module-info.java 2018-05-05 14:08:38.254833100 +0530 +++ new/modules/javafx.swing/src/main/java/module-info.java 2018-05-05 14:08:37.459231700 +0530 @@ -38,6 +38,7 @@ requires javafx.base; requires transitive java.desktop; + requires static jdk.unsupported.desktop; requires transitive javafx.graphics; exports javafx.embed.swing; --- old/modules/javafx.swing/src/main/java/javafx/embed/swing/SwingNode.java 2018-05-05 14:08:42.264040100 +0530 +++ new/modules/javafx.swing/src/main/java/javafx/embed/swing/SwingNode.java 2018-05-05 14:08:41.328038500 +0530 @@ -53,7 +53,6 @@ import java.awt.dnd.DragSource; import java.awt.dnd.DropTarget; import java.awt.dnd.InvalidDnDOperationException; -import java.awt.dnd.peer.DragSourceContextPeer; import java.awt.event.InputEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.WindowEvent; @@ -80,9 +79,10 @@ import com.sun.javafx.PlatformUtil; import com.sun.javafx.embed.swing.SwingNodeHelper; import com.sun.javafx.scene.NodeHelper; -import sun.awt.UngrabEvent; -import sun.swing.JLightweightFrame; -import sun.swing.LightweightContent; + +import jdk.swing.interop.LightweightFrameWrapper; +import jdk.swing.interop.LightweightContentWrapper; +import jdk.swing.interop.DragSourceContextWrapper; import static javafx.stage.WindowEvent.WINDOW_HIDDEN; @@ -176,8 +176,8 @@ private int swingMinHeight; private volatile JComponent content; - private volatile JLightweightFrame lwFrame; - final JLightweightFrame getLightweightFrame() { return lwFrame; } + private volatile LightweightFrameWrapper lwFrame; + final LightweightFrameWrapper getLightweightFrame() { return lwFrame; } private NGExternalNode peer; @@ -331,21 +331,21 @@ } /** - * Calls JLightweightFrame.notifyDisplayChanged. + * Calls LightweightFrameWrapper.notifyDisplayChanged. * Must be called on EDT only. */ - private static OptionalMethod jlfNotifyDisplayChanged; - private static OptionalMethod jlfOverrideNativeWindowHandle; + private static OptionalMethod jlfNotifyDisplayChanged; + private static OptionalMethod jlfOverrideNativeWindowHandle; static { - jlfNotifyDisplayChanged = new OptionalMethod<>(JLightweightFrame.class, + jlfNotifyDisplayChanged = new OptionalMethod<>(LightweightFrameWrapper.class, "notifyDisplayChanged", Double.TYPE, Double.TYPE); if (!jlfNotifyDisplayChanged.isSupported()) { jlfNotifyDisplayChanged = new OptionalMethod<>( - JLightweightFrame.class,"notifyDisplayChanged", Integer.TYPE); + LightweightFrameWrapper.class,"notifyDisplayChanged", Integer.TYPE); } - jlfOverrideNativeWindowHandle = new OptionalMethod<>(JLightweightFrame.class, + jlfOverrideNativeWindowHandle = new OptionalMethod<>(LightweightFrameWrapper.class, "overrideNativeWindowHandle", Long.TYPE, Runnable.class); } @@ -359,7 +359,7 @@ lwFrame = null; } if (content != null) { - lwFrame = new JLightweightFrame(); + lwFrame = new LightweightFrameWrapper(); SwingNodeWindowFocusListener snfListener = new SwingNodeWindowFocusListener(this); @@ -559,7 +559,8 @@ private final EventHandler ungrabHandler = event -> { if (!skipBackwardUnrgabNotification) { if (lwFrame != null) { - AccessController.doPrivileged(new PostEventAction(new UngrabEvent(lwFrame))); + AccessController.doPrivileged(new PostEventAction( + lwFrame.createUngrabEvent(lwFrame))); } } }; @@ -673,11 +674,11 @@ } /** - * Calls JLightweightFrame.setHostBounds. + * Calls LightweightFrameWrapper.setHostBounds. * Must be called on EDT only. */ - private static final OptionalMethod jlfSetHostBounds = - new OptionalMethod<>(JLightweightFrame.class, "setHostBounds", + private static final OptionalMethod jlfSetHostBounds = + new OptionalMethod<>(LightweightFrameWrapper.class, "setHostBounds", Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); private void locateLwFrame() { @@ -797,9 +798,9 @@ } private static class SwingNodeDisposer implements DisposerRecord { - JLightweightFrame lwFrame; + LightweightFrameWrapper lwFrame; - SwingNodeDisposer(JLightweightFrame ref) { + SwingNodeDisposer(LightweightFrameWrapper ref) { this.lwFrame = ref; } public void dispose() { @@ -838,7 +839,7 @@ } } - private static class SwingNodeContent implements LightweightContent { + private static class SwingNodeContent extends LightweightContentWrapper { private JComponent comp; private volatile FXDnD dnd; private WeakReference swingNodeRef; @@ -866,9 +867,7 @@ } } - // Note: we skip @Override annotation and implement both pre-hiDPI and post-hiDPI versions - // of the method for compatibility. - //@Override + @Override public void imageBufferReset(int[] data, int x, int y, int width, int height, int linestride) { imageBufferReset(data, x, y, width, height, linestride, 1); } @@ -879,7 +878,7 @@ swingNode.setImageBuffer(data, x, y, width, height, linestride, scale, scale); } } - //@Override + @Override public void imageBufferReset(int[] data, int x, int y, int width, int height, int linestride, double scaleX, double scaleY) { SwingNode swingNode = swingNodeRef.get(); if (swingNode != null) { @@ -984,7 +983,7 @@ } } - //@Override + @Override public synchronized T createDragGestureRecognizer( Class abstractRecognizerClass, DragSource ds, Component c, int srcActions, @@ -994,20 +993,20 @@ return dnd.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl); } - //@Override - public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException + @Override + public DragSourceContextWrapper createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { initDnD(); return dnd.createDragSourceContextPeer(dge); } - //@Override + @Override public void addDropTarget(DropTarget dt) { initDnD(); dnd.addDropTarget(dt); } - //@Override + @Override public void removeDropTarget(DropTarget dt) { initDnD(); dnd.removeDropTarget(dt); @@ -1049,7 +1048,7 @@ @Override public void handle(MouseEvent event) { - JLightweightFrame frame = lwFrame; + LightweightFrameWrapper frame = lwFrame; if (frame == null) { return; } @@ -1087,7 +1086,7 @@ int absX = (int) Math.round(event.getScreenX()); int absY = (int) Math.round(event.getScreenY()); java.awt.event.MouseEvent mouseEvent = - new java.awt.event.MouseEvent( + frame.createMouseEvent( frame, swingID, swingWhen, swingModifiers, relX, relY, absX, absY, event.getClickCount(), swingPopupTrigger, swingButton); @@ -1098,7 +1097,7 @@ private class SwingScrollEventHandler implements EventHandler { @Override public void handle(ScrollEvent event) { - JLightweightFrame frame = lwFrame; + LightweightFrameWrapper frame = lwFrame; if (frame == null) { return; } @@ -1122,7 +1121,7 @@ } } - private void sendMouseWheelEvent(Component source, double fxX, double fxY, int swingModifiers, double delta) { + private void sendMouseWheelEvent(LightweightFrameWrapper source, double fxX, double fxY, int swingModifiers, double delta) { int wheelRotation = (int) delta; int signum = (int) Math.signum(delta); if (signum * delta < 1) { @@ -1131,9 +1130,7 @@ int x = (int) Math.round(fxX); int y = (int) Math.round(fxY); MouseWheelEvent mouseWheelEvent = - new MouseWheelEvent(source, java.awt.event.MouseEvent.MOUSE_WHEEL, - System.currentTimeMillis(), swingModifiers, x, y, 0, 0, - 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1 , -wheelRotation); + lwFrame.createMouseWheelEvent(source, swingModifiers, x, y, -wheelRotation); AccessController.doPrivileged(new PostEventAction(mouseWheelEvent)); } } @@ -1141,7 +1138,7 @@ private class SwingKeyEventHandler implements EventHandler { @Override public void handle(KeyEvent event) { - JLightweightFrame frame = lwFrame; + LightweightFrameWrapper frame = lwFrame; if (frame == null) { return; } @@ -1176,9 +1173,9 @@ } } long swingWhen = System.currentTimeMillis(); - java.awt.event.KeyEvent keyEvent = new java.awt.event.KeyEvent( - frame, swingID, swingWhen, swingModifiers, - swingKeyCode, swingChar); + java.awt.event.KeyEvent keyEvent = frame.createKeyEvent(frame, + swingID, swingWhen, swingModifiers, swingKeyCode, + swingChar); AccessController.doPrivileged(new PostEventAction(keyEvent)); } } --- old/modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java 2018-05-05 14:08:46.663247900 +0530 +++ new/modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java 2018-05-05 14:08:45.945646600 +0530 @@ -77,13 +77,12 @@ import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; -import sun.awt.AppContext; -import sun.awt.SunToolkit; -import sun.java2d.SunGraphics2D; -import sun.java2d.SurfaceData; + import com.sun.javafx.logging.PlatformLogger; import com.sun.javafx.logging.PlatformLogger.Level; +import jdk.swing.interop.SwingInterOpUtils; + /** * {@code JFXPanel} is a component to embed JavaFX content into * Swing applications. The content to be displayed is specified @@ -450,10 +449,7 @@ // component. Fire the same MOUSE_PRESSED event after // requestFocus() so that 2nd mouse press will be honoured // since now fx have focus - AppContext context = SunToolkit.targetToAppContext(this); - if (context != null) { - SunToolkit.postEvent(context, e); - } + SwingInterOpUtils.postEvent(this, e); } } @@ -570,11 +566,8 @@ double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; Graphics g = getGraphics(); - if (g instanceof SunGraphics2D) { - SurfaceData sd = ((SunGraphics2D) g).surfaceData; - newScaleFactorX = sd.getDefaultScaleX(); - newScaleFactorY = sd.getDefaultScaleY(); - } + newScaleFactorX = SwingInterOpUtils.getDefaultScaleX(g); + newScaleFactorY = SwingInterOpUtils.getDefaultScaleY(g); if (oldWidth != pWidth || oldHeight != pHeight || newScaleFactorX != scaleFactorX || newScaleFactorY != scaleFactorY) { @@ -765,11 +758,8 @@ double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; - if (g instanceof SunGraphics2D) { - SurfaceData sd = ((SunGraphics2D)g).surfaceData; - newScaleFactorX = sd.getDefaultScaleX(); - newScaleFactorY = sd.getDefaultScaleY(); - } + newScaleFactorX = SwingInterOpUtils.getDefaultScaleX(g); + newScaleFactorY = SwingInterOpUtils.getDefaultScaleY(g); if (scaleFactorX != newScaleFactorX || scaleFactorY != newScaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); // The scene will request repaint. @@ -828,7 +818,7 @@ } private transient AWTEventListener ungrabListener = event -> { - if (event instanceof sun.awt.UngrabEvent) { + if (SwingInterOpUtils.isUngrabEvent(event)) { SwingFXUtils.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null && getScene() != null && @@ -877,7 +867,7 @@ AccessController.doPrivileged((PrivilegedAction) () -> { JFXPanel.this.getToolkit().addAWTEventListener(ungrabListener, - SunToolkit.GRAB_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); + SwingInterOpUtils.GRAB_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); return null; }); updateComponentSize(); // see RT-23603 @@ -928,12 +918,7 @@ } private void invokeOnClientEDT(Runnable r) { - AppContext context = SunToolkit.targetToAppContext(this); - if (context == null) { - if (log.isLoggable(Level.FINE)) log.fine("null AppContext encountered!"); - return; - } - SunToolkit.postEvent(context, new InvocationEvent(this, r)); + SwingInterOpUtils.postEvent(this, new InvocationEvent(this, r)); } private class HostContainer implements HostInterface { @@ -1054,9 +1039,7 @@ invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { - if (JFXPanel.this.getToolkit() instanceof SunToolkit) { - ((SunToolkit)JFXPanel.this.getToolkit()).grab(window); - } + SwingInterOpUtils.grab(JFXPanel.this.getToolkit(), window); } }); @@ -1072,9 +1055,7 @@ invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { - if (JFXPanel.this.getToolkit() instanceof SunToolkit) { - ((SunToolkit)JFXPanel.this.getToolkit()).ungrab(window); - } + SwingInterOpUtils.ungrab(JFXPanel.this.getToolkit(), window); } }); } --- old/modules/javafx.swing/src/main/java/javafx/embed/swing/FXDnD.java 2018-05-05 14:08:50.455054600 +0530 +++ new/modules/javafx.swing/src/main/java/javafx/embed/swing/FXDnD.java 2018-05-05 14:08:49.737453300 +0530 @@ -44,8 +44,6 @@ import java.awt.dnd.DropTargetListener; import java.awt.dnd.InvalidDnDOperationException; import java.awt.dnd.MouseDragGestureRecognizer; -import java.awt.dnd.peer.DragSourceContextPeer; -import java.awt.dnd.peer.DropTargetContextPeer; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.HashMap; @@ -58,10 +56,11 @@ import javafx.scene.input.Dragboard; import javafx.scene.input.MouseEvent; import javafx.scene.input.TransferMode; -import sun.awt.AWTAccessor; -import sun.awt.dnd.SunDragSourceContextPeer; -import sun.swing.JLightweightFrame; +import jdk.swing.interop.LightweightFrameWrapper; +import jdk.swing.interop.SwingInterOpUtils; +import jdk.swing.interop.DragSourceContextWrapper; +import jdk.swing.interop.DropTargetContextWrapper; /** * A utility class to connect DnD mechanism of Swing and FX. @@ -99,9 +98,8 @@ this.x = xArg; this.y = yArg; - final JLightweightFrame lwFrame = node.getLightweightFrame(); - Component c = AWTAccessor.getContainerAccessor().findComponentAt( - lwFrame, x, y, false); + final LightweightFrameWrapper lwFrame = node.getLightweightFrame(); + Component c = lwFrame.findComponentAt(lwFrame, x, y, false); if (c == null) return; synchronized (c.getTreeLock()) { @@ -114,7 +112,7 @@ //assert c == object.getComponent(); // Translate x, y from lwFrame to component coordinates - while (c != lwFrame && c != null) { + while ((lwFrame.isCompEqual(c,lwFrame)) && c != null) { x -= c.getX(); y -= c.getY(); c = c.getParent(); @@ -197,7 +195,7 @@ // Also, the modifiers here should've actually come from the last known mouse event (last MOVE or DRAG). // But we're OK with using the initial PRESS modifiers for now - int initialAction = SunDragSourceContextPeer.convertModifiersToDropAction( + int initialAction = DragSourceContextWrapper.convertModifiersToDropAction( modifiers, getSourceActions()); fireDragGestureRecognized(initialAction, new java.awt.Point(x, y)); @@ -281,7 +279,7 @@ }; - private final class FXDragSourceContextPeer extends SunDragSourceContextPeer { + private final class FXDragSourceContextPeer extends DragSourceContextWrapper { private volatile int sourceActions = 0; private final CachingTransferable transferable = new CachingTransferable(); @@ -337,6 +335,7 @@ } }; + //@Override public T createDragGestureRecognizer( Class abstractRecognizerClass, DragSource ds, Component c, int srcActions, @@ -345,7 +344,8 @@ return (T) new FXDragGestureRecognizer(ds, c, srcActions, dgl); } - public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException + //@Override + public DragSourceContextWrapper createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { return new FXDragSourceContextPeer(dge); } @@ -418,7 +418,7 @@ activeDTContextPeer = null; }; - private final class FXDropTargetContextPeer implements DropTargetContextPeer { + private final class FXDropTargetContextPeer extends DropTargetContextWrapper { private int targetActions = DnDConstants.ACTION_NONE; private int currentAction = DnDConstants.ACTION_NONE; @@ -469,7 +469,7 @@ SwingFXUtils.runOnEDTAndWait(FXDnD.this, () -> { if (target != dt) { if (ctx != null) { - AWTAccessor.getDropTargetContextAccessor().reset(ctx); + DropTargetContextWrapper.reset(ctx); } ctx = null; @@ -479,8 +479,8 @@ if (target != null) { if (ctx == null) { ctx = target.getDropTargetContext(); - AWTAccessor.getDropTargetContextAccessor() - .setDropTargetContextPeer(ctx, FXDropTargetContextPeer.this); + DropTargetContextWrapper.setDropTargetContextPeer(ctx, + new FXDropTargetContextPeer()); } DropTargetListener dtl = (DropTargetListener)target; --- old/modules/javafx.swing/src/main/java/javafx/embed/swing/SwingFXUtils.java 2018-05-05 14:08:54.261461300 +0530 +++ new/modules/javafx.swing/src/main/java/javafx/embed/swing/SwingFXUtils.java 2018-05-05 14:08:53.512660000 +0530 @@ -41,7 +41,8 @@ import javafx.scene.paint.Color; import com.sun.javafx.tk.Toolkit; import javax.swing.SwingUtilities; -import sun.awt.image.IntegerComponentRaster; + +import jdk.swing.interop.SwingInterOpUtils; /** * This class provides utility methods for converting data types between @@ -111,10 +112,10 @@ wimg = new WritableImage(bw, bh); } PixelWriter pw = wimg.getPixelWriter(); - IntegerComponentRaster icr = (IntegerComponentRaster) bimg.getRaster(); - int data[] = icr.getDataStorage(); - int offset = icr.getDataOffset(0); - int scan = icr.getScanlineStride(); + int data[] = SwingInterOpUtils.getData(bimg); + int offset = SwingInterOpUtils.getOffset(bimg); + int scan = SwingInterOpUtils.getScanlineStride(bimg); + PixelFormat pf = (bimg.isAlphaPremultiplied() ? PixelFormat.getIntArgbPreInstance() : PixelFormat.getIntArgbInstance()); @@ -281,10 +282,10 @@ if (bimg == null) { bimg = new BufferedImage(iw, ih, prefBimgType); } - IntegerComponentRaster icr = (IntegerComponentRaster) bimg.getRaster(); - int offset = icr.getDataOffset(0); - int scan = icr.getScanlineStride(); - int data[] = icr.getDataStorage(); + int offset = SwingInterOpUtils.getOffset(bimg); + int scan = SwingInterOpUtils.getScanlineStride(bimg); + int data[] = SwingInterOpUtils.getData(bimg); + WritablePixelFormat pf = getAssociatedPixelFormat(bimg); pr.getPixels(0, 0, iw, ih, pf, data, offset, scan); return bimg; --- old/modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingFXUtilsImpl.java 2018-05-05 14:08:58.114668000 +0530 +++ new/modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingFXUtilsImpl.java 2018-05-05 14:08:57.334666700 +0530 @@ -33,8 +33,7 @@ import java.security.PrivilegedAction; import java.util.concurrent.atomic.AtomicBoolean; import javafx.application.Platform; -import sun.awt.AWTAccessor; -import sun.awt.FwDispatcher; +import jdk.swing.interop.DispatcherWrapper; public class SwingFXUtilsImpl { @@ -65,7 +64,7 @@ } } - private static class FXDispatcher implements FwDispatcher { + private static class FXDispatcher extends DispatcherWrapper { @Override public boolean isDispatchThread() { @@ -90,11 +89,11 @@ //Called with reflection from PlatformImpl to avoid dependency public static void installFwEventQueue() { - AWTAccessor.getEventQueueAccessor().setFwDispatcher(getEventQueue(), new FXDispatcher()); + DispatcherWrapper.setFwDispatcher(getEventQueue(), new FXDispatcher()); } //Called with reflection from PlatformImpl to avoid dependency public static void removeFwEventQueue() { - AWTAccessor.getEventQueueAccessor().setFwDispatcher(getEventQueue(), null); + DispatcherWrapper.setFwDispatcher(getEventQueue(), null); } }