SceneManager.java

package edu.ntnu.idi.idatt.view;

import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 * SceneManager class for managing objects to the stage.
 *
 * <p>
 * This class provides methods for changing the root object to
 * the scene, providing simple use of components to change between the
 * pages
 * </p>
 *
 * @author Pawel Sapula
 */
public final class SceneManager {

  // Store scene reference.
  private static Scene scene;

  // Disable initialization.
  private SceneManager() {
  }

  /**
   * Method for intialization of the Scene Manager.
   *
   * <p>
   * This method enables initialization of the primary scene,
   * based on the stage from the program entry point, and a
   * page based on the page's root object.
   * </p>
   *
   * @param stage - Application's stage
   * @param root  - The root object / fundamental object of a page
   */
  public static void init(Stage stage, Parent root) {
    scene = new Scene(root);
    // Add styling sheet permamently for the scene.
    scene.getStylesheets().add(SceneManager.class.getResource("/themes/default.css").toExternalForm());
    stage.setScene(scene);
  }

  /**
   * Method for switching the scene's root variable.
   *
   * @param root - Parent JavaFX object.
   */
  public static void switchTo(Parent root) {
    scene.setRoot(root);
  }

}