From 62df1db34bb328c2b333f0f72769bf8d622967d6 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 7 May 2022 12:51:14 +0200 Subject: [PATCH] refactoring of GameController.java to do it the same way as the other controllers. --- .../projekt2/turnierverwaltung/Factory.java | 4 ++-- .../zhaw/projekt2/turnierverwaltung/Game.java | 7 +++--- .../main/gameScheduleView/GameController.java | 11 ++++----- .../main/gameScheduleView/GameDecorator.java | 23 ++++--------------- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java index c743000..c3cc6e6 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java @@ -62,8 +62,8 @@ public class Factory { FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml")); box.getChildren().add(loader.load()); GameController controller = loader.getController(); - controller.setup(new GameDecorator(game, tournamentDecorator)); - + controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, new GameDecorator(game)); + controller.loadContent(); } catch (IOException e) { e.printStackTrace(); //TODO LOGGER diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java index c294e05..8ca7041 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java @@ -45,6 +45,10 @@ public class Game implements Serializable { this.participant1 = participant1; } + public void setParticipant2(Participant participant2) { + this.participant2 = participant2; + } + public Participant getParticipant2() { return participant2; } @@ -67,7 +71,4 @@ public class Game implements Serializable { } } - public void setParticipant2(Participant participant2) { - this.participant2 = participant2; - } } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java index e050d2f..8d566b6 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java @@ -6,6 +6,7 @@ import javafx.fxml.FXML; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; +import javafx.scene.layout.Pane; public class GameController extends FXController{ @@ -29,10 +30,8 @@ public class GameController extends FXController{ @FXML void saveGamerResult(ActionEvent event) { - gameDecorator.setPoints1(Integer.parseInt(pointsTeamOne.getText())); - gameDecorator.setPoints2(Integer.parseInt(pointsTeamTwo.getText())); - gameDecorator.setLocation(placesChoiceBox.getValue()); - gameDecorator.getTournamentDecorator().refreshGameParticipants(); + gameDecorator.saveGame(pointsTeamOne.getText(), pointsTeamTwo.getText(), placesChoiceBox.getValue()); + getTournamentDecorator().refreshGameParticipants(); loadContent(); } @@ -44,9 +43,9 @@ public class GameController extends FXController{ pointsTeamTwo.setText(String.valueOf(gameDecorator.getPoints2())); } - public void setup(GameDecorator gameDecorator) { + public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane, GameDecorator gameDecorator) { + super.setup(tournamentDecorator, fileIO, factoryDecorator, pane); this.gameDecorator = gameDecorator; - loadContent(); } } \ No newline at end of file diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java index fcde13d..ef7ed94 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameDecorator.java @@ -8,24 +8,16 @@ import java.util.List; public class GameDecorator { private Game game; - private TournamentDecorator tournamentDecorator; private List listener = new ArrayList<>(); - public GameDecorator (Game game, TournamentDecorator tournamentDecorator) { + public GameDecorator (Game game) { this.game = game; - this.tournamentDecorator = tournamentDecorator; } - public TournamentDecorator getTournamentDecorator() { - return tournamentDecorator; - } - - public void setPoints1(int points1) { - game.setPoints1(points1); - } - - public void setPoints2(int points2) { - game.setPoints2(points2); + public void saveGame(String points1, String points2, Place place){ + game.setPoints1(Integer.parseInt(points1)); + game.setPoints2(Integer.parseInt(points2)); + game.setPlace(place); } public String getPoints1() { @@ -53,9 +45,4 @@ public class GameDecorator { public Place getLocation() { return game.getPlace(); } - - public void setLocation(Place place) { - game.setLocation(place); - } - }