Logging and docs added in several classes #27 #28 #53

Merged
brandleo merged 13 commits from logging_and_docs into main 2022-05-13 22:54:04 +02:00
19 changed files with 433 additions and 87 deletions
Showing only changes of commit bbaf70f9af - Show all commits

BIN
ClassDiagram.png Normal file

Binary file not shown.

View File

@ -8,8 +8,9 @@ public abstract class FXController {
FileIO fileIO; FileIO fileIO;
Pane pane; Pane pane;
IsObserver listener; IsObserver listener;
LanguageConfigurator languageConfigurator;
public FXController(){ public FXController() {
listener = new IsObserver() { listener = new IsObserver() {
@Override @Override
public void update() { public void update() {
@ -18,21 +19,30 @@ public abstract class FXController {
}; };
} }
public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane){ public void setup(LanguageConfigurator languageConfigurator) {
this.languageConfigurator = languageConfigurator;
shareGUIElementWithLanguageConfigurator();
}
public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane, LanguageConfigurator languageConfigurator) {
this.tournamentDecorator = tournamentDecorator; this.tournamentDecorator = tournamentDecorator;
this.fileIO = fileIO; this.fileIO = fileIO;
this.factoryDecorator = factoryDecorator; this.factoryDecorator = factoryDecorator;
this.pane = pane; this.pane = pane;
this.languageConfigurator = languageConfigurator;
shareGUIElementWithLanguageConfigurator();
addListener(); addListener();
} }
public abstract void shareGUIElementWithLanguageConfigurator();
public abstract void loadContent(); public abstract void loadContent();
protected void setTournamentDecorator(TournamentDecorator tournamentDecorator) { protected void setTournamentDecorator(TournamentDecorator tournamentDecorator) {
this.tournamentDecorator = tournamentDecorator; this.tournamentDecorator = tournamentDecorator;
} }
public void addListener(){ public void addListener() {
tournamentDecorator.addListener(listener); tournamentDecorator.addListener(listener);
factoryDecorator.addListener(listener); factoryDecorator.addListener(listener);
} }
@ -64,4 +74,8 @@ public abstract class FXController {
protected Pane getPane() { protected Pane getPane() {
return pane; return pane;
} }
protected LanguageConfigurator getLanguageConfigurator() {
return languageConfigurator;
}
} }

View File

@ -18,6 +18,7 @@ import java.util.logging.Logger;
public class Factory { public class Factory {
private TournamentDecorator tournamentDecorator; private TournamentDecorator tournamentDecorator;
private FileIO fileIO; private FileIO fileIO;
private static LanguageConfigurator languageConfigurator;
private static final Logger logger = Logger.getLogger(Factory.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(Factory.class.getCanonicalName());
@ -26,10 +27,10 @@ public class Factory {
* @param fileIO the fileIO instance which saves and reads the tournament from files. * @param fileIO the fileIO instance which saves and reads the tournament from files.
* @param tournamentDecorator the touramanetDecorator class to access the tournament. * @param tournamentDecorator the touramanetDecorator class to access the tournament.
*/ */
public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator) { public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator, LanguageConfigurator languageConfigurator) {
this.fileIO = fileIO; this.fileIO = fileIO;
this.tournamentDecorator = tournamentDecorator; this.tournamentDecorator = tournamentDecorator;
this.languageConfigurator = languageConfigurator;
} }
/** /**
@ -45,9 +46,12 @@ public class Factory {
* @return the boarder Pane which is loaded. * @return the boarder Pane which is loaded.
*/ */
public BorderPane loadMainWindow() { public BorderPane loadMainWindow() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("mainWindow.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
try { try {
return loader.load(); BorderPane pane = loader.load();
FXController controller = loader.getController();
controller.setup(languageConfigurator);
return pane;
} catch (IOException e) { } catch (IOException e) {
logger.warning("Fatal error program can not continue after this: " + e ); logger.warning("Fatal error program can not continue after this: " + e );
e.printStackTrace(); e.printStackTrace();
@ -127,7 +131,7 @@ public class Factory {
FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
box.getChildren().add(loader.load()); box.getChildren().add(loader.load());
GameController controller = loader.getController(); GameController controller = loader.getController();
controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, gameDecorator); controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, gameDecorator, languageConfigurator);
return controller; return controller;
} catch (IOException e) { } catch (IOException e) {
logger.warning("Fatal error program can not continue after this: " + e ); logger.warning("Fatal error program can not continue after this: " + e );
@ -186,6 +190,11 @@ public class Factory {
vBox.setBorder(null); vBox.setBorder(null);
} }
public LanguageConfigurator getLanguageConfigurator() {
return languageConfigurator;
}
/** /**
* Enum of all views which can be set to the center of the mainwindow. * Enum of all views which can be set to the center of the mainwindow.
*/ */
@ -222,7 +231,7 @@ public class Factory {
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName)); FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName));
this.pane = loader.load(); this.pane = loader.load();
FXController controller = loader.getController(); FXController controller = loader.getController();
controller.setup(tournamentDecorator, fileIO, factoryDecorator, borderPane); controller.setup(tournamentDecorator, fileIO, factoryDecorator, borderPane, languageConfigurator);
} }
} }

