Class Context

java.lang.Object
megalodonte.application.Context

public final class Context extends Object
Application context available to the startup handler. Provides access to the primary Stage, command-line arguments, and view/navigation methods.

Created once by Bootstrap.dispatch(Class, Stage, String[]) and passed to the application handler via MegalodonteApp.run(Consumer, Consumer).

  • Field Details

  • Method Details

    • backendContract

      public megalodonte.contracts.BackendContract backendContract()
    • getArgs

      public String[] getArgs()
      Returns the command-line arguments passed to the application. @return the arguments array
    • javafxStage

      public javafx.stage.Stage javafxStage()
      Returns the primary JavaFX stage managed by this context. @return the primary stage
    • useView

      public void useView(Class<? extends ScreenComponent> componentClass)
      Instantiates a ScreenComponent by class and renders it as the current view. Creates a new Scene with the default dimensions and centers the stage.
      Parameters:
      componentClass - the screen component class to instantiate
      Throws:
      RuntimeException - if instantiation fails
    • useView

      public void useView(ScreenComponent component)
      Renders a ScreenComponent as the current view. Creates a new Scene, applies the theme font, sets it on the stage, and schedules onMount.
      Parameters:
      component - the screen component to render
    • useView

      public void useView(ScreenComponent component, double sceneWidth, double sceneHeight)
      Creates the first scene at its intended size, avoiding native resize feedback at startup.
    • updateView

      public void updateView(ScreenComponent component)
      Re-renders component in place — swaps the current Scene's root node, keeping the Stage's existing Scene, size and position untouched. Unlike useView(ScreenComponent), which creates a brand-new Scene and re-centers the window (right for the first render, since the Stage doesn't have a size to preserve yet), this is for reactive re-renders of an already-showing screen — e.g. switching themes — where the window visibly jumping/resizing would be a regression, not a feature.

      Deliberately does NOT call component.onMount() — that hook is a one-time "just mounted" signal (e.g. HomeScreen.onMount() reopens the last saved layout from disk), not something that should re-fire on every re-render triggered by this method.

      Falls back to useView(ScreenComponent) if the Stage has no Scene yet (nothing to swap the root of).

      Parameters:
      component - the screen component to re-render in place
    • useView

      public void useView(RouteResult routeResult)
      Renders a route result, applying its RouteProps (dimensions, title, icon, resizability) to the stage. Does not call onMount — that is handled by the router.
      Parameters:
      routeResult - the resolved route to display
    • useView

      @Deprecated(forRemoval=true) public void useView(ComponentInterface<?> component)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Advise: onMount will not work using this method
      Parameters:
      component - the component to render (deprecated, use useView(ScreenComponent))
    • useRouter

      public Context.RouterBuilder useRouter(RouterBase router)
      Binds a router to this context and returns a Context.RouterBuilder to start navigation.
      Parameters:
      router - the router to bind
      Returns:
      a builder to call Context.RouterBuilder.start() on