Merge pull request #50 from PM2-IT21bWIN-ruiz-mach-krea/disabling_sendbutton
Solved #48 make it impossible to send messages if not connected.
This commit is contained in:
commit
bfe703c7d8
|
@ -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<State>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
|
||||
stateChanged(newValue);
|
||||
refreshConnectionState(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue