@Unstable(reason="class was recently added") public final class FxToolkit extends Object
Overview
This class methods cover three different kinds of fixtures:
registeredStage
.registeredStage
.registeredStage
.Additionally it keeps an internal context.
1. Container Fixtures
They can be registered as registeredStage
and provide a top-level container, i.e.
Stage
s.
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>)
.
2. Content Fixtures
They can be attached to the registeredStage
.
Either constructed by calling an Application.start()
, by
supplying Scene
s, Parent
s, or by consuming a Stage
.
Use: setupStage(Consumer<Stage>)
,
setupApplication(Class<? extends Application>)
,
setupScene(Supplier<Scene>)
or
setupSceneRoot(Supplier<Parent>)
3. Individual Fixtures
To setup individual Stages, Scenes or Nodes use setupFixture(Runnable)
and
setupFixture(Callable)
.
Internal Context
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(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 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 Stage |
registerStage(Supplier<Stage> stageSupplier)
Runs the stageSupplier on the
JavaFX Application Thread , registers the supplied stage,
and returns that stage. |
static Application |
setupApplication(Class<? extends Application> applicationClass,
String... applicationArgs)
Sets up the given application with its given arguments and returns that application once finished.
|
static Application |
setupApplication(Supplier<Application> applicationSupplier)
Sets up the supplied application and returns that application once finished.
|
static <T> T |
setupFixture(Callable<T> callable)
Runs the given
callable on the JavaFX Application Thread and returns once finished. |
static void |
setupFixture(Runnable runnable)
Runs the given
runnable on the JavaFX Application Thread and returns once finished. |
static Scene |
setupScene(Supplier<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 Parent |
setupSceneRoot(Supplier<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 Stage |
setupStage(Consumer<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 Stage registerPrimaryStage() throws 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)
.TimeoutException
- if execution is not finished before FxToolkitContext.getLaunchTimeoutInMillis()
public static Stage registerStage(Supplier<Stage> stageSupplier) throws TimeoutException
JavaFX Application Thread
, registers the supplied stage,
and returns that stage.TimeoutException
- if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()
public static Stage setupStage(Consumer<Stage> stageConsumer) throws TimeoutException
stageConsumer
on the
JavaFX Application Thread
and returns the stage once finished.TimeoutException
- if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()
public static Application setupApplication(Class<? extends Application> applicationClass, String... applicationArgs) throws TimeoutException
TimeoutException
- if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()
public static Application setupApplication(Supplier<Application> applicationSupplier) throws TimeoutException
TimeoutException
- if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()
@Unstable(reason="is missing apidocs") public static void cleanupApplication(Application application) throws TimeoutException
ToolkitService.cleanupApplication(Application)
(which usually
calls the stop
method of the application).application
- the application to clean upTimeoutException
- if cleanup is not finished before FxToolkitContext.getSetupTimeoutInMillis()
or the FX Application Thread is not runningpublic static Scene setupScene(Supplier<Scene> sceneSupplier) throws TimeoutException
sceneSupplier
on the JavaFX Application Thread
, sets the registered stage's scene to the
supplied scene, and returns the supplied scene once finished.TimeoutException
- if execution is not finished before FxToolkitContext.getSetupTimeoutInMillis()
public static Parent setupSceneRoot(Supplier<Parent> sceneRootSupplier) throws 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.TimeoutException
public static void setupFixture(Runnable runnable) throws TimeoutException
runnable
on the JavaFX Application Thread
and returns once finished.TimeoutException
public static <T> T setupFixture(Callable<T> callable) throws TimeoutException
callable
on the JavaFX Application Thread
and returns once finished.
before returning.TimeoutException
public static void showStage() throws TimeoutException
JavaFX Application Thread
: Shows the registered stage via Stage.show()
,
moves it to the front via Stage.toFront()
, and returns once finished.TimeoutException
public static void hideStage() throws TimeoutException
JavaFX Application Thread
: Hides the registered stage via Window.hide()
and returns once finished.TimeoutException
public static void cleanupStages() throws TimeoutException
JavaFX Application Thread
: Hides all windows returned from
JavaVersionAdapter.getWindows()
and returns once finished.TimeoutException
public static FxToolkitContext toolkitContext()
public static boolean isFXApplicationThreadRunning()