Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/edu/ntnu/idi/idatt/Launcher.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
}

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <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);
}

}
58 changes: 58 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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.
*/
public AbstractView(T type) {
instance = type;
instance.getChildren().add(this.createContent());
}

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

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

}
45 changes: 45 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java
Original file line number Diff line number Diff line change
@@ -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<StackPane> {

public PrimaryView() {
super(new StackPane());
this.getInstance().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;
}

}
27 changes: 27 additions & 0 deletions src/main/resources/themes/default.css
Original file line number Diff line number Diff line change
@@ -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);
}