diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java index c2c7a87..1b28669 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FXController.java @@ -8,8 +8,9 @@ public abstract class FXController { FileIO fileIO; Pane pane; IsObserver listener; + LanguageConfigurator languageConfigurator; - public FXController(){ + public FXController() { listener = new IsObserver() { @Override 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.fileIO = fileIO; this.factoryDecorator = factoryDecorator; this.pane = pane; + this.languageConfigurator = languageConfigurator; + shareGUIElementWithLanguageConfigurator(); addListener(); } + public abstract void shareGUIElementWithLanguageConfigurator(); + public abstract void loadContent(); protected void setTournamentDecorator(TournamentDecorator tournamentDecorator) { this.tournamentDecorator = tournamentDecorator; } - public void addListener(){ + public void addListener() { tournamentDecorator.addListener(listener); factoryDecorator.addListener(listener); } @@ -64,4 +74,8 @@ public abstract class FXController { protected Pane getPane() { return pane; } + + protected LanguageConfigurator getLanguageConfigurator() { + return languageConfigurator; + } } 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 dec1687..ee35ab1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java @@ -14,11 +14,12 @@ import java.io.IOException; public class Factory { private TournamentDecorator tournamentDecorator; private FileIO fileIO; + private static LanguageConfigurator languageConfigurator; - public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator) { + public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator, LanguageConfigurator languageConfigurator) { this.fileIO = fileIO; this.tournamentDecorator = tournamentDecorator; - + this.languageConfigurator = languageConfigurator; } public TournamentDecorator getTournamentDecorator() { @@ -30,9 +31,12 @@ public class Factory { } public BorderPane loadMainWindow() { - FXMLLoader loader = new FXMLLoader(getClass().getResource("mainWindow.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml")); try { - return loader.load(); + BorderPane pane = loader.load(); + FXController controller = loader.getController(); + controller.setup(languageConfigurator); + return pane; } catch (IOException e) { e.printStackTrace(); //TODO handle and logging @@ -82,7 +86,7 @@ public class Factory { FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml")); box.getChildren().add(loader.load()); GameController controller = loader.getController(); - controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, gameDecorator); + controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, gameDecorator, languageConfigurator); return controller; } catch (IOException e) { e.printStackTrace(); @@ -130,6 +134,10 @@ public class Factory { vBox.setBorder(null); } + public LanguageConfigurator getLanguageConfigurator() { + return languageConfigurator; + } + public enum View { tournamentList("tournamentList/tournamentList.fxml"), participantFormular("participantAddFormular/participantFormular.fxml"), @@ -151,7 +159,7 @@ public class Factory { FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName)); this.pane = loader.load(); FXController controller = loader.getController(); - controller.setup(tournamentDecorator, fileIO, factoryDecorator, borderPane); + controller.setup(tournamentDecorator, fileIO, factoryDecorator, borderPane, languageConfigurator); } } 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 5ab8da7..04c8104 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java @@ -54,7 +54,8 @@ public class FactoryDecorator implements IsObservable{ clearMessage(false); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); - printMessageToFooter("Fehler beim lesen der Datei.", true); + String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException"); + printMessageToFooter(msg, true); } //TODO handle and logging } @@ -169,6 +170,10 @@ public class FactoryDecorator implements IsObservable{ factory.resetFooter((BorderPane) pane, error); } + public LanguageConfigurator getLanguageConfigurator() { + return factory.getLanguageConfigurator(); + } + public void informListener() { for(IsObserver observer : listener) { observer.update(); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java new file mode 100644 index 0000000..396fa7c --- /dev/null +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java @@ -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 germanDictionary; + private Map englishDictionary; + private List labelList; + private List 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 + } +} 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 2e53ec6..b50f401 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -61,7 +61,8 @@ public class TournamentDecorator implements IsObservable{ public void saveTournament(){ executorService.execute(new saveTask()); 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 { if(fileIO.tournamentExists(name)){ //TODO:Logger - factoryDecorator.printMessageToFooter("Turniername existiert bereits",true); + String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("tournamentExists"); + factoryDecorator.printMessageToFooter(msg, true); return; } Tournament tournament = new Tournament(name, type); @@ -81,16 +83,19 @@ public class TournamentDecorator implements IsObservable{ } catch (InvalidNameException e) { e.printStackTrace(); //TODO: Logger - factoryDecorator.printMessageToFooter("Invalider Turniername",true); + String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName"); + factoryDecorator.printMessageToFooter(msg, true); } catch (Tournament.InvalidTypeException e) { e.printStackTrace(); //TODO: Logger - factoryDecorator.printMessageToFooter("Turniermodus nicht moeglich",true); + String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidMode"); + factoryDecorator.printMessageToFooter(msg, true); } catch (IOException e) { e.printStackTrace(); //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(); } catch (IOException e) { 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); } catch (Tournament.NumberOfParticipantInvalidException e) { 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(); } @@ -125,13 +132,16 @@ public class TournamentDecorator implements IsObservable{ informListener(); } catch (InvalidNameException e) { 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) { 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) { 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(); } catch (Tournament.ParticipantNotExistsException e) { 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(); } catch (InvalidNameException e) { 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(); } catch (Tournament.PlaceNotExistsException e) { e.printStackTrace(); //TODO handle and logging - factoryDecorator.printMessageToFooter("Ort existiert nicht",true); + String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("placeNotExist"); + factoryDecorator.printMessageToFooter(msg, true); } } @@ -190,7 +202,8 @@ public class TournamentDecorator implements IsObservable{ } catch (IOException e) { e.printStackTrace(); Platform.runLater(() -> { - factoryDecorator.printMessageToFooter("Datenzugriff nicht moeglich",true); + String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException"); + factoryDecorator.printMessageToFooter(msg, true); }); } } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java index 82d4c0a..8c4d22c 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java @@ -1,9 +1,6 @@ package ch.zhaw.projekt2.turnierverwaltung.main; -import ch.zhaw.projekt2.turnierverwaltung.Factory; -import ch.zhaw.projekt2.turnierverwaltung.FactoryDecorator; -import ch.zhaw.projekt2.turnierverwaltung.FileIO; -import ch.zhaw.projekt2.turnierverwaltung.TournamentDecorator; +import ch.zhaw.projekt2.turnierverwaltung.*; import javafx.application.Application; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; @@ -19,7 +16,8 @@ public class MainWindow extends Application { private FileIO fileIO = new FileIO(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds"); private FactoryDecorator factoryDecorator; private TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO); - private 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()); @Override @@ -29,6 +27,7 @@ public class MainWindow extends Application { factory.loadAllViews(factoryDecorator, pane); tournamentDecorator.setFactoryDecorator(factoryDecorator); factoryDecorator.openTournamentList(); + languageConfigurator.translateGUI(); Scene scene = new Scene(pane); primaryStage.setScene(scene); 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 ffb528b..2fd43e0 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,15 +1,33 @@ package ch.zhaw.projekt2.turnierverwaltung.main; import ch.zhaw.projekt2.turnierverwaltung.FXController; +import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; public class MainWindowController extends FXController { @FXML - void changeLangToGerman(ActionEvent event) { + private MenuItem closeBtn; + @FXML + private Label mainTitle; + + @FXML + private Menu menuItemLanguage; + + @FXML + void changeLangToGerman(ActionEvent event) { + getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN); + } + + @FXML + void changeLangToEnglish(ActionEvent event) { + getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH); } @FXML @@ -17,6 +35,15 @@ public class MainWindowController extends FXController { Platform.exit(); } + @Override + public void shareGUIElementWithLanguageConfigurator() { + getLanguageConfigurator().recieveLabel(mainTitle); + getLanguageConfigurator().recieveMenuItem(closeBtn); + getLanguageConfigurator().recieveMenuItem(menuItemLanguage); + } + + + @Override public void loadContent() { diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java index 17a823d..aedfb1a 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java @@ -1,20 +1,33 @@ package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; +import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator; import javafx.scene.control.Alert; import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; public class AlertNewSchedule extends Alert { - private ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); - private ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); - private boolean result; + private ButtonType yesButton; + private ButtonType noButton; + private Boolean result; + private String yes; + private String no; + private String titleDelete; + private String headerDelete; + private String contentDelete; - public AlertNewSchedule() { - super(AlertType.WARNING); - setTitle("Neu erstellen"); - setHeaderText("Spielplan neu erstellen?"); - setContentText("Sind Sie sicher, dass Sie den Spielplan neu erstellen moechten?\nAlle Spielfortschritte gehen daraufhin verloren!"); - getButtonTypes().setAll(yesButton,noButton); + public AlertNewSchedule(LanguageConfigurator languageConfigurator){ + super(Alert.AlertType.WARNING); + yes = languageConfigurator.getSelectedLanguage("yes"); + no = languageConfigurator.getSelectedLanguage("no"); + titleDelete = languageConfigurator.getSelectedLanguage("titleSchedule"); + headerDelete = languageConfigurator.getSelectedLanguage("headerSchedule"); + contentDelete = languageConfigurator.getSelectedLanguage("contentSchedule"); + yesButton = new ButtonType(yes, ButtonBar.ButtonData.YES); + noButton = new ButtonType(no, ButtonBar.ButtonData.NO); + setTitle(titleDelete); + setHeaderText(headerDelete); + setContentText(contentDelete); + getButtonTypes().setAll(yesButton, noButton); } public boolean showAndGetResult() { diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java index 07f4de1..2792a13 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java @@ -32,6 +32,14 @@ public class GameController extends FXController{ @FXML private TextField pointsTeamTwo; + @FXML + private Label locationLabel; + + @Override + public void shareGUIElementWithLanguageConfigurator() { + getLanguageConfigurator().recieveLabel(locationLabel); + } + @FXML void saveGameResult(Event event) { gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText()); @@ -48,6 +56,7 @@ public class GameController extends FXController{ @Override public void loadContent() { + getLanguageConfigurator().translateGUI(); participantNameOne.setText(gameDecorator.getParticipantOne()); participantNameTwo.setText(gameDecorator.getParticipantTwo()); pointsTeamOne.setText(String.valueOf(gameDecorator.getPoints1())); @@ -71,9 +80,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); this.gameDecorator = gameDecorator; + setup(languageConfigurator); placesChoiceBox.getSelectionModel().selectedItemProperty().addListener((ObservableValue observable, Place oldValue, Place newValue) -> saveGamePlace(newValue == null ? oldValue : newValue)); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java index f6e15a1..6a9a543 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java @@ -5,6 +5,7 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; +import javafx.scene.control.Labeled; import javafx.scene.layout.HBox; public class GameScheduleController extends FXController { @@ -27,10 +28,19 @@ public class GameScheduleController extends FXController { @FXML private CheckBox treeView; + @Override + public void shareGUIElementWithLanguageConfigurator() { + getLanguageConfigurator().recieveLabel(treeView); + getLanguageConfigurator().recieveLabel(createScheduleBtn); + getLanguageConfigurator().recieveLabel(editParticipantBtn); + getLanguageConfigurator().recieveLabel(editLocBtn); + getLanguageConfigurator().recieveLabel(closeTournamentBtn); + } + @FXML void createNewSchedule(ActionEvent event) { if (getTournamentDecorator().getTournament().getGameList().size() > 0) { - AlertNewSchedule alert = new AlertNewSchedule(); + AlertNewSchedule alert = new AlertNewSchedule(getLanguageConfigurator()); if (alert.showAndGetResult()) { getTournamentDecorator().createNewGameSchedule(); } 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 f2a6e7b..64a010b 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 @@ -68,6 +68,19 @@ public class ParticipantFormularController extends FXController { @FXML 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 void changedSelection(MouseEvent event){ Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java index b2a031a..21e6847 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java @@ -11,22 +11,9 @@ import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.VBox; public class PlacesFormularController extends FXController { - @FXML - private Button addBtn; - - @FXML - private VBox changeBtn; - - @FXML - private GridPane grid; - - @FXML - private Label newPlaceFormularTitle; @FXML private Button closeBtn; @@ -34,6 +21,8 @@ public class PlacesFormularController extends FXController { @FXML private Button deleteBtn; + @FXML + private Label newPlaceTitle; @FXML private Label placeListTitle; @@ -50,6 +39,17 @@ public class PlacesFormularController extends FXController { @FXML private Button saveBtn; + @Override + public void shareGUIElementWithLanguageConfigurator() { + getLanguageConfigurator().recieveLabel(placeListTitle); + getLanguageConfigurator().recieveLabel(newPlaceTitle); + getLanguageConfigurator().recieveLabel(placeNameLabel); + getLanguageConfigurator().recieveLabel(closeBtn); + getLanguageConfigurator().recieveLabel(deleteBtn); + getLanguageConfigurator().recieveLabel(saveBtn); + + } + @FXML void changedSelection(MouseEvent event){ Place place = placeListView.getSelectionModel().getSelectedItems().get(0); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java index 8aada10..5b3f650 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java @@ -1,20 +1,32 @@ package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList; +import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator; import javafx.scene.control.Alert; import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; public class AlertDelete extends Alert { - ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); - ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); + ButtonType yesButton; + ButtonType noButton; Boolean result; + String yes; + String no; + String titleDelete; + String headerDelete; + String contentDelete; - public AlertDelete(String name){ + public AlertDelete(LanguageConfigurator languageConfigurator){ super(Alert.AlertType.WARNING); - setTitle("Entfernen"); - setHeaderText("Turnier entfernen?"); - setContentText("Sind Sie sicher, dass sie das Turnier " + name + " entfernen wollen?\n" + - "Nach diesem Vorgang kann es nicht wiederhergestellt werden."); + yes = languageConfigurator.getSelectedLanguage("yes"); + no = languageConfigurator.getSelectedLanguage("no"); + titleDelete = languageConfigurator.getSelectedLanguage("titleDelete"); + 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); } 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 ab26504..d97c66b 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 @@ -25,8 +25,6 @@ public class TournamentListController extends FXController { @FXML private Button createBtn; - @FXML - private GridPane grid; @FXML private ChoiceBox modusChoiceBox; @@ -55,6 +53,17 @@ public class TournamentListController extends FXController { @FXML 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 void createTournament(ActionEvent event) { getTournamentDecorator().createTournament(tournamentNameField.getText(), modusChoiceBox.getValue()); @@ -69,7 +78,7 @@ public class TournamentListController extends FXController { @FXML void deleteTournament(ActionEvent event) { FileIO.TournamentFile tournamentFile = tournamentListView.getSelectionModel().getSelectedItems().get(0); - AlertDelete alert = new AlertDelete(tournamentFile.toString()); + AlertDelete alert = new AlertDelete(getLanguageConfigurator()); if(alert.showAndGetResult()){ getTournamentDecorator().deleteTournament(tournamentFile); } diff --git a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/MainWindow.fxml b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/MainWindow.fxml index 0648e2f..2681533 100644 --- a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/MainWindow.fxml +++ b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/MainWindow.fxml @@ -16,17 +16,18 @@ - + + - + -