Skip to content

UI portfolio labels #52

Merged
merged 4 commits into from
May 14, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package edu.ntnu.idi.idatt.view;

import edu.ntnu.idi.idatt.model.market.Stock;
import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.session.UserSession;
import edu.ntnu.idi.idatt.view.entry.StartController;
import edu.ntnu.idi.idatt.view.entry.StartModel;
import edu.ntnu.idi.idatt.view.entry.StartView;
import edu.ntnu.idi.idatt.view.primary.portfolio.PortfolioController;
import edu.ntnu.idi.idatt.view.primary.portfolio.PortfolioModel;
import edu.ntnu.idi.idatt.view.primary.portfolio.PortfolioView;
import edu.ntnu.idi.idatt.view.primary.exchange.ExchangeController;
import edu.ntnu.idi.idatt.view.primary.exchange.ExchangeModel;
import edu.ntnu.idi.idatt.view.primary.exchange.ExchangeView;
Expand All @@ -16,8 +20,10 @@
import edu.ntnu.idi.idatt.view.primary.transactions.TransactionView;
import javafx.scene.Parent;

import java.math.BigDecimal;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;

public class SceneFactory {

Expand Down Expand Up @@ -67,14 +73,9 @@ public static Parent createStartView() {

}
public static Parent createPortfolioView(){
Stock stock = new Stock("int", "intel", List.of(new BigDecimal("100")));
Share share = new Share(stock, new BigDecimal("50"), new BigDecimal("100"));
UserSession.getInstance().getPlayer().getPortfolio().addShare(share);
UserSession.getInstance().getPlayer().getPortfolio().addShare(share);
UserSession.getInstance().getPlayer().getPortfolio().addShare(share);
UserSession.getInstance().getPlayer().getPortfolio().addShare(share);
UserSession.getInstance().getPlayer().getPortfolio().addShare(share);
UserSession.getInstance().getPlayer().getPortfolio().addShare(share);

mark(() -> createPortfolioView());

PortfolioModel model = new PortfolioModel();
PortfolioView view = new PortfolioView();
PortfolioController controller = new PortfolioController(model);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;

Expand All @@ -15,27 +18,30 @@ 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 netWorth = new Label("Total net worth: "+portfolio.getNetWorth().toString());
Label percentageChange = new Label("Percentage change: ");
Label playerStatus = new Label("Novice");
Label portfolioWorth = new Label("Portfolio net worth: ");
Label totalShares = new Label("Total shares owned: ");

Label userTitle = new Label(String.format("%s's Portfolio", UserSession.getInstance().getPlayer().getName()));
Label netWorth = new Label();
netWorth.textProperty().bind(
UserSession.getInstance().netWorthProperty().asString("Net Worth: %.2f $"));
Label percentageChange = new Label("Percentage change: "+ UserSession.getInstance().netWorthProperty().doubleValue());
Label playerStatus = new Label("Player status: "+ UserSession.getInstance().getPlayer().getStatus());
Label totalShares = new Label("Total shares owned: "+ UserSession.getInstance().getPlayer().getPortfolio().getShares().size());
ArrayList<Label> labels = new ArrayList<>();
Collections.addAll(labels, netWorth, percentageChange, playerStatus, portfolioWorth, totalShares);
labels.forEach(e -> e.getStyleClass().add("user-box-text"));
userTitle.getStyleClass().add("user-box-title");

VBox leftColumn = new VBox(userTitle, netWorth, percentageChange, playerStatus);
VBox rightColumn = new VBox(portfolioWorth, totalShares);
Collections.addAll(labels, netWorth, percentageChange, playerStatus, totalShares);
labels.forEach(e -> e.getStyleClass().add("portfolio-box-text"));
userTitle.getStyleClass().add("portfolio-box-title");

UICompositor playerPortfolioComponent = new UICompositor.Builder()
.parent(new HBox())
.growWithAlignment(Pos.CENTER)
.addContent(leftColumn)
.wrap(new VBox())
.addAllContent(userTitle, netWorth, percentageChange)
.unwrap()
.filler()
.addContent(rightColumn)
.wrap(new VBox())
.growWithAlignment(Pos.BOTTOM_CENTER)
.addAllContent(playerStatus, totalShares)
.unwrap()
.build();

this.getChildren().add(playerPortfolioComponent.makeUI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@

import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.view.components.ui.UICompositor;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;

import java.util.ArrayList;
import java.util.Collections;


public class ShareComponent extends HBox {

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");
ticker.getStyleClass().add("portfolio-stock-names");
name.getStyleClass().add("portfolio-stock-names");
quantity.getStyleClass().add("portfolio-stock-names");
latestPrice.getStyleClass().add("portfolio-stock-names");

ArrayList<Label> labels = new ArrayList<>();
Collections.addAll(labels, name, quantity, ticker, latestPrice);
labels.forEach(e -> e.getStyleClass().add("portfolio-box-text"));
sellButton.getStyleClass().add("button");
String color = CssUtils.generateValueColors(share.getProfit().doubleValue());
CssUtils.apply(latestPrice, color);

UICompositor shareComponent = new UICompositor.Builder()
.parent(new HBox())
.growWithAlignment(Pos.CENTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ public Builder parent(Pane parent) {
}

public Builder growWithAlignment(Pos position) {
if (parent instanceof HBox) {
((HBox) parent).setAlignment(position);
parent.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(parent, Priority.ALWAYS);
Pane root = getRoot();
if (root instanceof HBox) {
((HBox) root).setAlignment(position);
root.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(root, Priority.ALWAYS);
}
if (parent instanceof VBox) {
((VBox) parent).setAlignment(position);
parent.setMaxHeight(Double.MAX_VALUE);
VBox.setVgrow(parent, Priority.ALWAYS);
if (root instanceof VBox) {
((VBox) root).setAlignment(position);
root.setMaxHeight(Double.MAX_VALUE);
VBox.setVgrow(root, Priority.ALWAYS);
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ public static Parent createMenu(String title, List<String> buttonLables, ActionE

UICompositor.Builder menuBuilder = new UICompositor.Builder()
.parent(new VBox())
.growWithAlignment(Pos.TOP_CENTER)
.properties((menu) -> menu.setPrefSize(300, Double.MAX_VALUE))
.growWithAlignment(Pos.CENTER)
.addContent(menuIcon);

buttons.forEach(b -> menuBuilder.addContent(b));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.ntnu.idi.idatt.view.portfolio;
package edu.ntnu.idi.idatt.view.primary.portfolio;

import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.session.UserSession;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.ntnu.idi.idatt.view.portfolio;
package edu.ntnu.idi.idatt.view.primary.portfolio;

import edu.ntnu.idi.idatt.model.portfolio.Portfolio;
import edu.ntnu.idi.idatt.view.components.Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.ntnu.idi.idatt.view.portfolio;
package edu.ntnu.idi.idatt.view.primary.portfolio;

import edu.ntnu.idi.idatt.view.SceneFactory;
import edu.ntnu.idi.idatt.view.SceneManager;
Expand All @@ -25,15 +25,15 @@ public Parent createContent() {

VBox.setVgrow(userBox, Priority.ALWAYS);
userBox.setPadding(new Insets(20));
root.setTop(userBox);

ScrollPane stockBox = new ScrollPane();
stockBox.setPadding(new Insets(10, 10, 20, 20));
root.setCenter(stockBox);
stockBox.setPadding(new Insets(0, 10, 0, 20));
shareBox = new VBox(20);

stockBox.setFitToWidth(true);
stockBox.getStyleClass().add("viewport-colour");
stockBox.getStyleClass().add("primary");
shareBox = new VBox(20);
root.setTop(userBox);
root.setCenter(stockBox);
stockBox.setContent(shareBox);
return root;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Parent createToolbar() {
public Parent createMenu() {
return UIFactory.createMenu("Account",
List.of(" • Portfolio", " • Transactions"),
() -> System.out.println("Portfolio clicked!"),
() -> SceneManager.switchTo(SceneFactory.createPortfolioView()),
() -> SceneManager.switchTo(SceneFactory.createTransactionView()));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Parent createToolbar() {
public Parent createMenu() {
return UIFactory.createMenu("Account",
List.of(" • Portfolio", " • Transactions"),
() -> System.out.println("Portfolio clicked!"),
() -> SceneManager.switchTo(SceneFactory.createPortfolioView()),
() -> {
});

Expand Down
44 changes: 16 additions & 28 deletions src/main/resources/themes/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
-fx-background-color: #3B8C6E;
}


.title {
-fx-font-size: 56px;
-fx-font-weight: 700;
Expand Down Expand Up @@ -39,6 +38,21 @@
-fx-text-fill: #EEEEEE;
}

.portfolio-box-text{
-fx-font-size: 20px;
-fx-font-weight: 700;
-fx-text-fill: #EEEEEE;
-fx-padding: 10;
-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5);
}
.portfolio-box-title{
-fx-font-size: 32px;
-fx-font-weight: 700;
-fx-text-fill: #EEEEEE;
-fx-padding: 10;
-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5);
}

.red {
-fx-text-fill: #FF0000;
}
Expand Down Expand Up @@ -72,27 +86,15 @@
-fx-cursor: hand;
}

.portfolio-vbox {
-fx-background-color: #A9A9A9;
}

.viewport-colour > .viewport {
-fx-background-color: #3B8C6E;
}

.rowBox {
-fx-background-color: #A9A9A9;
-fx-background-color: #404950;
-fx-alignment: center;
}

.portfolio-stock-names {
-fx-font-size: 20px;
-fx-font-weight: 700;
-fx-text-fill: #EEEEEE;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.3), 10, 0.5, 0, 5);
-fx-padding: 5;
}

.searchbar {
-fx-background-color: #FFFFFF;
-fx-background-radius: 20;
Expand All @@ -108,18 +110,4 @@
-fx-border-radius: 20;
-fx-cursor: hand;
}
.user-box-text{
-fx-font-size: 16px;
-fx-font-weight: 700;
-fx-text-fill: #EEEEEE;
-fx-padding: 10 10 10 10;
-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5);
}
.user-box-title{
-fx-font-size: 32px;
-fx-font-weight: 700;
-fx-text-fill: #EEEEEE;
-fx-padding: 10 10 0 10;
-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5);
}

Loading