From 003f065662c0b3f9ffd66d478f2436a0c0840fb4 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 13 May 2022 23:29:39 +0200 Subject: [PATCH 1/3] fixed merge problem. --- .../projekt2/turnierverwaltung/Factory.java | 9 ++++++- .../turnierverwaltung/FactoryDecorator.java | 27 +++++++++++++++---- .../TournamentDecorator.java | 1 + 3 files changed, 31 insertions(+), 6 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 1c63e4a..f58213e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java @@ -70,7 +70,7 @@ public class Factory { view.loadView(tournamentDecorator, fileIO, factoryDecorator, pane); } catch (IOException e) { e.printStackTrace(); - //TODO Handle and logging. + logger.warning("failed to load views."); } } } @@ -82,6 +82,7 @@ public class Factory { public void showTournamentList(BorderPane pane) { tournamentDecorator.setTournament(null); setCenterOfBorderPane(pane, View.tournamentList); + logger.fine("showing Tournament List"); } /** @@ -90,6 +91,7 @@ public class Factory { */ public void showParticipantFormular(BorderPane pane) { setCenterOfBorderPane(pane, View.participantFormular); + logger.fine("showing Participant Formular"); } /** @@ -98,6 +100,7 @@ public class Factory { */ public void showPlacesFormular(BorderPane pane) { setCenterOfBorderPane(pane, View.placesFormular); + logger.fine("showing Places Formular"); } /** @@ -106,6 +109,7 @@ public class Factory { */ public void showGameScheduler(BorderPane pane) { setCenterOfBorderPane(pane, View.gameScheduler); + logger.fine("showing Game Scheduler"); } /** @@ -132,6 +136,7 @@ public class Factory { box.getChildren().add(loader.load()); GameController controller = loader.getController(); controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, gameDecorator, languageConfigurator); + logger.fine("loaded game view"); return controller; } catch (IOException e) { logger.warning("Fatal error program can not continue after this: " + e ); @@ -147,6 +152,7 @@ public class Factory { * @param error true if it's a error message. */ public void printMessageToFooter(BorderPane pane, String msg, boolean error) { + logger.fine("message is printed to footer of window."); VBox bottom = (VBox) pane.getBottom(); Label label = new Label(); VBox innerVbox; @@ -179,6 +185,7 @@ public class Factory { * @param error true if the error message should be cleared. */ public void resetFooter(BorderPane pane,boolean error) { + logger.fine("messages are removed from footer of window."); VBox bottom = (VBox) pane.getBottom(); VBox vBox; if (error) { 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 258996e..840f25e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java @@ -140,11 +140,20 @@ public class FactoryDecorator implements IsObservable { informListener(); } + /** + * Initializes the view of gameSchedule + */ public void openScheduleView() { factory.showGameScheduler((BorderPane) pane); informListener(); } + /** + * Method to load all game views to show. + * @param hBoxCenter the box where the games should be shown. + * @param tournamentDecorator the tournamentDecorator to communicate to tournament + * @param treeView true if the games should be arranged like a tree. + */ public void loadGameList(HBox hBoxCenter, TournamentDecorator tournamentDecorator, boolean treeView) { hBoxCenter.getChildren().clear(); @@ -194,6 +203,13 @@ public class FactoryDecorator implements IsObservable { } } + /** + * Method to draw the lines between the game views in the tree view. + * @param gameVBox the box with the games where lines should be drawn. + * @param gameBoxHeight the heigth of a single game box. + * @param lineLength the length of the horizontal lines. + * @return a box which contains the drawn lines. + */ public VBox drawLines(VBox gameVBox, double gameBoxHeight, double lineLength) { VBox completeLineVBox = new VBox(); completeLineVBox.setAlignment(Pos.CENTER_LEFT); @@ -227,8 +243,8 @@ public class FactoryDecorator implements IsObservable { /** * Method Initializes the Game View, in order to do that a vbox is needed and the gameDecorator * @param vBox used for display - * @param gameDecorator - * @return + * @param gameDecorator the gameDecorator Object to communicate with game + * @return the controller of the loaded game view. */ public GameController openGameView(VBox vBox, GameDecorator gameDecorator) { @@ -255,9 +271,10 @@ public class FactoryDecorator implements IsObservable { factory.resetFooter((BorderPane) pane, error); } - - - + /** + * getter Method of languageConfigurator + * @return the languageConfigurator object. + */ public LanguageConfigurator getLanguageConfigurator() { return factory.getLanguageConfigurator(); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java index 0078957..2d5ae00 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -10,6 +10,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; + public class TournamentDecorator implements IsObservable{ private Tournament tournament; private FileIO fileIO; From 7f2776d49dabfa0afcaad8500ef0e8fed59bf7f0 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 13 May 2022 23:31:06 +0200 Subject: [PATCH 2/3] javadocs in FactoryDecorator.java --- .../ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 840f25e..c59b8dd 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java @@ -110,7 +110,7 @@ public class FactoryDecorator implements IsObservable { printMessageToFooter("Fehler beim lesen der Datei.", true); String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException"); printMessageToFooter(msg, true); - } //TODO handle and logging + } } /** From 6f043e7925532d6f66802d9abcc0673bd40afe67 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 13 May 2022 23:49:18 +0200 Subject: [PATCH 3/3] javadocs in TournamentDecorator.java --- .../TournamentDecorator.java | 70 ++++++++++++++++--- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java index 2d5ae00..955949f 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; public class TournamentDecorator implements IsObservable{ @@ -18,48 +19,84 @@ public class TournamentDecorator implements IsObservable{ private ExecutorService executorService; private FactoryDecorator factoryDecorator; + private static final Logger logger = Logger.getLogger(TournamentDecorator.class.getCanonicalName()); + + /** + * Constructor to initialize TournamentDecorator + * adds a listener to save the tournament every time if something is changed. + * creates a executer service to do the saving process in separate thread for better performance. + * @param fileIO + */ public TournamentDecorator(FileIO fileIO){ + logger.fine("initializing TournamentDecorator"); setFileIO(fileIO); addListener(new IsObserver() { @Override public void update() { if(tournament != null){ - saveTournament(); + logger.fine("listener to save tournament was added"); } } }); executorService = Executors.newFixedThreadPool(1); } + /** + * Setter method of FactoryDecorator + * @param factoryDecorator the factory decorator to load different views. + */ public void setFactoryDecorator(FactoryDecorator factoryDecorator) { this.factoryDecorator = factoryDecorator; } + /** + * Setter Method of FileIO + * @param fileIO the fileIO object to read and save to files. + */ public void setFileIO(FileIO fileIO) { this.fileIO = fileIO; } + /** + * setter Method of Tournament + * @param tournament the new Tournament Object which was selected by user. + */ public void setTournament(Tournament tournament) { this.tournament = tournament; } + /** + * getter Method of Tournament + * @return the actual tournament which is open. + */ public Tournament getTournament() { return tournament; } + /** + * Method to add a listener in list. + * @param observer the observer object which should be informed. + */ @Override public void addListener(IsObserver observer) { listener.add(observer); } + /** + * Method to remove a listener from list. + * @param observer the object to remove. + */ @Override public void removeListener(IsObserver observer) { listener.remove(observer); } - + /** + * Method to save the actual tournament to files. + */ public void saveTournament(){ + logger.fine("Saving Tournament to File."); executorService.execute(new saveTask()); factoryDecorator.clearMessage(false); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("save"); @@ -67,40 +104,49 @@ public class TournamentDecorator implements IsObservable{ } - + /** + * Method to create a new Tournament. It checks if the name is valid, creates a new instance of Tournament and calls + * FileIO to save the new Tournament. + * @param name The name which was entered by the user. + * @param type The type of Tournament + */ public void createTournament(String name, Tournament.Type type){ - try { if(fileIO.tournamentExists(name)){ - //TODO:Logger + logger.warning("a tournament with name " + name + "exists already."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("tournamentExists"); factoryDecorator.printMessageToFooter(msg, true); return; } Tournament tournament = new Tournament(name, type); + logger.fine("new tournament instance was created."); fileIO.saveTournament(tournament); + logger.fine("new Tournament File is saved."); factoryDecorator.clearMessage(true); informListener(); } catch (InvalidNameException e) { e.printStackTrace(); - //TODO: Logger + logger.warning("The name which was entered is invalid."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName"); factoryDecorator.printMessageToFooter(msg, true); } catch (Tournament.InvalidTypeException e) { e.printStackTrace(); - //TODO: Logger + logger.warning("The selected type of tournament is not valid."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidMode"); factoryDecorator.printMessageToFooter(msg, true); - } catch (IOException e) { e.printStackTrace(); - //TODO: Logger + logger.warning("Creating a new Tournament File was failed."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException"); factoryDecorator.printMessageToFooter(msg, true); } } + /** + * Method to delete a Tournament File + * @param tournamentFile The File which should be deleted. + */ public void deleteTournament(FileIO.TournamentFile tournamentFile){ try { fileIO.deleteTournament(tournamentFile); @@ -113,8 +159,11 @@ public class TournamentDecorator implements IsObservable{ } } + /** + * Method to create the list of games. The participants are entered in random order. + */ public void createNewGameSchedule() { - //TODO: logging + logger.fine("Creating new Game Schedule"); try { tournament.createGameSchedule(); factoryDecorator.clearMessage(true); @@ -122,6 +171,7 @@ public class TournamentDecorator implements IsObservable{ e.printStackTrace(); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("numberParticipant"); factoryDecorator.printMessageToFooter(msg, true); + logger.warning("Failed to create Game Schedule. The number of Participants is invalid."); } informListener(); }