--- old/modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingFXUtilsImpl.java 2018-07-13 14:08:34.244514500 +0530 +++ new/modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingFXUtilsImpl.java 2018-07-13 14:08:32.977853600 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -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 swFXUtilIOP; - 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 iopFactoryInstance = null; + try { + iopFactoryInstance = InteropFactory.getInstance(); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); } + swFXUtilIOP = iopFactoryInstance.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()); + swFXUtilIOP.setFwDispatcher(getEventQueue()); } //Called with reflection from PlatformImpl to avoid dependency public static void removeFwEventQueue() { - AWTAccessor.getEventQueueAccessor().setFwDispatcher(getEventQueue(), null); + swFXUtilIOP.setFwDispatcher(getEventQueue()); } }