View File

@ -108,7 +108,9 @@ public class FactoryDecorator implements IsObservable {
e.printStackTrace(); e.printStackTrace();
logger.warning("Failed to open tournament file Error: " + e); logger.warning("Failed to open tournament file Error: " + e);
printMessageToFooter("Fehler beim lesen der Datei.", true); printMessageToFooter("Fehler beim lesen der Datei.", true);
} String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException");
printMessageToFooter(msg, true);
} //TODO handle and logging
} }
/** /**
@ -253,6 +255,13 @@ public class FactoryDecorator implements IsObservable {
factory.resetFooter((BorderPane) pane, error); factory.resetFooter((BorderPane) pane, error);
} }
public LanguageConfigurator getLanguageConfigurator() {
return factory.getLanguageConfigurator();
}
/** /**
* Method that informs all listeners of an update. * Method that informs all listeners of an update.
*/ */

View File

@ -0,0 +1,196 @@
package ch.zhaw.projekt2.turnierverwaltung;
import javafx.scene.control.Labeled;
import javafx.scene.control.MenuItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LanguageConfigurator {
private Language selectedLanguage;
private Map<String,String> germanDictionary;
private Map<String,String> englishDictionary;
private List<Labeled> labelList;
private List<MenuItem> menuItemList;
public LanguageConfigurator() {
selectedLanguage = Language.GERMAN;
labelList = new ArrayList<>();
menuItemList = new ArrayList<>();
germanDictionary = new HashMap<>();
englishDictionary = new HashMap<>();
setUpDictionaries();
}
private void setUpDictionaries() {
//Main
germanDictionary.put("menuItemLanguage","Sprache");
englishDictionary.put("menuItemLanguage","Language");
germanDictionary.put("closeBtn","Beenden");
englishDictionary.put("closeBtn","Close");
germanDictionary.put("mainTitle","Turnier Manager");
englishDictionary.put("mainTitle","Tournament Manager");
//Tournamentlist
germanDictionary.put("tournamentListTitle","Bestehende Turniere");
englishDictionary.put("tournamentListTitle","Existing tournaments");
germanDictionary.put("openBtn","Oeffnen");
englishDictionary.put("openBtn","Open");
germanDictionary.put("deleteBtn","Loeschen");
englishDictionary.put("deleteBtn","Delete");
germanDictionary.put("newTournamentFormularTitle","Neues Turnier erstellen");
englishDictionary.put("newTournamentFormularTitle","Create new tournament");
germanDictionary.put("tournamentNameLabel","Turnier Name:");
englishDictionary.put("tournamentNameLabel","Tournament Name:");
germanDictionary.put("tournamentModLabel","Turnier Modus:");
englishDictionary.put("tournamentModLabel","Tournament Mode:");
germanDictionary.put("createBtn","Erstellen");
englishDictionary.put("createBtn","Create");
//PlaceList
germanDictionary.put("placeListTitle","Hinzugefuegt");
englishDictionary.put("placeListTitle","Added");
germanDictionary.put("saveBtn","Speichern");
englishDictionary.put("saveBtn","Save");
germanDictionary.put("newPlaceTitle","Ort aendern/erstellen");
englishDictionary.put("newPlaceTitle","Create/Change Location");
germanDictionary.put("placeNameLabel","Ort:");
englishDictionary.put("placeNameLabel","Location:");
//GameSchedule
germanDictionary.put("treeView","Baumansicht");
englishDictionary.put("treeView","Treeview");
germanDictionary.put("createScheduleBtn","Spielplan erstellen");
englishDictionary.put("createScheduleBtn","Create game schedule");
germanDictionary.put("editParticipantBtn","Teilnehmer bearbeiten");
englishDictionary.put("editParticipantBtn","Edit Participants");
germanDictionary.put("editLocBtn","Orte bearbeiten");
englishDictionary.put("editLocBtn","Edit Locations");
germanDictionary.put("closeTournamentBtn","Turnier schliessen");
englishDictionary.put("closeTournamentBtn","Close tournament");
//ParticipantFormular
germanDictionary.put("participantListTitle","Hinzugefuegt");
englishDictionary.put("participantListTitle","Added");
germanDictionary.put("newParticipantFormularTitle","Teilnehmer aendern/erstellen");
englishDictionary.put("newParticipantFormularTitle","Change/Create Participant");
germanDictionary.put("participantNameLabel","Name:");
englishDictionary.put("participantNameLabel","Name:");
germanDictionary.put("firstNameLabel","Vorname:");
englishDictionary.put("firstNameLabel","First Name:");
germanDictionary.put("phoneNumberLabel","Telefon:");
englishDictionary.put("phoneNumberLabel","Phone:");
germanDictionary.put("birthDateLabel","Geb. Datum:");
englishDictionary.put("birthDateLabel","Birthdate:");
//Game
germanDictionary.put("locationLabel","Ort:");
englishDictionary.put("locationLabel","Location:");
//Error
germanDictionary.put("IOException","Fehler beim lesen der Datei");
englishDictionary.put("IOException","Could not read file");
germanDictionary.put("tournamentExists","Turniername vergeben");
englishDictionary.put("tournamentExists","Tournament exists already");
germanDictionary.put("invalidName","Name nicht gueltig");
englishDictionary.put("invalidName","Name not valid");
germanDictionary.put("invalidMode","Modus nicht gueltig");
englishDictionary.put("invalidMode","Mode not valid");
germanDictionary.put("numberParticipant","Anzahl Spieler muss mindestens 4 sein und eine Potenz von 2");
englishDictionary.put("numberParticipant","Number of players must be greater than 3 and power of 2");
germanDictionary.put("invalidPhone","Telefonnummer nicht gueltig");
englishDictionary.put("invalidPhone","Phonenumber not valid");
germanDictionary.put("invalidDate","Geburtsdatum nicht gueltig");
englishDictionary.put("invalidDate","Birthdate not valid");
germanDictionary.put("participantNotExist","Teilnehmer existiert nicht");
englishDictionary.put("participantNotExist","Participant does not exist");
germanDictionary.put("placeNotExist","Teilnehmer existiert nicht");
englishDictionary.put("placeNotExist","Participant does not exist");
//SaveMsg
germanDictionary.put("save","Zuletzt gespeichert: ");
englishDictionary.put("save","Last saved: ");
//Alert
germanDictionary.put("yes","Ja");
englishDictionary.put("yes","Yes");
germanDictionary.put("no","Nein");
englishDictionary.put("no","No");
germanDictionary.put("titleDelete","Entfernen");
englishDictionary.put("titleDelete","Remove");
germanDictionary.put("headerDelete","Turnier entfernen?");
englishDictionary.put("headerDelete","Delete Tournament?");
germanDictionary.put("contentDelete","Sind Sie sicher, dass sie das Turnier entfernen wollen?\nNach diesem Vorgang kann es nicht wiederhergestellt werden.");
englishDictionary.put("contentDelete","Are you shure you want to delete the tournament?\nAfter that there is no way to restore.");
germanDictionary.put("titleSchedule","Neu erstellen");
englishDictionary.put("titleSchedule","Create new");
germanDictionary.put("headerSchedule","Spielplan neu erstellen?");
englishDictionary.put("headerSchedule","Create new Schedule?");
germanDictionary.put("contentSchedule","Sind Sie sicher, dass Sie den Spielplan neu erstellen moechten?\nAlle Spielfortschritte gehen daraufhin verloren!");
englishDictionary.put("contentSchedule","Are you shure you want to create a new game schedule?\nAll results will be lost!");
}
public void translateGUI() {
String word = "";
for (Labeled label : labelList) {
switch (selectedLanguage) {
case GERMAN -> {
word = germanDictionary.get(label.getId());
}
case ENGLISH -> {
word = englishDictionary.get(label.getId());
}
}
if(word != null) {
label.setText(word);
} else {
//TODO LOG
}
}
for (MenuItem item : menuItemList) {
switch (selectedLanguage) {
case GERMAN -> {
word = germanDictionary.get(item.getId());
}
case ENGLISH -> {
word = englishDictionary.get(item.getId());
}
}
if(word != null) {
item.setText(word);
} else {
//TODO LOG
}
}
}
public void recieveLabel(Labeled label) {
if (label != null) {
labelList.add(label);
}
}
public void recieveMenuItem(MenuItem item) {
menuItemList.add(item);
}
public void changeLanguage(Language language) {
this.selectedLanguage = language;
translateGUI();
}
public String getSelectedLanguage(String getMsg) {
String word = "";
switch (selectedLanguage) {
case GERMAN -> word = germanDictionary.getOrDefault(getMsg,"check Logs");
case ENGLISH -> word = englishDictionary.getOrDefault(getMsg,"check Logs");
}
if (word.equals("check Logs")) {
//TODO Log
}
return word;
}
public enum Language {
ENGLISH,GERMAN
}
}

