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
15 changes: 7 additions & 8 deletions src/main/java/no/ntnu/idatt1005/group03/UI/AboutUsScreen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.ntnu.idatt1005.group03.UI;

import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
Expand Down Expand Up @@ -50,12 +49,12 @@ public void start(Stage stage) {
ScrollPane scrollPane = wrapInScrollPane(content);
layout.setCenter(scrollPane);

Scene scene = new Scene(layout, 625, 550);
scene.getStylesheets().add(getClass().getResource("/styles/app.css").toExternalForm());

stage.setTitle("About Us");
stage.setScene(scene);
stage.show();
ScreenManager.showRoot(
stage,
layout,
"About Us",
getClass().getResource("/styles/app.css").toExternalForm()
);
}

// --- UI COMPONENTS ---
Expand Down Expand Up @@ -91,4 +90,4 @@ private ScrollPane wrapInScrollPane(VBox content) {
scrollPane.getStyleClass().add("dark-scroll-pane");
return scrollPane;
}
}
}
16 changes: 7 additions & 9 deletions src/main/java/no/ntnu/idatt1005/group03/UI/AccountScreen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.ntnu.idatt1005.group03.UI;

import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
Expand Down Expand Up @@ -62,13 +61,12 @@ public void start(Stage stage) {

accountLayout.setCenter(mainContent);

Scene scene = new Scene(accountLayout, 450, 600);
// CONNECT TO CSS
scene.getStylesheets().add(getClass().getResource("/styles/app.css").toExternalForm());

stage.setTitle("Account");
stage.setScene(scene);
stage.show();
ScreenManager.showRoot(
stage,
accountLayout,
"Account",
getClass().getResource("/styles/app.css").toExternalForm()
);
}

private VBox createProfileSection() {
Expand Down Expand Up @@ -145,4 +143,4 @@ private VBox createLogoutSection() {
VBox.setVgrow(logoutBox, Priority.ALWAYS);
return logoutBox;
}
}
}
17 changes: 7 additions & 10 deletions src/main/java/no/ntnu/idatt1005/group03/UI/DonationScreen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.ntnu.idatt1005.group03.UI;

import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
Expand Down Expand Up @@ -91,14 +90,12 @@ public void start(Stage stage) {
donateButton,
backButton);

Scene scene = new Scene(layout, 400, 330);

// CONNECT TO CSS
scene.getStylesheets().add(getClass().getResource("/styles/app.css").toExternalForm());

stage.setTitle("Donation");
stage.setScene(scene);
stage.show();
ScreenManager.showRoot(
stage,
layout,
"Donation",
getClass().getResource("/styles/app.css").toExternalForm()
);
}

