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