View File

@ -61,7 +61,8 @@ public class TournamentDecorator implements IsObservable{
public void saveTournament(){ public void saveTournament(){
executorService.execute(new saveTask()); executorService.execute(new saveTask());
factoryDecorator.clearMessage(false); factoryDecorator.clearMessage(false);
factoryDecorator.printMessageToFooter("Zuletzt gespeichert: " + new Date().toString(),false); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("save");
factoryDecorator.printMessageToFooter(msg + new Date().toString(),false);
} }
@ -71,7 +72,8 @@ public class TournamentDecorator implements IsObservable{
try { try {
if(fileIO.tournamentExists(name)){ if(fileIO.tournamentExists(name)){
//TODO:Logger //TODO:Logger
factoryDecorator.printMessageToFooter("Turniername existiert bereits",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("tournamentExists");
factoryDecorator.printMessageToFooter(msg, true);
return; return;
} }
Tournament tournament = new Tournament(name, type); Tournament tournament = new Tournament(name, type);
@ -81,16 +83,19 @@ public class TournamentDecorator implements IsObservable{
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
e.printStackTrace(); e.printStackTrace();
//TODO: Logger //TODO: Logger
factoryDecorator.printMessageToFooter("Invalider Turniername",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName");
factoryDecorator.printMessageToFooter(msg, true);
} catch (Tournament.InvalidTypeException e) { } catch (Tournament.InvalidTypeException e) {
e.printStackTrace(); e.printStackTrace();
//TODO: Logger //TODO: Logger
factoryDecorator.printMessageToFooter("Turniermodus nicht moeglich",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidMode");
factoryDecorator.printMessageToFooter(msg, true);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
//TODO: Logger //TODO: Logger
factoryDecorator.printMessageToFooter("Fehler bei Dateizugriff",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException");
factoryDecorator.printMessageToFooter(msg, true);
} }
} }
@ -102,7 +107,8 @@ public class TournamentDecorator implements IsObservable{
informListener(); informListener();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Fehler bei Dateizugriff",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException");
factoryDecorator.printMessageToFooter(msg, true);
} }
} }
@ -113,7 +119,8 @@ public class TournamentDecorator implements IsObservable{
factoryDecorator.clearMessage(true); factoryDecorator.clearMessage(true);
} catch (Tournament.NumberOfParticipantInvalidException e) { } catch (Tournament.NumberOfParticipantInvalidException e) {
e.printStackTrace(); e.printStackTrace();
factoryDecorator.printMessageToFooter("Anzahl Teilnehmer muss mindestens 4 betragen und eine Potenz von 2 sein.",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("numberParticipant");
factoryDecorator.printMessageToFooter(msg, true);
} }
informListener(); informListener();
} }
@ -125,13 +132,16 @@ public class TournamentDecorator implements IsObservable{
informListener(); informListener();
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalider Teilnehmername",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName");
factoryDecorator.printMessageToFooter(msg, true);
} catch (Person.InvalidPhoneNumberException e) { } catch (Person.InvalidPhoneNumberException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalide Telefonnummer",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidPhone");
factoryDecorator.printMessageToFooter(msg, true);
} catch (Player.InvalidDateException e) { } catch (Player.InvalidDateException e) {
e.printStackTrace(); e.printStackTrace();
factoryDecorator.printMessageToFooter("Ungueltiges Geburtsdatum", true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidDate");
factoryDecorator.printMessageToFooter(msg, true);
} }
} }
@ -142,8 +152,8 @@ public class TournamentDecorator implements IsObservable{
informListener(); informListener();
} catch (Tournament.ParticipantNotExistsException e) { } catch (Tournament.ParticipantNotExistsException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Teilnehmer existiert nicht",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("participantNotExist");
factoryDecorator.printMessageToFooter(msg, true);
} }
} }
@ -154,7 +164,8 @@ public class TournamentDecorator implements IsObservable{
informListener(); informListener();
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalider Ortsname",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName");
factoryDecorator.printMessageToFooter(msg, true);
} }
} }
@ -165,7 +176,8 @@ public class TournamentDecorator implements IsObservable{
informListener(); informListener();
} catch (Tournament.PlaceNotExistsException e) { } catch (Tournament.PlaceNotExistsException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Ort existiert nicht",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("placeNotExist");
factoryDecorator.printMessageToFooter(msg, true);
} }
} }
@ -191,7 +203,8 @@ public class TournamentDecorator implements IsObservable{
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Platform.runLater(() -> { Platform.runLater(() -> {
factoryDecorator.printMessageToFooter("Datenzugriff nicht moeglich",true); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException");
factoryDecorator.printMessageToFooter(msg, true);
}); });
} }
} }

