fix plusieurs connexion au me^me utilisateur
This commit is contained in:
parent
f496eb89b1
commit
d318c5d34f
7 changed files with 183 additions and 95 deletions
|
@ -31,9 +31,10 @@ public class Controller {
|
||||||
final static int portUDPlistening_remoteUsr2 = 31002; // TO REMOVE when we use broadcast
|
final static int portUDPlistening_remoteUsr2 = 31002; // TO REMOVE when we use broadcast
|
||||||
final static int portUDPlistening_remoteUsr3 = 31003; // TO REMOVE when we use broadcast
|
final static int portUDPlistening_remoteUsr3 = 31003; // TO REMOVE when we use broadcast
|
||||||
|
|
||||||
|
public Boolean interfaceRunning;
|
||||||
/*** ATTRIBUTS ***/
|
/*** ATTRIBUTS ***/
|
||||||
protected LocalUser myUser;
|
protected LocalUser myUser;
|
||||||
protected Interface hisView;
|
protected Interface view;
|
||||||
private ListeningThreadUDP udp_connect_thread;
|
private ListeningThreadUDP udp_connect_thread;
|
||||||
private ListeningThreadTCPConnection tcp_connect_thread;
|
private ListeningThreadTCPConnection tcp_connect_thread;
|
||||||
private Historique histoire;
|
private Historique histoire;
|
||||||
|
@ -126,8 +127,8 @@ public class Controller {
|
||||||
public LocalUser getMyUser() {
|
public LocalUser getMyUser() {
|
||||||
return myUser;
|
return myUser;
|
||||||
}
|
}
|
||||||
public Interface getHisView() {
|
public Interface getview() {
|
||||||
return hisView;
|
return view;
|
||||||
}
|
}
|
||||||
public ListeningThreadUDP getUdp_connect_thread() {
|
public ListeningThreadUDP getUdp_connect_thread() {
|
||||||
return udp_connect_thread;
|
return udp_connect_thread;
|
||||||
|
@ -143,8 +144,8 @@ public class Controller {
|
||||||
public void setMyUser(LocalUser myUser) {
|
public void setMyUser(LocalUser myUser) {
|
||||||
this.myUser = myUser;
|
this.myUser = myUser;
|
||||||
}
|
}
|
||||||
public void setHisView(Interface hisView) {
|
public void setview(Interface view) {
|
||||||
this.hisView = hisView;
|
this.view = view;
|
||||||
}
|
}
|
||||||
public void setUdp_connect_thread(ListeningThreadUDP udp_connect_thread) {
|
public void setUdp_connect_thread(ListeningThreadUDP udp_connect_thread) {
|
||||||
this.udp_connect_thread = udp_connect_thread;
|
this.udp_connect_thread = udp_connect_thread;
|
||||||
|
@ -186,11 +187,11 @@ public class Controller {
|
||||||
public void changePseudo() throws IOException {
|
public void changePseudo() throws IOException {
|
||||||
String oldPseudo = this.myUser.getPseudo(); //Saves the old one for comparison
|
String oldPseudo = this.myUser.getPseudo(); //Saves the old one for comparison
|
||||||
|
|
||||||
String tmpPseudo = hisView.PseudotextField.getText(); // Read user input
|
String tmpPseudo = view.PseudotextField.getText(); // Read user input
|
||||||
|
|
||||||
while(!(this.validatePseudo(tmpPseudo)) || tmpPseudo.equals(oldPseudo)) {
|
while(!(this.validatePseudo(tmpPseudo)) || tmpPseudo.equals(oldPseudo)) {
|
||||||
hisView.Pseudolabel.setText("Already exists, enter another nickname. Your current username is: " + oldPseudo); // Read user input
|
view.Pseudolabel.setText("Already exists, enter another nickname. Your current username is: " + oldPseudo); // Read user input
|
||||||
tmpPseudo = hisView.PseudotextField.getText(); // Read user input
|
tmpPseudo = view.PseudotextField.getText(); // Read user input
|
||||||
}
|
}
|
||||||
|
|
||||||
this.myUser.setPseudo(tmpPseudo);
|
this.myUser.setPseudo(tmpPseudo);
|
||||||
|
@ -328,29 +329,48 @@ public class Controller {
|
||||||
dgramSocket.close();
|
dgramSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openSession(Chat c) {
|
/**
|
||||||
|
* @parameters
|
||||||
|
* @param chat : Chat
|
||||||
|
* <p>
|
||||||
|
* Ajout ou mise à jour l'utilisateur distant dans notre liste d'utilisateur distant
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public void openSession(RemoteUser rm) {
|
||||||
|
myUser.addChats(rm);
|
||||||
|
Chat c = myUser.getChats().get(myUser.getChatIndexOf(rm));
|
||||||
|
|
||||||
|
if(c.getActive()) {
|
||||||
|
JOptionPane.showMessageDialog(null ,"Already a session with "+c.getRemoteUser().getPseudo());
|
||||||
|
}
|
||||||
|
else {
|
||||||
Socket link=null;
|
Socket link=null;
|
||||||
try {
|
try {
|
||||||
System.out.println("("+this.myUser.getPseudo()+") Connecting to "+c.getRemoteUser().getPortTCP()+" of " + c.getRemoteUser().getPseudo());
|
System.out.println("("+this.myUser.getPseudo()+") Connecting to "+c.getRemoteUser().getPortTCP()+" of " + c.getRemoteUser().getPseudo());
|
||||||
link=new Socket(c.getRemoteUser().getAddIP(),c.getRemoteUser().getPortTCP());
|
link=new Socket(c.getRemoteUser().getAddIP(),c.getRemoteUser().getPortTCP()/*, InetAddress.getLocalHost() ,myUser.getPortTCP()*/);
|
||||||
}catch(IOException e) {
|
}catch(IOException e) {
|
||||||
System.out.println("Error linking to TCP server of "+ c.getRemoteUser().getPortTCP());
|
System.out.println("Error linking to TCP server of "+ c.getRemoteUser().getPortTCP());
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setSocket(link);
|
c.setSocket(link);
|
||||||
JOptionPane.showMessageDialog(null ,"New chat with "+c.getRemoteUser().getPseudo());
|
JOptionPane.showMessageDialog(null ,"New session with "+c.getRemoteUser().getPseudo());
|
||||||
|
// TODO Récupération de la conversation (historique)
|
||||||
try {
|
try {
|
||||||
System.out.println(this.getHistory().retrieveMessage(getMyUser(), c.getRemoteUser()));
|
System.out.println(this.getHistory().retrieveMessage(getMyUser(), c.getRemoteUser()));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println("souci avec le retrieveMsg");
|
System.out.println("souci avec le retrieveMsg");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// TODO Récupération de la conversation (historique)
|
c.activate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeSession(Chat c) {
|
public void closeSession(Chat c) {
|
||||||
c.closeSocket();
|
sendMsg(new Msg_Text(myUser.getAddIP(),"end"), c);
|
||||||
// TODO Serait mieux d'enlever le chat de la liste de myUser
|
this.myUser.closeChat(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMsg(Message msg,Chat c) {
|
public void sendMsg(Message msg,Chat c) {
|
||||||
|
@ -377,8 +397,11 @@ public class Controller {
|
||||||
//System.out.println(message);
|
//System.out.println(message);
|
||||||
out.println(dateFormat.format(date));
|
out.println(dateFormat.format(date));
|
||||||
out.println(message);
|
out.println(message);
|
||||||
|
c.addMessage(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Plus utilisé
|
// Plus utilisé
|
||||||
public void TCPmessage(int index) throws IOException {
|
public void TCPmessage(int index) throws IOException {
|
||||||
Socket link=null;
|
Socket link=null;
|
||||||
|
@ -468,12 +491,11 @@ public class Controller {
|
||||||
|
|
||||||
if (index >= 0 && index<this.myUser.getRemoteUsersList().size()) {
|
if (index >= 0 && index<this.myUser.getRemoteUsersList().size()) {
|
||||||
|
|
||||||
if(this.myUser.getIndexOf(this.myUser.getRemoteUsersList().get(index))==-1){
|
if(this.myUser.getChatIndexOf(this.myUser.getRemoteUsersList().get(index))==-1){
|
||||||
JOptionPane.showMessageDialog(null ,"User "+this.myUser.getRemoteUsersList().get(index).getPseudo()+" is already in chat with you");
|
JOptionPane.showMessageDialog(null ,"User "+this.myUser.getRemoteUsersList().get(index).getPseudo()+" is already in chat with you");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Chat chat=this.myUser.addChats(this.myUser.getRemoteUsersList().get(index));
|
this.openSession(myUser.getRemoteUsersList().get(index));
|
||||||
this.openSession(chat);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -499,21 +521,23 @@ public class Controller {
|
||||||
Controller ctr1 = new Controller(31011,31001,31021,histoire);
|
Controller ctr1 = new Controller(31011,31001,31021,histoire);
|
||||||
|
|
||||||
/** Création de l'interface graphique **/
|
/** Création de l'interface graphique **/
|
||||||
Boolean interfaceRunning = true;
|
ctr1.interfaceRunning =true;
|
||||||
ctr1.hisView=Interface.createAndShowGUI(ctr1);
|
ctr1.view=Interface.createAndShowGUI(ctr1);
|
||||||
|
|
||||||
/** Simulation of a session **/
|
/** Simulation of a session **/
|
||||||
|
|
||||||
// SELECT REMOTE USER
|
|
||||||
Chat chatwithrm0 = ctr1.myUser.addChats(ctr1.myUser.getRemoteUsersList().get(0));
|
|
||||||
// AFFICHAGE REMOTE USER CHOISIE
|
// AFFICHAGE REMOTE USER CHOISIE
|
||||||
System.out.println("("+ctr1.myUser.getPseudo()+" ) OPEN SESSION WITH "+ctr1.myUser.getRemoteUsersList().get(0).getPseudo());
|
System.out.println("("+ctr1.myUser.getPseudo()+" ) OPEN SESSION WITH "+ctr1.myUser.getRemoteUsersList().get(0).getPseudo());
|
||||||
|
// SELECTION DE L UTILISATEUR
|
||||||
|
RemoteUser rm0 = ctr1.myUser.getRemoteUsersList().get(0);
|
||||||
// OPEN SESSION
|
// OPEN SESSION
|
||||||
ctr1.openSession(chatwithrm0);
|
ctr1.openSession(rm0);
|
||||||
|
// RECUPERATION DE LA CONVERSATION
|
||||||
|
Chat chatwithrm0 = ctr1.myUser.getChats().get(ctr1.myUser.getChatIndexOf(rm0));
|
||||||
// SEND MESSAGE
|
// SEND MESSAGE
|
||||||
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"test"), chatwithrm0);
|
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"test"), chatwithrm0);
|
||||||
// CLOSE SESSION
|
// CLOSE SESSION
|
||||||
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"end"), chatwithrm0);
|
|
||||||
ctr1.closeSession(chatwithrm0);
|
ctr1.closeSession(chatwithrm0);
|
||||||
|
|
||||||
|
|
||||||
|
@ -524,26 +548,24 @@ public class Controller {
|
||||||
//ctr1.changePseudo();
|
//ctr1.changePseudo();
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
while(interfaceRunning) {
|
|
||||||
|
|
||||||
}*/
|
while(ctr1.interfaceRunning) {
|
||||||
|
//ctr1.view
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Fin de la boucle");
|
||||||
|
|
||||||
/** Close thread and socket **/
|
/** Close thread and socket **/
|
||||||
// SLEEP 20 SEC
|
|
||||||
System.out.println("Sleep mode for 20 seconds ...");
|
|
||||||
Thread.sleep(20000);
|
|
||||||
|
|
||||||
// REMOTEUSER_1 - MIKE
|
// REMOTEUSER_1 - MIKE
|
||||||
ctr2.myUser.closeAllRemainingChatSocket();
|
ctr2.myUser.closeAllChat();
|
||||||
ctr2.tcp_connect_thread.close();
|
ctr2.tcp_connect_thread.close();
|
||||||
ctr2.udp_connect_thread.close();
|
ctr2.udp_connect_thread.close();
|
||||||
// REMOTEUSER_2 - ALICE
|
// REMOTEUSER_2 - ALICE
|
||||||
ctr3.myUser.closeAllRemainingChatSocket();
|
ctr3.myUser.closeAllChat();
|
||||||
ctr3.tcp_connect_thread.close();
|
ctr3.tcp_connect_thread.close();
|
||||||
ctr3.udp_connect_thread.close();
|
ctr3.udp_connect_thread.close();
|
||||||
// LOCAL USER
|
// LOCAL USER
|
||||||
ctr1.myUser.closeAllRemainingChatSocket();
|
ctr1.myUser.closeAllChat();
|
||||||
ctr1.tcp_connect_thread.close();
|
ctr1.tcp_connect_thread.close();
|
||||||
ctr1.udp_connect_thread.close();
|
ctr1.udp_connect_thread.close();
|
||||||
// AFFICHAGE
|
// AFFICHAGE
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package controller;
|
package controller;
|
||||||
|
|
||||||
|
import model.Chat;
|
||||||
import model.LocalUser;
|
import model.LocalUser;
|
||||||
|
import model.Msg_Text;
|
||||||
|
import model.RemoteUser;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -37,29 +41,51 @@ public class ListeningThreadTCPChat extends ListeningThread{
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
|
/**** function variables ****/
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
String msg = null;
|
String msg = null;
|
||||||
String input;
|
String input;
|
||||||
String dateString;
|
String dateString;
|
||||||
Date date;
|
Date date;
|
||||||
Calendar date1=Calendar.getInstance();
|
Calendar date1=Calendar.getInstance();
|
||||||
// TODO retrouver le chat lié à ce thread
|
|
||||||
// Chat c =
|
|
||||||
// RemoteUser rm=c.getRemoteUser();
|
|
||||||
|
|
||||||
|
|
||||||
|
Chat c = null;
|
||||||
|
/************ Check rm user information **********/
|
||||||
|
/*
|
||||||
|
RemoteUser rm = new RemoteUser("Unknown",this.socket.getInetAddress(),this.socket.getPort());
|
||||||
|
int indexRM = controller.myUser.getActiveUserIndexOf(rm);
|
||||||
|
// Check if rm is identifiable
|
||||||
|
System.out.println(rm);
|
||||||
|
if(indexRM!=-1) {
|
||||||
|
rm = controller.myUser.getRemoteUsersList().get(indexRM);
|
||||||
|
// Check if chat already created
|
||||||
|
int indexChat = controller.myUser.getChatIndexOf(rm);
|
||||||
|
if(indexChat!=-1) {
|
||||||
|
System.out.println("("+this.controller.myUser.getPseudo()+") Session déjà créer, on recupère le chat associé");
|
||||||
|
c = controller.myUser.getChats().get(indexChat);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c = this.controller.myUser.addChats(rm);
|
||||||
|
this.controller.openSession(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("("+this.controller.myUser.getPseudo()+") Remote User unidentifiable => CLOSING CONNECTION");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*** listening tcp message from rm until session is close ***/
|
||||||
try {
|
try {
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") WAIT FOR NEW MESSAGE ");
|
System.out.println("("+this.controller.myUser.getPseudo()+") WAIT FOR NEW MESSAGE FROM ");//+rm.getPseudo());
|
||||||
in =new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
|
in =new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
while (!(input=in.readLine()).equals("end")) {
|
while (!(input=in.readLine()).equals("end")/* && c.getActive()*/) {
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") recoit : "+input);
|
System.out.println("("+this.controller.myUser.getPseudo()+") recoit : "+input);
|
||||||
// TODO save history (On doit choisir entre sauvegarder à la reception ou a l'emission) même appel dans controller.sendMsg()
|
//c.addMessage(new Msg_Text(rm.getAddIP(),input));
|
||||||
//this.controller.getHistory().saveMessage(this.controller.myUser, rm,input ,dateString );
|
|
||||||
// TODO Update le chat avec ce nouveau message
|
|
||||||
// TODO Prévenir l'interface de la réception d'un nouveau message
|
// TODO Prévenir l'interface de la réception d'un nouveau message
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class Chat {
|
||||||
private RemoteUser remoteUser;
|
private RemoteUser remoteUser;
|
||||||
private ArrayList<Message> messages = new ArrayList<Message>();
|
private ArrayList<Message> messages = new ArrayList<Message>();
|
||||||
private Socket userSocket;
|
private Socket userSocket;
|
||||||
|
private Boolean active = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of Chat (local)
|
* Constructor of Chat (local)
|
||||||
|
@ -34,6 +35,9 @@ public class Chat {
|
||||||
public Socket getUserSocket() {
|
public Socket getUserSocket() {
|
||||||
return userSocket;
|
return userSocket;
|
||||||
}
|
}
|
||||||
|
public Boolean getActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
/*** SETTERS ***/
|
/*** SETTERS ***/
|
||||||
public void setRemoteUser(RemoteUser rm) {
|
public void setRemoteUser(RemoteUser rm) {
|
||||||
|
@ -45,8 +49,12 @@ public class Chat {
|
||||||
public void addMessage(Message msg) {
|
public void addMessage(Message msg) {
|
||||||
this.messages.add(msg);
|
this.messages.add(msg);
|
||||||
}
|
}
|
||||||
|
public void activate() {
|
||||||
|
this.active = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void closeSocket() {
|
public void close() {
|
||||||
|
this.active = false;
|
||||||
try {
|
try {
|
||||||
this.userSocket.close();
|
this.userSocket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -54,4 +62,5 @@ public class Chat {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,40 +78,59 @@ public class LocalUser extends User{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addChats(RemoteUser rm) {
|
||||||
/**
|
|
||||||
* @parameters
|
|
||||||
* @param remoteUser : remoteUser => référence de l'utilisateur distant
|
|
||||||
* @param localUser_portTCP : int => le numéro de port TCP d'écoute de la conversation de l'utilisateur local
|
|
||||||
* @param remoteUser_portTCP : int => le numéro de port TCP d'écoute de la conversation de l'utilisateur distant
|
|
||||||
* <p>
|
|
||||||
* Ajout ou mise à jour l'utilisateur distant dans notre liste d'utilisateur distant
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public Chat addChats(RemoteUser rm) {
|
|
||||||
Chat newChat= new Chat(rm);
|
Chat newChat= new Chat(rm);
|
||||||
this.chats.add(newChat);
|
|
||||||
return newChat;
|
if(getChatIndexOf(rm)==-1) {
|
||||||
|
this.getChats().add(newChat);
|
||||||
|
}/*
|
||||||
|
else {
|
||||||
|
System.out.println("pb add chat, déjà un chat avec cet rm user");
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndexOf(RemoteUser remoteUser) {
|
|
||||||
int i=0;
|
public int getChatIndexOf(RemoteUser rm) {
|
||||||
Boolean found = (this.chats.get(i).getRemoteUser() == remoteUser);
|
int index=0;
|
||||||
while(i<this.chats.size() && !found) {
|
|
||||||
i++;
|
Boolean found = false;
|
||||||
found = (this.chats.get(i).getRemoteUser() == remoteUser);
|
while(index<this.chats.size() && !found) {
|
||||||
|
|
||||||
|
found = (this.chats.get(index).getRemoteUser() == rm);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
if(found) {
|
if(found) {
|
||||||
return i;
|
return index-1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeAllRemainingChatSocket() {
|
public int getActiveUserIndexOf(RemoteUser rm) {
|
||||||
for(int i=0;i<this.chats.size();i++) {
|
int index = 0;
|
||||||
this.chats.get(i).closeSocket();
|
Boolean found = false;
|
||||||
|
while(index<this.remoteUsersList.size() && !found) {
|
||||||
|
found = (this.remoteUsersList.get(index) == rm);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
if(found) {
|
||||||
|
return index-1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeChat(Chat c) {
|
||||||
|
this.chats.get(getChatIndexOf(c.getRemoteUser())).close();
|
||||||
|
this.chats.remove(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeAllChat() {
|
||||||
|
int length =this.chats.size();
|
||||||
|
for(int i=0;i<length;i++) {
|
||||||
|
this.closeChat(this.chats.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,11 @@ public class RemoteUser extends User{
|
||||||
super(pseudo, addIP, portTCP);
|
super(pseudo, addIP, portTCP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RemoteUser [pseudo=" + pseudo + ", addIP=" + addIP + ", portTCP=" + portTCP + ", IPcode=" + IPcode
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ public abstract class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L; //JFrame stuff
|
private static final long serialVersionUID = 1L; //JFrame stuff
|
||||||
|
|
||||||
public static Controller hisController;
|
public Controller controller;
|
||||||
|
|
||||||
public JLabel Pseudolabel;
|
public JLabel Pseudolabel;
|
||||||
public JTextField PseudotextField;
|
public JTextField PseudotextField;
|
||||||
|
@ -31,7 +31,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
final static String LOOKANDFEEL = "System";
|
final static String LOOKANDFEEL = "System";
|
||||||
|
|
||||||
public Interface(Controller controller) {
|
public Interface(Controller controller) {
|
||||||
this.hisController = controller;
|
this.controller = controller;
|
||||||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,15 +46,15 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
PseudotextField = new JTextField(); //Pseudo setup
|
PseudotextField = new JTextField(); //Pseudo setup
|
||||||
PseudotextField.setColumns(10);
|
PseudotextField.setColumns(10);
|
||||||
PseudotextField.addActionListener(this);
|
PseudotextField.addActionListener(this);
|
||||||
Pseudolabel = new JLabel("Your current username is: " + hisController.getMyUser().getPseudo());
|
Pseudolabel = new JLabel("Your current username is: " + controller.getMyUser().getPseudo());
|
||||||
Pseudolabel.setLabelFor(PseudotextField);
|
Pseudolabel.setLabelFor(PseudotextField);
|
||||||
|
|
||||||
RemoteUserButton = new JButton("Click here to get Remote User list"); //Remote user list setup
|
RemoteUserButton = new JButton("Click here to get Remote User list"); //Remote user list setup
|
||||||
RemoteUserButton.addActionListener(this);
|
RemoteUserButton.addActionListener(this);
|
||||||
//Convert the Userlist to Pseudotab
|
//Convert the Userlist to Pseudotab
|
||||||
String[] pseudotab = new String[hisController.getMyUser().getRemoteUsersList().size()];
|
String[] pseudotab = new String[controller.getMyUser().getRemoteUsersList().size()];
|
||||||
for(int i=0; i < hisController.getMyUser().getRemoteUsersList().size(); i++) {
|
for(int i=0; i < controller.getMyUser().getRemoteUsersList().size(); i++) {
|
||||||
pseudotab[i] = "(" + Integer.toString(i) + "): " + hisController.getMyUser().getRemoteUsersList().get(i).getPseudo();
|
pseudotab[i] = "(" + Integer.toString(i) + "): " + controller.getMyUser().getRemoteUsersList().get(i).getPseudo();
|
||||||
}
|
}
|
||||||
RemoteUserbox = new JComboBox(pseudotab);
|
RemoteUserbox = new JComboBox(pseudotab);
|
||||||
RemoteUserbox.setEditable(true);
|
RemoteUserbox.setEditable(true);
|
||||||
|
@ -98,7 +98,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
MessagetextField.setVisible(true);
|
MessagetextField.setVisible(true);
|
||||||
Messagelabel.setVisible(true);
|
Messagelabel.setVisible(true);
|
||||||
try {
|
try {
|
||||||
hisController.changePseudo();
|
controller.changePseudo();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
System.out.println("Error in change pseudo\n");
|
System.out.println("Error in change pseudo\n");
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -113,7 +113,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
}else {
|
}else {
|
||||||
JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste
|
JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste
|
||||||
int selectedUsernb = Integer.parseInt(String.valueOf(((String) cb.getSelectedItem()).charAt(1)));
|
int selectedUsernb = Integer.parseInt(String.valueOf(((String) cb.getSelectedItem()).charAt(1)));
|
||||||
hisController.openSession(hisController.getMyUser().addChats(hisController.getMyUser().getRemoteUsersList().get(selectedUsernb)));
|
controller.openSession(controller.getMyUser().getRemoteUsersList().get(selectedUsernb));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,19 +169,23 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
JFrame frame = new JFrame("Clavardage App");
|
JFrame frame = new JFrame("Clavardage App");
|
||||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
|
||||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
||||||
@Override
|
|
||||||
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
|
||||||
System.out.println("GUI has been closed");
|
|
||||||
hisController.interfaceRunning = false;
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Interface app = new Interface(controller);
|
Interface app = new Interface(controller);
|
||||||
Component contents = app.createComponents();
|
Component contents = app.createComponents();
|
||||||
frame.getContentPane().add(contents, BorderLayout.CENTER);
|
frame.getContentPane().add(contents, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
|
||||||
|
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
||||||
|
System.out.println("GUI has been closed");
|
||||||
|
app.controller.interfaceRunning = false;
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Display the window.
|
//Display the window.
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
Loading…
Reference in a new issue