From 7af48449e0d973829dbd2fd25b7eb3a49779f0d2 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 29 Apr 2022 17:30:26 +0200 Subject: [PATCH] created Abstract Class FXController.java --- .../turnierverwaltung/FXController.java | 19 +++++++++++++++++++ .../projekt2/turnierverwaltung/Factory.java | 2 ++ .../main/MainWindowController.java | 3 ++- .../participantFormularController.java | 3 ++- .../tournamentListController.java | 3 ++- 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java new file mode 100644 index 0000000..5c5c545 --- /dev/null +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java @@ -0,0 +1,19 @@ +package ch.zhaw.projekt2.turnierverwaltung; + +public abstract class FXController { + Tournament tournament; + Factory factory; + + public void setup(Tournament tournament, Factory factory){ + this.tournament = tournament; + this.factory = factory; + } + + protected Tournament getTournament() { + return tournament; + } + + protected Factory getFactory() { + return factory; + } +} 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 2b671d1..5e851fa 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java @@ -51,6 +51,8 @@ public class Factory { try { FXMLLoader loader = new FXMLLoader(location); pane.setCenter(loader.load()); + FXController controller = loader.getController(); + controller.setup(tournament, this); } catch (IOException e) { e.printStackTrace(); //TODO handle and logging? diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java index 577a538..f33fb69 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java @@ -1,9 +1,10 @@ package ch.zhaw.projekt2.turnierverwaltung.main; +import ch.zhaw.projekt2.turnierverwaltung.FXController; import javafx.event.ActionEvent; import javafx.fxml.FXML; -public class MainWindowController { +public class MainWindowController extends FXController { @FXML void changeLangToGerman(ActionEvent event) { diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/participantFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/participantFormularController.java index 8056644..6991216 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/participantFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/participantFormularController.java @@ -1,5 +1,6 @@ package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular; +import ch.zhaw.projekt2.turnierverwaltung.FXController; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -10,7 +11,7 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; -public class participantFormularController { +public class participantFormularController extends FXController { @FXML private Button addBtn; diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/tournamentListController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/tournamentListController.java index cb8799f..cc399e7 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/tournamentListController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/tournamentListController.java @@ -1,5 +1,6 @@ package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList; +import ch.zhaw.projekt2.turnierverwaltung.FXController; import ch.zhaw.projekt2.turnierverwaltung.main.MainWindow; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -9,7 +10,7 @@ import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.layout.GridPane; -public class tournamentListController { +public class tournamentListController extends FXController { @FXML private Button createBtn;