Skip to content

Commit

Permalink
Updated CharityPageController
Browse files Browse the repository at this point in the history
Added javadoc and methods for setting categories and creating labels for categories dynamically.
  • Loading branch information
roaraf committed Apr 18, 2026
1 parent ca8001e commit 2ce2376
Showing 1 changed file with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -42,6 +45,8 @@ public class CharityPageController {

@FXML private Label keyValueFormaalLabel;

@FXML private VBox categoriesContainer;

@FXML
public void initialize() {}

Expand All @@ -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) {
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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 {
Expand All @@ -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<String> 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);
Expand Down

0 comments on commit 2ce2376

Please sign in to comment.