java.lang.Object
app.supernaut.fx.FxLauncherAbstract
- All Implemented Interfaces:
FxLauncher
- Direct Known Subclasses:
MicronautFxLauncher,SimpleFxLauncher
Base JavaFX implementation of
FxLauncher. This implementation provides the following functionality:
- Starts OpenJFX applications.
-
Constructor provides an option to start
BackgroundAppon a new thread (this allows theBackgroundAppand the OpenJFXApplicationDelegateto initialize in parallel.) -
Implements
FxLauncher.launchAsync(java.lang.String[], java.lang.Class<? extends app.supernaut.fx.ApplicationDelegate>, java.lang.Class<? extends app.supernaut.BackgroundApp>)which initializes the OpenJFXApplicationDelegateon a new thread. This is not needed for a typical, packaged OpenJFX application which can just callFxLauncher.launch(java.lang.String[], java.lang.Class<? extends app.supernaut.fx.ApplicationDelegate>, java.lang.Class<? extends app.supernaut.BackgroundApp>)from itsstatic main(), but is useful in various testing scenarios. -
Defines the
FxLauncherAbstract.AppFactoryinterface for constructing theBackgroundAppandApplicationDelegate. This allows subclasses (or callers) to provide their own implementation of the application creation logic. The AppFactory interface was designed to allow usage of Dependency Injection frameworks like Micronaut to create dependency-injected implementations ofApplicationDelegateandBackgroundApp. TheAppFactoryinterface was also designed to be lazily-instantiated so theAppFactory(dependency-injection framework) can initialize in parallel to OpenJFX. -
Uses the same
AppFactory(dependency-injection context) to initialize the ApplicationDelegate and Background application. ACountDownLatchis used to make sure theAppFactory(which may be initialized on another thread along with the BackgroundApp) is ready whenOpenJfxProxyApplicationcallscreateAppDelegate(Application proxyApplication).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface that can be used to create and pre-initializeApplicationDelegateandBackgroundApp.static classDefault implementation of AppFactory. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CompletableFuture<ApplicationDelegate>This future returns an initialized ApplicationDelegateprotected final CompletableFuture<BackgroundApp>This future returns an initialized BackgroundApp -
Constructor Summary
ConstructorsConstructorDescriptionFxLauncherAbstract(Supplier<FxLauncherAbstract.AppFactory> appFactorySupplier, boolean initializeBackgroundAppOnNewThread) Construct an Asynchronous Launcher that works with OpenJFX. -
Method Summary
Modifier and TypeMethodDescriptioncreateAppDelegate(javafx.application.Application proxyApplication) Called byOpenJfxProxyApplicationto create its delegateApplicationDelegateobject.Get a future that will be completed when the ApplicationDelegate is initialized.Get a future that will be completed when the Background app is initialized.voidlaunch(String[] args, Class<? extends ApplicationDelegate> appDelegate) Launch and run the application on the current thread.voidlaunch(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on the current thread.launchAsync(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on a newly created thread.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface app.supernaut.fx.FxLauncher
name
-
Field Details
-
futureBackgroundApp
This future returns an initialized BackgroundApp -
futureAppDelegate
This future returns an initialized ApplicationDelegate
-
-
Constructor Details
-
FxLauncherAbstract
public FxLauncherAbstract(Supplier<FxLauncherAbstract.AppFactory> appFactorySupplier, boolean initializeBackgroundAppOnNewThread) Construct an Asynchronous Launcher that works with OpenJFX.- Parameters:
appFactorySupplier- A Supplier that will lazily instantiate an AppFactory.initializeBackgroundAppOnNewThread- If true, initializesappFactorySupplierandBackgroundAppon new thread, if false start them on calling thread (typically the main thread)
-
-
Method Details
-
launchAsync
public CompletableFuture<ApplicationDelegate> launchAsync(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on a newly created thread. This method is useful for testing and possibly for other application startup scenarios.- Specified by:
launchAsyncin interfaceFxLauncher- Parameters:
args- command-line argsappDelegate- class object for ApplicationDelegatebackgroundApp- class object for BackgroundApp- Returns:
- A future that is completed when ApplicationDelegate app is initialized
-
launch
public void launch(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on the current thread. Does not return until after ApplicationDelegate closes.- Specified by:
launchin interfaceFxLauncher- Parameters:
args- command-line argsappDelegate- class object for ApplicationDelegatebackgroundApp- class object for BackgroundApp
-
launch
Launch and run the application on the current thread. Uses default/no-op background application. Does not return until after ApplicationDelegate closes.- Specified by:
launchin interfaceFxLauncher- Parameters:
args- command-line argsappDelegate- class object for ApplicationDelegate
-
createAppDelegate
Called byOpenJfxProxyApplicationto create its delegateApplicationDelegateobject. Waits on aCountDownLatchto make sure theAppFactoryis ready.- Specified by:
createAppDelegatein interfaceFxLauncher- Parameters:
proxyApplication- The calling instance ofOpenJfxProxyApplication- Returns:
- The newly constructed OpenJFX-compatible
ApplicationDelegate
-
getAppDelegate
Get a future that will be completed when the ApplicationDelegate is initialized.- Specified by:
getAppDelegatein interfaceFxLauncher- Returns:
- A future that is completed when ApplicationDelegate is initialized
-
getBackgroundApp
Get a future that will be completed when the Background app is initialized.- Specified by:
getBackgroundAppin interfaceFxLauncher- Returns:
- A future that is completed when Background app is initialized
-