Class ControllerManager
This class is used internally by the framework and should not be used directly.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddKeyEventHandler(Object instance, OnKey.Target target, javafx.event.EventType<javafx.scene.input.KeyEvent> type, javafx.event.EventHandler<javafx.scene.input.KeyEvent> handler) voidcleanup()Destroys all controllers that have been initialized and are currently displayed.voidDestroys the given controller/component by calling all methods annotated withOnDestroy.@Nullable ResourceBundleReturns the title of the given controller instance if it has one.voidInitializes the given controller/component.io.reactivex.rxjava3.disposables.Disposableinit(@NotNull Object instance, @NotNull Map<@NotNull String, @Nullable Object> parameters, boolean disposeOnNewMainController) Initializes the given controller/component.javafx.scene.NodeinitAndRender(Object instance, Map<String, Object> parameters) Initializes and renders the given controller.@NotNull javafx.scene.NodeLoads a fxml file using a custom controller factory.javafx.scene.NodeRenders the given controller/component instance.voidsetDefaultResourceBundle(ResourceBundle resourceBundle) Sets the default resource bundle for all controllers that don't have a resource bundle set.
-
Constructor Details
-
ControllerManager
@Inject public ControllerManager()
-
-
Method Details
-
initAndRender
Initializes and renders the given controller. Calls theOnInitandOnRendermethods. Seeinit(Object, Map)andrender(Object, Map).The controller/component instance(s) will be added to the set of initialized controllers and will be destroyed when a new main controller is set.
- Parameters:
instance- The controller instanceparameters- The parameters to pass to the controller- Returns:
- The rendered controller
-
init
public io.reactivex.rxjava3.disposables.Disposable init(@NotNull @NotNull Object instance, @NotNull @NotNull Map<@NotNull String, @Nullable Object> parameters, boolean disposeOnNewMainController) Initializes the given controller/component. Calls theOnInitmethod(s) and recursively initializes all subcomponents.Order: Controller -> Subcomponents -> Subcomponents of subcomponents -> ...
- Parameters:
instance- The controller/component instanceparameters- The parameters to pass to the controller/componentdisposeOnNewMainController- Whether the controller/component should be destroyed when a new main controller is set- Returns:
- A disposable that can be used to destroy the controller/component and all its subcomponents manually
-
init
public void init(@NotNull @NotNull Object instance, @NotNull @NotNull Map<@NotNull String, @Nullable Object> parameters) Initializes the given controller/component. Calls theOnInitmethod(s) and recursively initializes all subcomponents.All initialized controllers will be added to the list of initialized controllers. If a controller/component is added to the list, all its subcomponents will follow right after it.
- Parameters:
instance- The controller/component instanceparameters- The parameters to pass to the controller
-
render
Renders the given controller/component instance. Renders all subcomponents recursively and then calls theOnRendermethod(s) before returning the rendered controller.Important: This method assumes that the controller has already been initialized. The controller will not automatically be destroyed when using only this method. Use
init(Object, Map, boolean)before, to initialize and automatically destroy the controller or destroy it yourself afterward.If the controller specifies a fxml file in its
Controller.view(), it will be loaded and the controller will be set as the controller of the fxml file.If the controller is a component (extends from a JavaFX Node), the component itself will be rendered and returned. This can be combined with the
Component.view()to set the controller as the root of the fxml file.If the controller specifies a method as
Controller.view(), the method will be called and the returned Parent will be used as the view. In order to specify a method, the view must start with a '#'. The method must be in the controller class and must return a (subclass of) Parent. Example:@Controller(view = "#getView")will call the methodParent getView()in the controller.- Parameters:
instance- The controller instanceparameters- The parameters to pass to the controller- Returns:
- The rendered controller/component
-
addKeyEventHandler
@Internal public void addKeyEventHandler(Object instance, OnKey.Target target, javafx.event.EventType<javafx.scene.input.KeyEvent> type, javafx.event.EventHandler<javafx.scene.input.KeyEvent> handler) -
destroy
Destroys the given controller/component by calling all methods annotated withOnDestroy.Important: Do not use this method on a controller's view but on the controller itself.
If the controller has subcomponents, they will be destroyed first recursively in reverse order.
If the controller has an undestroyed Subscriber field, a warning will be logged in development mode.
- Parameters:
instance- The controller/component instance to destroy
-
cleanup
public void cleanup()Destroys all controllers that have been initialized and are currently displayed. -
loadFXML
@Internal @NotNull public @NotNull javafx.scene.Node loadFXML(@NotNull @NotNull String fileName, @NotNull @NotNull Object instance, boolean setRoot) Loads a fxml file using a custom controller factory. This method is used internally by the framework and should not be used directly.If the fxml file contains an element with a controller class annotated with
Controller, an instance provided by the router will be used as the controller for the element.- Parameters:
fileName- The name of the fxml resource file (with path and file extension)instance- The controller instance to use- Returns:
- A parent representing the fxml file
-
getDefaultResourceBundle
-
setDefaultResourceBundle
Sets the default resource bundle for all controllers that don't have a resource bundle set.- Parameters:
resourceBundle- The default resource bundle
-
getTitle
Returns the title of the given controller instance if it has one. If the title is a key, the title will be looked up in the resource bundle of the controller.- Parameters:
instance- The controller instance- Returns:
- The title of the controller
-