From 98b3f06475ed14b55e2f7133537fdfbf2fd9befd Mon Sep 17 00:00:00 2001 From: danieskj Date: Thu, 14 May 2026 15:34:09 +0200 Subject: [PATCH] fix(UICompositor): growWithAlignment logic --- .../elements/PlayerPortfolioComponent.java | 20 ++++++++++++------- .../components/elements/ShareComponent.java | 3 +++ .../view/components/ui/UICompositor.java | 17 ++++++++-------- .../view/primary/portfolio/PortfolioView.java | 8 ++++---- .../idatt/view/primary/stock/StockView.java | 2 +- .../primary/transactions/TransactionView.java | 2 +- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java index f4f3a14..e4cfa9d 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java @@ -1,6 +1,7 @@ package edu.ntnu.idi.idatt.view.components.elements; import edu.ntnu.idi.idatt.model.portfolio.Portfolio; +import edu.ntnu.idi.idatt.session.UserSession; import edu.ntnu.idi.idatt.view.components.ui.UICompositor; import javafx.geometry.Pos; import javafx.scene.control.Label; @@ -15,11 +16,14 @@ public class PlayerPortfolioComponent extends HBox { public PlayerPortfolioComponent(Portfolio portfolio){ this.setMaxSize(Double.MAX_VALUE, 500); this.getStyleClass().add("light"); + Label userTitle = new Label("Name Title"); Label invisibleTitle = new Label(" "); - Label netWorth = new Label("Total net worth: "+portfolio.getNetWorth().toString()); + Label netWorth = new Label(); + netWorth.textProperty().bind( + UserSession.getInstance().netWorthProperty().asString("Net Worth: %.2f $")); Label percentageChange = new Label("Percentage change: "); - Label playerStatus = new Label("Player status: "); + Label playerStatus = new Label("Player status: "+ UserSession.getInstance().getPlayer().getStatus()); Label portfolioWorth = new Label("Portfolio net worth: "); Label totalShares = new Label("Total shares owned: "); @@ -29,15 +33,17 @@ public PlayerPortfolioComponent(Portfolio portfolio){ userTitle.getStyleClass().add("portfolio-box-title"); invisibleTitle.getStyleClass().add("portfolio-box-title"); - VBox leftColumn = new VBox(userTitle, netWorth, percentageChange, playerStatus); - VBox rightColumn = new VBox(invisibleTitle, portfolioWorth, totalShares); - UICompositor playerPortfolioComponent = new UICompositor.Builder() .parent(new HBox()) .growWithAlignment(Pos.CENTER) - .addContent(leftColumn) + .wrap(new VBox()) + .addAllContent(userTitle, netWorth, percentageChange, playerStatus) + .unwrap() .filler() - .addContent(rightColumn) + .wrap(new VBox()) + .growWithAlignment(Pos.CENTER) + .addAllContent(portfolioWorth, totalShares) + .unwrap() .build(); this.getChildren().add(playerPortfolioComponent.makeUI()); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java index e33da72..7546158 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java @@ -19,17 +19,20 @@ public ShareComponent(Share share){ this.setMaxSize(Double.MAX_VALUE, 300); this.setPadding(new Insets(30)); this.getStyleClass().add("rowBox"); + Label name = new Label(share.getStock().getCompany()); Label quantity = new Label("Owned shares: "+share.getQuantity().toString()); Label ticker = new Label("("+share.getStock().getSymbol()+")"); Label latestPrice = new Label("Latest price: "+share.getStock().getSalesPrice().toString()); Button sellButton = new Button("Sell"); + ArrayList