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
|
@FXML
|
||||||
private Button sendButton;
|
private Button sendButton;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a message object and stores it used as Model and also starts message Listener via messageListener method.
|
* 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();
|
startConnectionHandlerListener();
|
||||||
serverAddressField.setText(connectionHandler.getServerAddressProperty().get());
|
serverAddressField.setText(connectionHandler.getServerAddressProperty().get());
|
||||||
serverPortField.setText(String.valueOf(connectionHandler.getServerPortProperty().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.
|
* @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())
|
// update UI (need to be run in UI thread: see Platform.runLater())
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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) {
|
if (newState == DISCONNECTED) {
|
||||||
|
@ -255,7 +263,7 @@ public class ChatWindowController {
|
||||||
connectionHandler.getStateProperty().addListener(new ChangeListener<State>() {
|
connectionHandler.getStateProperty().addListener(new ChangeListener<State>() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
|
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
|
||||||
stateChanged(newValue);
|
refreshConnectionState(newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue