-
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.
feat: Implement TransactionComponent class
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/main/java/edu/ntnu/idi/idatt/view/components/elements/TransactionComponent.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,94 @@ | ||
| package edu.ntnu.idi.idatt.view.components.elements; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.market.Stock; | ||
| import edu.ntnu.idi.idatt.model.transaction.Purchase; | ||
| import edu.ntnu.idi.idatt.model.transaction.Sale; | ||
| import edu.ntnu.idi.idatt.model.transaction.Transaction; | ||
| import edu.ntnu.idi.idatt.service.transaction.PurchaseCalculator; | ||
| import edu.ntnu.idi.idatt.service.transaction.SaleCalculator; | ||
| 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.Label; | ||
| import javafx.scene.layout.VBox; | ||
|
|
||
| public class TransactionComponent extends VBox { | ||
|
|
||
| public TransactionComponent(Transaction transaction) { | ||
|
|
||
| Stock stock = transaction.getShare().getStock(); | ||
|
|
||
| Label title; | ||
| Label name = new Label(stock.getCompany() + " (" + stock.getSymbol() + ")"); | ||
| Label totalValue; | ||
| Label taxComissionValue; | ||
| Label grossValue; | ||
| Label amountOfShares; | ||
| Label saleProfit; | ||
|
|
||
| if (transaction instanceof Purchase) { | ||
| title = new Label("PURCHASE"); | ||
| CssUtils.apply(title, CssUtils.GREEN); | ||
|
|
||
| PurchaseCalculator calculator = (PurchaseCalculator) transaction.getCalculator(); | ||
| totalValue = new Label("Total: " + calculator.calculateTotal() + " USD"); | ||
| taxComissionValue = new Label( | ||
| "Tax & Comission: " + calculator.calculateTax().add(calculator.calculateCommision()) + " USD"); | ||
| grossValue = new Label("Gross: " + calculator.calculateGross() + " USD"); | ||
| amountOfShares = new Label("Shares: " + transaction.getShare().getQuantity() + " [" + stock.getSymbol() + "]"); | ||
| saleProfit = new Label(); | ||
|
|
||
| } else if (transaction instanceof Sale) { | ||
| title = new Label("SALE"); | ||
| CssUtils.apply(title, CssUtils.RED); | ||
|
|
||
| SaleCalculator calculator = (SaleCalculator) transaction.getCalculator(); | ||
| totalValue = new Label("Total: " + calculator.calculateTotal() + " USD"); | ||
| taxComissionValue = new Label( | ||
| "Tax & Comission: " + calculator.calculateTax().add(calculator.calculateCommision()) + " USD"); | ||
| grossValue = new Label("Gross: " + calculator.calculateGross() + " USD"); | ||
| amountOfShares = new Label("Shares: " + transaction.getShare().getQuantity() + " [" + stock.getSymbol() + "]"); | ||
| saleProfit = new Label("Profit: " + calculator.calculateProfit() + " USD"); | ||
|
|
||
| CssUtils.apply(saleProfit, CssUtils.generateValueColors(calculator.calculateProfit().doubleValue())); | ||
| } | ||
|
|
||
| else { | ||
| System.out.println("Failed to initialize transactionComponent!"); | ||
| return; | ||
| } | ||
|
|
||
| this.setPrefSize(400, Double.MAX_VALUE); | ||
| this.setMinWidth(400); | ||
| this.setPadding(new Insets(40)); | ||
| this.setAlignment(Pos.TOP_CENTER); | ||
|
|
||
| // TODO: CHANGE AND IN STOCKComponent | ||
| this.setStyle("-fx-background-color: #404950;"); | ||
|
|
||
| CssUtils.apply(title, CssUtils.BIG_TEXT_32); | ||
| CssUtils.apply(name, CssUtils.BIG_TEXT_32); | ||
| List<Label> labels = List.of(totalValue, taxComissionValue, grossValue, amountOfShares, saleProfit); | ||
| labels.forEach(l -> CssUtils.apply(l, CssUtils.MED_TEXT_16)); | ||
|
|
||
| UICompositor transactionComponent = new UICompositor.Builder() | ||
| .parent(new VBox()) | ||
| .growWithAlignment(Pos.CENTER) | ||
| .addContent(title) | ||
| .addContent(name) | ||
| .filler() | ||
| .addContent(totalValue) | ||
| .addContent(taxComissionValue) | ||
| .addContent(grossValue) | ||
| .addContent(amountOfShares) | ||
| .addContent(saleProfit) | ||
| .build(); | ||
|
|
||
| this.getChildren().add(transactionComponent.makeUI()); | ||
|
|
||
| } | ||
|
|
||
| } |