javadoc application main+connexion fini

This commit is contained in:
m-gues 2021-02-14 17:22:32 +01:00
parent a6097ca49a
commit ce26d1673b
4 changed files with 91 additions and 23 deletions

View file

@ -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);
@ -154,6 +163,10 @@ public class ControleurConnexion implements ActionListener{
}
}
/**
* Restore the associated instance of VueConnexion to its initial state
*
*/
private void resetView() {
this.etat = Etat.DEBUT;
this.vue.addPasswordPanel();

View file

@ -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 {

View file

@ -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;
}

View file

@ -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;