-
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 #40 from IDATT2003-gruppe06/feat/JavaFX-boilerplate
Feat/java fx boilerplate
- Loading branch information
Showing
16 changed files
with
483 additions
and
21 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package millions; | ||
|
|
||
| import javafx.application.Application; | ||
| import javafx.scene.Scene; | ||
| import javafx.stage.Stage; | ||
| import millions.controller.GameController; | ||
| import millions.view.StartView; | ||
|
|
||
| public class App extends Application { | ||
|
|
||
| @Override | ||
| public void start(Stage stage) { | ||
| GameController controller = new GameController(); | ||
| StartView startView = new StartView(stage); | ||
|
|
||
| Scene scene = new Scene(startView, 400, 350); | ||
| stage.setTitle("Millions"); | ||
| stage.setScene(scene); | ||
| stage.show(); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| launch(args); | ||
| } | ||
| } |
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,33 @@ | ||
| package millions.controller; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
| import millions.controller.fileIO.CSVStockFileParser; | ||
| import millions.controller.fileIO.StockFileReader; | ||
| import millions.model.Exchange; | ||
| import millions.model.Player; | ||
| import millions.model.Stock; | ||
|
|
||
| public class GameController { | ||
| private Player player; | ||
| private Exchange exchange; | ||
|
|
||
| public void startGame(String name, BigDecimal startingMoney, Path stockFilePath) { | ||
| StockFileReader reader = new StockFileReader(stockFilePath); | ||
| List<String> lines = reader.readFile(); | ||
| CSVStockFileParser parser = new CSVStockFileParser(lines); | ||
| List<Stock> stocks = parser.parse(); | ||
|
|
||
| player = new Player(name, startingMoney); | ||
| exchange = new Exchange("Exchange", stocks); | ||
| } | ||
|
|
||
| public Player getPlayer() { | ||
| return player; | ||
| } | ||
|
|
||
| public Exchange getExchange() { | ||
| return exchange; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package millions.model; | ||
|
|
||
| public interface ExchangeListener { | ||
|
|
||
| void onWeekAdvanced(int newWeek); | ||
|
|
||
| void onTransactionCompleted(Transaction transaction); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package millions.model; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public interface PlayerListener { | ||
|
|
||
| void onMoneyChanged(BigDecimal newBalance); | ||
|
|
||
| void onPortfolioChanged(); | ||
|
|
||
| void onStatusChanged(String newStatus); | ||
| } |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/millions/model/factories/PurchaseFactory.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,10 @@ | ||
| package millions.model.factories; | ||
|
|
||
| import millions.model.Purchase; | ||
| import millions.model.Share; | ||
|
|
||
| public class PurchaseFactory extends TransactionFactory { | ||
| public Purchase createTransaction(Share share, int week) { | ||
| return new Purchase(share, week); | ||
| } | ||
| } |
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,10 @@ | ||
| package millions.model.factories; | ||
|
|
||
| import millions.model.Sale; | ||
| import millions.model.Share; | ||
|
|
||
| public class SaleFactory extends TransactionFactory { | ||
| public Sale createTransaction(Share share, int week) { | ||
| return new Sale(share, week); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/millions/model/factories/TransactionFactory.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,8 @@ | ||
| package millions.model.factories; | ||
|
|
||
| import millions.model.Share; | ||
| import millions.model.Transaction; | ||
|
|
||
| public abstract class TransactionFactory { | ||
| public abstract Transaction createTransaction(Share share, int week); | ||
| } |
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 millions.view; | ||
|
|
||
| import java.io.File; | ||
| import javafx.geometry.Insets; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.TextField; | ||
| import javafx.scene.layout.VBox; | ||
| import javafx.stage.FileChooser; | ||
| import javafx.stage.Stage; | ||
|
|
||
| public class StartView extends VBox { | ||
|
|
||
| private TextField nameField; | ||
| private TextField startingAmountField; | ||
| private File selectedFile; | ||
| private Button filepickerButton; | ||
| private Button startButton; | ||
|
|
||
| public StartView(Stage stage) { | ||
| setAlignment(Pos.CENTER); | ||
| setSpacing(12); | ||
| setPadding(new Insets(40)); | ||
|
|
||
| nameField = new TextField(); | ||
| nameField.setPromptText("Player name:"); | ||
| nameField.setMaxWidth(250); | ||
| nameField.textProperty().addListener((obs, oldVal, newVal) -> checkStartButtonValid()); | ||
|
|
||
| startingAmountField = new TextField(); | ||
| startingAmountField.setPromptText("Starting amount:"); | ||
| startingAmountField.setMaxWidth(250); | ||
| startingAmountField | ||
| .textProperty() | ||
| .addListener((obs, oldVal, newVal) -> checkStartButtonValid()); | ||
|
|
||
| filepickerButton = new Button(); | ||
| filepickerButton.setText("Pick file"); | ||
| filepickerButton.setMaxWidth(250); | ||
| filepickerButton.setOnAction( | ||
| e -> { | ||
| FileChooser chooser = new FileChooser(); | ||
| chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("CSV files", "*.csv")); | ||
| chooser.setTitle("Select stock CSV file"); | ||
| File file = chooser.showOpenDialog(stage); | ||
|
|
||
| if (file != null) { | ||
| selectedFile = file; | ||
| filepickerButton.setText(file.getName()); | ||
| } | ||
| }); | ||
|
|
||
| startButton = new Button("Start game"); | ||
| startButton.setDisable(true); | ||
|
|
||
| Label title = new Label("Millions"); | ||
| title.setStyle("-fx-font-size: 32px; -fx-font-weight: bold;"); | ||
|
|
||
| getChildren().addAll(title, nameField, startingAmountField, filepickerButton, startButton); | ||
| } | ||
|
|
||
| private void checkStartButtonValid() { | ||
| boolean valid = true; | ||
|
|
||
| if (nameField.getText().isBlank()) { | ||
| valid = false; | ||
| } | ||
|
|
||
| try { | ||
| Integer.valueOf(startingAmountField.getText()); | ||
| } catch (NumberFormatException e) { | ||
| valid = false; | ||
| } | ||
|
|
||
| startButton.setDisable(!valid); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return nameField.getText(); | ||
| } | ||
|
|
||
| public String getStartingAmount() { | ||
| return startingAmountField.getText(); | ||
| } | ||
|
|
||
| public File getSelectedFile() { | ||
| return selectedFile; | ||
| } | ||
|
|
||
| public Button getStartButton() { | ||
| return startButton; | ||
| } | ||
| } |
Oops, something went wrong.