Commit 1d78af2c authored by Stefan Michel's avatar Stefan Michel

an gui angebunden muss noch getestet werden

parent b4194b42
package controller;
import java.io.*;
import java.nio.file.Files;
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
*/
public class PropertiesManager {
private static PropertiesManager ourInstance = new PropertiesManager();
private Properties prop;
private String properties = "/simulator.properties";
private String defaultProperties = "#role=tutor or student\n" +
"role=student\n" +
"tutorhost=localhost\n" +
"tutorport=3579";
private PropertiesManager() {
try {
prop = new Properties();
InputStream in = getClass().getResourceAsStream(properties);
// wenn simulator.properties nicht existiert: default erstellen
if (in == null) {
setUpDefaultProps();
} else {
prop.load(in);
// pruefen, ob properties korrekt
String role = prop.getProperty("role");
if (!(role.equals("student") || role.equals("tutor"))) {
Files.delete(Paths.get("resources/simulator.properties"));
setUpDefaultProps();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static PropertiesManager getInstance() {
return ourInstance;
}
public static void main(String[] args) {
System.out.println(ourInstance.getString("role"));
}
private void setUpDefaultProps() {
try (FileOutputStream outputStream = new FileOutputStream("resources" + properties)) {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(defaultProperties);
outputStreamWriter.flush();
outputStreamWriter.close();
outputStream.close();
Reader reader = new StringReader(defaultProperties);
prop.load(reader);
} catch (IOException e) {
e.printStackTrace();
}
}
public String getString(String key) {
return prop.getProperty(key);
}
}
package network;
import java.io.Serializable;
public class CodeTerrain implements Serializable {
private String code;
private String terrain;
public CodeTerrain(String code, String terrain) {
this.code = code;
this.terrain = terrain;
}
public String getCode() {
return code;
}
public String getTerrain() {
return terrain;
}
}
package network;
import java.rmi.Remote;
public interface ITutor extends Remote {
CodeTerrain sendCodeTerrain(CodeTerrain codeTerrain);
}
package network;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
import java.util.Queue;
public class Tutor extends UnicastRemoteObject implements ITutor {
private final Queue<CodeTerrain> codeTerrains = new LinkedList<>();
protected Tutor() throws RemoteException {
}
@Override
public CodeTerrain sendCodeTerrain(CodeTerrain codeTerrain) {
return null;
}
}
package network;
import controller.PropertiesManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class TutorManager {
private final PropertiesManager propertiesManager = PropertiesManager.getInstance();
private final int port = Integer.parseInt(propertiesManager.getString("port"));
private ITutor tutor;
private Registry registry;
public TutorManager() {
try {
this.tutor = new Tutor();
LocateRegistry.createRegistry(port);
this.registry = LocateRegistry.getRegistry(port);
this.registry.rebind("Tutor", tutor);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
......@@ -46,6 +46,7 @@ public class MainViewCreationFX extends VBox implements Observer {
private ThreadManager threadManager;
private MenuItem start, pause, stop;
private Slider slider;
private PropertiesManager propertiesManager = PropertiesManager.getInstance();
public MainViewCreationFX(Terrain terrain, TerrainController terrainController, IOController ioController,
HamsterController hamsterController, ThreadManager threadManager, DatabaseManager databaseManager) {
......@@ -182,17 +183,39 @@ public class MainViewCreationFX extends VBox implements Observer {
Menu hamsterMenu = buildHamsterMenu();
Menu simulationMenu = buildSimulationMenu();
Menu beispielMenu = buildBeispielMenu();
Menu tutorialMenu = buildTutorialMenu();
menuBar.getMenus().addAll(editorMenu, territoriumMenu, hamsterMenu, simulationMenu, beispielMenu);
menuBar.getMenus().addAll(editorMenu, territoriumMenu, hamsterMenu, simulationMenu, beispielMenu, tutorialMenu);
}
private Menu buildTutorialMenu() {
if (propertiesManager.getString("role").equals("tutor")) {
return buildTutorMenu();
} else {
return buildStudentMenu();
}
}
private Menu buildTutorMenu() {
MenuItem anfrageLaden = new MenuItem("Anfrage _laden");
MenuItem anfrageBeantworten = new MenuItem("Anfrage _beantworten");
return new Menu("T_utor", null, anfrageLaden, anfrageBeantworten);
}
private Menu buildStudentMenu() {
MenuItem anfrageSchicken = new MenuItem("Anfrage _schicken");
MenuItem anfrageHolen = new MenuItem("Anfrage _holen");
return new Menu("St_udent", null, anfrageSchicken, anfrageHolen);
}
private Menu buildBeispielMenu() {
//MenuItems werden mit Grafiken und Accelelatoren gebaut
MenuItem speichern = new MenuItem("_Speichern...");
speichern.setOnAction(event -> {
new DataBaseEntryDialogBox(databaseManager, terrain, terrainController, textArea.getText());
});
speichern.setOnAction(event ->
new DataBaseEntryDialogBox(databaseManager, terrain, terrainController, textArea.getText()));
MenuItem laden = new MenuItem("_Laden...");
laden.setOnAction(event -> new GetEntryByTagDialogBox(databaseManager, terrain, terrainController, textArea));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment