sovled #42
This commit is contained in:
parent
5f6266c017
commit
46b0e4386a
|
@ -17,39 +17,34 @@ import java.io.IOException;
|
|||
|
||||
import static ch.zhaw.pm2.multichat.protocol.ConnectionHandler.State.*;
|
||||
|
||||
|
||||
public class ChatWindowController {
|
||||
private ClientConnectionHandler connectionHandler;
|
||||
private ClientMessageList messages;
|
||||
|
||||
private final WindowCloseHandler windowCloseHandler = new WindowCloseHandler();
|
||||
|
||||
@FXML
|
||||
private Pane rootPane;
|
||||
@FXML
|
||||
private TextField serverAddressField;
|
||||
@FXML
|
||||
private TextField serverPortField;
|
||||
@FXML
|
||||
private TextField userNameField;
|
||||
@FXML
|
||||
private TextField messageField;
|
||||
@FXML
|
||||
private TextArea messageArea;
|
||||
@FXML
|
||||
private Button connectButton;
|
||||
@FXML
|
||||
private Button sendButton;
|
||||
@FXML
|
||||
private TextField filterValue;
|
||||
@FXML private Pane rootPane;
|
||||
@FXML private TextField serverAddressField;
|
||||
@FXML private TextField serverPortField;
|
||||
@FXML private TextField userNameField;
|
||||
@FXML private TextField messageField;
|
||||
@FXML private TextArea messageArea;
|
||||
@FXML private Button connectButton;
|
||||
@FXML private Button sendButton;
|
||||
@FXML private TextField filterValue;
|
||||
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
public void setMessages(ClientMessageList messages) {
|
||||
this.messages = messages;
|
||||
messageListener();
|
||||
}
|
||||
|
||||
public void setConnectionHandler(ClientConnectionHandler connectionHandler) {
|
||||
public void setConnectionHandler(ClientConnectionHandler connectionHandler){
|
||||
this.connectionHandler = connectionHandler;
|
||||
startConnectionHandlerListener();
|
||||
serverAddressField.setText(connectionHandler.getServerAddressProperty().get());
|
||||
|
@ -61,7 +56,7 @@ public class ChatWindowController {
|
|||
}
|
||||
|
||||
@FXML
|
||||
private void toggleConnection() {
|
||||
private void toggleConnection () {
|
||||
if (connectionHandler == null || connectionHandler.getStateProperty().get() != CONNECTED) {
|
||||
connect();
|
||||
} else {
|
||||
|
@ -69,20 +64,16 @@ public class ChatWindowController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void connect() {
|
||||
try {
|
||||
messages.clear(); // clear message list
|
||||
startConnectionHandler();
|
||||
connectionHandler.connect();
|
||||
} catch (ChatProtocolException | IOException e) {
|
||||
} catch(ChatProtocolException | IOException e) {
|
||||
addError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates disconnecting of the connectionHandler, also checks if connectionHandler is avaible.
|
||||
*/
|
||||
private void disconnect() {
|
||||
if (connectionHandler == null) {
|
||||
addError("No connection handler");
|
||||
|
@ -95,9 +86,6 @@ public class ChatWindowController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@FXML
|
||||
private void message() {
|
||||
String messageString = messageField.getText().strip();
|
||||
|
@ -115,13 +103,13 @@ public class ChatWindowController {
|
|||
}
|
||||
|
||||
@FXML
|
||||
private void applyFilter() {
|
||||
private void applyFilter( ) {
|
||||
Platform.runLater(() -> this.messageArea.setText(messages.getFilteredMessages(filterValue.getText().strip())));
|
||||
}
|
||||
|
||||
private void startConnectionHandler() throws IOException {
|
||||
String userName = userNameField.getText();
|
||||
if (!userName.contains(" ")) {
|
||||
if(!userName.contains(" ")) {
|
||||
String serverAddress = serverAddressField.getText();
|
||||
int serverPort = Integer.parseInt(serverPortField.getText());
|
||||
connectionHandler.initialize(serverAddress, serverPort, userName);
|
||||
|
@ -145,7 +133,7 @@ public class ChatWindowController {
|
|||
connectButton.setText((newState == CONNECTED || newState == CONFIRM_DISCONNECT) ? "Disconnect" : "Connect");
|
||||
}
|
||||
});
|
||||
if (newState == DISCONNECTED) {
|
||||
if(newState == DISCONNECTED){
|
||||
connectionHandler.stopReceiving();
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +205,6 @@ public class ChatWindowController {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
private void messageListener() {
|
||||
messages.getChangedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue