Skip to content

Commit

Permalink
Update[Organization]: Update rendering of organization Logo to render…
Browse files Browse the repository at this point in the history
… more quicker
  • Loading branch information
Fredrik Marjoni committed Apr 18, 2026
1 parent d9cfc51 commit 8295379
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 23 deletions.
42 changes: 33 additions & 9 deletions src/main/java/edu/group5/app/view/causespage/CausesPageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CausesPageView extends BorderPane {

private GridPane organizationGrid;
private Map<Integer, Organization> allOrganizations;
private Map<Integer, OrganizationCard> cardCache = new HashMap<>();

public CausesPageView(NavigationController nav, OrganizationController orgController) {
ParameterValidator.objectChecker(nav, "NavigationController");
Expand Down Expand Up @@ -205,18 +206,41 @@ private Map<Integer, Organization> filterOrganizations(String searchTerm) {
));
}


private void updateOrganizationGrid(String searchTerm) {
if (organizationGrid == null) {
return;
if (organizationGrid == null) return;

// Save existing cards into cache before clearing
for (var node : organizationGrid.getChildren()) {
if (node instanceof OrganizationCard card) {
cardCache.put(card.getOrganization().orgNumber(), card);
}
}


Map<Integer, Organization> filtered = filterOrganizations(searchTerm);

organizationGrid.getChildren().clear();
organizationGrid.getColumnConstraints().clear();

// Rebuild grid with filtered organizations
GridPane updated = createOrganizationSection(searchTerm);

organizationGrid.getChildren().addAll(updated.getChildren());
organizationGrid.getColumnConstraints().addAll(updated.getColumnConstraints());

int column = 0;
int row = 0;

for (Organization org : filtered.values()) {
OrganizationCard card = cardCache.get(org.orgNumber());
if (card != null) {
organizationGrid.add(card, column, row);
column++;
if (column == 4) {
column = 0;
row++;
}
}
}

for (int i = 0; i < 4; i++) {
ColumnConstraints col = new ColumnConstraints();
col.setPercentWidth(25);
organizationGrid.getColumnConstraints().add(col);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void updateLogo(String logoUrl) {
if (imageContainer == null) return;
imageContainer.getChildren().clear();
if (logoUrl != null && !logoUrl.isBlank()) {
ImageView logo = new ImageView(new Image(logoUrl, true));
ImageView logo = new ImageView(new Image(logoUrl, 80, 80, true, true, true));
logo.setId("logo");
logo.setSmooth(true);
logo.setPreserveRatio(true);
Expand Down Expand Up @@ -96,7 +96,7 @@ private StackPane createImageContainer(String img) {


if (img != null && !img.isBlank()) {
ImageView logo = new ImageView(new Image(img, true));
ImageView logo = new ImageView(new Image(img, 80, 80, true, true, true));
logo.setId("logo");
logo.setSmooth(true);
logo.setPreserveRatio(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.group5.app.control.NavigationController;
import edu.group5.app.control.OrganizationController;
import edu.group5.app.model.organization.Organization;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -90,23 +91,38 @@ private StackPane createImageContainer() {
imageContainer.setMaxWidth(120);

Organization org = organizationController.getCurrentOrganization();

if (org != null && org.logoUrl() != null && !org.logoUrl().isBlank()) {
ImageView logo = new ImageView(new Image(org.logoUrl(), true));
logo.setId("logo");
logo.setSmooth(true);
logo.setPreserveRatio(true);
logo.setFitHeight(350);
logo.setFitWidth(350);
imageContainer.getChildren().add(logo);
// Load image in background thread to avoid blocking UI
new Thread(() -> {
try {
Image image = new Image(org.logoUrl(), 120, 120, true, true);
Platform.runLater(() -> {
ImageView logo = new ImageView(image);
logo.setId("logo");
logo.setSmooth(true);
logo.setPreserveRatio(true);
logo.setFitHeight(350);
logo.setFitWidth(350);
imageContainer.getChildren().clear();
imageContainer.getChildren().add(logo);
});
} catch (Exception e) {
// Logo failed to load, show placeholder
Platform.runLater(() -> {
imageContainer.getChildren().clear();
Text text = new Text("No image");
text.setStyle("-fx-font-size: 10;");
imageContainer.getChildren().add(text);
});
}
}, "LogoLoader").start();
} else {
StackPane placeholder = new StackPane();

Text text = new Text("No image");
text.setStyle("-fx-font-size: 10;");

placeholder.getChildren().add(text);
imageContainer.getChildren().add(placeholder);
imageContainer.getChildren().add(text);
}

return imageContainer;
}

Expand Down

0 comments on commit 8295379

Please sign in to comment.