Package org.fulib.fx.controller
Class Router
java.lang.Object
org.fulib.fx.controller.Router
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToHistory(javafx.util.Pair<Either<TraversableNodeTree.Node<javax.inject.Provider<?>>, Object>, Map<String, Object>> pair) javafx.util.Pair<Object,javafx.scene.Node> back()Goes back to the previous controller in the history.booleancontainsRoute(String route) Returns whether the router contains the given route.current()Returns the current field and its parameters.javafx.util.Pair<Object,javafx.scene.Node> forward()Goes forward to the next controller in the history.Returns the controller or component with the given route without initializing and rendering it.voidregisterRoute(@NotNull String route, @NotNull javax.inject.Provider<?> provider) Registers a route with the given provider.voidregisterRoutes(@NotNull Object routes) Registers all routes in the given class.@NotNull javafx.util.Pair<Object,javafx.scene.Parent> renderRoute(@NotNull String route, @NotNull Map<@NotNull String, @Nullable Object> parameters) Initializes and renders the controller/component with the given route.booleanChecks if a router class has been registered already.voidsetHistorySize(int size) Updates the history size.toString()
-
Constructor Details
-
Router
@Inject public Router()
-
-
Method Details
-
registerRoutes
Registers all routes in the given class.- Parameters:
routes- The class to register the routes from
-
routesRegistered
public boolean routesRegistered()Checks if a router class has been registered already.- Returns:
- True if a router class has been registered already.
-
registerRoute
public void registerRoute(@NotNull @NotNull String route, @NotNull @NotNull javax.inject.Provider<?> provider) Registers a route with the given provider. When adding a route, the route has to be unique, otherwise an exception will be thrown.The route has to start with a slash, otherwise it will be added automatically.
This method doesn't check if the provider provides a valid controller or component.
- Parameters:
route- The route to registerprovider- The provider to register- Throws:
RuntimeException- If the route is already registered
-
renderRoute
@NotNull public @NotNull javafx.util.Pair<Object,javafx.scene.Parent> renderRoute(@NotNull @NotNull String route, @NotNull @NotNull Map<@NotNull String, @Nullable Object> parameters) Initializes and renders the controller/component with the given route. This only works for controllers and components having a parent as their root node.- Parameters:
route- The route of the controllerparameters- The parameters to pass to the controller- Returns:
- A pair containing the controller instance and the rendered parent (will be the same if the controller is a component)
- Throws:
RuntimeException- If the route couldn't be found
-
getRoute
Returns the controller or component with the given route without initializing and rendering it. The route will be seen as absolute, meaning it will be treated as a full path.- Parameters:
route- The route of the controller- Returns:
- The controller instance
-
containsRoute
Returns whether the router contains the given route. The route will be seen as absolute, meaning it will be treated as a full path.- Parameters:
route- The route to check- Returns:
- True if the route exists
-
addToHistory
-
back
Goes back to the previous controller in the history.- Returns:
- The rendered controller
-
forward
Goes forward to the next controller in the history.- Returns:
- The rendered controller
-
current
Returns the current field and its parameters. This is used internally for reloading the current controller.- Returns:
- The current controller object and its parameters
-
setHistorySize
public void setHistorySize(int size) Updates the history size. Setting the size to 1 will disable the history except for the current controller which will be stored for reloading.- Parameters:
size- The size of the history
-
toString
-