From 5e88960c8a9cf437b98f7c7c0f9b8a35fef8a4ce Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 7 May 2022 15:34:08 +0200 Subject: [PATCH] extracted Method loadGameTree to FactoryDecorator.java --- .../turnierverwaltung/FactoryDecorator.java | 26 +++++++++++++++ .../GameScheduleController.java | 32 +------------------ 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java index a186616..739f7ff 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java @@ -3,6 +3,7 @@ package ch.zhaw.projekt2.turnierverwaltung; import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController; import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; @@ -75,10 +76,35 @@ public class FactoryDecorator implements IsObservable{ informListener(); } + public void loadGameTree(HBox hBoxCenter, TournamentDecorator tournamentDecorator) { + hBoxCenter.getChildren().clear(); + + List> gameList = tournamentDecorator.getTournament().getGameList(); + + List gameDecorators = new ArrayList<>(); + for (int i = 0; i < gameList.size(); i++) { + List newGameDecorators = new ArrayList<>(); + VBox vBox = new VBox(); + for (int j = 0; j < gameList.get(i).size(); j++) { + GameDecorator gameDecorator = new GameDecorator(gameList.get(i).get(j)); + newGameDecorators.add(gameDecorator); + GameController controller = openGameView(vBox,gameDecorator); + if(i>0){ + controller.addListener(gameDecorators.get(j*2)); + controller.addListener(gameDecorators.get(j*2+1)); + } + controller.loadContent(); + } + hBoxCenter.getChildren().add(vBox); + gameDecorators = newGameDecorators; + } + } + public GameController openGameView(VBox vBox, GameDecorator gameDecorator) { return factory.loadGameView(vBox ,gameDecorator, this); } + public void informListener() { for(IsObserver observer : listener) { observer.update(); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java index 075a1e8..f0dab5e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java @@ -1,20 +1,11 @@ package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; import ch.zhaw.projekt2.turnierverwaltung.FXController; -import ch.zhaw.projekt2.turnierverwaltung.Game; import ch.zhaw.projekt2.turnierverwaltung.Tournament; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.VBox; -import org.checkerframework.checker.units.qual.C; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; public class GameScheduleController extends FXController { @@ -52,28 +43,7 @@ public class GameScheduleController extends FXController { @Override public void loadContent() { - hBoxCenter.getChildren().clear(); - - List> gameList = getTournamentDecorator().getTournament().getGameList(); - - List gameDecorators = new ArrayList<>(); - for (int i = 0; i < gameList.size(); i++) { - List newGameDecorators = new ArrayList<>(); - VBox vBox = new VBox(); - for (int j = 0; j < gameList.get(i).size(); j++) { - GameDecorator gameDecorator = new GameDecorator(gameList.get(i).get(j)); - newGameDecorators.add(gameDecorator); - GameController controller = getFactoryDecorator().openGameView(vBox,gameDecorator); - if(i>0){ - controller.addListener(gameDecorators.get(j*2)); - controller.addListener(gameDecorators.get(j*2+1)); - } - controller.loadContent(); - } - hBoxCenter.getChildren().add(vBox); - gameDecorators = newGameDecorators; - } - + getFactoryDecorator().loadGameTree(hBoxCenter, getTournamentDecorator()); } }