From 2ce2376deffed296e501467f7122bd67790a4063 Mon Sep 17 00:00:00 2001 From: Roar Date: Sat, 18 Apr 2026 17:13:31 +0200 Subject: [PATCH] Updated CharityPageController Added javadoc and methods for setting categories and creating labels for categories dynamically. --- .../controller/CharityPageController.java | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) 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 b52a0cb..d831b25 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java @@ -11,7 +11,10 @@ import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; import javafx.scene.shape.Arc; +import javafx.scene.shape.Rectangle; import ntnu.systemutvikling.team6.controller.components.LoaderScene; import ntnu.systemutvikling.team6.models.Charity; @@ -42,6 +45,8 @@ public class CharityPageController { @FXML private Label keyValueFormaalLabel; + @FXML private VBox categoriesContainer; + @FXML public void initialize() {} @@ -55,7 +60,7 @@ public void initialize() {} * front page when the user clicks on a charity, to set the charity that is being displayed on the * page. * - * @param charity + * @param charity the charity to be displayed */ @FXML public void setCharity(Charity charity) { @@ -94,6 +99,9 @@ public void setCharity(Charity charity) { keyValueAdminLabel.setText(String.format("%.1f%%", numbers.get(1))); setArc(keyValueFormaalArc, numbers.getLast()); keyValueFormaalLabel.setText(String.format("%.1f%%", numbers.getLast())); + + // Sets the categories + setCategories(charity.getCategory()); } /** @@ -129,6 +137,11 @@ public void handleSearch(ActionEvent event) { LoaderScene.LoadScene("availableOrganization", event, null, query); } + /** + * Opens OS default webbrowser and loads the url of the charity on click. + * + * @param event the onclick event + */ @FXML public void handleHomepageClick(ActionEvent event) { try { @@ -140,6 +153,54 @@ public void handleHomepageClick(ActionEvent event) { } } + /** + * Creates the labels (and the rectangle surrounding it) for the categories + * + * @param category the String for the category + * @return a fxml object used to populate the category scroll pane + */ + private StackPane createCategoryChip(String category) { + + Rectangle rect = new Rectangle(); + rect.setArcWidth(30); + rect.setArcHeight(30); + rect.setHeight(40); + rect.setWidth(200); + rect.setFill(javafx.scene.paint.Color.web("#F5F5F5")); + rect.setStroke(javafx.scene.paint.Color.web("#4F4F4F")); + + Label label = new Label(category); + label.setStyle("-fx-font-weight: bold; -fx-font-size: 14px;"); + + StackPane stack = new StackPane(rect, label); + stack.setPadding(new javafx.geometry.Insets(5)); + + return stack; + } + + /** + * Takes a list of categories for the charities and populates a scroll pane with labels containing + * the charities. + * + * @param categories the list of categories for the charity + */ + public void setCategories(List categories) { + categoriesContainer.getChildren().clear(); + + for (String category : categories) { + if (category == null || category.isEmpty()) continue; + + StackPane chip = createCategoryChip(category); + categoriesContainer.getChildren().add(chip); + } + } + + /** + * Sets the fill of the arc for the different key values. + * + * @param arc the arc for one of the 3 key values + * @param percent the percentage of the key value + */ private void setArc(Arc arc, double percent) { double angle = -360 * (percent / 100.0); arc.setLength(angle);