javadoc application main+connexion fini
This commit is contained in:
parent
a6097ca49a
commit
ce26d1673b
4 changed files with 91 additions and 23 deletions
|
@ -13,6 +13,7 @@ import standard.VueStandard;
|
||||||
|
|
||||||
public class ControleurConnexion implements ActionListener{
|
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 enum Etat {DEBUT, ID_OK};
|
||||||
|
|
||||||
private VueConnexion vue;
|
private VueConnexion vue;
|
||||||
|
@ -23,6 +24,14 @@ public class ControleurConnexion implements ActionListener{
|
||||||
private SQLiteManager sqlManager;
|
private SQLiteManager sqlManager;
|
||||||
private VueStandard vueStd;
|
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) {
|
public ControleurConnexion(VueConnexion vue, int numtest) {
|
||||||
this.vue = vue;
|
this.vue = vue;
|
||||||
this.etat = Etat.DEBUT;
|
this.etat = Etat.DEBUT;
|
||||||
|
@ -55,10 +64,10 @@ public class ControleurConnexion implements ActionListener{
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String pseudo;
|
String pseudo;
|
||||||
|
@ -73,7 +82,6 @@ public class ControleurConnexion implements ActionListener{
|
||||||
inputOK = (res == 1);
|
inputOK = (res == 1);
|
||||||
|
|
||||||
} catch (SQLException e2) {
|
} catch (SQLException e2) {
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,17 +125,13 @@ public class ControleurConnexion implements ActionListener{
|
||||||
try {
|
try {
|
||||||
Utilisateur.setSelf(this.username, pseudo, "localhost", this.portTCP);
|
Utilisateur.setSelf(this.username, pseudo, "localhost", this.portTCP);
|
||||||
} catch (UnknownHostException e2) {
|
} catch (UnknownHostException e2) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//broadcast new pseudo
|
//broadcast new pseudo
|
||||||
try {
|
try {
|
||||||
this.comUDP.sendMessageInfoPseudo();
|
this.comUDP.sendMessageInfoPseudo();
|
||||||
} catch (UnknownHostException e1) {
|
} catch (UnknownHostException e1) {
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -135,7 +139,6 @@ public class ControleurConnexion implements ActionListener{
|
||||||
this.vue.setVisible(false);
|
this.vue.setVisible(false);
|
||||||
this.setVueStandard();
|
this.setVueStandard();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else this.vue.setConnexionInfo("Ce nom est déjà utilisé, veuillez en choisir un autre");
|
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 {
|
private void setVueStandard() throws IOException {
|
||||||
if(this.vueStd == null) {
|
if(this.vueStd == null) {
|
||||||
this.vueStd = new VueStandard("Standard", this.comUDP, this.portTCP, this.sqlManager, this.vue);
|
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);
|
this.vueStd.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the associated instance of VueConnexion to its initial state
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void resetView() {
|
private void resetView() {
|
||||||
this.etat = Etat.DEBUT;
|
this.etat = Etat.DEBUT;
|
||||||
this.vue.addPasswordPanel();
|
this.vue.addPasswordPanel();
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package connexion;
|
package connexion;
|
||||||
|
|
||||||
//Importe les librairies
|
//Import librairies
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import database.SQLiteManager;
|
import database.SQLiteManager;
|
||||||
import main.Vue;
|
import main.Vue;
|
||||||
import messages.MauvaisTypeMessageException;
|
|
||||||
|
|
||||||
public class VueConnexion extends Vue {
|
public class VueConnexion extends Vue {
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,7 @@ import java.net.*;
|
||||||
|
|
||||||
public class Utilisateur implements Serializable{
|
public class Utilisateur implements Serializable{
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -14,48 +12,103 @@ public class Utilisateur implements Serializable{
|
||||||
private InetAddress ip;
|
private InetAddress ip;
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
|
//Represents the user that is currently using the application
|
||||||
private static Utilisateur self;
|
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 {
|
public Utilisateur(String id, String pseudo, InetAddress ip, int port) throws UnknownHostException {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.pseudo = pseudo;
|
this.pseudo = pseudo;
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
|
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----- GETTERS ----- //
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns user id as String
|
||||||
|
*
|
||||||
|
* @return user id as String
|
||||||
|
*/
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns user pseudo as String
|
||||||
|
*
|
||||||
|
* @return user pseudo as String
|
||||||
|
*/
|
||||||
public String getPseudo() {
|
public String getPseudo() {
|
||||||
return pseudo;
|
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() {
|
public InetAddress getIp() {
|
||||||
return ip;
|
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() {
|
public int getPort() {
|
||||||
return port;
|
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 {
|
public static void setSelf(String id, String pseudo, String host, int port) throws UnknownHostException {
|
||||||
if(Utilisateur.self == null) {
|
if(Utilisateur.self == null) {
|
||||||
Utilisateur.self = new Utilisateur(id, pseudo, InetAddress.getByName(host), port);
|
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() {
|
public static void resetSelf() {
|
||||||
Utilisateur.self = null;
|
Utilisateur.self = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package main;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
|
||||||
|
// General class from which all VueX class derivate
|
||||||
|
|
||||||
public class Vue extends JFrame{
|
public class Vue extends JFrame{
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
Loading…
Reference in a new issue