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
24 changes: 23 additions & 1 deletion src/main/java/no/ntnu/idatt1005/group03/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@
import no.ntnu.idatt1005.group03.DAO.DatabaseConnection;
import no.ntnu.idatt1005.group03.UI.LoginScreen;

/**
* Starts the application and initializes required resources.
*
* <p>This class serves as the main entry point of the application. It is part of the
* overall application bootstrap layer and is responsible for starting the JavaFX runtime,
* initializing the database, and launching the first user interface screen.</p>
*
* <p>When the application starts, the database schema is initialized before the login
* screen is displayed to the user.</p>
*/
public class App extends Application {

/**
* Starts the JavaFX application.
*
* <p>This method initializes the database and launches the login screen on the provided
* primary stage. If the user interface fails to load, an error message is printed.</p>
*
* @param primaryStage the primary JavaFX stage for the application
*/
@Override
public void start(Stage primaryStage) {
// 1. Initialize the database so it is ready for the rest of the app
Expand All @@ -21,8 +39,12 @@ public void start(Stage primaryStage) {
}
}

/**
* Launches the JavaFX application.
*
* @param args command-line arguments passed to the application
*/
public static void main(String[] args) {
// This command tells JavaFX to start the visual application
launch(args);
}
}
28 changes: 25 additions & 3 deletions src/main/java/no/ntnu/idatt1005/group03/UI/AboutUsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,36 @@
import javafx.stage.Stage;
import no.ntnu.idatt1005.group03.Model.User;

