javadoc
This commit is contained in:
		
							parent
							
								
									8cb83ef7ef
								
							
						
					
					
						commit
						dad15d52d2
					
				| 
						 | 
				
			
			@ -23,7 +23,6 @@ import static ch.zhaw.pm2.multichat.protocol.ConnectionHandler.State.*;
 | 
			
		|||
 * To Contact the Model Elements needed it also holds references to message and the Connectionhandler.
 | 
			
		||||
 */
 | 
			
		||||
public class ChatWindowController {
 | 
			
		||||
    public Button sendButton; //TODO necessary to have a attribute when not used or delete?
 | 
			
		||||
    private ClientConnectionHandler connectionHandler;
 | 
			
		||||
    private ClientMessageList messages;
 | 
			
		||||
    private final WindowCloseHandler windowCloseHandler = new WindowCloseHandler();
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +43,8 @@ public class ChatWindowController {
 | 
			
		|||
    private Button connectButton;
 | 
			
		||||
    @FXML
 | 
			
		||||
    private TextField filterValue;
 | 
			
		||||
    @FXML
 | 
			
		||||
    private Button sendButton;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +70,7 @@ public class ChatWindowController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method which closes the Application via use of the disconnect Method. //TODO evtl Löschen?
 | 
			
		||||
     * Method which closes the Application via use of the disconnect Method.
 | 
			
		||||
     */
 | 
			
		||||
    private void applicationClose() {
 | 
			
		||||
        disconnect();
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +122,7 @@ public class ChatWindowController {
 | 
			
		|||
     */
 | 
			
		||||
    @FXML
 | 
			
		||||
    private void message() {
 | 
			
		||||
        String messageString = messageField.getText().strip(); //TODO MVC ok?
 | 
			
		||||
        String messageString = messageField.getText().strip();
 | 
			
		||||
        try {
 | 
			
		||||
            if (connectionHandler == null) {
 | 
			
		||||
                addError("No connection handler");
 | 
			
		||||
| 
						 | 
				
			
			@ -190,7 +191,7 @@ public class ChatWindowController {
 | 
			
		|||
    public void setUserName(String userName) {
 | 
			
		||||
        Platform.runLater(new Runnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {             //TODO MVC ok??
 | 
			
		||||
            public void run() {
 | 
			
		||||
                userNameField.setText(userName);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
| 
						 | 
				
			
			@ -234,14 +235,13 @@ public class ChatWindowController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Nested Class in charge of Closing the wind
 | 
			
		||||
     * Nested Class in charge of Closing the window
 | 
			
		||||
     */
 | 
			
		||||
    class WindowCloseHandler implements EventHandler<WindowEvent> {
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * //TODO
 | 
			
		||||
         *
 | 
			
		||||
         * @param event the event which occurred
 | 
			
		||||
         * @param event the event which occurred when Windows is closed
 | 
			
		||||
         */
 | 
			
		||||
        public void handle(WindowEvent event) {
 | 
			
		||||
            applicationClose();
 | 
			
		||||
| 
						 | 
				
			
			@ -251,7 +251,6 @@ public class ChatWindowController {
 | 
			
		|||
    /**
 | 
			
		||||
     * Starts several new Listener for Connection Handler changes by using several observable properties.
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    public void startConnectionHandlerListener() {
 | 
			
		||||
        connectionHandler.getStateProperty().addListener(new ChangeListener<State>() {
 | 
			
		||||
            @Override
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,12 +47,12 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * //TODO complete javadoc
 | 
			
		||||
     * Called to initialize the ClientConnectionHandler when trying to start a connection
 | 
			
		||||
     *
 | 
			
		||||
     * @param serverAddress
 | 
			
		||||
     * @param serverPort
 | 
			
		||||
     * @param userName
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     * @param serverAddress to connect to
 | 
			
		||||
     * @param serverPort to connect to
 | 
			
		||||
     * @param userName to connect as
 | 
			
		||||
     * @throws IOException if connection to Server not possible
 | 
			
		||||
     */
 | 
			
		||||
    public void initialize(String serverAddress, int serverPort, String userName) throws IOException {
 | 
			
		||||
        state.set(NEW);
 | 
			
		||||
| 
						 | 
				
			
			@ -155,7 +155,7 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab
 | 
			
		|||
        } catch (IOException e) {
 | 
			
		||||
            System.err.println("Failed to close connection." + e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
        System.out.println("Closed Connection Handler to Server"); //TODO should be shown also when failed to close ?
 | 
			
		||||
        System.out.println("Closed Connection Handler to Server");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -255,7 +255,7 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * //Connects TODO
 | 
			
		||||
     * Send connect attempt to Server
 | 
			
		||||
     *
 | 
			
		||||
     * @throws ChatProtocolException Error that is thrown if the state is not set to NEW
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			@ -266,9 +266,9 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * //TODO
 | 
			
		||||
     * Send Disconnect attempt to server
 | 
			
		||||
     *
 | 
			
		||||
     * @throws ChatProtocolException
 | 
			
		||||
     * @throws ChatProtocolException Error tha si thrown if state is invalid
 | 
			
		||||
     */
 | 
			
		||||
    public void disconnect() throws ChatProtocolException {
 | 
			
		||||
        if (state.get() != NEW && state.get() != CONNECTED)
 | 
			
		||||
| 
						 | 
				
			
			@ -278,11 +278,11 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * //TODO
 | 
			
		||||
     * Sends message to Server
 | 
			
		||||
     *
 | 
			
		||||
     * @param messageString
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws ChatProtocolException
 | 
			
		||||
     * @param messageString The message the user wants to send
 | 
			
		||||
     * @return true if message is valid else false
 | 
			
		||||
     * @throws ChatProtocolException if illegal connection state
 | 
			
		||||
     */
 | 
			
		||||
    public boolean message(String messageString) throws ChatProtocolException {
 | 
			
		||||
        if (state.get() != CONNECTED) throw new ChatProtocolException("Illegal state for message: " + state);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,20 +75,6 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab
 | 
			
		|||
        this.connectionRegistry = registry;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** //TODO needed method?
 | 
			
		||||
     * @return the username of the connected client
 | 
			
		||||
     */
 | 
			
		||||
    public String getUserName() {
 | 
			
		||||
        return this.userName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** //TODO needed method?
 | 
			
		||||
     * @return state of the connection. Possible states are see {@link ch.zhaw.pm2.multichat.protocol.ConnectionHandler.State}
 | 
			
		||||
     */
 | 
			
		||||
    public State getState() {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * These methods runs in a while-loop as long as the socket between server and client is available
 | 
			
		||||
     * and the connection State is not ERROR.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue