changeset 4281:1297b31c4bec

RT-31441: FX doesn't care about nested event loops and shutdowns too early
author Alexander Zvegintsev
date Fri, 12 Jul 2013 14:51:23 +0400
parents 448737b47996
children 691071d37f9d
files modules/graphics/src/main/java/com/sun/glass/ui/Application.java modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java modules/graphics/src/main/java/com/sun/javafx/tk/DummyToolkit.java modules/graphics/src/main/java/com/sun/javafx/tk/TKListener.java modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java modules/graphics/src/stub/java/com/sun/javafx/pgstub/StubToolkit.java
diffstat 7 files changed, 45 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/Application.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/Application.java	Fri Jul 12 14:51:23 2013 +0400
@@ -485,6 +485,11 @@
         GetApplication()._leaveNestedEventLoop(retValue);
     }
 
+    public static boolean isNestedLoopRunning() {
+        checkEventThread();
+        return nestedEventLoopCounter > 0;
+    }
+
     //TODO: move to the EventHandler
     public void menuAboutAction() {
         System.err.println("about");
--- a/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java	Fri Jul 12 14:51:23 2013 +0400
@@ -177,6 +177,11 @@
                 numWindows.set(windows.size());
                 checkIdle();
             }
+
+            @Override
+            public void exitedLastNestedLoop() {
+                checkIdle();
+            }
         };
         Toolkit.getToolkit().addTkListener(toolkitListener);
 
@@ -335,8 +340,10 @@
 
             // In case there is an event in process, allow for it to show
             // another window. If no new window is shown before all pending
-            // runnables (including this one) are done, then we will shutdown.
-            if (lastWindowClosed && pendingRunnables.get() == 0) {
+            // runnables (including this one) are done and there is no running
+            // nested loops, then we will shutdown.
+            if (lastWindowClosed && pendingRunnables.get() == 0
+                    && !Toolkit.getToolkit().isNestedLoopRunning()) {
 //                System.err.println("Last window closed and no pending runnables");
                 if (reallyIdle.getAndSet(true)) {
 //                    System.err.println("Really idle now");
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/DummyToolkit.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/DummyToolkit.java	Fri Jul 12 14:51:23 2013 +0400
@@ -268,6 +268,11 @@
     }
 
     @Override
+    public boolean isNestedLoopRunning() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
     public AbstractMasterTimer getMasterTimer() {
         return null;
     }
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/TKListener.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/TKListener.java	Fri Jul 12 14:51:23 2013 +0400
@@ -30,4 +30,5 @@
 
 public interface TKListener {
     public void changedTopLevelWindows(List<TKStage> windows);
+    public void exitedLastNestedLoop();
 }
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java	Fri Jul 12 14:51:23 2013 +0400
@@ -266,6 +266,8 @@
      */
     public abstract void exitNestedEventLoop(Object key, Object rval);
 
+    public abstract boolean isNestedLoopRunning();
+
     public abstract TKStage createTKStage(StageStyle stageStyle, boolean primary,
             Modality modality, TKStage owner, boolean rtl);
 
@@ -402,6 +404,12 @@
         }
     }
 
+    public void notifyLastNestedLoopExited() {
+        for (TKListener listener: toolkitListeners.keySet()) {
+            listener.exitedLastNestedLoop();
+        }
+    }
+
     // notify the pulse timer code that we need the next pulse to happen
     // this flag is cleared each cycle so subsequent pulses must be requested
     public abstract void requestNextPulse();
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java	Fri Jul 12 14:51:23 2013 +0400
@@ -592,7 +592,13 @@
         EventLoop eventLoop = Application.GetApplication().createEventLoop();
         eventLoopMap.put(key, eventLoop);
 
-        return eventLoop.enter();
+        Object ret = eventLoop.enter();
+
+        if (!isNestedLoopRunning()) {
+            notifyLastNestedLoopExited();
+        }
+        
+        return ret;
     }
 
     @Override public void exitNestedEventLoop(Object key, Object rval) {
@@ -1098,6 +1104,11 @@
     }
 
     @Override
+    public boolean isNestedLoopRunning() {
+        return Application.isNestedLoopRunning();
+    }
+
+    @Override
     public boolean isSupported(ConditionalFeature feature) {
         switch (feature) {
             case SCENE3D:
--- a/modules/graphics/src/stub/java/com/sun/javafx/pgstub/StubToolkit.java	Fri Jul 12 12:41:02 2013 +0400
+++ b/modules/graphics/src/stub/java/com/sun/javafx/pgstub/StubToolkit.java	Fri Jul 12 14:51:23 2013 +0400
@@ -702,6 +702,11 @@
         throw new UnsupportedOperationException("Not supported yet.");
     }
 
+    @Override
+    public boolean isNestedLoopRunning() {
+        return false;
+    }
+
     private KeyCode platformShortcutKey = KeyCode.SHORTCUT;
 
     public void setPlatformShortcutKey(final KeyCode platformShortcutKey) {