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.
 | 
					 * To Contact the Model Elements needed it also holds references to message and the Connectionhandler.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class ChatWindowController {
 | 
					public class ChatWindowController {
 | 
				
			||||||
    public Button sendButton; //TODO necessary to have a attribute when not used or delete?
 | 
					 | 
				
			||||||
    private ClientConnectionHandler connectionHandler;
 | 
					    private ClientConnectionHandler connectionHandler;
 | 
				
			||||||
    private ClientMessageList messages;
 | 
					    private ClientMessageList messages;
 | 
				
			||||||
    private final WindowCloseHandler windowCloseHandler = new WindowCloseHandler();
 | 
					    private final WindowCloseHandler windowCloseHandler = new WindowCloseHandler();
 | 
				
			||||||
| 
						 | 
					@ -44,6 +43,8 @@ public class ChatWindowController {
 | 
				
			||||||
    private Button connectButton;
 | 
					    private Button connectButton;
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private TextField filterValue;
 | 
					    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() {
 | 
					    private void applicationClose() {
 | 
				
			||||||
        disconnect();
 | 
					        disconnect();
 | 
				
			||||||
| 
						 | 
					@ -121,7 +122,7 @@ public class ChatWindowController {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private void message() {
 | 
					    private void message() {
 | 
				
			||||||
        String messageString = messageField.getText().strip(); //TODO MVC ok?
 | 
					        String messageString = messageField.getText().strip();
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if (connectionHandler == null) {
 | 
					            if (connectionHandler == null) {
 | 
				
			||||||
                addError("No connection handler");
 | 
					                addError("No connection handler");
 | 
				
			||||||
| 
						 | 
					@ -190,7 +191,7 @@ public class ChatWindowController {
 | 
				
			||||||
    public void setUserName(String userName) {
 | 
					    public void setUserName(String userName) {
 | 
				
			||||||
        Platform.runLater(new Runnable() {
 | 
					        Platform.runLater(new Runnable() {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
            public void run() {             //TODO MVC ok??
 | 
					            public void run() {
 | 
				
			||||||
                userNameField.setText(userName);
 | 
					                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> {
 | 
					    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) {
 | 
					        public void handle(WindowEvent event) {
 | 
				
			||||||
            applicationClose();
 | 
					            applicationClose();
 | 
				
			||||||
| 
						 | 
					@ -251,7 +251,6 @@ public class ChatWindowController {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Starts several new Listener for Connection Handler changes by using several observable properties.
 | 
					     * Starts several new Listener for Connection Handler changes by using several observable properties.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void startConnectionHandlerListener() {
 | 
					    public void startConnectionHandlerListener() {
 | 
				
			||||||
        connectionHandler.getStateProperty().addListener(new ChangeListener<State>() {
 | 
					        connectionHandler.getStateProperty().addListener(new ChangeListener<State>() {
 | 
				
			||||||
            @Override
 | 
					            @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 serverAddress to connect to
 | 
				
			||||||
     * @param serverPort
 | 
					     * @param serverPort to connect to
 | 
				
			||||||
     * @param userName
 | 
					     * @param userName to connect as
 | 
				
			||||||
     * @throws IOException
 | 
					     * @throws IOException if connection to Server not possible
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void initialize(String serverAddress, int serverPort, String userName) throws IOException {
 | 
					    public void initialize(String serverAddress, int serverPort, String userName) throws IOException {
 | 
				
			||||||
        state.set(NEW);
 | 
					        state.set(NEW);
 | 
				
			||||||
| 
						 | 
					@ -155,7 +155,7 @@ public class ClientConnectionHandler extends ConnectionHandler implements Runnab
 | 
				
			||||||
        } catch (IOException e) {
 | 
					        } catch (IOException e) {
 | 
				
			||||||
            System.err.println("Failed to close connection." + e.getMessage());
 | 
					            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
 | 
					     * @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 {
 | 
					    public void disconnect() throws ChatProtocolException {
 | 
				
			||||||
        if (state.get() != NEW && state.get() != CONNECTED)
 | 
					        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
 | 
					     * @param messageString The message the user wants to send
 | 
				
			||||||
     * @return
 | 
					     * @return true if message is valid else false
 | 
				
			||||||
     * @throws ChatProtocolException
 | 
					     * @throws ChatProtocolException if illegal connection state
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean message(String messageString) throws ChatProtocolException {
 | 
					    public boolean message(String messageString) throws ChatProtocolException {
 | 
				
			||||||
        if (state.get() != CONNECTED) throw new ChatProtocolException("Illegal state for message: " + state);
 | 
					        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;
 | 
					        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
 | 
					     * 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.
 | 
					     * and the connection State is not ERROR.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue