Tournament list #11

Merged
schrom01 merged 13 commits from TournamentList into main 2022-05-01 18:45:02 +02:00
5 changed files with 97 additions and 37 deletions
Showing only changes of commit 61b943b091 - Show all commits

View File

@ -3,45 +3,44 @@ package ch.zhaw.projekt2.turnierverwaltung;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
public abstract class FXController { public abstract class FXController {
Tournament tournament;
TournamentDecorator tournamentDecorator; TournamentDecorator tournamentDecorator;
Factory factory; FactoryDecorator factoryDecorator;
FileIO fileIO; FileIO fileIO;
Pane pane; Pane pane;
public void setup(Tournament tournament, FileIO fileIO, Factory factory, Pane pane){ public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane){
setTournament(tournament); this.tournamentDecorator = tournamentDecorator;
this.fileIO = fileIO; this.fileIO = fileIO;
this.factory = factory; this.factoryDecorator = factoryDecorator;
this.pane = pane; this.pane = pane;
tournamentDecorator = new TournamentDecorator(fileIO, tournament);
tournamentDecorator.addListener(new IsObserver() { tournamentDecorator.addListener(new IsObserver() {
@Override @Override
public void update() { public void update() {
loadContent(); loadContent();
} }
}); });
factoryDecorator.addListener(new IsObserver() {
@Override
public void update() {
loadContent();
}
});
} }
public abstract void loadContent(); public abstract void loadContent();
public void setTournament(Tournament tournament) {
this.tournament = tournament;
tournamentDecorator.setTournament(tournament);
}
protected TournamentDecorator getTournamentDecorator() { protected TournamentDecorator getTournamentDecorator() {
return tournamentDecorator; return tournamentDecorator;
} }
protected FactoryDecorator getFactoryDecorator() {
return factoryDecorator;
}
protected FileIO getFileIO() { protected FileIO getFileIO() {
return fileIO; return fileIO;
} }
protected Factory getFactory() {
return factory;
}
protected Pane getPane() { protected Pane getPane() {
return pane; return pane;
} }

View File

@ -8,19 +8,20 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
public class Factory { public class Factory {
private Tournament tournament; private TournamentDecorator tournamentDecorator;
private FileIO fileIO; private FileIO fileIO;
public Factory(FileIO fileIO){ public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator){
this.fileIO = fileIO; this.fileIO = fileIO;
this.tournamentDecorator = tournamentDecorator;
} }
public Tournament getTournament() { public TournamentDecorator getTournamentDecorator() {
return tournament; return tournamentDecorator;
} }
public void setTournament(Tournament tournament) { public void setTournament(Tournament tournament) {
this.tournament = tournament; this.tournamentDecorator = tournamentDecorator;
} }
public BorderPane loadMainWindow(){ public BorderPane loadMainWindow(){
@ -34,23 +35,23 @@ public class Factory {
return null; return null;
} }
public void loadTournamentList(BorderPane pane){ public void loadTournamentList(BorderPane pane, FactoryDecorator factoryDecorator){
TournamentListController controller = (TournamentListController) setCenterOfBorderPane(pane, getClass().getResource("tournamentList/tournamentList.fxml")); TournamentListController controller = (TournamentListController) setCenterOfBorderPane(pane, getClass().getResource("tournamentList/tournamentList.fxml"), factoryDecorator);
} }
//Can be used to Open new Scene in same Stage. //Can be used to Open new Scene in same Stage.
//This way possible to later give object to Controller //This way possible to later give object to Controller
public void loadParticipantFormular(BorderPane pane) { public void loadParticipantFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
setCenterOfBorderPane(pane, getClass().getResource("participantAddFormular/participantFormular.fxml")); setCenterOfBorderPane(pane, getClass().getResource("participantAddFormular/participantFormular.fxml"), factoryDecorator);
} }
private FXController setCenterOfBorderPane(BorderPane pane, URL location) { private FXController setCenterOfBorderPane(BorderPane pane, URL location, FactoryDecorator factoryDecorator) {
FXController controller = null; FXController controller = null;
try { try {
FXMLLoader loader = new FXMLLoader(location); FXMLLoader loader = new FXMLLoader(location);
pane.setCenter(loader.load()); pane.setCenter(loader.load());
controller = loader.getController(); controller = loader.getController();
controller.setup(tournament, fileIO, this, pane); controller.setup(tournamentDecorator, fileIO, factoryDecorator, pane);
controller.loadContent(); controller.loadContent();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -0,0 +1,62 @@
package ch.zhaw.projekt2.turnierverwaltung;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FactoryDecorator implements IsObservable{
private Factory factory;
private FileIO fileIO;
private Pane pane;
private List<IsObserver> listener = new ArrayList<>();
public FactoryDecorator(FileIO fileIO, Factory factory, Pane pane){
setFactory(factory);
setFileIO(fileIO);
setPane(pane);
}
public void setFileIO(FileIO fileIO) {
this.fileIO = fileIO;
}
public void setFactory(Factory factory) {
this.factory = factory;
}
public void setPane(Pane pane) {
this.pane = pane;
}
@Override
public void addListener(IsObserver observer) {
listener.add(observer);
}
@Override
public void removeListener(IsObserver observer) {
listener.remove(observer);
}
public void openTournament(FileIO.TournamentFile tournamentFile){
try {
factory.setTournament(fileIO.loadTournament(tournamentFile));
factory.loadParticipantFormular((BorderPane) pane, this); //TODO load TournamentView instead of ParticipantFormular?
informListener();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} //TODO handle and logging
}
public void informListener() {
for(IsObserver observer : listener) {
observer.update();
}
}
}

View File

@ -1,7 +1,9 @@
package ch.zhaw.projekt2.turnierverwaltung.main; package ch.zhaw.projekt2.turnierverwaltung.main;
import ch.zhaw.projekt2.turnierverwaltung.Factory; import ch.zhaw.projekt2.turnierverwaltung.Factory;
import ch.zhaw.projekt2.turnierverwaltung.FactoryDecorator;
import ch.zhaw.projekt2.turnierverwaltung.FileIO; import ch.zhaw.projekt2.turnierverwaltung.FileIO;
import ch.zhaw.projekt2.turnierverwaltung.TournamentDecorator;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -14,13 +16,16 @@ import java.io.IOException;
public class MainWindow extends Application { public class MainWindow extends Application {
private FileIO fileIO = new FileIO(System.getProperty("user.dir") + "/tournierverwaltung_angrynerds"); private FileIO fileIO = new FileIO(System.getProperty("user.dir") + "/tournierverwaltung_angrynerds");
private Factory factory = new Factory(fileIO); //TODO make it private! private TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO, null);
private Factory factory = new Factory(fileIO, tournamentDecorator); //TODO make it private!
private FactoryDecorator factoryDecorator;
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
BorderPane pane = factory.loadMainWindow(); BorderPane pane = factory.loadMainWindow();
factory.loadTournamentList(pane); factoryDecorator = new FactoryDecorator(fileIO, factory, pane);
factory.loadTournamentList(pane, factoryDecorator);
Scene scene = new Scene(pane); Scene scene = new Scene(pane);

View File

@ -61,15 +61,8 @@ public class TournamentListController extends FXController {
@FXML @FXML
void openTournament(ActionEvent event) { void openTournament(ActionEvent event) {
File tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0);
try { getFactoryDecorator().openTournament(tournamentFile);
getFactory().setTournament(getFileIO().loadTournament(tournamentFile));
getFactory().loadParticipantFormular((BorderPane) getPane()); //TODO load TournamentView instead of ParticipantFormular?
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} //TODO handle and logging
} }
@FXML @FXML