From f194033a1807ee536d0653a23ed2c277d3890062 Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Sun, 15 Mar 2026 17:15:01 +0100 Subject: [PATCH] Feat: JavaDoc for Controllers --- .../controller/CharityPageController.java | 31 ++++++++++--- .../controller/DonationPageController.java | 46 +++++++++++++++---- .../team6/controller/FrontpageController.java | 37 +++++++++++++-- .../team6/controller/LoaderScene.java | 16 +++++++ .../OrganizationCardController.java | 5 ++ 5 files changed, 115 insertions(+), 20 deletions(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java index 47f8ee7..ea63c91 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java @@ -14,16 +14,26 @@ import java.io.IOException; +/** + * This controller represents the charity page, where the user can read about the charity and choose to donate to it. + * It also has a button to return to the front page. + */ public class CharityPageController { - @FXML - private Label CharityDescription; + @FXML private Label CharityDescription; - @FXML - private Label CharityName; - @FXML - public void initialize() {} + @FXML private Label CharityName; + + @FXML public void initialize() {} private Charity charity; + + /** + * This method is used to set the charity that is being displayed on the page. It also updates the labels with the charity's name and description. + * It acts like an initializer for the charity page, since the charity is not known until the user clicks on a charity from the front page. + * Param charity is the charity that is being displayed on the page, + * AND is called on from the front page when the user clicks on a charity, to set the charity that is being displayed on the page. + * @param charity + */ @FXML public void setCharity(Charity charity){ this.charity = charity; @@ -32,9 +42,18 @@ public void setCharity(Charity charity){ CharityName.setText(charity.getName()); } + + /** + * This method is used to switch to the front page. + * @param event + */ public void switchToFrontPage(ActionEvent event){ LoaderScene.LoadScene("FrontPage", event, charity); } + /** + * This method is used to switch to the donation page. + * @param event + */ public void switchToDonationPage(ActionEvent event){ LoaderScene.LoadScene("donationPage", event, charity); } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java index 0d5d2b3..a355c46 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java @@ -10,33 +10,47 @@ import ntnu.systemutvikling.team6.models.Charity; import java.util.Optional; +/** + * This controller represents the donation page, where the user can enter a donation amount and confirm their donation to the charity. + * It also has a button to return to the front page. + */ public class DonationPageController { - @FXML - private Charity charity; + @FXML private Charity charity; - @FXML - private TextField donatioAmount; + @FXML private TextField donatioAmount; - @FXML - private Label CharityName; + @FXML private Label CharityName; - @FXML - public void initialize() { - } + /** + * Initialize method for the donation page. Sets the charity name label to the name of the charity that is being donated to. + * The charity is set from the original page it was called from when the user clicks on the donate button, and is passed as a parameter to this method. + * + * @param charity + */ @FXML public void setCharity(Charity charity) { this.charity = charity; CharityName.setText(charity.getName()); - Alert a = new Alert(Alert.AlertType.CONFIRMATION); } + /** + * This method is used to switch back to the front page when the user clicks the back button. + * @param event + */ + public void switchToFrontPage(ActionEvent event) { LoaderScene.LoadScene("FrontPage", event, null); } + /** + * This method is used to process the donation when the user clicks the donate button. + * Checks if the input is valid and displays appropriate error messages if it is not. If the input is valid, it shows a confirmation dialog to the user. + * Shows a confirmation dialog. If the user confirms, the donation is processed and the user is taken back to the front page. + * @param event + */ public void Donate(ActionEvent event){ String input = donatioAmount.getText().trim(); @@ -78,10 +92,22 @@ public void Donate(ActionEvent event){ } } + /** + * Invoke DAO object to add the donation to the database. + * This method is called from the Donate method after the user confirms their donation. + * @param charity + * @param amount + */ public void processDonation(Charity charity, double amount){ DonationDAO.addDonation(charity, amount); } + /** + * Show an JavaFx alert dialog with the specified type, title, and message. + * @param type + * @param title + * @param message + */ private void showAlert(Alert.AlertType type, String title, String message){ Alert alert = new Alert(type); alert.setTitle(title); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index 6ac5e38..5e7b1fe 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -15,21 +15,41 @@ import java.util.Random; import java.util.stream.Collectors; +/** + * Landing page's controller. This is the first page the user sees when they open the application. It displays a random featured charity, some statistics about the charities and donations, and a list of all charities in the database. The user can click on a charity to see more details about it, or click on the featured charity to see more details about it. + * It also has buttons to switch to the charity page and the donation page for the featured charity + */ + public class FrontpageController { - @FXML private Charity featuredCharity; - @FXML + @FXML + private Charity featuredCharity; + + @FXML private FlowPane cardsContainer; + + @FXML private Label Carosel_Organisasjon; + @FXML private Label Carosel_Beskrivelse; + @FXML private Label Total_Orgnisasjon; + @FXML private Label Total_Donations; + @FXML private Label PreApproved_Percentage; + /** + * Initialize method for the front page. This method is called when the front page is loaded. + * It retrieves the list of charities and donations from the database. + * The list of charities is displayed as a list of cards, where each card represents a charity from the Innsamlingskontrollen + * A random charity is selected to be featured on the page, and its name and description are displayed in the carousel section. + * The total number of charities, total amount of donations, and percentage of pre-approved charities are also displayed on the page. + */ @FXML public void initialize() { try { @@ -54,12 +74,12 @@ public void initialize() { Random random = new Random(); int randomIndex = random.nextInt(Charities_size); Charity randomCharity = Charities.getAllCharities().get(randomIndex); + this.featuredCharity = randomCharity; Carosel_Organisasjon.setText(randomCharity.getName()); Carosel_Beskrivelse.setText(randomCharity.getDescription()); Total_Orgnisasjon.setText(Integer.toString(Charities_size)); - Total_Donations.setText(Double.toString(Donations.getAllDonations().stream().mapToDouble(Donation::getAmount).sum())); PreApproved_Percentage.setText( String.format("%.2f", Charities.getAllCharities().stream().filter(Charity::getPreApproved).count() * 100.0 / Charities_size) @@ -70,10 +90,19 @@ public void initialize() { } } - /* EVENTS */ + /** + * This method is used to switch to the charity page for the selected charity + * + * @param event + */ public void switchToCharityPage(ActionEvent event){ LoaderScene.LoadScene("CharityPage", event, featuredCharity); } + /** + * This method is used to switch to the donation page for the selected charity. + * + * @param event + */ public void switchToDonationPage(ActionEvent event){ LoaderScene.LoadScene("DonationPage", event, featuredCharity); } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java index 1263f58..e8b7036 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/LoaderScene.java @@ -13,7 +13,22 @@ import java.io.IOException; import java.util.Objects; +/** + * This class is a utility class that is used to load different scenes in the application. + * For now, It is used to switch between the front page, charity page, and donation page. + * It takes care of loading the FXML file, setting the controller, and switching the scene. + */ + public class LoaderScene { + /** + * When going to a new scene, this method is called to load the new scene. + * It takes the name of the scene to load, the event that triggered the scene change, and the charity that is being passed to the new scene (if applicable). + * It loads the FXML file for the new scene, sets the controller, and switches the scene. + * + * @param sceneName + * @param event + * @param charity + */ public static void LoadScene(String sceneName, ActionEvent event, Charity charity){ try { System.out.println(HmHApplication.class.getResource("/fxml/"+ sceneName +".fxml")); @@ -24,6 +39,7 @@ public static void LoadScene(String sceneName, ActionEvent event, Charity charit System.out.println("Controller: " + fxmlLoader.getController()); Object controller = fxmlLoader.getController(); + // Needs to be expanded when more pages get implemented. if (controller instanceof CharityPageController charityController) { charityController.setCharity(charity); } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java index d6456e7..5ac3006 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/OrganizationCardController.java @@ -14,6 +14,11 @@ import java.io.IOException; import java.util.Objects; +/** + * This controller represents the organization card that is displayed on the front page and is looped upon in FronpageController. + * It is used to display the name and description of a charity, and to switch to the charity page or donation page when the user clicks on the card. + */ + public class OrganizationCardController { @FXML private Label organizationName;