Package org.fulib.fx

Class FulibFxApp

java.lang.Object
javafx.application.Application
org.fulib.fx.FulibFxApp

public abstract class FulibFxApp extends javafx.application.Application
  • Nested Class Summary

    Nested classes/interfaces inherited from class javafx.application.Application

    javafx.application.Application.Parameters
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final io.reactivex.rxjava3.core.Scheduler
     
    static final Logger
     

    Fields inherited from class javafx.application.Application

    STYLESHEET_CASPIAN, STYLESHEET_MODENA
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyTitle(Object controller, javafx.stage.Stage stage)
    Applies the title of the given controller to the stage.
    Returns auto refresher of the application.
    boolean
    Returns to the previous controller in the history if possible.
    protected void
     
    <T extends javafx.scene.Node>
    T
    destroy(T rendered)
    Destroys a rendered controller extending Parent.
    protected void
    display(@NotNull javafx.scene.Parent parent)
    Displays the given parent.
    Formats the title of a controller using the title pattern.
    boolean
    Forwards to the next controller in the history if possible.
    Returns the currently used component of the application.
    getTitle(Object controller)
    Returns the title of the given controller.
    <T extends javafx.scene.Node>
    T
    initAndRender(@NotNull String route)
    Initializes and renders the component with the given route.
    <T extends javafx.scene.Node>
    T
    initAndRender(@NotNull String route, @NotNull Map<@NotNull String,@Nullable Object> params)
    Initializes and renders the component with the given route.
    <T extends javafx.scene.Node>
    T
    initAndRender(@NotNull String route, @NotNull Map<@NotNull String,@Nullable Object> params, @Nullable io.reactivex.rxjava3.disposables.DisposableContainer onDestroy)
    Initializes and renders the component with the given route.
    <T extends javafx.scene.Node>
    T
    initAndRender(T component)
    Initializes and renders a component instance (a controller with the Component annotation).
    <T extends javafx.scene.Node>
    T
    initAndRender(T component, @NotNull Map<@NotNull String,@Nullable Object> params)
    Initializes and renders a component instance (a controller with the Component annotation).
    <T extends javafx.scene.Node>
    T
    initAndRender(T component, @NotNull Map<@NotNull String,@Nullable Object> params, @Nullable io.reactivex.rxjava3.disposables.DisposableContainer onDestroy)
    Initializes and renders a component instance (a controller with the Component annotation).
    protected void
    onShow(Optional<String> route, Object controller, javafx.scene.Parent rendered, Map<String,Object> params)
    Called when the application shows a new controller.
    protected void
    prepareDisplay(@Nullable String route, @NotNull javafx.scene.Parent parent, @NotNull Object controller, @NotNull Map<String,Object> params)
    Prepares the display of a controller by setting all required properties and calling the onShow method.
    void
    Refreshes the current controller.
    void
    Registers all routes in the given class.
    static @NotNull Path
    Returns the path to the 'resources' directory.
    void
    Sets the default resource bundle to use for FXML files if no resource bundle is provided in the controller/component.
    void
    setHistorySize(int size)
    Sets the history size of the application.
    static void
    setResourcesPath(@NotNull Path path)
    Sets the path to the 'resources' directory.
    void
    setTitlePattern(String titlePattern)
    Sets the title pattern for the application.
    void
    Sets the title pattern for the application.
    @NotNull javafx.scene.Parent
    show(@NotNull Object controller)
    Initializes, renders and displays a controller.
    @NotNull javafx.scene.Parent
    show(@NotNull Object controller, @NotNull Map<String,Object> params)
    Initializes, renders and displays a controller.
    @NotNull javafx.scene.Parent
    show(@NotNull String route)
    Initializes, renders and displays a controller.
    @NotNull javafx.scene.Parent
    show(@NotNull String route, @NotNull Map<@NotNull String,@Nullable Object> params)
    Initializes, renders and displays a controller.
    javafx.stage.Stage
    Returns the stage of the application.
    void
    start(javafx.stage.Stage primaryStage)
     
    void
     

    Methods inherited from class javafx.application.Application

    getHostServices, getParameters, getUserAgentStylesheet, init, launch, launch, notifyPreloader, setUserAgentStylesheet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FX_SCHEDULER

      public static final io.reactivex.rxjava3.core.Scheduler FX_SCHEDULER
    • LOGGER

      public static final Logger LOGGER
  • Constructor Details

    • FulibFxApp

      public FulibFxApp()
  • Method Details

    • resourcesPath

      @NotNull public static @NotNull Path resourcesPath()
      Returns the path to the 'resources' directory.
      Returns:
      The path to the resources directory
    • setResourcesPath

      public static void setResourcesPath(@NotNull @NotNull Path path)
      Sets the path to the 'resources' directory. If your 'resources' directory differs from "src/main/resources", you can set it here.

      If your project is contained in another directory (e.g. gradle submodule), you can set the path to the 'resources' directory here.

      Parameters:
      path - The path to the resources directory (e.g. "example/src/main/resources")
    • initAndRender

      @NotNull public <T extends javafx.scene.Node> T initAndRender(@NotNull @NotNull String route)
      Initializes and renders the component with the given route.

      The component has to be destroyed manually, for example by calling destroy(Node).

      Type Parameters:
      T - The type of the component
      Parameters:
      route - The route of the component to render
      Returns:
      The rendered component
    • initAndRender

      @NotNull public <T extends javafx.scene.Node> T initAndRender(@NotNull T component)
      Initializes and renders a component instance (a controller with the Component annotation).

      The component has to be destroyed manually, for example by calling destroy(Node).

      Type Parameters:
      T - The type of the component
      Parameters:
      component - The component instance
      Returns:
      The rendered component
    • initAndRender

      @NotNull public <T extends javafx.scene.Node> T initAndRender(@NotNull @NotNull String route, @NotNull @NotNull Map<@NotNull String,@Nullable Object> params)
      Initializes and renders the component with the given route.

      The component has to be destroyed manually, for example by calling destroy(Node).

      Type Parameters:
      T - The type of the component
      Parameters:
      route - The route of the component to render
      params - The arguments passed to the component
      Returns:
      The rendered component
    • initAndRender

      @NotNull public <T extends javafx.scene.Node> T initAndRender(@NotNull T component, @NotNull @NotNull Map<@NotNull String,@Nullable Object> params)
      Initializes and renders a component instance (a controller with the Component annotation).

      The component has to be destroyed manually, for example by calling destroy(Node).

      Type Parameters:
      T - The type of the component
      Parameters:
      component - The component instance
      params - The arguments passed to the component
      Returns:
      The rendered component
    • initAndRender

      @NotNull public <T extends javafx.scene.Node> T initAndRender(@NotNull @NotNull String route, @NotNull @NotNull Map<@NotNull String,@Nullable Object> params, @Nullable @Nullable io.reactivex.rxjava3.disposables.DisposableContainer onDestroy)
      Initializes and renders the component with the given route.

      If a disposable is provided, the disposable will be modified to include the cleanup of the rendered component. The provided disposable can be used to destroy the component with all its children manually.

      If no disposable is provided, the component has to be destroyed manually, for example by calling destroy(Node).

      Type Parameters:
      T - The type of the component
      Parameters:
      route - The route of the component to render
      params - The arguments passed to the component
      onDestroy - A disposable which will be modified to include the disposable of the component
      Returns:
      The rendered component
    • initAndRender

      @NotNull public <T extends javafx.scene.Node> T initAndRender(@NotNull T component, @NotNull @NotNull Map<@NotNull String,@Nullable Object> params, @Nullable @Nullable io.reactivex.rxjava3.disposables.DisposableContainer onDestroy)
      Initializes and renders a component instance (a controller with the Component annotation).

      If a disposable is provided, the disposable will be modified to include the cleanup of the rendered component. The provided disposable can be used to destroy the component with all its children manually.

      If no disposable is provided, the component has to be destroyed manually, for example by calling destroy(Node).

      Parameters:
      component - The component instance
      params - The arguments passed to the component
      onDestroy - A disposable which will be modified to include the disposable of the component
      Returns:
      The rendered component
    • destroy

      @NotNull public <T extends javafx.scene.Node> T destroy(@NotNull T rendered)
      Destroys a rendered controller extending Parent.
      Type Parameters:
      T - The type of the controller
      Parameters:
      rendered - The rendered controller instance
      Returns:
      The destroyed controller instance
      Throws:
      IllegalArgumentException - If the given instance is not a controller extending Parent
    • start

      @MustBeInvokedByOverriders public void start(javafx.stage.Stage primaryStage)
      Specified by:
      start in class javafx.application.Application
    • stop

      public void stop()
      Overrides:
      stop in class javafx.application.Application
    • show

      @NotNull public @NotNull javafx.scene.Parent show(@NotNull @NotNull String route)
      Initializes, renders and displays a controller.
      Parameters:
      route - The route of the controller to render
      Returns:
      The rendered parent of the controller
    • show

      @NotNull public @NotNull javafx.scene.Parent show(@NotNull @NotNull Object controller)
      Initializes, renders and displays a controller.
      Parameters:
      controller - The controller to render
      Returns:
      The rendered parent of the controller
    • show

      @NotNull public @NotNull javafx.scene.Parent show(@NotNull @NotNull Object controller, @NotNull @NotNull Map<String,Object> params)
      Initializes, renders and displays a controller.
      Parameters:
      controller - The controller to render
      params - The arguments passed to the controller
      Returns:
      The rendered parent of the controller
    • show

      @NotNull public @NotNull javafx.scene.Parent show(@NotNull @NotNull String route, @NotNull @NotNull Map<@NotNull String,@Nullable Object> params)
      Initializes, renders and displays a controller.
      Parameters:
      route - The route of the controller to render
      params - The arguments passed to the controller
      Returns:
      The rendered parent of the controller
    • prepareDisplay

      protected void prepareDisplay(@Nullable @Nullable String route, @NotNull @NotNull javafx.scene.Parent parent, @NotNull @NotNull Object controller, @NotNull @NotNull Map<String,Object> params)
      Prepares the display of a controller by setting all required properties and calling the onShow method. The controller will be displayed using display(Parent).
      Parameters:
      route - The route of the controller to render
      parent - The parent to display
      controller - The controller instance
      params - The arguments passed to the controller
    • display

      protected void display(@NotNull @NotNull javafx.scene.Parent parent)
      Displays the given parent. Will be called when showing a main controller or when reloading the currently displayed controller. This method can be overridden to add custom behavior like multiple controllers on top of each other.
      Parameters:
      parent - The parent to display
    • cleanup

      protected void cleanup()
    • onShow

      protected void onShow(Optional<String> route, Object controller, javafx.scene.Parent rendered, Map<String,Object> params)
      Called when the application shows a new controller.

      This method is called after the controller is initialized and rendered.

      Parameters:
      route - The route of the controller (empty if the controller has been shown directly)
      controller - The controller instance
      rendered - The rendered parent of the controller
      params - The arguments passed to the controller
    • stage

      public javafx.stage.Stage stage()
      Returns the stage of the application.
      Returns:
      The stage of the application
    • frameworkComponent

      @Internal public FrameworkComponent frameworkComponent()
      Returns the currently used component of the application.

      Warning: This method should only be used for internal purposes.

      Returns:
      The component
    • registerRoutes

      public void registerRoutes(Object routes)
      Registers all routes in the given class.
      Parameters:
      routes - The class to register the routes from
    • setDefaultResourceBundle

      public void setDefaultResourceBundle(ResourceBundle resourceBundle)
      Sets the default resource bundle to use for FXML files if no resource bundle is provided in the controller/component.
    • autoRefresher

      public AutoRefresher autoRefresher()
      Returns auto refresher of the application.
    • back

      public boolean back()
      Returns to the previous controller in the history if possible.
      Returns:
      True if the application could go back, false otherwise
    • forward

      public boolean forward()
      Forwards to the next controller in the history if possible.
      Returns:
      True if the application could go forward, false otherwise
    • refresh

      public void refresh()
      Refreshes the current controller.

      The controller will be cleaned up and then re-initialized and re-rendered. This method will re-use the current route and parameters and not update the history.

    • setTitlePattern

      public void setTitlePattern(Function<String,String> titlePattern)
      Sets the title pattern for the application. This title pattern expects a function that will be called with the title of the controller and should return the final title.
      Parameters:
      titlePattern - The title pattern
    • setTitlePattern

      public void setTitlePattern(String titlePattern)
      Sets the title pattern for the application. This title pattern expects a '%s' placeholder which will be replaced with the title of the controller.
      Parameters:
      titlePattern - The title pattern
    • formatTitle

      public String formatTitle(String title)
      Formats the title of a controller using the title pattern.
      Parameters:
      title - The title of the controller
      Returns:
      The formatted title
    • getTitle

      public Optional<String> getTitle(Object controller)
      Returns the title of the given controller.
      Parameters:
      controller - The controller instance
      Returns:
      The title of the controller
    • applyTitle

      public void applyTitle(Object controller, javafx.stage.Stage stage)
      Applies the title of the given controller to the stage.
      Parameters:
      controller - The controller instance
      stage - The stage to apply the title to
    • setHistorySize

      public void setHistorySize(int size)
      Sets the history size of the application.

      The smaller the history size, the less memory is used.

      The larger the history size, the more controllers can be navigated back and forth.

      The default history size is 10. It cannot be smaller than 1.

      Parameters:
      size - The history size