-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from danieskj/ui-portfolio-screen
UI portfolio screen
- Loading branch information
Showing
9 changed files
with
262 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/edu/ntnu/idi/idatt/view/components/elements/PlayerPortfolioComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package edu.ntnu.idi.idatt.view.components.elements; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.portfolio.Portfolio; | ||
| 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.util.ArrayList; | ||
| import java.util.Collections; | ||
|
|
||
| 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: "); | ||
|
|
||
| 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); | ||
|
|
||
| UICompositor playerPortfolioComponent = new UICompositor.Builder() | ||
| .parent(new HBox()) | ||
| .growWithAlignment(Pos.CENTER) | ||
| .addContent(leftColumn) | ||
| .filler() | ||
| .addContent(rightColumn) | ||
| .build(); | ||
|
|
||
| this.getChildren().add(playerPortfolioComponent.makeUI()); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package edu.ntnu.idi.idatt.view.components.elements; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.portfolio.Share; | ||
| import edu.ntnu.idi.idatt.view.components.ui.UICompositor; | ||
| import javafx.geometry.Insets; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.layout.HBox; | ||
|
|
||
|
|
||
| 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"); | ||
| sellButton.getStyleClass().add("button"); | ||
| UICompositor shareComponent = new UICompositor.Builder() | ||
| .parent(new HBox()) | ||
| .growWithAlignment(Pos.CENTER) | ||
| .addAllContent(name, ticker) | ||
| .filler() | ||
| .addContent(latestPrice) | ||
| .filler() | ||
| .addContent(quantity) | ||
| .filler() | ||
| .addContent(sellButton) | ||
| .build(); | ||
|
|
||
| this.getChildren().add(shareComponent.makeUI()); | ||
| } | ||
|
|
||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/ntnu/idi/idatt/view/portfolio/PortfolioController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package edu.ntnu.idi.idatt.view.portfolio; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.portfolio.Share; | ||
| import edu.ntnu.idi.idatt.session.UserSession; | ||
| import edu.ntnu.idi.idatt.view.components.AbstractController; | ||
| import edu.ntnu.idi.idatt.view.components.elements.ShareComponent; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class PortfolioController extends AbstractController<PortfolioModel> { | ||
| private final ArrayList<ShareComponent> loadedShareComponents = new ArrayList<>(); | ||
| private UserSession session = UserSession.getInstance(); | ||
|
|
||
| public PortfolioController(PortfolioModel model){ | ||
| super(model); | ||
| for(Share share: session.getPlayer().getPortfolio().getShares()){ | ||
| ShareComponent shareComponent = new ShareComponent(share); | ||
| loadedShareComponents.add(shareComponent); | ||
| } | ||
| model.getSharesList().setAll(loadedShareComponents); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/edu/ntnu/idi/idatt/view/portfolio/PortfolioModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package edu.ntnu.idi.idatt.view.portfolio; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.portfolio.Portfolio; | ||
| import edu.ntnu.idi.idatt.view.components.Model; | ||
| import edu.ntnu.idi.idatt.view.components.elements.ShareComponent; | ||
| import javafx.collections.FXCollections; | ||
| import javafx.collections.ObservableList; | ||
|
|
||
| public class PortfolioModel implements Model { | ||
| private final ObservableList<ShareComponent> sharesList = FXCollections.observableArrayList(); | ||
| private final Portfolio portfolio = new Portfolio(); | ||
|
|
||
| public Portfolio getPortfolio() { | ||
| return portfolio; | ||
| } | ||
| public ObservableList<ShareComponent> getSharesList(){ | ||
| return sharesList; | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
src/main/java/edu/ntnu/idi/idatt/view/portfolio/PortfolioView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package edu.ntnu.idi.idatt.view.portfolio; | ||
|
|
||
| import edu.ntnu.idi.idatt.view.SceneFactory; | ||
| import edu.ntnu.idi.idatt.view.SceneManager; | ||
| import edu.ntnu.idi.idatt.view.components.AbstractViewUI; | ||
| import edu.ntnu.idi.idatt.view.components.elements.PlayerPortfolioComponent; | ||
| import edu.ntnu.idi.idatt.view.components.ui.UIFactory; | ||
| import javafx.beans.binding.Bindings; | ||
| import javafx.geometry.Insets; | ||
| import javafx.scene.Parent; | ||
| import javafx.scene.control.ScrollPane; | ||
| import javafx.scene.layout.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class PortfolioView extends AbstractViewUI { | ||
| private VBox shareBox; | ||
| private VBox userBox; | ||
|
|
||
| @Override | ||
| public Parent createContent() { | ||
| BorderPane root = new BorderPane(); | ||
| userBox = new VBox(20); | ||
| root.getStyleClass().add("primary"); | ||
|
|
||
| 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.setFitToWidth(true); | ||
| stockBox.getStyleClass().add("viewport-colour"); | ||
| stockBox.getStyleClass().add("primary"); | ||
| shareBox = new VBox(20); | ||
| stockBox.setContent(shareBox); | ||
| return root; | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createNavigation() { | ||
| return UIFactory.createNavigation("Portfolio", | ||
| List.of(" • Title"), | ||
| () -> System.out.println("Newspaper clicked")); | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createHeader() { | ||
| return UIFactory.createHeader("Search", | ||
| query -> System.out.println(query)); | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createToolbar() { | ||
| return UIFactory.createToolbar(() -> this.toggleMenu(), | ||
| () -> SceneManager.switchTo(SceneFactory.createStartView())); | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createMenu() { | ||
| return UIFactory.createMenu("Account", | ||
| List.of(" • Portfolio", " • Transactions"), | ||
| () -> SceneManager.switchTo(SceneFactory.createPortfolioView()), | ||
| () -> System.out.println("Transaction clicked!")); | ||
| } | ||
| public void setModel(PortfolioModel model){ | ||
| userBox.getChildren().clear(); | ||
| PlayerPortfolioComponent portfolioComponent = new PlayerPortfolioComponent(model.getPortfolio()); | ||
| userBox.getChildren().add(portfolioComponent); | ||
| Bindings.bindContent(shareBox.getChildren(), model.getSharesList()); | ||
| } | ||
|
|
||
| public void setController(PortfolioController controller){ | ||
|
|
||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters