Class ScreenController

java.lang.Object
no.ntnu.principes.controller.screen.ScreenController

public class ScreenController extends Object
Controls the navigation and display of screens and modals in the application. Manages screen transitions, modal dialogs, and maintains navigation history.
  • Constructor Details

    • ScreenController

      public ScreenController(StageController stageController)
      Manages the initialization and hierarchical layout of the graphical user interface, including the setup of containers for main screens, modals, and the title bar. also links its operations to a specified StageController.
      Parameters:
      stageController - The StageController for which this ScreenController is managing screens and modals for.
  • Method Details

    • addScreen

      public void addScreen(String name, BaseScreen screen)
      Adds a screen to the collection, associating it with a unique name. The screen can later be retrieved or manipulated by its name.
      Parameters:
      name - A unique identifier for the screen. Must not be null or empty. If a screen with the same name already exists, it will be replaced.
      screen - The screen instance to add. Must not be null.
    • removeScreen

      public void removeScreen(String name)
      Removes a screen and its associated context. This includes removing the screen from the screen registry, clearing its context, and removing any references from navigation and modal stacks.
      Parameters:
      name - The unique identifier of the screen to be removed. Must not be null or empty. If the screen does not exist, no action will be performed.
    • getContext

      public ScreenContext getContext(String screenId)
      Eases the process of obtaining a ScreenContext for a given screen ID.
    • getCurrentScreen

      public javafx.scene.Parent getCurrentScreen()
      Retrieves the currently active screen in the screen container.
      Returns:
      The currently active Parent screen, or null if no screens are present in the container.
    • getCurrentModalInstance

      public BaseModal getCurrentModalInstance()
      Retrieves the current modal instance if it is of type BaseModal.
      Returns:
      The current BaseModal instance, or null if no modals are open or the current modal is not a BaseModal.
    • canGoBack

      public boolean canGoBack()
      Checks if the navigation stack has more than one screen, indicating that the user can navigate back to a previous screen.
      Returns:
      true if there is a previous screen to navigate back to; false otherwise.
    • hasOpenModals

      public boolean hasOpenModals()
      Checks if there are any open modals in the modal stack.
      Returns:
      true if there are open modals; false otherwise.
    • getCurrentScreenId

      public javafx.beans.value.ObservableStringValue getCurrentScreenId()
      Retrieves the current screen ID as an observable string value.
      Returns:
      The current screen ID as an ObservableStringValue.
    • getCurrentModalId

      public String getCurrentModalId()
      Retrieves the current modal ID from the modal stack.
      Returns:
      The current modal ID as a string, or null if no modals are open.
    • utility

      public void utility(javafx.scene.Node node)
      Sets the main container to display a utility node.

      This method is used to display a utility node in the main container, for utility stages, like the sidebar and debug windows.

      Parameters:
      node - The node to be displayed in the main container.
    • close

      public void close()
      Cleans up resources used by the current instance.

      This method removes any listeners and clears stored data to ensure the instance is properly reset and does not hold onto unnecessary references.

      • Calls tearDownListeners() to deregister any attached listeners.
      • Invokes clear() to remove any internal state or data.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object