public class AboutUsScreen {

private final User user;
/**
* Displays the "About Us" screen in the application.
*
* <p>This class is part of the <b>UI layer</b> in the MVC architecture and is responsible
* for presenting informational content about the application. It builds and displays a
* JavaFX screen containing a top menu, a large image, and a button for navigating back
* to the home screen.</p>
*
* <p>The screen content is wrapped in a {@code ScrollPane} to support vertical scrolling
* when the content exceeds the available window height.</p>
*/
public class AboutUsScreen {

/**
* Constructs a new {@code AboutUsScreen} instance.
*
* @param user the current user context for the screen
*/
public AboutUsScreen(User user) {
this.user = user;
}

/**
* Builds and displays the About Us screen on the provided stage.
*
* <p>This method creates the layout, applies the stylesheet, sets the scene on the stage,
* and shows the window.</p>
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
public void start(Stage stage) {
BorderPane layout = new BorderPane();

Expand Down
25 changes: 23 additions & 2 deletions src/main/java/no/ntnu/idatt1005/group03/UI/AccountScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,44 @@
import javafx.scene.layout.VBox;
import javafx.scene.layout.Priority;
import javafx.geometry.Insets;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.StackPane;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import no.ntnu.idatt1005.group03.Model.User;
import javafx.scene.layout.Region;
import no.ntnu.idatt1005.group03.Model.Donation;

/**
* Displays the account screen for a logged-in user.
*
* <p>This class is part of the <b>UI layer</b> in the MVC architecture and is responsible
* for presenting account-related information to the user. It builds and displays a JavaFX
* screen containing the user's profile details, donation history, and logout option.</p>
*
* <p>The screen is composed of separate sections for profile information, donation records,
* and logout functionality.</p>
*/
public class AccountScreen {

private final User user;

/**
* Constructs a new {@code AccountScreen} instance.
*
* @param user the currently logged-in user whose account information will be displayed
*/
public AccountScreen(User user) {
this.user = user;
}

/**
* Builds and displays the account screen on the provided stage.
*
* <p>This method creates the layout, applies the stylesheet, sets the scene on the stage,
* and shows the window.</p>
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
public void start(Stage stage) {
BorderPane accountLayout = new BorderPane();
accountLayout.setTop(new TopMenu("Account"));
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/no/ntnu/idatt1005/group03/UI/DonationScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
Expand All @@ -19,19 +18,43 @@
import java.net.URI;
import java.time.LocalDate;

/**
* Displays the donation screen for a selected organization.
*
* <p>This class is part of the <b>UI layer</b> in the MVC architecture and is responsible
* for presenting donation-related actions to the user. It allows the user to view the
* selected organization, visit its website, add or remove it from favorites, and register
* a donation.</p>
*
* <p>The screen validates donation input before creating a {@link Donation} object and
* adding it to the current user's donation list.</p>
*/
public class DonationScreen {

private final Organization organization;
private final User user;
private final FavoriteController favoriteController;


/**
* Constructs a new {@code DonationScreen} instance.
*
* @param organization the organization the user may donate to
* @param user the currently logged-in user
*/
public DonationScreen(Organization organization, User user) {
this.organization = organization;
this.user = user;
this.favoriteController = new FavoriteController();
}

/**
* Builds and displays the donation screen on the provided stage.
*
* <p>This method creates the layout, applies the stylesheet, sets the scene on the stage,
* and shows the window.</p>
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
public void start(Stage stage) {

VBox layout = new VBox(15);
Expand Down

This file was deleted.

20 changes: 20 additions & 0 deletions src/main/java/no/ntnu/idatt1005/group03/UI/LoginScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@

import java.util.Optional;

/**
* Displays the login and sign-up screen for the application.
*
* <p>This class is part of the <b>UI layer</b> in the MVC architecture and serves as the
* entry point for user authentication. It provides two scenes: one for user registration
* and one for user login. The class coordinates user input with the authentication
* controller and handles navigation to the home screen after successful authentication.</p>
*
* <p>The class extends {@link Application} and is responsible for initializing the
* primary stage used for login and registration.</p>
*/
public class LoginScreen extends Application { // homepage

private Scene scene1; // Sign Up
Expand All @@ -29,6 +40,15 @@ public class LoginScreen extends Application { // homepage
private Label loginErrLabel;
private FavoriteController favoriteController;

/**
* Initializes and displays the login screen on the provided primary stage.
*
* <p>This method creates the authentication controller and favorite controller,
* initializes feedback labels, builds both the sign-up and login scenes,
* and displays the initial scene.</p>
*
* @param primaryStage the primary JavaFX stage for the application
*/
@Override
public void start(Stage primaryStage) {
this.stage = primaryStage;
Expand Down
58 changes: 25 additions & 33 deletions src/main/java/no/ntnu/idatt1005/group03/UI/OrganizationsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,43 @@

import java.util.List;

/**
* Displays the main organization overview screen for the user.
*
* <p>This class is part of the <b>UI layer</b> in the MVC architecture and is responsible
* for presenting available organizations to the user. It allows the user to browse
* organizations, search by name or category, view favorite organizations, mark or unmark
* favorites, and navigate to the donation screen for a selected organization.</p>
*
* <p>The screen retrieves organization data through the {@link OrganizationController}
* and favorite-related actions through the {@link FavoriteController}.</p>
*/
public class OrganizationsScreen {

private final User user;
private final OrganizationController orgController;
private final FavoriteController favoriteController;

/**
* Constructs a new {@code OrganizationsScreen} instance.
*
* @param user the currently logged-in user
*/
public OrganizationsScreen(User user) {
this.user = user;
this.orgController = new OrganizationController();
this.favoriteController = new FavoriteController();
}


/**
* Builds and displays the organizations screen on the provided stage.
*
* <p>This method creates the layout, loads the list of organizations, applies the stylesheet,
* sets the scene on the stage, and shows the window.</p>
*
* @param stage the JavaFX stage on which the screen will be displayed
*/
public void start(Stage stage) {

BorderPane mainLayout = new BorderPane();
Expand Down Expand Up @@ -186,37 +211,4 @@ private ScrollPane wrapInScrollPane(VBox content) {
scrollPane.getStyleClass().add("transparent-scroll-pane");
return scrollPane;
}

private HBox createOldHeader(User user, Stage stage) {
HBox header = new HBox(15);
header.setPadding(new Insets(15));
header.getStyleClass().add("top-header");
header.setAlignment(javafx.geometry.Pos.CENTER_LEFT);

Image image = new Image(getClass().getResourceAsStream("/images/donate2.png"));
ImageView imageView = new ImageView(image);
imageView.setFitWidth(40);
imageView.setFitHeight(40);
imageView.setPreserveRatio(true);

Hyperlink aboutUs = new Hyperlink("About us");
aboutUs.getStyleClass().add("nav-link");
aboutUs.setOnAction(e -> {
AboutUsScreen abscreen = new AboutUsScreen(user);
abscreen.start(stage);
});

Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);

Button accountButton = new Button("Account");
accountButton.getStyleClass().addAll("btn", "btn-primary");
accountButton.setOnAction(e -> {
AccountScreen accScreen = new AccountScreen(user);
accScreen.start(stage);
});

header.getChildren().addAll(imageView, spacer, aboutUs, accountButton);
return header;
}
}
53 changes: 52 additions & 1 deletion src/main/java/no/ntnu/idatt1005/group03/UI/ScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,93 @@
import no.ntnu.idatt1005.group03.Model.Organization;
import no.ntnu.idatt1005.group03.Model.User;

/**
* Manages screen navigation and shared UI state in the application.
*
* <p>This class is part of the <b>UI layer</b> in the MVC architecture and is responsible
* for centralizing navigation between screens. It stores references to the main application
* stage and the currently logged-in user, allowing different screens to be shown without
* passing these values around manually each time.</p>
*
* <p>The class provides static methods for switching between the main screens of the
* application, including the home screen, account screen, about screen, donation screen,
* and login screen.</p>
*/
public class ScreenManager {

private static Stage mainStage;
private static User currentUser;

/**
* Prevents instantiation of this utility class.
*/
private ScreenManager() {
}

// Setup methods
/**
* Sets the main stage used for screen navigation.
*
* @param stage the main JavaFX stage of the application
*/
public static void setMainStage(Stage stage) {
mainStage = stage;
}

/**
* Sets the currently logged-in user.
*
* @param user the user to store as the current user
*/
public static void setCurrentUser(User user) {
currentUser = user;
}

/**
* Returns the currently logged-in user.
*
* @return the current user, or {@code null} if no user is logged in
*/
public static User getCurrentUser() {
return currentUser;
}

// Navigation Methods
/**
* Displays the home screen for the current user.
*/
public static void showHomeScreen() {
new OrganizationsScreen(currentUser).start(mainStage);
}

/**
* Displays the About Us screen for the current user.
*/
public static void showAboutUsScreen() {
new AboutUsScreen(currentUser).start(mainStage);
}

/**
* Displays the account screen for the current user.
*/
public static void showAccountScreen() {
new AccountScreen(currentUser).start(mainStage);
}

/**
* Displays the donation screen for the selected organization.
*
* @param org the organization the user may donate to
*/
public static void showDonationScreen(Organization org) {
new DonationScreen(org, currentUser).start(mainStage);
}

// Add this for later when we build the Login/Logout flow!
/**
* Logs out the current user and returns to the login screen.
*
* <p>This method clears the stored user reference and displays the login screen again.</p>
*/
public static void logout() {
currentUser = null;
new LoginScreen().start(mainStage);
Expand Down
Loading
Loading