From 866d55ae7a8717c440a43b0da16801f89a004a3e Mon Sep 17 00:00:00 2001 From: pawelsa Date: Fri, 24 Apr 2026 20:10:32 +0200 Subject: [PATCH 1/5] feat: Implement a static view manager --- .../edu/ntnu/idi/idatt/view/SceneManager.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java 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); + } + +} From 767d577b4b6864a6fd0cf4174b5ac429e36c2e69 Mon Sep 17 00:00:00 2001 From: pawelsa Date: Fri, 24 Apr 2026 20:11:00 +0200 Subject: [PATCH 2/5] feat: Implement an abstract view class --- .../idatt/view/components/AbstractView.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java 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..f50ab32 --- /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 { + + protected T root; + + /** + * Constructor for AbstractView. + */ + public AbstractView(T type) { + root = type; + root.getChildren().add(this.createContent()); + } + + /** + * Getter for current view instance. + * + * @return Instance of current view. + */ + public T getInstance() { + return root; + } + + /** + * Abstract method for creating view content. + */ + public abstract Parent createContent(); + +} From 336291315af8cb5fa7448c3ca9dec1e63c70a4af Mon Sep 17 00:00:00 2001 From: pawelsa Date: Fri, 24 Apr 2026 20:11:25 +0200 Subject: [PATCH 3/5] feat: Create basic start page --- .../java/edu/ntnu/idi/idatt/Launcher.java | 6 +-- .../idi/idatt/view/primary/PrimaryView.java | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java 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/primary/PrimaryView.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java new file mode 100644 index 0000000..523786f --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java @@ -0,0 +1,45 @@ +package edu.ntnu.idi.idatt.view.primary; + +import java.util.List; + +import edu.ntnu.idi.idatt.view.components.AbstractView; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Parent; +import javafx.scene.control.Label; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; + +public class PrimaryView extends AbstractView { + + public PrimaryView() { + super(new StackPane()); + root.getStyleClass().add("dark"); + } + + @Override + public Parent createContent() { + StackPane root = new StackPane(); + root.getStyleClass().add("light"); + StackPane.setAlignment(root, Pos.CENTER); + StackPane.setMargin(root, new Insets(40.0)); + + Label title = new Label("Millions"); + title.getStyleClass().add("title"); + StackPane.setAlignment(title, Pos.TOP_CENTER); + + VBox wrapper = new VBox(); + + Label playerName = new Label("Player name:"); + playerName.getStyleClass().add("big-text-32"); + + Label startBalance = new Label("Start balance:"); + startBalance.getStyleClass().add("big-text-32"); + + wrapper.getChildren().addAll(List.of(playerName, startBalance)); + + root.getChildren().addAll(List.of(title, wrapper)); + return root; + } + +} From 7b0109ef8f3a9bfc94d17c6629c4932d50aa3d15 Mon Sep 17 00:00:00 2001 From: pawelsa Date: Fri, 24 Apr 2026 20:11:42 +0200 Subject: [PATCH 4/5] chore: Move .css stylesheet to resources/ --- src/main/resources/themes/default.css | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/resources/themes/default.css diff --git a/src/main/resources/themes/default.css b/src/main/resources/themes/default.css new file mode 100644 index 0000000..29bcf92 --- /dev/null +++ b/src/main/resources/themes/default.css @@ -0,0 +1,27 @@ +.dark { + -fx-background-color: #0B2B40; +} + +.light { + -fx-background-color: #1E5959; +} + +.primary { + -fx-background-color: #3B8C6E; +} + +.title { + -fx-font-size: 56px; + -fx-font-weight: 700; + -fx-text-fill: #EEEEEE; + -fx-padding: 30px; + -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5); +} + +.big-text-32{ + -fx-font-size: 32px; + -fx-font-weight: 700; + -fx-text-fill: #EEEEEE; + -fx-padding: 30px; + -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5); +} From af9fe84dfbdba336df2594bb0bfa0a61d2aa4fb8 Mon Sep 17 00:00:00 2001 From: pawelsa Date: Fri, 24 Apr 2026 20:14:20 +0200 Subject: [PATCH 5/5] chore: Correct naming conventions and acessibility for safety. --- .../edu/ntnu/idi/idatt/view/components/AbstractView.java | 8 ++++---- .../java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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 index f50ab32..18d51a2 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java @@ -31,14 +31,14 @@ */ public abstract class AbstractView { - protected T root; + private T instance; /** * Constructor for AbstractView. */ public AbstractView(T type) { - root = type; - root.getChildren().add(this.createContent()); + instance = type; + instance.getChildren().add(this.createContent()); } /** @@ -47,7 +47,7 @@ public AbstractView(T type) { * @return Instance of current view. */ public T getInstance() { - return root; + return instance; } /** diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java index 523786f..7e94df1 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java @@ -14,7 +14,7 @@ public class PrimaryView extends AbstractView { public PrimaryView() { super(new StackPane()); - root.getStyleClass().add("dark"); + this.getInstance().getStyleClass().add("dark"); } @Override