AbstractView.java

package edu.ntnu.idi.idatt.view.components;

import javafx.scene.Parent;
import javafx.scene.layout.Pane;

/**
 * INFO!
 *
 * <p>
 * This class is based on the generic Type parameter - T. It's experimental
 * for the time of creating the class (24.04.26), since parent don't have access
 * to the
 * getChildren() method which could provide usefuleness in creating a standalone
 * abstract class.
 *
 * Since most views will be based on the Pane subclasses, it is fully
 * functional, but
 * may throw errors if the typeparameter isn't of this type.
 * </p>
 *
 * Reference: https://docs.oracle.com/javase/8/javafx/api/overview-tree.html
 */

/**
 * AbstractView class
 *
 * <p>
 * Provides a simple abstraction of the Pane subclasses,
 * making it a useful framework for creating different views.
 * </p>
 */
public abstract class AbstractView<T extends Pane> {

  private T instance;

  /**
   * Constructor for AbstractView.
   */
  protected AbstractView(T type) {
    instance = type;
    instance.getChildren().add(this.createContent());
  }

  /**
   * Constructor for AbstractView without initialization.
   */
  protected AbstractView() {

  }

  /**
   * Getter for current view instance.
   *
   * @return Instance of current view.
   */
  public T getInstance() {
    return instance;
  }

  /**
   * Setter for current view instance.
   */
  public void setInstance(T instance) {
    this.instance = instance;
  }

  /**
   * Abstract method for creating view content.
   */
  public abstract Parent createContent();

}