diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java index c09d7ae..2bf0951 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java @@ -46,7 +46,6 @@ public class ChatWindowController { @FXML private Button sendButton; - /** * Takes a message object and stores it used as Model and also starts message Listener via messageListener method. * @@ -67,6 +66,7 @@ public class ChatWindowController { startConnectionHandlerListener(); serverAddressField.setText(connectionHandler.getServerAddressProperty().get()); serverPortField.setText(String.valueOf(connectionHandler.getServerPortProperty().get())); + refreshConnectionState(connectionHandler.getStateProperty().get()); } /** @@ -170,12 +170,20 @@ public class ChatWindowController { * * @param newState is the state that it should be set to. */ - public void stateChanged(State newState) { + public void refreshConnectionState(State newState) { // update UI (need to be run in UI thread: see Platform.runLater()) Platform.runLater(new Runnable() { @Override public void run() { - connectButton.setText((newState == CONNECTED || newState == CONFIRM_DISCONNECT) ? "Disconnect" : "Connect"); + if(newState == CONNECTED || newState == CONFIRM_DISCONNECT){ + connectButton.setText("Disconnect"); + messageField.setDisable(false); + sendButton.setDisable(false); + } else { + connectButton.setText("Connect"); + messageField.setDisable(true); + sendButton.setDisable(true); + } } }); if (newState == DISCONNECTED) { @@ -255,7 +263,7 @@ public class ChatWindowController { connectionHandler.getStateProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, State oldValue, State newValue) { - stateChanged(newValue); + refreshConnectionState(newValue); } });