View File

@ -1,9 +1,6 @@
package ch.zhaw.projekt2.turnierverwaltung.main; package ch.zhaw.projekt2.turnierverwaltung.main;
import ch.zhaw.projekt2.turnierverwaltung.Factory; import ch.zhaw.projekt2.turnierverwaltung.*;
import ch.zhaw.projekt2.turnierverwaltung.FactoryDecorator;
import ch.zhaw.projekt2.turnierverwaltung.FileIO;
import ch.zhaw.projekt2.turnierverwaltung.TournamentDecorator;
import javafx.application.Application; import javafx.application.Application;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
@ -19,10 +16,11 @@ public class MainWindow extends Application {
private final FileIO fileIO = new FileIO(System.getProperty("user.dir") + private final FileIO fileIO = new FileIO(System.getProperty("user.dir") +
System.getProperty("file.separator") + "tournierverwaltung_angrynerds"); System.getProperty("file.separator") + "tournierverwaltung_angrynerds");
private FactoryDecorator factoryDecorator; private FactoryDecorator factoryDecorator;
private final TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO); private TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO);
private final Factory factory = new Factory(fileIO, tournamentDecorator); private LanguageConfigurator languageConfigurator = new LanguageConfigurator();
private Factory factory = new Factory(fileIO, tournamentDecorator, languageConfigurator);
private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName());
private static final Logger logger = Logger.getLogger(MainWindow.class.getCanonicalName());
/** /**
* Start method used to initialize the main window and load it's needed component * Start method used to initialize the main window and load it's needed component
@ -38,6 +36,7 @@ public class MainWindow extends Application {
factory.loadAllViews(factoryDecorator, pane); factory.loadAllViews(factoryDecorator, pane);
tournamentDecorator.setFactoryDecorator(factoryDecorator); tournamentDecorator.setFactoryDecorator(factoryDecorator);
factoryDecorator.openTournamentList(); factoryDecorator.openTournamentList();
languageConfigurator.translateGUI();
Scene scene = new Scene(pane); Scene scene = new Scene(pane);
primaryStage.setScene(scene); primaryStage.setScene(scene);

View File

@ -1,8 +1,12 @@
package ch.zhaw.projekt2.turnierverwaltung.main; package ch.zhaw.projekt2.turnierverwaltung.main;
import ch.zhaw.projekt2.turnierverwaltung.FXController; import ch.zhaw.projekt2.turnierverwaltung.FXController;
import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -14,14 +18,29 @@ import java.util.logging.Logger;
*/ */
public class MainWindowController extends FXController { public class MainWindowController extends FXController {
private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName());
@FXML
private MenuItem closeBtn;
@FXML
private Label mainTitle;
@FXML
private Menu menuItemLanguage;
/** /**
* Method changes the language Setting to german * Method changes the language Setting to german
*/ */
@FXML @FXML
void changeLangToGerman() { void changeLangToGerman(ActionEvent event) {
logger.fine("language setting changed to german"); getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN);
}
@FXML
void changeLangToEnglish(ActionEvent event) {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH);
} }
/** /**
@ -36,6 +55,15 @@ public class MainWindowController extends FXController {
/** /**
* There is no content to load * There is no content to load
*/ */
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(mainTitle);
getLanguageConfigurator().recieveMenuItem(closeBtn);
getLanguageConfigurator().recieveMenuItem(menuItemLanguage);
}
@Override @Override
public void loadContent() { public void loadContent() {
} }

