-
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 #98 from Team-40-IDATT2003/92-finish-top-bar
92 finish top bar
- Loading branch information
Showing
15 changed files
with
431 additions
and
268 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
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
1 change: 1 addition & 0 deletions
1
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewElement.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
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardActions.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,7 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard; | ||
|
|
||
| public enum DashBoardActions { | ||
| BUY_SHARES, | ||
| SELL_SHARES, | ||
| SELECT_STOCK; | ||
| } |
80 changes: 80 additions & 0 deletions
80
...ain/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.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,80 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.g40.mappe.engine.Exchange; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.model.Player; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.utils.Validator; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.TextFormatter; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
|
|
||
| public class DashBoardController extends ViewController<DashBoardView> { | ||
|
|
||
| private Player player; | ||
| private Exchange exchange; | ||
| private List<Stock> stockList; | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public DashBoardController(final DashBoardView viewElement, | ||
| final EventManager eventManager, | ||
| final Player player, | ||
| final Exchange exchange, | ||
| final List<Stock> stockList) | ||
| throws IllegalArgumentException { | ||
| this.player = player; | ||
| this.stockList = stockList; | ||
| this.exchange = exchange; | ||
| super(viewElement, eventManager); | ||
| } | ||
|
|
||
| private void handleStockSelection(Stock stock) { | ||
| getViewElement().setCurrentStock(stock); | ||
| getViewElement().updateGraph(); | ||
| } | ||
|
|
||
| private void populateStockList() { | ||
| getViewElement().clearStockList(); | ||
| for (Stock s : stockList) { | ||
| Button stockBtn = getViewElement().createStockButton(s.getSymbol()); | ||
|
|
||
| getViewElement().setOnStockAction(stockBtn, s, selectedStock -> { | ||
| handleStockSelection(selectedStock); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| protected void initInteractions() { | ||
| populateStockList(); | ||
| getViewElement().setCurrentStock(stockList.getFirst()); | ||
| getViewElement().updateGraph(); | ||
| getViewElement().setOnAction(DashBoardActions.BUY_SHARES, () -> { | ||
| if (Validator.NOT_EMPTY.isValid(getViewElement().getQuantityInputField().getText())) { | ||
| BigDecimal amountToBuy = new BigDecimal(getViewElement().getQuantityInputField().getText()); | ||
| exchange.buy( | ||
| getViewElement().getCurrentStock().getSymbol(), | ||
| amountToBuy, | ||
| player | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| exchange.weekProperty().addListener((observable,o,n) -> { | ||
| getViewElement().updateGraph(); | ||
| }); | ||
|
|
||
| getViewElement().getQuantityInputField().setTextFormatter(new TextFormatter<>(change -> { | ||
| if (change.getControlNewText().matches("([0-9]*(\\.[0-9]*)?)?")) { | ||
| return change; | ||
| } | ||
| return null; | ||
| })); | ||
| } | ||
| } |
Oops, something went wrong.