Skip to content

Commit

Permalink
Feat: JavaDoc for Controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 15, 2026
1 parent 0c87bda commit f194033
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f194033

Please sign in to comment.