Merge remote-tracking branch 'origin/logging_and_docs' into logging_and_docs

This commit is contained in:
Leonardo Brandenberger 2022-05-13 22:43:07 +02:00
commit 56030d0baa
2 changed files with 77 additions and 16 deletions

View File

@ -13,7 +13,7 @@ import java.io.IOException;
import java.util.logging.Logger;
/**
*
* Class to load the views from FXML Files and switch between the views.
*/
public class Factory {
private TournamentDecorator tournamentDecorator;
@ -21,16 +21,29 @@ public class Factory {
private static final Logger logger = Logger.getLogger(Factory.class.getCanonicalName());
/**
* Contructor to create Factory instance.
* @param fileIO the fileIO instance which saves and reads the tournament from files.
* @param tournamentDecorator the touramanetDecorator class to access the tournament.
*/
public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator) {
this.fileIO = fileIO;
this.tournamentDecorator = tournamentDecorator;
}
/**
* Setter Method of tournament
* @param tournament the new tournament Object.
*/
public void setTournament(Tournament tournament) {
this.tournamentDecorator.setTournament(tournament);
}
/**
* Method to load the main Window (without the content in the center)
* @return the boarder Pane which is loaded.
*/
public BorderPane loadMainWindow() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("mainWindow.fxml"));
try {
@ -42,6 +55,11 @@ public class Factory {
return null;
}
/**
* Class which loads all views of Enum View
* @param factoryDecorator the FactoryDecorator which is used to setup the controller.
* @param pane the pane where the loaded view will be visible
*/
public void loadAllViews(FactoryDecorator factoryDecorator, BorderPane pane){
for(View view : View.values()){
try {
@ -53,32 +71,57 @@ public class Factory {
}
}
public void showTournamentList(BorderPane pane, FactoryDecorator factoryDecorator) {
/**
* Method to show the view TournamentList
* @param pane the Pane where the View will be visible
*/
public void showTournamentList(BorderPane pane) {
tournamentDecorator.setTournament(null);
setCenterOfBorderPane(pane, View.tournamentList);
}
//Can be used to Open new Scene in same Stage.
//This way possible to later give object to Controller
public void showParticipantFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
/**
* Method to show the view ParticipantFormular
* @param pane the Pane where the View will be visible
*/
public void showParticipantFormular(BorderPane pane) {
setCenterOfBorderPane(pane, View.participantFormular);
}
public void showPlacesFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
/**
* Method to show the view PlacesFormular
* @param pane the Pane where the View will be visible
*/
public void showPlacesFormular(BorderPane pane) {
setCenterOfBorderPane(pane, View.placesFormular);
}
public void showGameScheduler(BorderPane pane, FactoryDecorator factoryDecorator) {
/**
* Method to show the view GameScheduler
* @param pane the Pane where the View will be visible
*/
public void showGameScheduler(BorderPane pane) {
setCenterOfBorderPane(pane, View.gameScheduler);
}
/**
* Method to change the view in the center of the boarder pane in the mainWindow
* @param pane the Pane where the View will be visible
* @param view the view which should be visible
*/
private void setCenterOfBorderPane(BorderPane pane, View view) {
FXController controller = null;
pane.setCenter(view.getPane());
resetFooter(pane, true);
}
/**
* Method to load a Game View
* @param box the box where the game view should be added.
* @param gameDecorator the gameDecorator instance of the game.
* @param factoryDecorator the factoryDecorator instance.
* @return the controller of the GameView
*/
public GameController loadGameView(VBox box, GameDecorator gameDecorator, FactoryDecorator factoryDecorator) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
@ -93,6 +136,12 @@ public class Factory {
return null;
}
/**
* Method to print information for the user to the footer of mainwindow.
* @param pane the pane where the footer should be shown.
* @param msg the text to show.
* @param error true if it's a error message.
*/
public void printMessageToFooter(BorderPane pane, String msg, boolean error) {
VBox bottom = (VBox) pane.getBottom();
Label label = new Label();
@ -121,9 +170,9 @@ public class Factory {
}
/**
*
* @param pane
* @param error
* Method to remove the messages in the footer.
* @param pane the pane were the footer should be reseted
* @param error true if the error message should be cleared.
*/
public void resetFooter(BorderPane pane,boolean error) {
VBox bottom = (VBox) pane.getBottom();
@ -138,7 +187,7 @@ public class Factory {
}
/**
* Enum for keeping the different fxml form views
* Enum of all views which can be set to the center of the mainwindow.
*/
public enum View {
tournamentList("tournamentList/tournamentList.fxml"),
@ -149,6 +198,10 @@ public class Factory {
private String fxmlFileName;
private Pane pane;
/**
* Constructor of View
* @param fxmlFileName The name of the FXML File to load.
*/
private View(String fxmlFileName) {
this.fxmlFileName = fxmlFileName;
}
@ -157,6 +210,14 @@ public class Factory {
return pane;
}
/**
* Method to laod the view
* @param tournamentDecorator the tournamentDecorator object which will be passed to the controller.
* @param fileIO the fileIO object which will be passed to the controller.
* @param factoryDecorator the factoryDecorator object which will be passed to the controller.
* @param borderPane the borderPane object which will be passed to the controller.
* @throws IOException if the fxml file is not found or can not be loaded correctly.
*/
public void loadView(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, BorderPane borderPane) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName));
this.pane = loader.load();

View File

@ -116,7 +116,7 @@ public class FactoryDecorator implements IsObservable {
*/
public void openTournamentList() {
logger.fine("Showing TournamentList view");
factory.showTournamentList((BorderPane) pane, this);
factory.showTournamentList((BorderPane) pane);
informListener();
}
@ -125,7 +125,7 @@ public class FactoryDecorator implements IsObservable {
*/
public void openParticipantForm() {
logger.fine("Showing participant form view");
factory.showParticipantFormular((BorderPane) pane, this);
factory.showParticipantFormular((BorderPane) pane);
informListener();
}
@ -134,12 +134,12 @@ public class FactoryDecorator implements IsObservable {
*/
public void openPlacesForm() {
logger.fine("Showing places form view");
factory.showPlacesFormular((BorderPane) pane, this);
factory.showPlacesFormular((BorderPane) pane);
informListener();
}
public void openScheduleView() {
factory.showGameScheduler((BorderPane) pane, this);
factory.showGameScheduler((BorderPane) pane);
informListener();
}