Skip to content

Commit

Permalink
feat: Change latestPrice label to switch between colors
Browse files Browse the repository at this point in the history
  • Loading branch information
danieskj committed May 14, 2026
1 parent e55aed1 commit 5b93da8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
14 changes: 6 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,6 @@ 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);
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
Expand Up @@ -16,19 +16,21 @@ 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 percentageChange = new Label("Percentage change: ");
Label playerStatus = new Label("Novice");
Label playerStatus = new Label("Player status: ");
Label portfolioWorth = new Label("Portfolio net worth: ");
Label totalShares = new Label("Total shares owned: ");

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");
labels.forEach(e -> e.getStyleClass().add("portfolio-box-text"));
userTitle.getStyleClass().add("portfolio-box-title");
invisibleTitle.getStyleClass().add("portfolio-box-title");

VBox leftColumn = new VBox(userTitle, netWorth, percentageChange, playerStatus);
VBox rightColumn = new VBox(portfolioWorth, totalShares);
VBox rightColumn = new VBox(invisibleTitle, portfolioWorth, totalShares);

UICompositor playerPortfolioComponent = new UICompositor.Builder()
.parent(new HBox())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -20,11 +21,13 @@ public ShareComponent(Share share){
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");
ticker.getStyleClass().add("portfolio-box-text");
name.getStyleClass().add("portfolio-box-text");
quantity.getStyleClass().add("portfolio-box-text");
latestPrice.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
@@ -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 Down
41 changes: 15 additions & 26 deletions src/main/resources/themes/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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,10 +87,6 @@
-fx-cursor: hand;
}

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

.viewport-colour > .viewport {
-fx-background-color: #3B8C6E;
}
Expand All @@ -85,14 +96,6 @@
-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 +111,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);
}

0 comments on commit 5b93da8

Please sign in to comment.