--- old/modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java 2018-07-11 20:57:46.042400900 +0530 +++ new/modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java 2018-07-11 20:57:44.885254000 +0530 @@ -38,6 +38,7 @@ import java.awt.Insets; import java.awt.EventQueue; import java.awt.SecondaryLoop; +import java.awt.GraphicsEnvironment; import java.awt.event.AWTEventListener; import java.awt.event.ComponentEvent; import java.awt.event.FocusEvent; @@ -77,13 +78,17 @@ 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 com.sun.javafx.embed.swing.InteropFactory; +import com.sun.javafx.embed.swing.SwingDnD; +import com.sun.javafx.embed.swing.SwingEvents; +import com.sun.javafx.embed.swing.SwingCursors; +import com.sun.javafx.embed.swing.SwingNodeHelper; +import com.sun.javafx.embed.swing.JFXPanelInterop; + /** * {@code JFXPanel} is a component to embed JavaFX content into * Swing applications. The content to be displayed is specified @@ -185,6 +190,17 @@ private static boolean fxInitialized; + private static InteropFactory instance = null; + private JFXPanelInterop jfxPaneliop; + + static { + try { + instance = InteropFactory.getInstance(); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); + } + } + private synchronized void registerFinishListener() { if (instanceCount.getAndIncrement() > 0) { // Already registered @@ -256,6 +272,7 @@ public JFXPanel() { super(); + jfxPaneliop = instance.createJFXPanelImpl(); initFx(); hostContainer = new HostContainer(); @@ -450,10 +467,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); - } + jfxPaneliop.postEvent(this, e); } } @@ -570,11 +584,12 @@ 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 = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(). + getDefaultTransform().getScaleX(); + newScaleFactorY = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(). + getDefaultTransform().getScaleY(); if (oldWidth != pWidth || oldHeight != pHeight || newScaleFactorX != scaleFactorX || newScaleFactorY != scaleFactorY) { @@ -765,11 +780,12 @@ double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; - if (g instanceof SunGraphics2D) { - SurfaceData sd = ((SunGraphics2D)g).surfaceData; - newScaleFactorX = sd.getDefaultScaleX(); - newScaleFactorY = sd.getDefaultScaleY(); - } + newScaleFactorX = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(). + getDefaultTransform().getScaleX(); + newScaleFactorY = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(). + getDefaultTransform().getScaleY(); if (scaleFactorX != newScaleFactorX || scaleFactorY != newScaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); // The scene will request repaint. @@ -828,8 +844,8 @@ } private transient AWTEventListener ungrabListener = event -> { - if (event instanceof sun.awt.UngrabEvent) { - SwingFXUtils.runOnFxThread(() -> { + if (jfxPaneliop.isUngrabEvent(event)) { + SwingNodeHelper.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null && getScene() != null && getScene().getFocusOwner() != null && @@ -847,7 +863,7 @@ final Window eventWindow = source instanceof Window ? (Window)source : SwingUtilities.getWindowAncestor(source); if (jfxPanelWindow == eventWindow) { - SwingFXUtils.runOnFxThread(() -> { + SwingNodeHelper.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null) { // No need to check if grab is active or not. // NoAutoHide popups don't request the grab and @@ -877,11 +893,11 @@ AccessController.doPrivileged((PrivilegedAction) () -> { JFXPanel.this.getToolkit().addAWTEventListener(ungrabListener, - SunToolkit.GRAB_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); + jfxPaneliop.setMask()); return null; }); updateComponentSize(); // see RT-23603 - SwingFXUtils.runOnFxThread(() -> { + SwingNodeHelper.runOnFxThread(() -> { if ((stage != null) && !stage.isShowing()) { stage.show(); sendMoveEventToFX(); @@ -904,7 +920,7 @@ * chain of parent components are removed. */ @Override public void removeNotify() { - SwingFXUtils.runOnFxThread(() -> { + SwingNodeHelper.runOnFxThread(() -> { if ((stage != null) && stage.isShowing()) { stage.hide(); } @@ -928,12 +944,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)); + jfxPaneliop.postEvent(this, new InvocationEvent(this, r)); } private class HostContainer implements HostInterface { @@ -1054,9 +1065,7 @@ invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { - if (JFXPanel.this.getToolkit() instanceof SunToolkit) { - ((SunToolkit)JFXPanel.this.getToolkit()).grab(window); - } + jfxPaneliop.grab(JFXPanel.this.getToolkit(), window); } }); @@ -1072,9 +1081,7 @@ invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { - if (JFXPanel.this.getToolkit() instanceof SunToolkit) { - ((SunToolkit)JFXPanel.this.getToolkit()).ungrab(window); - } + jfxPaneliop.ungrab(JFXPanel.this.getToolkit(), window); } }); }