Commit e3792f46 authored by Stefan Michel's avatar Stefan Michel
Browse files

internationalisiert

parent 21c9197c
loadrequest=Anfrage _laden
answerrequest=Anfrage _beantworten
norequestalert=keine Anfrage die geladen werden kann!
norequestloadedalert=du hast keine Anfrage geladen!
tutor=T_utor
sendrequest=Anfrage _schicken
getrequest=Anfrage _holen
noconnectionalert=keine Verbindung zum Tutor!
noresponsealert=du hast noch keine Antwort!
student=St_udent
save=_Speichern...
load=_Laden...
examples=_Beispiele
new=_Neu
open=_Öffnen
compile=_Kompilieren
print=_Drucken
exit=_Beenden
editor=_Editor
savemenu=_Speichern
xml=_XML
jaxb=_JAXB
seri=_Serialisieren
java=_.java
loadmenu=_Laden
deseri=_Deserialisieren
savepic=_Als Bild speichern
changesize=_Größe ändern...
sethamster=_Hamster platzieren
setcorn=_Korn platzieren
setwall=_Mauer platzieren
delete=_Kachel löschen
terrain=_Territorium
corns=_Körner im Maul...
left=_linksUm
forward=_vor
take=_nimm
give=_gib
hamster=_Hamster
start=_Start/Fortsetzen
pause=_Pause
stop=_Stop
simulation=_Simulation
alreadyopenalert=Dieses Programm ist bereits offen!
loadrequest=Anfrage _laden
answerrequest=Anfrage _beantworten
norequestalert=keine Anfrage die geladen werden kann!
norequestloadedalert=du hast keine Anfrage geladen!
tutor=T_utor
sendrequest=Anfrage _schicken
getrequest=Anfrage _holen
noconnectionalert=keine Verbindung zum Tutor!
noresponsealert=du hast noch keine Antwort!
student=St_udent
save=_Speichern...
load=_Laden...
examples=_Beispiele
new=_Neu
open=_Öffnen
compile=_Kompilieren
print=_Drucken
exit=_Beenden
editor=_Editor
savemenu=_Speichern
xml=_XML
jaxb=_JAXB
seri=_Serialisieren
java=_.java
loadmenu=_Laden
deseri=_Deserialisieren
savepic=_Als Bild speichern
changesize=_Größe ändern...
sethamster=_Hamster platzieren
setcorn=_Korn platzieren
setwall=_Mauer platzieren
delete=_Kachel löschen
terrain=_Territorium
corns=_Körner im Maul...
left=_linksUm
forward=_vor
take=_nimm
give=_gib
hamster=_Hamster
start=_Start/Fortsetzen
pause=_Pause
stop=_Stop
simulation=_Simulation
alreadyopenalert=Dieses Programm ist bereits offen!
language=Sprache ändern
\ No newline at end of file
loadrequest=_load request
answerrequest=_answer request
norequestalert=no request to be load!
norequestloadedalert=no request loaded!
tutor=T_utor
sendrequest=_send Request
getrequest=_get Request
noconnectionalert=no connection to tutor!
noresponsealert=no Answer to get!
student=St_udent
save=_save...
load=_load...
examples=_examples
new=_new
open=_open
compile=_compile
print=_print
exit=e_xit
editor=ed_itor
savemenu=_save
xml=_XML
jaxb=_JAXB
seri=_serialize
java=_.java
loadmenu=_load
deseri=_deserialize
savepic=_save as picture
changesize=ch_ange size...
sethamster=set _hamster
setcorn=set _corn
setwall=_set _wall
delete=_delete tile
terrain=_terrain
corns=_corns in mouth..
left=_left
forward=_forward
take=_take
give=_give
hamster=_hamster
start=_start/resume
pause=_pause
stop=s_top
simulation=_simulation
alreadyopenalert=this program was already opened!
language=language
#role=tutor or student
role=student
#Wed Jan 31 00:19:24 CET 2018
tutorport=3579
tutorhost=localhost
tutorport=3579
\ No newline at end of file
language=de
role=student
package controller;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
public class LanguageManager {
private static LanguageManager ourInstance = new LanguageManager();
private ResourceBundle bundle;
private Properties properties;
private Locale locale;
private String propertiesPath = "resources/simulator.properties";
private String bundlePath = "language";
public static LanguageManager getInstance() {
return ourInstance;
}
// aus dem JavaPraktikum Beispiel
private LanguageManager() {
properties = new Properties();
String language;
try {
properties.load(new FileInputStream(
propertiesPath));
language = properties.getProperty("language");
} catch (IOException e) {
e.printStackTrace();
language = null;
}
setUpLocale(language);
}
private void setUpLocale(String language) {
if (language != null) {
locale = new Locale(language);
} else {
locale = Locale.getDefault();
}
bundle = ResourceBundle.getBundle(bundlePath, locale);
}
public String getString(String key) {
String value = bundle.getString(key);
try {
return new String(value.getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
public void setLanguage(String language) {
try {
properties.setProperty("language", language);
FileOutputStream output = new FileOutputStream(propertiesPath);
properties.store(output,null);
output.close();
} catch (IOException e) {
e.printStackTrace();
}
setUpLocale(language);
}
}
......@@ -6,13 +6,13 @@ import java.nio.file.Paths;
import java.util.Properties;
/**
* stellt schnittstelle fuer alle anderen Klassen auf die properties datei dar.
* stellt sicher dass die properties entweder student oder tutor anzeigt
* stellt schnittstelle fuer alle anderen Klassen auf die propertiesPath datei dar.
* stellt sicher dass die propertiesPath entweder student oder tutor anzeigt
*/
public class PropertiesManager {
private static PropertiesManager ourInstance = new PropertiesManager();
private Properties prop;
private String properties = "/simulator.properties";
private String propertiesPath = "/simulator.properties";
private String defaultProperties = "#role=tutor or student\n" +
"role=student\n" +
"tutorhost=localhost\n" +
......@@ -21,18 +21,18 @@ public class PropertiesManager {
private PropertiesManager() {
try {
prop = new Properties();
InputStream in = getClass().getResourceAsStream(properties);
InputStream in = getClass().getResourceAsStream(propertiesPath);
// wenn simulator.properties nicht existiert: default erstellen
// wenn simulator.propertiesPath nicht existiert: default erstellen
if (in == null) {
setUpDefaultProps();
} else {
prop.load(in);
// pruefen, ob properties korrekt
// pruefen, ob propertiesPath korrekt
String role = prop.getProperty("role");
if (!(role.equals("student") || role.equals("tutor"))) {
Files.delete(Paths.get("resources/simulator.properties"));
Files.delete(Paths.get("resources/simulator.propertiesPath"));
setUpDefaultProps();
}
}
......@@ -52,7 +52,7 @@ public class PropertiesManager {
private void setUpDefaultProps() {
try (FileOutputStream outputStream = new FileOutputStream("resources" + properties)) {
try (FileOutputStream outputStream = new FileOutputStream("resources" + propertiesPath)) {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(defaultProperties);
outputStreamWriter.flush();
......
......@@ -26,7 +26,7 @@ public class ThreadManager {
}
public void stopThread() {
//TODO andere methode als stop finden
//TODO: andere methode als stop finden
terrain.getHamster().stopHamster();
}
......
......@@ -50,6 +50,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
private Slider slider;
private PropertiesManager propertiesManager = PropertiesManager.getInstance();
private NetworkManager networkManager = NetworkManager.getInstance();
private LanguageManager langManager = LanguageManager.getInstance();
public MainViewCreationFX(Terrain terrain, TerrainController terrainController, IOController ioController,
HamsterController hamsterController, ThreadManager threadManager, DatabaseManager databaseManager) {
......@@ -177,6 +178,9 @@ public class MainViewCreationFX extends BorderPane implements Observer {
// ---------------------------
private void buildMenuBarFX() {
menuBar.getMenus().clear();
//Hier werden die Menues gebaut
Menu editorMenu = buildEditorMenu();
Menu territoriumMenu = buildTerritoriumMenu();
......@@ -184,8 +188,29 @@ public class MainViewCreationFX extends BorderPane implements Observer {
Menu simulationMenu = buildSimulationMenu();
Menu beispielMenu = buildBeispielMenu();
Menu tutorialMenu = buildTutorialMenu();
Menu langMenu = buildLangMenu();
menuBar.getMenus().addAll(editorMenu, territoriumMenu, hamsterMenu, simulationMenu, beispielMenu, tutorialMenu);
menuBar.getMenus().addAll(editorMenu, territoriumMenu, hamsterMenu, simulationMenu, beispielMenu, tutorialMenu, langMenu);
}
private Menu buildLangMenu() {
Menu langMenu = new Menu(langManager.getString("language"));
MenuItem deMenuItem = new MenuItem("Deutsch");
deMenuItem.setOnAction(event -> {
langManager.setLanguage("de");
buildMenuBarFX();
});
MenuItem enMenuItem = new MenuItem("English");
enMenuItem.setOnAction(event -> {
langManager.setLanguage("en");
buildMenuBarFX();
});
langMenu.getItems().addAll(deMenuItem, enMenuItem);
return langMenu;
}
private Menu buildTutorialMenu() {
......@@ -197,8 +222,8 @@ public class MainViewCreationFX extends BorderPane implements Observer {
}
private Menu buildTutorMenu() {
MenuItem anfrageLaden = new MenuItem("Anfrage _laden");
MenuItem anfrageBeantworten = new MenuItem("Anfrage _beantworten");
MenuItem anfrageLaden = new MenuItem(langManager.getString("loadrequest"));
MenuItem anfrageBeantworten = new MenuItem(langManager.getString("answerrequest"));
anfrageLaden.setDisable(false);
anfrageBeantworten.setDisable(true);
......@@ -210,7 +235,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
anfrageLaden.setDisable(true);
anfrageBeantworten.setDisable(false);
} else {
new Alert(Alert.AlertType.ERROR, "keine Anfrage die geladen werden kann!").show();
new Alert(Alert.AlertType.ERROR, langManager.getString("norequestalert")).show();
}
});
......@@ -218,19 +243,19 @@ public class MainViewCreationFX extends BorderPane implements Observer {
String terrain = terrainController.getXMLString();
String code = getInputText();
if (!networkManager.addAnswer(code, terrain))
new Alert(Alert.AlertType.ERROR, "du hast keine Anfrage geladen!").show();
new Alert(Alert.AlertType.ERROR, langManager.getString("norequestloadedalert")).show();
else
anfrageBeantworten.setDisable(true);
anfrageLaden.setDisable(false);
});
return new Menu("T_utor", null, anfrageLaden, anfrageBeantworten);
return new Menu(langManager.getString("tutor"), null, anfrageLaden, anfrageBeantworten);
}
private Menu buildStudentMenu() {
MenuItem anfrageSchicken = new MenuItem("Anfrage _schicken");
MenuItem anfrageHolen = new MenuItem("Anfrage _holen");
MenuItem anfrageSchicken = new MenuItem(langManager.getString("sendrequest"));
MenuItem anfrageHolen = new MenuItem(langManager.getString("getrequest"));
anfrageSchicken.setDisable(false);
anfrageHolen.setDisable(true);
......@@ -243,7 +268,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
anfrageSchicken.setDisable(true);
anfrageHolen.setDisable(false);
} catch (NullPointerException e) {
new Alert(Alert.AlertType.ERROR, "keine Verbindung zum Tutor!").show();
new Alert(Alert.AlertType.ERROR, langManager.getString("noconnectionalert") ).show();
}
});
......@@ -255,47 +280,47 @@ public class MainViewCreationFX extends BorderPane implements Observer {
anfrageHolen.setDisable(true);
anfrageSchicken.setDisable(false);
} else {
new Alert(Alert.AlertType.ERROR, "du hast noch keine Antwort!").show();
new Alert(Alert.AlertType.ERROR, langManager.getString("noresponsealert")).show();
}
});
return new Menu("St_udent", null, anfrageSchicken, anfrageHolen);
return new Menu(langManager.getString("student"), null, anfrageSchicken, anfrageHolen);
}
private Menu buildBeispielMenu() {
//MenuItems werden mit Grafiken und Accelelatoren gebaut
MenuItem speichern = new MenuItem("_Speichern...");
MenuItem speichern = new MenuItem(langManager.getString("save"));
speichern.setOnAction(event ->
new DataBaseEntryDialogBox(databaseManager, terrain, terrainController, textArea.getText()));
MenuItem laden = new MenuItem("_Laden...");
MenuItem laden = new MenuItem(langManager.getString("load"));
laden.setOnAction(event -> new GetEntryByTagDialogBox(databaseManager, terrain, terrainController, textArea));
return new Menu("_Beispiele", null, speichern, laden);
return new Menu(langManager.getString("examples"), null, speichern, laden);
}
// In den naechsten Methoden werden die Menues gebaut
private Menu buildEditorMenu() {
//MenuItems werden mit Grafiken und Accelelatoren gebaut
MenuItem neu = new MenuItem("_Neu", new ImageView(new Image("/New16.gif")));
MenuItem neu = new MenuItem(langManager.getString("new"), new ImageView(new Image("/New16.gif")));
neu.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN));
neu.setOnAction(event -> new SetFileNameDialogBox(ioController, terrain));
MenuItem oeffnen = new MenuItem("_Öffnen", new ImageView(new Image("/Open16.gif")));
MenuItem oeffnen = new MenuItem(langManager.getString("open"), new ImageView(new Image("/Open16.gif")));
oeffnen.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN));
oeffnen.setOnAction(event -> openFileChooser());
MenuItem kompilieren = new MenuItem("_Kompilieren");
MenuItem kompilieren = new MenuItem(langManager.getString("compile"));
kompilieren.setAccelerator(new KeyCodeCombination(KeyCode.K, KeyCombination.CONTROL_DOWN));
kompilieren.setOnAction(event -> ioController.compile(terrain.getHamsterName()));
MenuItem drucken = new MenuItem("_Drucken", new ImageView(new Image("/Print16.gif")));
MenuItem drucken = new MenuItem(langManager.getString("print"), new ImageView(new Image("/Print16.gif")));
drucken.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.CONTROL_DOWN));
MenuItem beenden = new MenuItem("_Beenden");
MenuItem beenden = new MenuItem(langManager.getString("exit"));
beenden.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.CONTROL_DOWN));
beenden.setOnAction(event -> {
ioController.saveFile(terrain.getHamsterName());
......@@ -304,28 +329,28 @@ public class MainViewCreationFX extends BorderPane implements Observer {
});
return new Menu("_Editor", null, neu, oeffnen, new SeparatorMenuItem(), kompilieren,
return new Menu(langManager.getString("editor"), null, neu, oeffnen, new SeparatorMenuItem(), kompilieren,
drucken, new SeparatorMenuItem(), beenden);
}
private Menu buildTerritoriumMenu() {
//Submenues werden gebaut (dafür keine extra methode)
Menu speichern = new Menu("_Speichern");
MenuItem xml = new MenuItem("_XML");
MenuItem jaxb = new MenuItem("_JAXB");
MenuItem seri = new MenuItem("_Serialisieren");
MenuItem java = new MenuItem("_.java");
Menu speichern = new Menu(langManager.getString("savemenu"));
MenuItem xml = new MenuItem(langManager.getString("xml"));
MenuItem jaxb = new MenuItem(langManager.getString("jaxb"));
MenuItem seri = new MenuItem(langManager.getString("seri"));
MenuItem java = new MenuItem(langManager.getString("java"));
speichern.getItems().addAll(xml, jaxb, seri, java);
java.setOnAction(event -> ioController.saveFile("name"));
java.setOnAction(event -> ioController.saveFile(terrain.getName()));
seri.setOnAction(event -> terrainController.serializeTerrain());
xml.setOnAction(event -> terrainController.parseXMLAndGetTerrainName());
Menu laden = new Menu("_Laden");
MenuItem xmlladen = new MenuItem("_XML");
MenuItem jaxbladen = new MenuItem("_JAXB");
MenuItem seriladen = new MenuItem("_Deserialisieren");
Menu laden = new Menu(langManager.getString("loadmenu"));
MenuItem xmlladen = new MenuItem(langManager.getString("xml"));
MenuItem jaxbladen = new MenuItem(langManager.getString("jaxb"));
MenuItem seriladen = new MenuItem(langManager.getString("deseri"));
laden.getItems().addAll(xmlladen, jaxbladen, seriladen);
seriladen.setOnAction(event -> {
......@@ -340,21 +365,21 @@ public class MainViewCreationFX extends BorderPane implements Observer {
terrainController.loadXML(file.toString());
});
Menu bildspeichern = new Menu("_Als Bild speichern");
Menu bildspeichern = new Menu(langManager.getString("savepic"));
MenuItem jpg = new MenuItem("_JPEG");
MenuItem png = new MenuItem("_PNG");
bildspeichern.getItems().addAll(jpg, png);
MenuItem drucken = new MenuItem("_Drucken");
MenuItem groesse = new MenuItem("_Größe ändern...");
MenuItem drucken = new MenuItem(langManager.getString("print"));
MenuItem groesse = new MenuItem(langManager.getString("changesize"));
groesse.setOnAction(event -> new SetMapSizeDialogBox(terrain));
//Togglemenu wird gebaut
ToggleGroup toggleGroup = new ToggleGroup();
hamsterMenuItem = new RadioMenuItem("_Hamster platzieren");
cornMenuItem = new RadioMenuItem("_Korn platzieren");
wallMenuItem = new RadioMenuItem("_Mauer platzieren");
deleteMenuItem = new RadioMenuItem("_Kachel löschen");
hamsterMenuItem = new RadioMenuItem(langManager.getString("sethamster"));
cornMenuItem = new RadioMenuItem(langManager.getString("setcorn"));
wallMenuItem = new RadioMenuItem(langManager.getString("setwall"));
deleteMenuItem = new RadioMenuItem(langManager.getString("delete"));
// Hier die Daten vom MouseEvent werden nur an den TerrainController geschickt je nach dem welcher Button aktiv ist
territoriumPanel.setOnMouseClicked((MouseEvent event) -> selectionLogic(hamsterMenuItem.isSelected(),
......@@ -367,42 +392,43 @@ public class MainViewCreationFX extends BorderPane implements Observer {
hamsterMenuItem.isSelected();
return new Menu("_Territorium", null, speichern, laden, bildspeichern,
return new Menu(langManager.getString("terrain"), null, speichern, laden, bildspeichern,
drucken, groesse, new SeparatorMenuItem(), hamsterMenuItem, cornMenuItem, wallMenuItem, deleteMenuItem);
}
private Menu buildHamsterMenu() {
MenuItem koernerImMaul = new MenuItem("_Körner im Maul...");
//TODO: koerner anzeigen im alert
MenuItem koernerImMaul = new MenuItem(langManager.getString("corns"));
MenuItem linksUm = new MenuItem("_linksUm");
MenuItem linksUm = new MenuItem(langManager.getString("left"));
linksUm.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
linksUm.setOnAction(event -> hamsterController.turnLeft());
MenuItem vor = new MenuItem("_vor");
MenuItem vor = new MenuItem(langManager.getString("forward"));
vor.setAccelerator(new KeyCodeCombination(KeyCode.V, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
vor.setOnAction(event -> hamsterController.forward());
MenuItem nimm = new MenuItem("_nimm");
MenuItem nimm = new MenuItem(langManager.getString("take"));
nimm.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
nimm.setOnAction(event -> hamsterController.pickUp());
MenuItem gib = new MenuItem("_gib");
MenuItem gib = new MenuItem(langManager.getString("give"));
gib.setAccelerator(new KeyCodeCombination(KeyCode.G, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
gib.setOnAction(event -> hamsterController.putDown());
return new Menu("_Hamster", null, koernerImMaul, linksUm, vor, nimm, gib);
return new Menu(langManager.getString("hamster"), null, koernerImMaul, linksUm, vor, nimm, gib);
}
private Menu buildSimulationMenu() {
start = new MenuItem("_Start/Fortsetzen", new ImageView(new Image("/Play16.gif")));
start = new MenuItem(langManager.getString("start"), new ImageView(new Image("/Play16.gif")));
start.setAccelerator(new KeyCodeCombination(KeyCode.F11, KeyCombination.CONTROL_DOWN));
pause = new MenuItem("_Pause", new ImageView(new Image("/Pause16.gif")));
pause = new MenuItem(langManager.getString("pause"), new ImageView(new Image("/Pause16.gif")));
pause.setDisable(true);
stop = new MenuItem("_Stop", new ImageView(new Image("/Stop16.gif")));
stop = new MenuItem(langManager.getString("stop"), new ImageView(new Image("/Stop16.gif")));
stop.setAccelerator(new KeyCodeCombination(KeyCode.F12, KeyCombination.CONTROL_DOWN));
stop.setDisable(true);
......@@ -410,7 +436,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
pause.setOnAction(event -> threadManager.pauseThread());
stop.setOnAction(event -> threadManager.stopThread());
return new Menu("_Simulation", null, start, pause, stop);
return new Menu(langManager.getString("simulation"), null, start, pause, stop);
}
/**
......@@ -419,6 +445,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
public void openFileChooser() {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new ExtensionFilter("Java Files", "*.java"));
fileChooser.setInitialDirectory(new File("terrains/"));
File file = fileChooser.showOpenDialog(this.getScene().getWindow());
if (file != null) {
// StringBuilder schneller, da nicht synchronized
......@@ -429,7 +456,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
ioController.openFile(cutName.toString());
Main.activePrograms.add(cutName.toString());
} else
new Alert(Alert.AlertType.ERROR, "Dieses Programm ist bereits offen!").showAndWait();
new Alert(Alert.AlertType.ERROR, langManager.getString("alreadyopenalert")).showAndWait();
}
}
......@@ -439,7 +466,6 @@ public class MainViewCreationFX extends BorderPane implements Observer {
fileChooser.setInitialDirectory(new File("terrains/"));
File file = fileChooser.showOpenDialog(this.getScene().getWindow());
if (file != null) {
// StringBuilder schneller, da nicht synchronized
return file;
}
return null;
......@@ -453,22 +479,25 @@ public class MainViewCreationFX extends BorderPane implements Observer {
// neu und open
Button neu = new Button(null, new ImageView(new Image("/New24.gif")));
neu.setTooltip(new Tooltip("Neu"));
neu.setTooltip(new