public final class FxToolkit
extends java.lang.Object
This class methods cover three different kinds of fixtures:
registeredStage.registeredStage.registeredStage.
They can be registered as registeredStage and provide a top-level container, i.e.
Stages.
The primary stage can be registered as registeredStage using registerPrimaryStage().
This call is mandatory before any other JavaFX fixture can be created.
Other stages can be registered as registeredStage using registerStage(Supplier<Stage>).
They can be attached to the registeredStage.
Either constructed by calling an Application.start(), by
supplying Scenes, Parents, or by consuming a Stage.
Use: setupStage(Consumer<Stage>),
setupApplication(Class<? extends Application>),
setupScene(Supplier<Scene>) or
setupSceneRoot(Supplier<Parent>)
To setup individual Stages, Scenes or Nodes use setupFixture(Runnable) and
setupFixture(Callable).
Is internally responsible for handle the registered Stage for attachments, handle timeouts, provide the Application for the Toolkit launch and execute the setup in the JavaFX thread. The primary Stage is constructed by the platform.
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanupApplication(javafx.application.Application application)
Performs the clean up of the application.
|
static void |
cleanupStages()
Runs on the
JavaFX Application Thread: Hides all windows returned from
JavaVersionAdapter.getWindows() and returns once finished. |
static void |
hideStage()
Runs on the
JavaFX Application Thread: Hides the registered stage via Window.hide()
and returns once finished. |
static boolean |
isFXApplicationThreadRunning()
Detects if the JavaFx Application Thread is currently running.
|
static javafx.stage.Stage |
registerPrimaryStage()
Sets up the
PrimaryStageApplication to use in tests, prevents it from shutting
down when the last window is closed, and returns the Stage from Application.start(Stage). |
static javafx.stage.Stage |
registerStage(java.util.function.Supplier<javafx.stage.Stage> stageSupplier)
Runs the stageSupplier on the
JavaFX Application Thread, registers the supplied stage,
and returns that stage. |
static javafx.application.Application |
setupApplication(java.lang.Class<? extends javafx.application.Application> applicationClass,
java.lang.String... applicationArgs)
Sets up the given application with its given arguments and returns that application once finished.
|
static javafx.application.Application |
setupApplication(java.util.function.Supplier<javafx.application.Application> applicationSupplier)
Sets up the supplied application and returns that application once finished.
|
static <T> T |
setupFixture(java.util.concurrent.Callable<T> callable)
Runs the given
callable on the JavaFX Application Thread and returns once finished. |
static void |
setupFixture(java.lang.Runnable runnable)
Runs the given
runnable on the JavaFX Application Thread and returns once finished. |
static javafx.scene.Scene |
setupScene(java.util.function.Supplier<javafx.scene.Scene> sceneSupplier)
Runs the
sceneSupplier on the JavaFX Application Thread, sets the registered stage's scene to the
supplied scene, and returns the supplied scene once finished. |
static javafx.scene.Parent |
setupSceneRoot(java.util.function.Supplier<javafx.scene.Parent> sceneRootSupplier)
Runs the
sceneRootSupplier on the JavaFX Application Thread, sets the registered stage's scene's
root node to the supplied root node, and returns the supplied root node once finished. |
static javafx.stage.Stage |
setupStage(java.util.function.Consumer<javafx.stage.Stage> stageConsumer)
Sets up the registered stage by passing it into the given
stageConsumer on the
JavaFX Application Thread and returns the stage once finished. |
static void |
showStage()
Runs on the
JavaFX Application Thread: Shows the registered stage via Stage.show(),
moves it to the front via Stage.toFront(), and returns once finished. |
static FxToolkitContext |
toolkitContext()
Returns the internal context.
|
public static javafx.stage.Stage registerPrimaryStage()
throws java.util.concurrent.TimeoutException
PrimaryStageApplication to use in tests, prevents it from shutting
down when the last window is closed, and returns the Stage from Application.start(Stage).java.util.concurrent.TimeoutException - if execution is not finished before FxToolkitContext.getLaunchTimeoutInMillis()public static javafx.stage.Stage registerStage(java.util.function.Supplier<javafx.stage.Stage> stageSupplier)
throws java.util.concurrent.TimeoutException
JavaFX Application Thread, registers the supplied stage,
and returns that stage.java.util.concurrent.TimeoutException - if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()public static javafx.stage.Stage setupStage(java.util.function.Consumer<javafx.stage.Stage> stageConsumer)
throws java.util.concurrent.TimeoutException
stageConsumer on the
JavaFX Application Thread and returns the stage once finished.java.util.concurrent.TimeoutException - if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()public static javafx.application.Application setupApplication(java.lang.Class<? extends javafx.application.Application> applicationClass,
java.lang.String... applicationArgs)
throws java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutException - if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()public static javafx.application.Application setupApplication(java.util.function.Supplier<javafx.application.Application> applicationSupplier)
throws java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutException - if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()public static void cleanupApplication(javafx.application.Application application)
throws java.util.concurrent.TimeoutException
ToolkitService.cleanupApplication(Application) (which usually
calls the stop method of the application).application - the application to clean upjava.util.concurrent.TimeoutException - if cleanup is not finished before FxToolkitContext.getSetupTimeoutInMillis()
or the FX Application Thread is not runningpublic static javafx.scene.Scene setupScene(java.util.function.Supplier<javafx.scene.Scene> sceneSupplier)
throws java.util.concurrent.TimeoutException
sceneSupplier on the JavaFX Application Thread, sets the registered stage's scene to the
supplied scene, and returns the supplied scene once finished.java.util.concurrent.TimeoutException - if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()public static javafx.scene.Parent setupSceneRoot(java.util.function.Supplier<javafx.scene.Parent> sceneRootSupplier)
throws java.util.concurrent.TimeoutException
sceneRootSupplier on the JavaFX Application Thread, sets the registered stage's scene's
root node to the supplied root node, and returns the supplied root node once finished.java.util.concurrent.TimeoutExceptionpublic static void setupFixture(java.lang.Runnable runnable)
throws java.util.concurrent.TimeoutException
runnable on the JavaFX Application Thread and returns once finished.java.util.concurrent.TimeoutExceptionpublic static <T> T setupFixture(java.util.concurrent.Callable<T> callable)
throws java.util.concurrent.TimeoutException
callable on the JavaFX Application Thread and returns once finished.
before returning.java.util.concurrent.TimeoutExceptionpublic static void showStage()
throws java.util.concurrent.TimeoutException
JavaFX Application Thread: Shows the registered stage via Stage.show(),
moves it to the front via Stage.toFront(), and returns once finished.java.util.concurrent.TimeoutExceptionpublic static void hideStage()
throws java.util.concurrent.TimeoutException
JavaFX Application Thread: Hides the registered stage via Window.hide()
and returns once finished.java.util.concurrent.TimeoutExceptionpublic static void cleanupStages()
throws java.util.concurrent.TimeoutException
JavaFX Application Thread: Hides all windows returned from
JavaVersionAdapter.getWindows() and returns once finished.java.util.concurrent.TimeoutExceptionpublic static FxToolkitContext toolkitContext()
public static boolean isFXApplicationThreadRunning()