modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java

Print this page




 320         if (!toolkitRunning.getAndSet(true)) {
 321             user.setName("JavaFX Application Thread");
 322             // Set context class loader to the same as the thread that called startup
 323             user.setContextClassLoader(ccl);
 324             setFxUserThread(user);
 325 
 326             // Glass screens were inited in Application.run(), assign adapters
 327             assignScreensAdapters();
 328             /*
 329              *  Glass Application instance is now valid - create the ResourceFactory
 330              *  on the render thread
 331              */
 332             renderer.createResourceFactory();
 333 
 334             pulseRunnable = () -> QuantumToolkit.this.pulse();
 335             timerRunnable = () -> {
 336                 try {
 337                     QuantumToolkit.this.postPulse();
 338                 } catch (Throwable th) {
 339                     th.printStackTrace(System.err);
 340                     // } catch (RuntimeException re) {
 341                     // ignore spurious Glass timer events while exiting...
 342                 }
 343             };
 344             pulseTimer = Application.GetApplication().createTimer(timerRunnable);
 345 
 346             Application.GetApplication().setEventHandler(new Application.EventHandler() {
 347                 @Override public void handleQuitAction(Application app, long time) {
 348                     GlassStage.requestClosingAllWindows();
 349                 }
 350 
 351                 @Override public boolean handleThemeChanged(String themeName) {
 352                     return PlatformImpl.setAccessibilityTheme(themeName);
 353                 }
 354             });
 355         }
 356         // Initialize JavaFX scene graph
 357         initSceneGraph();
 358         launchLatch.countDown();
 359         try {
 360             Application.invokeAndWait(this.userRunnable);
 361 


 733             AsyncOperationListener listener, String url,
 734             int width, int height, boolean preserveRatio, boolean smooth) {
 735         return new PrismImageLoader2.AsyncImageLoader(listener, url, width, height, preserveRatio, smooth);
 736     }
 737 
 738     // Note that this method should only be called by PlatformImpl.runLater
 739     // It should not be called directly by other FX code since the underlying
 740     // glass invokeLater method is not thread-safe with respect to toolkit
 741     // shutdown. Calling Platform.runLater *is* thread-safe even when the
 742     // toolkit is shutting down.
 743     @Override public void defer(Runnable runnable) {
 744         if (!toolkitRunning.get()) return;
 745 
 746         Application.invokeLater(runnable);
 747     }
 748 
 749     @Override public void exit() {
 750         // This method must run on the FX application thread
 751         checkFxUserThread();
 752 



 753         // We need to wait for the last frame to finish so that the renderer
 754         // is not running while we are shutting down glass.
 755         PaintCollector.getInstance().waitForRenderingToComplete();
 756 
 757         notifyShutdownHooks();
 758 
 759         runWithRenderLock(() -> {
 760             //TODO - should update glass scene view state
 761             //TODO - doesn't matter because we are exiting
 762             Application app = Application.GetApplication();
 763             app.terminate();
 764             return null;
 765         });
 766 
 767         dispose();
 768 
 769         super.exit();
 770     }
 771 
 772     public void dispose() {
 773         if (toolkitRunning.compareAndSet(true, false)) {
 774             pulseTimer.stop();
 775             renderer.stopRenderer();
 776 
 777             try {
 778                 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 779                     Runtime.getRuntime().removeShutdownHook(shutdownHook);
 780                     return null;
 781                 });
 782             } catch (IllegalStateException ignore) {
 783                 // throw when shutdown hook already removed
 784             }
 785         }
 786     }
 787 
 788     @Override public boolean isForwardTraversalKey(KeyEvent e) {
 789         return (e.getCode() == KeyCode.TAB)
 790                    && (e.getEventType() == KeyEvent.KEY_PRESSED)
 791                    && !e.isShiftDown();
 792     }
 793 
 794     @Override public boolean isBackwardTraversalKey(KeyEvent e) {




 320         if (!toolkitRunning.getAndSet(true)) {
 321             user.setName("JavaFX Application Thread");
 322             // Set context class loader to the same as the thread that called startup
 323             user.setContextClassLoader(ccl);
 324             setFxUserThread(user);
 325 
 326             // Glass screens were inited in Application.run(), assign adapters
 327             assignScreensAdapters();
 328             /*
 329              *  Glass Application instance is now valid - create the ResourceFactory
 330              *  on the render thread
 331              */
 332             renderer.createResourceFactory();
 333 
 334             pulseRunnable = () -> QuantumToolkit.this.pulse();
 335             timerRunnable = () -> {
 336                 try {
 337                     QuantumToolkit.this.postPulse();
 338                 } catch (Throwable th) {
 339                     th.printStackTrace(System.err);


 340                 }
 341             };
 342             pulseTimer = Application.GetApplication().createTimer(timerRunnable);
 343 
 344             Application.GetApplication().setEventHandler(new Application.EventHandler() {
 345                 @Override public void handleQuitAction(Application app, long time) {
 346                     GlassStage.requestClosingAllWindows();
 347                 }
 348 
 349                 @Override public boolean handleThemeChanged(String themeName) {
 350                     return PlatformImpl.setAccessibilityTheme(themeName);
 351                 }
 352             });
 353         }
 354         // Initialize JavaFX scene graph
 355         initSceneGraph();
 356         launchLatch.countDown();
 357         try {
 358             Application.invokeAndWait(this.userRunnable);
 359 


 731             AsyncOperationListener listener, String url,
 732             int width, int height, boolean preserveRatio, boolean smooth) {
 733         return new PrismImageLoader2.AsyncImageLoader(listener, url, width, height, preserveRatio, smooth);
 734     }
 735 
 736     // Note that this method should only be called by PlatformImpl.runLater
 737     // It should not be called directly by other FX code since the underlying
 738     // glass invokeLater method is not thread-safe with respect to toolkit
 739     // shutdown. Calling Platform.runLater *is* thread-safe even when the
 740     // toolkit is shutting down.
 741     @Override public void defer(Runnable runnable) {
 742         if (!toolkitRunning.get()) return;
 743 
 744         Application.invokeLater(runnable);
 745     }
 746 
 747     @Override public void exit() {
 748         // This method must run on the FX application thread
 749         checkFxUserThread();
 750 
 751         // Turn off pulses so no extraneous runnables are submitted
 752         pulseTimer.stop();
 753 
 754         // We need to wait for the last frame to finish so that the renderer
 755         // is not running while we are shutting down glass.
 756         PaintCollector.getInstance().waitForRenderingToComplete();
 757 
 758         notifyShutdownHooks();
 759 
 760         runWithRenderLock(() -> {
 761             //TODO - should update glass scene view state
 762             //TODO - doesn't matter because we are exiting
 763             Application app = Application.GetApplication();
 764             app.terminate();
 765             return null;
 766         });
 767 
 768         dispose();
 769 
 770         super.exit();
 771     }
 772 
 773     public void dispose() {
 774         if (toolkitRunning.compareAndSet(true, false)) {

 775             renderer.stopRenderer();
 776 
 777             try {
 778                 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 779                     Runtime.getRuntime().removeShutdownHook(shutdownHook);
 780                     return null;
 781                 });
 782             } catch (IllegalStateException ignore) {
 783                 // throw when shutdown hook already removed
 784             }
 785         }
 786     }
 787 
 788     @Override public boolean isForwardTraversalKey(KeyEvent e) {
 789         return (e.getCode() == KeyCode.TAB)
 790                    && (e.getEventType() == KeyEvent.KEY_PRESSED)
 791                    && !e.isShiftDown();
 792     }
 793 
 794     @Override public boolean isBackwardTraversalKey(KeyEvent e) {