24 */
25
26 package javafx.application;
27
28 import com.sun.javafx.tk.Toolkit;
29 import javafx.beans.property.ReadOnlyBooleanProperty;
30 import javafx.beans.property.ReadOnlyBooleanWrapper;
31 import com.sun.javafx.application.PlatformImpl;
32
33 /**
34 * Application platform support class.
35 * @since JavaFX 2.0
36 */
37 public final class Platform {
38
39 // To prevent instantiation
40 private Platform() {
41 }
42
43 /**
44 * Run the specified Runnable on the JavaFX Application Thread at some
45 * unspecified
46 * time in the future. This method, which may be called from any thread,
47 * will post the Runnable to an event queue and then return immediately to
48 * the caller. The Runnables are executed in the order they are posted.
49 * A runnable passed into the runLater method will be
50 * executed before any Runnable passed into a subsequent call to runLater.
51 * If this method is called after the JavaFX runtime has been shutdown, the
52 * call will be ignored: the Runnable will not be executed and no
53 * exception will be thrown.
54 *
55 * <p>
56 * NOTE: applications should avoid flooding JavaFX with too many
57 * pending Runnables. Otherwise, the application may become unresponsive.
58 * Applications are encouraged to batch up multiple operations into fewer
59 * runLater calls.
60 * Additionally, long-running operations should be done on a background
61 * thread where possible, freeing up the JavaFX Application Thread for GUI
62 * operations.
63 * </p>
64 *
65 * <p>
66 * This method must not be called before the FX runtime has been
67 * initialized. For standard JavaFX applications that extend
68 * {@see Application}, and use either the Java launcher or one of the
69 * launch methods in the Application class to launch the application,
70 * the FX runtime is initialized by the launcher before the Application
71 * class is loaded.
72 * For Swing applications that use JFXPanel to display FX content, the FX
73 * runtime is initialized when the first JFXPanel instance is constructed.
74 * For SWT application that use FXCanvas to display FX content, the FX
75 * runtime is initialized when the first FXCanvas instance is constructed.
76 * </p>
77 *
78 * @param runnable the Runnable whose run method will be executed on the
79 * JavaFX Application Thread
80 *
81 * @throws IllegalStateException if the FX runtime has not been initialized
82 */
83 public static void runLater(Runnable runnable) {
84 PlatformImpl.runLater(runnable);
85 }
86
87 // NOTE: Add the following if we decide to expose it publicly
88 // public static void runAndWait(Runnable runnable) {
89 // PlatformImpl.runAndWait(runnable);
90 // }
91
92 /**
93 * Requests the Java Runtime to perform a pulse. This will run a pulse
94 * even if there are no animation timers, scene graph modifications,
95 * or window events that would otherwise cause the pulse to run.
|
24 */
25
26 package javafx.application;
27
28 import com.sun.javafx.tk.Toolkit;
29 import javafx.beans.property.ReadOnlyBooleanProperty;
30 import javafx.beans.property.ReadOnlyBooleanWrapper;
31 import com.sun.javafx.application.PlatformImpl;
32
33 /**
34 * Application platform support class.
35 * @since JavaFX 2.0
36 */
37 public final class Platform {
38
39 // To prevent instantiation
40 private Platform() {
41 }
42
43 /**
44 * This method starts the JavaFX runtime. The specified Runnable will then be
45 * called on the JavaFX Application Thread. In general it is not necessary to
46 * explicitly call this method, since it is invoked as a consequence of
47 * how most JavaFX applications are built. However there are valid use cases
48 * for calling this method directly. Because this method starts the JavaFX
49 * runtime, there is not yet any JavaFX Application Thread, so it is normal
50 * that this method is called directly on the main thread of the application.
51 *
52 * <p>
53 * This method may or may not return to the caller before the run method
54 * of the specified Runnable has been called. In any case, once this method
55 * returns, you may call {@link #runLater} with additional Runnables.
56 * Those Runnables will be called, also on the JavaFX Application Thread,
57 * after the Runnable passed into this method has been called.
58 * </p>
59 *
60 * <p>As noted, it is normally the case that the JavaFX Application Thread
61 * is started automatically. It is important that this method only be called
62 * when the JavaFX runtime has not yet been initialized. Situations where
63 * the JavaFX runtime is started automatically include:
64 * </p>
65 *
66 * <ul>
67 * <li>For standard JavaFX applications that extend {@link Application}, and
68 * use either the Java launcher or one of the launch methods in the
69 * Application class to launch the application, the FX runtime is
70 * initialized automatically by the launcher before the Application
71 * class is loaded.</li>
72 * <li>For Swing applications that use JFXPanel to display FX content, the
73 * FX runtime is initialized when the first JFXPanel instance is
74 * constructed.</li>
75 * <li>For SWT application that use FXCanvas to display FX content, the FX
76 * runtime is initialized when the first FXCanvas instance is
77 * constructed.</li>
78 * </ul>
79 *
80 * <p>When an application does not follow any of these common approaches,
81 * then it becomes the responsibility of the developer to manually start the
82 * JavaFX runtime by calling this startup method.
83 * </p>
84 *
85 * <p>Calling this method when the JavaFX runtime is already running will result in an
86 * {@link IllegalStateException} being thrown - it is only valid to request
87 * that the JavaFX runtime be started once.
88 * </p>
89 *
90 * @throws IllegalStateException if the JavaFX runtime is already running
91 *
92 * @param runnable the Runnable whose run method will be executed on the
93 * JavaFX Application Thread once it has been started.
94 *
95 * @since 9
96 */
97 public static void startup(Runnable runnable) {
98 PlatformImpl.startup(runnable, true);
99 }
100
101 /**
102 * Run the specified Runnable on the JavaFX Application Thread at some
103 * unspecified
104 * time in the future. This method, which may be called from any thread,
105 * will post the Runnable to an event queue and then return immediately to
106 * the caller. The Runnables are executed in the order they are posted.
107 * A runnable passed into the runLater method will be
108 * executed before any Runnable passed into a subsequent call to runLater.
109 * If this method is called after the JavaFX runtime has been shutdown, the
110 * call will be ignored: the Runnable will not be executed and no
111 * exception will be thrown.
112 *
113 * <p>
114 * NOTE: applications should avoid flooding JavaFX with too many
115 * pending Runnables. Otherwise, the application may become unresponsive.
116 * Applications are encouraged to batch up multiple operations into fewer
117 * runLater calls.
118 * Additionally, long-running operations should be done on a background
119 * thread where possible, freeing up the JavaFX Application Thread for GUI
120 * operations.
121 * </p>
122 *
123 * <p>
124 * This method must not be called before the FX runtime has been
125 * initialized. For standard JavaFX applications that extend
126 * {@see Application}, and use either the Java launcher or one of the
127 * launch methods in the Application class to launch the application,
128 * the FX runtime is initialized by the launcher before the Application
129 * class is loaded.
130 * For Swing applications that use JFXPanel to display FX content, the FX
131 * runtime is initialized when the first JFXPanel instance is constructed.
132 * For SWT application that use FXCanvas to display FX content, the FX
133 * runtime is initialized when the first FXCanvas instance is constructed.
134 * For applications that do not follow any of these approaches, then it is
135 * necessary to manually start the JavaFX runtime by calling
136 * {@link #startup(Runnable)} once.
137 * </p>
138 *
139 * @param runnable the Runnable whose run method will be executed on the
140 * JavaFX Application Thread
141 *
142 * @throws IllegalStateException if the FX runtime has not been initialized
143 */
144 public static void runLater(Runnable runnable) {
145 PlatformImpl.runLater(runnable);
146 }
147
148 // NOTE: Add the following if we decide to expose it publicly
149 // public static void runAndWait(Runnable runnable) {
150 // PlatformImpl.runAndWait(runnable);
151 // }
152
153 /**
154 * Requests the Java Runtime to perform a pulse. This will run a pulse
155 * even if there are no animation timers, scene graph modifications,
156 * or window events that would otherwise cause the pulse to run.
|