Commit 0bed38d8 authored by Stefan Michel's avatar Stefan Michel

View umgebaut, das ganze wird jetzt in BorderPane gebaut statt in VBox

parent e250c784
#role=tutor or student
role=tutor
role=student
tutorhost=localhost
tutorport=3579
\ No newline at end of file
......@@ -47,6 +47,7 @@ public class Main extends Application {
terrain.setHamsterName(name);
ioController.setUpHamster(name);
Stage newStage = new Stage();
newStage.setResizable(true);
Scene scene = new Scene(new MainViewCreationFX(terrain, terrainController, ioController, hamsterController,
threadManager, databaseManager), 1000, 500);
......@@ -83,6 +84,7 @@ public class Main extends Application {
primaryStage.setScene(scene);
primaryStage.setTitle(terrain.getHamsterName());
primaryStage.show();
primaryStage.setResizable(true);
primaryStage.setOnCloseRequest(event -> {
activePrograms.remove(terrain.getHamsterName());
ioController.saveFile(terrain.getHamsterName());
......
......@@ -66,9 +66,9 @@ public class NetworkManager {
return tutor.getNextRequest();
}
public void addAnswer(String code, String terrain) {
public boolean addAnswer(String code, String terrain) {
CodeTerrain codeTerrain = new CodeTerrain(code, terrain);
tutor.addAnswer(codeTerrain);
return tutor.addAnswer(codeTerrain);
}
// clean server shutdown
......
......@@ -9,7 +9,9 @@ public class Tutor extends UnicastRemoteObject implements ITutor {
private final Queue<CodeTerrain> requests = new LinkedList<>();
private final Map<UUID, CodeTerrain> answerMap = new HashMap<>();
private UUID lastId;
// eine queue der IDs damit bei die lastId nicht immer ueberschrieben wird, wenn
// eine zweite CodeTerrain nachricht ankommt, waehrend der tutor noch eine bearbeitet
private final Queue<UUID> lastIds = new LinkedList<>();
protected Tutor() throws RemoteException {
......@@ -18,14 +20,15 @@ public class Tutor extends UnicastRemoteObject implements ITutor {
// METHODS FROM INTERFACE
@Override
public UUID sendCodeTerrain(CodeTerrain codeTerrain) throws RemoteException {
public UUID sendCodeTerrain(CodeTerrain codeTerrain) {
requests.add(codeTerrain);
lastId = UUID.randomUUID();
UUID lastId = UUID.randomUUID();
lastIds.add(lastId);
return lastId;
}
@Override
public CodeTerrain getAnswer(UUID id) throws RemoteException {
public CodeTerrain getAnswer(UUID id) {
return answerMap.remove(id);
}
......@@ -35,8 +38,14 @@ public class Tutor extends UnicastRemoteObject implements ITutor {
return requests.poll();
}
public void addAnswer(CodeTerrain codeTerrain) {
answerMap.put(lastId, codeTerrain);
public boolean addAnswer(CodeTerrain codeTerrain) {
UUID lastId = lastIds.poll();
if (lastId != null) {
answerMap.put(lastId, codeTerrain);
return true;
} else {
return false;
}
}
}
......@@ -31,7 +31,7 @@ import java.util.*;
/**
* Created by Stefan Michel on 14.11.17.
*/
public class MainViewCreationFX extends VBox implements Observer {
public class MainViewCreationFX extends BorderPane implements Observer {
private final MenuBar menuBar = new MenuBar();
private final ToolBar toolBar = new ToolBar();
......@@ -84,6 +84,9 @@ public class MainViewCreationFX extends VBox implements Observer {
//toolbar erstellen
buildToolBarFX();
VBox vBox = new VBox();
vBox.getChildren().addAll(menuBar, toolBar);
splitPane.getItems().addAll(textArea, terrainPane);
//TODO anderen weg finden das center den gesamten bereich ausfuellt
......@@ -94,14 +97,18 @@ public class MainViewCreationFX extends VBox implements Observer {
footer.setMinHeight(20);
//elemente ins Borderpane einsetzen
BorderPane borderPane = new BorderPane();
borderPane.setTop(toolBar);
borderPane.setCenter(splitPane);
borderPane.setBottom(footer);
this.setTop(vBox);
this.setCenter(splitPane);
this.setBottom(footer);
this.getBottom().maxHeight(0);
//elemente in die VBox einsetzen und returnen
this.getChildren().addAll(menuBar, borderPane);
// this.getChildren().addAll(menuBar, borderPane);
//ioController erstellen
ioController.setMainViewCreationFX(this);
......@@ -201,35 +208,66 @@ public class MainViewCreationFX extends VBox implements Observer {
private Menu buildTutorMenu() {
MenuItem anfrageLaden = new MenuItem("Anfrage _laden");
MenuItem anfrageBeantworten = new MenuItem("Anfrage _beantworten");
anfrageLaden.setDisable(false);
anfrageBeantworten.setDisable(true);
anfrageLaden.setOnAction(event -> {
CodeTerrain codeTerrain = networkManager.loadRequest();
if (codeTerrain != null) {
textArea.setText(codeTerrain.getCode());
terrainController.loadTerrainFromString(codeTerrain.getTerrain());
anfrageLaden.setDisable(true);
anfrageBeantworten.setDisable(false);
} else {
new Alert(Alert.AlertType.ERROR, "keine Anfrage die geladen werden kann!").show();
}
});
MenuItem anfrageBeantworten = new MenuItem("Anfrage _beantworten");
anfrageBeantworten.setOnAction(event -> {
String terrain = terrainController.getXMLString();
String code = getInputText();
networkManager.addAnswer(code, terrain);
if (!networkManager.addAnswer(code, terrain))
new Alert(Alert.AlertType.ERROR, "du hast keine Anfrage geladen!").show();
else
anfrageBeantworten.setDisable(true);
anfrageLaden.setDisable(false);
});
return new Menu("T_utor", null, anfrageLaden, anfrageBeantworten);
}
private Menu buildStudentMenu() {
MenuItem anfrageSchicken = new MenuItem("Anfrage _schicken");
MenuItem anfrageHolen = new MenuItem("Anfrage _holen");
anfrageSchicken.setDisable(false);
anfrageHolen.setDisable(true);
anfrageSchicken.setOnAction(event -> {
String terrain = terrainController.getXMLString();
String code = getInputText();
networkManager.sendRequest(code, terrain);
try {
networkManager.sendRequest(code, terrain);
anfrageSchicken.setDisable(true);
anfrageHolen.setDisable(false);
} catch (NullPointerException e) {
new Alert(Alert.AlertType.ERROR, "keine Verbindung zum Tutor!").show();
}
});
MenuItem anfrageHolen = new MenuItem("Anfrage _holen");
anfrageHolen.setOnAction(event -> {
CodeTerrain codeTerrain = networkManager.getRequest();
textArea.setText(codeTerrain.getCode());
terrainController.loadTerrainFromString(codeTerrain.getTerrain());
if (codeTerrain != null) {
textArea.setText(codeTerrain.getCode());
terrainController.loadTerrainFromString(codeTerrain.getTerrain());
anfrageHolen.setDisable(true);
anfrageSchicken.setDisable(false);
} else {
new Alert(Alert.AlertType.ERROR, "du hast noch keine Antwort!").show();
}
});
return new Menu("St_udent", null, anfrageSchicken, anfrageHolen);
......
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