--- old/modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingFXUtilsImpl.java 2018-07-06 11:54:59.327253200 +0530 +++ new/modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingFXUtilsImpl.java 2018-07-06 11:54:58.507649100 +0530 @@ -25,62 +25,22 @@ package com.sun.javafx.embed.swing; -import com.sun.javafx.application.PlatformImpl; -import com.sun.javafx.tk.Toolkit; import java.awt.EventQueue; -import java.awt.SecondaryLoop; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.concurrent.atomic.AtomicBoolean; -import javafx.application.Platform; -import sun.awt.AWTAccessor; -import sun.awt.FwDispatcher; public class SwingFXUtilsImpl { - private static class FwSecondaryLoop implements SecondaryLoop { + private static SwingFXUtilsImplInterop sfuiop; - private final AtomicBoolean isRunning = new AtomicBoolean(false); - - @Override - public boolean enter() { - if (isRunning.compareAndSet(false, true)) { - PlatformImpl.runAndWait(() -> { - Toolkit.getToolkit().enterNestedEventLoop(FwSecondaryLoop.this); - }); - return true; - } - return false; - } - - @Override - public boolean exit() { - if (isRunning.compareAndSet(true, false)) { - PlatformImpl.runAndWait(() -> { - Toolkit.getToolkit().exitNestedEventLoop(FwSecondaryLoop.this, null); - }); - return true; - } - return false; - } - } - - private static class FXDispatcher implements FwDispatcher { - - @Override - public boolean isDispatchThread() { - return Platform.isFxApplicationThread(); - } - - @Override - public void scheduleDispatch(Runnable runnable) { - Platform.runLater(runnable); - } - - @Override - public SecondaryLoop createSecondaryLoop() { - return new FwSecondaryLoop(); + static { + InteropFactory instance = null; + try { + instance = InteropFactory.getInstance(); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); } + sfuiop = instance.createSwingFXUtilsImpl(); } private static EventQueue getEventQueue() { @@ -90,11 +50,11 @@ //Called with reflection from PlatformImpl to avoid dependency public static void installFwEventQueue() { - AWTAccessor.getEventQueueAccessor().setFwDispatcher(getEventQueue(), new FXDispatcher()); + sfuiop.setFwDispatcher(getEventQueue()); } //Called with reflection from PlatformImpl to avoid dependency public static void removeFwEventQueue() { - AWTAccessor.getEventQueueAccessor().setFwDispatcher(getEventQueue(), null); + sfuiop.setFwDispatcher(getEventQueue()); } }