Class Router

java.lang.Object
org.fulib.fx.controller.Router

@Singleton public class Router extends Object
  • Constructor Details

    • Router

      @Inject public Router()
  • Method Details

    • registerRoutes

      public void registerRoutes(@NotNull @NotNull Object routes)
      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 register
      provider - 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 controller
      parameters - 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

      public Object getRoute(String route)
      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

      public boolean containsRoute(String route)
      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

      public void addToHistory(javafx.util.Pair<Either<TraversableNodeTree.Node<javax.inject.Provider<?>>,Object>,Map<String,Object>> pair)
    • back

      public javafx.util.Pair<Object,javafx.scene.Node> back()
      Goes back to the previous controller in the history.
      Returns:
      The rendered controller
    • forward

      public javafx.util.Pair<Object,javafx.scene.Node> forward()
      Goes forward to the next controller in the history.
      Returns:
      The rendered controller
    • current

      public javafx.util.Pair<Object,Map<String,Object>> 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

      public String toString()
      Overrides:
      toString in class Object