diff --git a/src/main/java/edu/ntnu/idi/idatt/Launcher.java b/src/main/java/edu/ntnu/idi/idatt/Launcher.java index 601d11e..c390dbd 100644 --- a/src/main/java/edu/ntnu/idi/idatt/Launcher.java +++ b/src/main/java/edu/ntnu/idi/idatt/Launcher.java @@ -1,8 +1,8 @@ package edu.ntnu.idi.idatt; +import edu.ntnu.idi.idatt.view.SceneManager; +import edu.ntnu.idi.idatt.view.primary.PrimaryView; import javafx.application.Application; -import javafx.scene.Scene; -import javafx.scene.layout.VBox; import javafx.stage.Stage; public final class Launcher { @@ -21,7 +21,7 @@ public void start(Stage stage) { stage.setWidth(1200); stage.setHeight(700); stage.setTitle("Stock Game"); - stage.setScene(new Scene(new VBox())); + SceneManager.init(stage, new PrimaryView().getInstance()); stage.show(); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java b/src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java new file mode 100644 index 0000000..be87d13 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java @@ -0,0 +1,55 @@ +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. + * + *
+ * This class provides methods for changing the root object to + * the scene, providing simple use of components to change between the + * pages + *
+ * + * @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. + * + *+ * 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. + *
+ * + * @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); + } + +} diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java new file mode 100644 index 0000000..18d51a2 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java @@ -0,0 +1,58 @@ +package edu.ntnu.idi.idatt.view.components; + +import javafx.scene.Parent; +import javafx.scene.layout.Pane; + +/** + * INFO! + * + *+ * 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. + *
+ * + * Reference: https://docs.oracle.com/javase/8/javafx/api/overview-tree.html + */ + +/** + * AbstractView class + * + *+ * Provides a simple abstraction of the Pane subclasses, + * making it a useful framework for creating different views. + *
+ */ +public abstract class AbstractView