From ce26d1673baa68e0eb51e7aa67b3ef99350d7ed0 Mon Sep 17 00:00:00 2001 From: m-gues Date: Sun, 14 Feb 2021 17:22:32 +0100 Subject: [PATCH] javadoc application main+connexion fini --- POO/src/connexion/ControleurConnexion.java | 29 +++++--- POO/src/connexion/VueConnexion.java | 3 +- POO/src/main/Utilisateur.java | 79 ++++++++++++++++++---- POO/src/main/Vue.java | 3 + 4 files changed, 91 insertions(+), 23 deletions(-) diff --git a/POO/src/connexion/ControleurConnexion.java b/POO/src/connexion/ControleurConnexion.java index 5f3d55d..5de1cd2 100644 --- a/POO/src/connexion/ControleurConnexion.java +++ b/POO/src/connexion/ControleurConnexion.java @@ -13,6 +13,7 @@ import standard.VueStandard; public class ControleurConnexion implements ActionListener{ + //Controller state : either DEBUT at initialization or ID_OK if the user has signed in private enum Etat {DEBUT, ID_OK}; private VueConnexion vue; @@ -23,6 +24,14 @@ public class ControleurConnexion implements ActionListener{ private SQLiteManager sqlManager; private VueStandard vueStd; + + /** + * Create and initialize the object in charge of monitoring all actions depending on what the user do. + * + * @param vue : associated instance of VueConnexion + * @param numtest : on local mode, allows you to choose which port to use. Integer between 0 and 3 + * + */ public ControleurConnexion(VueConnexion vue, int numtest) { this.vue = vue; this.etat = Etat.DEBUT; @@ -55,10 +64,10 @@ public class ControleurConnexion implements ActionListener{ } } catch (IOException e) { - e.printStackTrace(); } } + @Override public void actionPerformed(ActionEvent e) { String pseudo; @@ -73,7 +82,6 @@ public class ControleurConnexion implements ActionListener{ inputOK = (res == 1); } catch (SQLException e2) { - e2.printStackTrace(); } @@ -117,17 +125,13 @@ public class ControleurConnexion implements ActionListener{ try { Utilisateur.setSelf(this.username, pseudo, "localhost", this.portTCP); } catch (UnknownHostException e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); } //broadcast new pseudo try { this.comUDP.sendMessageInfoPseudo(); } catch (UnknownHostException e1) { - e1.printStackTrace(); } catch (IOException e1) { - e1.printStackTrace(); } try { @@ -135,7 +139,6 @@ public class ControleurConnexion implements ActionListener{ this.vue.setVisible(false); this.setVueStandard(); } catch (IOException e1) { - e1.printStackTrace(); } } else this.vue.setConnexionInfo("Ce nom est déjà utilisé, veuillez en choisir un autre"); @@ -143,6 +146,12 @@ public class ControleurConnexion implements ActionListener{ } + // ----- SETTING & RESETTING VIEW ----- // + + /** + * Create a new VueStandard instance and give it the hand. + * + */ private void setVueStandard() throws IOException { if(this.vueStd == null) { this.vueStd = new VueStandard("Standard", this.comUDP, this.portTCP, this.sqlManager, this.vue); @@ -153,7 +162,11 @@ public class ControleurConnexion implements ActionListener{ this.vueStd.setVisible(true); } } - + + /** + * Restore the associated instance of VueConnexion to its initial state + * + */ private void resetView() { this.etat = Etat.DEBUT; this.vue.addPasswordPanel(); diff --git a/POO/src/connexion/VueConnexion.java b/POO/src/connexion/VueConnexion.java index efef823..fc46a9b 100644 --- a/POO/src/connexion/VueConnexion.java +++ b/POO/src/connexion/VueConnexion.java @@ -1,12 +1,11 @@ package connexion; -//Importe les librairies +//Import librairies import java.awt.*; import javax.swing.*; import database.SQLiteManager; import main.Vue; -import messages.MauvaisTypeMessageException; public class VueConnexion extends Vue { diff --git a/POO/src/main/Utilisateur.java b/POO/src/main/Utilisateur.java index 9004c3b..1c69b88 100644 --- a/POO/src/main/Utilisateur.java +++ b/POO/src/main/Utilisateur.java @@ -4,9 +4,7 @@ import java.net.*; public class Utilisateur implements Serializable{ - /** - * - */ + private static final long serialVersionUID = 1L; private String id; @@ -14,48 +12,103 @@ public class Utilisateur implements Serializable{ private InetAddress ip; private int port; + //Represents the user that is currently using the application private static Utilisateur self; + + /** + * Create and initialize an object representing an user + * + * @param id : user id as String + * @param pseudo : name under which other users can see this user as String + * @param ip : ip of the device this user is currently using as InetAddress + * @param port : on local mode, port used for the TCP listen socket as int + * + */ public Utilisateur(String id, String pseudo, InetAddress ip, int port) throws UnknownHostException { this.id = id; this.pseudo = pseudo; this.ip = ip; - this.port = port; } + // ----- GETTERS ----- // + /** + * Returns user id as String + * + * @return user id as String + */ public String getId() { return id; } + /** + * Returns user pseudo as String + * + * @return user pseudo as String + */ public String getPseudo() { return pseudo; } - - public void setPseudo(String pseudo) { - this.pseudo = pseudo; - } - + + /** + * Returns user device's ip as String + * + * @return user device's ip as String + */ public InetAddress getIp() { return ip; } + /** + * Returns the port the user uses for their TCP listen socket as int + * + * @return TCP listen socket port as int + */ public int getPort() { return port; } + /** + * Returns the user currently using this instance of the application as Utilisateur + * + * @return current user as Utilisateur + */ + public static Utilisateur getSelf() { + return Utilisateur.self; + } + + + // ----- SETTERS ----- // + + /** + * Change the pseudo used by an user + * + * @param pseudo : new pseudo as String + */ + public void setPseudo(String pseudo) { + this.pseudo = pseudo; + } + + /** + * Sets the self static attribute with a new Utilisateur + * + * @param id : user id as String + * @param pseudo : name under which other users can see this user as String + * @param ip : ip of the device this user is currently using as InetAddress + * @param port : on local mode, port used for the TCP listen socket as int + */ public static void setSelf(String id, String pseudo, String host, int port) throws UnknownHostException { if(Utilisateur.self == null) { Utilisateur.self = new Utilisateur(id, pseudo, InetAddress.getByName(host), port); } } - public static Utilisateur getSelf() { - return Utilisateur.self; - } - + /** + * Sets the self static attribute with null + */ public static void resetSelf() { Utilisateur.self = null; } diff --git a/POO/src/main/Vue.java b/POO/src/main/Vue.java index 8aa9dd7..f981960 100644 --- a/POO/src/main/Vue.java +++ b/POO/src/main/Vue.java @@ -2,6 +2,9 @@ package main; import javax.swing.JFrame; + +// General class from which all VueX class derivate + public class Vue extends JFrame{ private static final long serialVersionUID = 1L;