View File

@ -1,6 +1,8 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.FileIO; import ch.zhaw.projekt2.turnierverwaltung.FileIO;
import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
@ -12,21 +14,27 @@ import java.util.logging.Logger;
* Class that is used to display the popup window to confirm a sensitive action of the user. * Class that is used to display the popup window to confirm a sensitive action of the user.
*/ */
public class AlertNewSchedule extends Alert { public class AlertNewSchedule extends Alert {
private final ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); private ButtonType yesButton;
private final ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); private ButtonType noButton;
private boolean result; private Boolean result;
private String yes;
private String no;
private String titleDelete;
private String headerDelete;
private String contentDelete;
private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); public AlertNewSchedule(LanguageConfigurator languageConfigurator){
super(Alert.AlertType.WARNING);
/** yes = languageConfigurator.getSelectedLanguage("yes");
* Popup to ask the user if he is sure that he wants to reshuffle the game board. no = languageConfigurator.getSelectedLanguage("no");
*/ titleDelete = languageConfigurator.getSelectedLanguage("titleSchedule");
public AlertNewSchedule() { headerDelete = languageConfigurator.getSelectedLanguage("headerSchedule");
super(AlertType.WARNING); contentDelete = languageConfigurator.getSelectedLanguage("contentSchedule");
logger.fine("Displaying Popup to ask user if he wants to reshuffle the game board"); yesButton = new ButtonType(yes, ButtonBar.ButtonData.YES);
setTitle("Neu erstellen"); noButton = new ButtonType(no, ButtonBar.ButtonData.NO);
setHeaderText("Spielplan neu erstellen?"); setTitle(titleDelete);
setContentText("Sind Sie sicher, dass Sie den Spielplan neu erstellen moechten?\nAlle Spielfortschritte gehen daraufhin verloren!"); setHeaderText(headerDelete);
setContentText(contentDelete);
getButtonTypes().setAll(yesButton, noButton); getButtonTypes().setAll(yesButton, noButton);
} }

View File

@ -36,7 +36,16 @@ public class GameController extends FXController{
private TextField pointsTeamTwo; private TextField pointsTeamTwo;
@FXML @FXML
void saveGameResult() {
private Label locationLabel;
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(locationLabel);
}
@FXML
void saveGameResult(Event event) {
gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText()); gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText());
} }
@ -51,6 +60,7 @@ public class GameController extends FXController{
@Override @Override
public void loadContent() { public void loadContent() {
getLanguageConfigurator().translateGUI();
participantNameOne.setText(gameDecorator.getParticipantOne()); participantNameOne.setText(gameDecorator.getParticipantOne());
participantNameTwo.setText(gameDecorator.getParticipantTwo()); participantNameTwo.setText(gameDecorator.getParticipantTwo());
pointsTeamOne.setText(String.valueOf(gameDecorator.getPoints1())); pointsTeamOne.setText(String.valueOf(gameDecorator.getPoints1()));
@ -74,9 +84,10 @@ public class GameController extends FXController{
} }
public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane, GameDecorator gameDecorator) { public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane, GameDecorator gameDecorator,LanguageConfigurator languageConfigurator) {
setTournamentDecorator(tournamentDecorator); setTournamentDecorator(tournamentDecorator);
this.gameDecorator = gameDecorator; this.gameDecorator = gameDecorator;
setup(languageConfigurator);
placesChoiceBox.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends Place> observable, Place oldValue, Place newValue) -> saveGamePlace(newValue == null ? oldValue : newValue)); placesChoiceBox.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends Place> observable, Place oldValue, Place newValue) -> saveGamePlace(newValue == null ? oldValue : newValue));
} }

View File