private Label createOrgNameLabel() {
Expand Down Expand Up @@ -203,4 +200,4 @@ private Button createBackButton() {
backButton.setOnAction(e -> ScreenManager.showHomeScreen());
return backButton;
}
}
}
48 changes: 28 additions & 20 deletions src/main/java/no/ntnu/idatt1005/group03/UI/LoginScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.ntnu.idatt1005.group03.UI;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -32,8 +33,7 @@
*/
public class LoginScreen extends Application { // homepage

private Scene scene1; // Sign Up
private Scene scene2; // Log In
private Scene authScene;
private AuthController authController;
private Stage stage;
private Label signUpErrLabel;
Expand All @@ -51,6 +51,9 @@ public class LoginScreen extends Application { // homepage
*/
@Override
public void start(Stage primaryStage) {
boolean MaximizeOnStartup = primaryStage.getScene() == null;
String stylesheet = getClass().getResource("/styles/app.css").toExternalForm();

this.stage = primaryStage;
this.authController = new AuthController(new UserRepositoryDAO());
this.favoriteController = new FavoriteController();
Expand All @@ -61,16 +64,27 @@ public void start(Stage primaryStage) {
loginErrLabel = new Label();
loginErrLabel.setTextFill(Color.RED);

scene1 = createScene1();
scene2 = createScene2();
if (primaryStage.getScene() == null) {
authScene = new Scene(createSignUpRoot());
authScene.getStylesheets().add(stylesheet);
primaryStage.setTitle("Log in screen");
primaryStage.setScene(authScene);
primaryStage.show();
} else {
authScene = primaryStage.getScene();
authScene.setRoot(createSignUpRoot());
authScene.getStylesheets().setAll(stylesheet);
primaryStage.setTitle("Log in screen");
primaryStage.show();
}

primaryStage.setTitle("Log in screen");
primaryStage.setScene(scene1);
primaryStage.show();
if (MaximizeOnStartup) {
Platform.runLater(() -> primaryStage.setMaximized(true));
}
}

// -------- SCENE 1 (Sign Up) --------
private Scene createScene1() {
private GridPane createSignUpRoot() {
GridPane root1 = createBaseGrid();

Label nameLabel = new Label("Email address");
Expand Down Expand Up @@ -113,11 +127,11 @@ private Scene createScene1() {
accountBox.setAlignment(Pos.CENTER);
root1.add(accountBox, 1, 9, 3, 1);

return wrapInScene(root1);
return root1;
}

// -------- SCENE 2 (Log In) --------
private Scene createScene2() {
private GridPane createLoginRoot() {
GridPane root2 = createBaseGrid();

Label usernameLabel2 = new Label("Email address or username");
Expand Down Expand Up @@ -156,7 +170,7 @@ private Scene createScene2() {

GridPane.setHalignment(forgot, HPos.CENTER);

return wrapInScene(root2);
return root2;
}

// -------- REUSABLE COMPONENTS --------
Expand Down Expand Up @@ -186,14 +200,14 @@ private void addHeader(GridPane grid, boolean isScene2) {
signloginButton.getStyleClass().addAll("btn", isScene2 ? "btn-outline" : "btn-secondary", "btn-toggle");
signloginButton.setOnAction(e -> {
signUpErrLabel.setText("");
stage.setScene(scene1);
authScene.setRoot(createSignUpRoot());
});

Button loginButton = new Button("Log in");
loginButton.getStyleClass().addAll("btn", isScene2 ? "btn-secondary" : "btn-outline", "btn-toggle");
loginButton.setOnAction(e -> {
loginErrLabel.setText("");
stage.setScene(scene2);
authScene.setRoot(createLoginRoot());
});

HBox buttonBox = new HBox(0); // 0px spacing
Expand All @@ -204,12 +218,6 @@ private void addHeader(GridPane grid, boolean isScene2) {
grid.add(buttonBox, 1, 0, 3, 1);
}

private Scene wrapInScene(GridPane root) {
Scene scene = new Scene(root, 450, 350);
scene.getStylesheets().add(getClass().getResource("/styles/app.css").toExternalForm());
return scene;
}

// -------- ACTION LOGIC --------

private void handleSignUp(String username, String email, String password, String confirmPassword) {
Expand Down Expand Up @@ -238,4 +246,4 @@ private void handleLogin(String usernameOrEmail, String password) {
loginErrLabel.setText("Wrong username, email, or password.");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.ntnu.idatt1005.group03.UI;

import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
Expand Down Expand Up @@ -87,12 +86,12 @@ public void start(Stage stage) {
ScrollPane scrollPane = wrapInScrollPane(content);
mainLayout.setCenter(scrollPane);

Scene scene = new Scene(mainLayout, 625, 550);
scene.getStylesheets().add(getClass().getResource("/styles/app.css").toExternalForm());

stage.setTitle("Organizations");
stage.setScene(scene);
stage.show();
ScreenManager.showRoot(
stage,
mainLayout,
"Organizations",
getClass().getResource("/styles/app.css").toExternalForm()
);
}

private Text createHeaderSection() {
Expand Down Expand Up @@ -211,4 +210,4 @@ private ScrollPane wrapInScrollPane(VBox content) {
scrollPane.getStyleClass().add("transparent-scroll-pane");
return scrollPane;
}
}
}
38 changes: 37 additions & 1 deletion src/main/java/no/ntnu/idatt1005/group03/UI/ScreenManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.ntnu.idatt1005.group03.UI;

import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import no.ntnu.idatt1005.group03.Model.Organization;
import no.ntnu.idatt1005.group03.Model.User;
Expand Down Expand Up @@ -55,6 +57,40 @@ public static User getCurrentUser() {
return currentUser;
}

public static void showScene(Stage stage, Scene scene, String title) {
Scene currentScene = stage.getScene();
stage.setTitle(title);
if (currentScene == null) {
stage.setScene(scene);
stage.show();
} else {
currentScene.setRoot(scene.getRoot());
currentScene.getStylesheets().setAll(scene.getStylesheets());
}
}

/**
* Shows a new root on the given stage while reusing the existing scene when possible.
*
* @param stage the stage to update
* @param root the root node to display
* @param title the window title
* @param stylesheet the stylesheet URL to apply
*/
public static void showRoot(Stage stage, Parent root, String title, String stylesheet) {
Scene currentScene = stage.getScene();
stage.setTitle(title);
if (currentScene == null) {
Scene scene = new Scene(root);
scene.getStylesheets().add(stylesheet);
stage.setScene(scene);
stage.show();
} else {
currentScene.setRoot(root);
currentScene.getStylesheets().setAll(stylesheet);
}
}

// Navigation Methods
/**
* Displays the home screen for the current user.
Expand Down Expand Up @@ -95,4 +131,4 @@ public static void logout() {
currentUser = null;
new LoginScreen().start(mainStage);
}
}
}
Loading