@ -5,6 +5,7 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
import javafx.scene.control.Labeled;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
public class GameScheduleController extends FXController { public class GameScheduleController extends FXController {
@ -27,10 +28,19 @@ public class GameScheduleController extends FXController {
@FXML @FXML
private CheckBox treeView; private CheckBox treeView;
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(treeView);
getLanguageConfigurator().recieveLabel(createScheduleBtn);
getLanguageConfigurator().recieveLabel(editParticipantBtn);
getLanguageConfigurator().recieveLabel(editLocBtn);
getLanguageConfigurator().recieveLabel(closeTournamentBtn);
}
@FXML @FXML
void createNewSchedule(ActionEvent event) { void createNewSchedule(ActionEvent event) {
if (getTournamentDecorator().getTournament().getGameList().size() > 0) { if (getTournamentDecorator().getTournament().getGameList().size() > 0) {
AlertNewSchedule alert = new AlertNewSchedule(); AlertNewSchedule alert = new AlertNewSchedule(getLanguageConfigurator());
if (alert.showAndGetResult()) { if (alert.showAndGetResult()) {
getTournamentDecorator().createNewGameSchedule(); getTournamentDecorator().createNewGameSchedule();
} }

View File

@ -68,6 +68,19 @@ public class ParticipantFormularController extends FXController {
@FXML @FXML
private Button saveBtn; private Button saveBtn;
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(participantListTitle);
getLanguageConfigurator().recieveLabel(closeBtn);
getLanguageConfigurator().recieveLabel(deleteBtn);
getLanguageConfigurator().recieveLabel(newParticipantFormularTitle);
getLanguageConfigurator().recieveLabel(participantNameLabel);
getLanguageConfigurator().recieveLabel(firstNameLabel);
getLanguageConfigurator().recieveLabel(phoneNumberLabel);
getLanguageConfigurator().recieveLabel(birthDateLabel);
getLanguageConfigurator().recieveLabel(saveBtn);
}
@FXML @FXML
void changedSelection(MouseEvent event){ void changedSelection(MouseEvent event){
Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0); Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0);

View File

@ -11,6 +11,8 @@ import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.input.MouseEvent;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@ -18,17 +20,6 @@ import java.util.logging.Logger;
*/ */
public class PlacesFormularController extends FXController { public class PlacesFormularController extends FXController {
@FXML
private Button addBtn;
@FXML
private VBox changeBtn;
@FXML
private GridPane grid;
@FXML
private Label newPlaceFormularTitle;
@FXML @FXML
private Button closeBtn; private Button closeBtn;
@ -36,6 +27,8 @@ public class PlacesFormularController extends FXController {
@FXML @FXML
private Button deleteBtn; private Button deleteBtn;
@FXML
private Label newPlaceTitle;
@FXML @FXML
private Label placeListTitle; private Label placeListTitle;
@ -52,8 +45,21 @@ public class PlacesFormularController extends FXController {
@FXML @FXML
private Button saveBtn; private Button saveBtn;
private static final Logger logger = Logger.getLogger(PlacesFormularController.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(PlacesFormularController.class.getCanonicalName());
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(placeListTitle);
getLanguageConfigurator().recieveLabel(newPlaceTitle);
getLanguageConfigurator().recieveLabel(placeNameLabel);
getLanguageConfigurator().recieveLabel(closeBtn);
getLanguageConfigurator().recieveLabel(deleteBtn);
getLanguageConfigurator().recieveLabel(saveBtn);
}
/** /**
* Selects an item (place) from the List view * Selects an item (place) from the List view
*/ */

View File

@ -1,20 +1,32 @@
package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList; package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList;
import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
public class AlertDelete extends Alert { public class AlertDelete extends Alert {
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); ButtonType yesButton;
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); ButtonType noButton;
Boolean result; Boolean result;
String yes;
String no;
String titleDelete;
String headerDelete;
String contentDelete;
public AlertDelete(String name){ public AlertDelete(LanguageConfigurator languageConfigurator){
super(Alert.AlertType.WARNING); super(Alert.AlertType.WARNING);
setTitle("Entfernen"); yes = languageConfigurator.getSelectedLanguage("yes");
setHeaderText("Turnier entfernen?"); no = languageConfigurator.getSelectedLanguage("no");
setContentText("Sind Sie sicher, dass sie das Turnier " + name + " entfernen wollen?\n" + titleDelete = languageConfigurator.getSelectedLanguage("titleDelete");
"Nach diesem Vorgang kann es nicht wiederhergestellt werden."); headerDelete = languageConfigurator.getSelectedLanguage("headerDelete");
contentDelete = languageConfigurator.getSelectedLanguage("contentDelete");
yesButton = new ButtonType(yes, ButtonBar.ButtonData.YES);
noButton = new ButtonType(no, ButtonBar.ButtonData.NO);
setTitle(titleDelete);
setHeaderText(headerDelete);
setContentText(contentDelete);
getButtonTypes().setAll(yesButton, noButton); getButtonTypes().setAll(yesButton, noButton);
} }

View File

@ -25,8 +25,6 @@ public class TournamentListController extends FXController {
@FXML @FXML
private Button createBtn; private Button createBtn;
@FXML
private GridPane grid;
@FXML @FXML
private ChoiceBox<Tournament.Type> modusChoiceBox; private ChoiceBox<Tournament.Type> modusChoiceBox;
@ -55,6 +53,17 @@ public class TournamentListController extends FXController {
@FXML @FXML
private TextField tournamentNameField; private TextField tournamentNameField;
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(createBtn);
getLanguageConfigurator().recieveLabel(newTournamentFormularTitle);
getLanguageConfigurator().recieveLabel(openBtn);
getLanguageConfigurator().recieveLabel(deleteBtn);
getLanguageConfigurator().recieveLabel(tournamentListTitle);
getLanguageConfigurator().recieveLabel(tournamentModLabel);
getLanguageConfigurator().recieveLabel(tournamentNameLabel);
}
@FXML @FXML
void createTournament(ActionEvent event) { void createTournament(ActionEvent event) {
getTournamentDecorator().createTournament(tournamentNameField.getText(), modusChoiceBox.getValue()); getTournamentDecorator().createTournament(tournamentNameField.getText(), modusChoiceBox.getValue());
@ -69,7 +78,7 @@ public class TournamentListController extends FXController {
@FXML @FXML
void deleteTournament(ActionEvent event) { void deleteTournament(ActionEvent event) {
FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0);
AlertDelete alert = new AlertDelete(tournamentFile.toString()); AlertDelete alert = new AlertDelete(getLanguageConfigurator());
if(alert.showAndGetResult()){ if(alert.showAndGetResult()){
getTournamentDecorator().deleteTournament(tournamentFile); getTournamentDecorator().deleteTournament(tournamentFile);
} }

View File

@ -16,17 +16,18 @@
<menus> <menus>
<Menu mnemonicParsing="false" text="Start"> <Menu mnemonicParsing="false" text="Start">
<items> <items>
<Menu mnemonicParsing="false" text="Sprache"> <Menu fx:id="menuItemLanguage" mnemonicParsing="false" text="Sprache">
<items> <items>
<MenuItem mnemonicParsing="false" onAction="#changeLangToGerman" text="Deutsch" /> <MenuItem mnemonicParsing="false" onAction="#changeLangToGerman" text="Deutsch" />
<MenuItem mnemonicParsing="false" onAction="#changeLangToEnglish" text="English" />
</items> </items>
</Menu> </Menu>
<MenuItem mnemonicParsing="false" onAction="#closeApplication" text="Close" /> <MenuItem fx:id="closeBtn" mnemonicParsing="false" onAction="#closeApplication" text="Close" />
</items> </items>
</Menu> </Menu>
</menus> </menus>
</MenuBar> </MenuBar>
<Label text="Turnier Manager"> <Label fx:id="mainTitle" text="Turnier Manager">
<font> <font>
<Font name="System Bold" size="40.0" /> <Font name="System Bold" size="40.0" />
</font> </font>

View File

@ -42,7 +42,7 @@
</HBox> </HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children> <children>
<Label text="Ort"> <Label fx:id="locationLabel" text="Ort">
<HBox.margin> <HBox.margin>
<Insets right="20.0" /> <Insets right="20.0" />
</HBox.margin> </HBox.margin>

View File

@ -18,7 +18,7 @@
<top> <top>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children> <children>
<CheckBox fx:id="treeView" mnemonicParsing="false" onAction="#changeView" selected="true" text="Baumansicht"> <CheckBox fx:id="treeView" minWidth="100.0" mnemonicParsing="false" onAction="#changeView" selected="true" text="Baumansicht" textOverrun="WORD_ELLIPSIS" wrapText="true">
<HBox.margin> <HBox.margin>
<Insets left="20.0" right="20.0" /> <Insets left="20.0" right="20.0" />
</HBox.margin> </HBox.margin>

View File

@ -1,11 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?> <?import javafx.scene.control.Label?>
<?import javafx.scene.text.*?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular.PlacesFormularController"> <HBox alignment="CENTER" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular.PlacesFormularController">
<children> <children>
<VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS"> <VBox alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
<children> <children>
@ -48,7 +56,7 @@
</Separator> </Separator>
<VBox fx:id="changeBtn" alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS"> <VBox fx:id="changeBtn" alignment="TOP_CENTER" prefHeight="331.0" prefWidth="308.0" HBox.hgrow="ALWAYS">
<children> <children>
<Label fx:id="newplaceFormularTitle" text="Ort ändern/erstellen"> <Label fx:id="newPlaceTitle" text="Ort ändern/erstellen">
<font> <font>
<Font name="System Bold" size="21.0" /> <Font name="System Bold" size="21.0" />
</font> </font>