v1 chat_local
This commit is contained in:
parent
7f503531d1
commit
7bd2f3ecb6
9 changed files with 245 additions and 179 deletions
|
@ -28,17 +28,22 @@ import view.Interface;
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
|
||||||
/*** CONSTANTES ***/
|
/*** CONSTANTES ***/
|
||||||
final static int portUDPlistening_remoteUsr2 = 31002; // TO REMOVE when we use broadcast
|
int NB_SECOND_WAITING_RESPONSE_BROADCAST = 2;
|
||||||
final static int portUDPlistening_remoteUsr3 = 31003; // TO REMOVE when we use broadcast
|
|
||||||
|
|
||||||
public Boolean interfaceRunning;
|
// TO REMOVE when we use broadcast
|
||||||
|
final static int portUDPlistening_usr1 = 31001;
|
||||||
|
final static int portUDPlistening_remoteUsr2 = 31002;
|
||||||
|
final static int portUDPlistening_remoteUsr3 = 31003;
|
||||||
|
final static int [] tabBroadcast = {portUDPlistening_usr1,portUDPlistening_remoteUsr2,portUDPlistening_remoteUsr3};
|
||||||
|
|
||||||
|
public Boolean interfaceRunning = false;
|
||||||
/*** ATTRIBUTS ***/
|
/*** ATTRIBUTS ***/
|
||||||
protected LocalUser myUser;
|
protected LocalUser myUser;
|
||||||
protected Interface view;
|
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;
|
||||||
private Chat activeChat;
|
protected Chat activeChat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of Controller
|
* Constructor of Controller
|
||||||
|
@ -82,7 +87,8 @@ public class Controller {
|
||||||
|
|
||||||
notify_remote_users();
|
notify_remote_users();
|
||||||
|
|
||||||
|
interfaceRunning =true;
|
||||||
|
view=Interface.createAndShowGUI(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,13 +116,32 @@ public class Controller {
|
||||||
catch(UnknownHostException e) {
|
catch(UnknownHostException e) {
|
||||||
JOptionPane.showMessageDialog(null ,"Could not find local address!");
|
JOptionPane.showMessageDialog(null ,"Could not find local address!");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.myUser = new LocalUser(pseudo,addIP,portUDPsend,portUDPlistening,portTCP);
|
this.myUser = new LocalUser(pseudo,addIP,portUDPsend,portUDPlistening,portTCP);
|
||||||
|
try {
|
||||||
|
if(this.validatePseudo(pseudo)) {
|
||||||
|
|
||||||
|
|
||||||
|
this.udp_connect_thread = new ListeningThreadUDP("UDP Listening thread",this);
|
||||||
|
this.udp_connect_thread.start();
|
||||||
|
|
||||||
|
this.tcp_connect_thread = new ListeningThreadTCPConnection("TCP main Listening thread",this);
|
||||||
|
this.tcp_connect_thread.start();
|
||||||
|
|
||||||
|
interfaceRunning =true;
|
||||||
|
view=Interface.createAndShowGUI(this);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Unavailable "+pseudo);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.udp_connect_thread = new ListeningThreadUDP("UDP Listening thread",this);
|
|
||||||
this.udp_connect_thread.start();
|
|
||||||
|
|
||||||
this.tcp_connect_thread = new ListeningThreadTCPConnection("TCP main Listening thread",this);
|
|
||||||
this.tcp_connect_thread.start();
|
|
||||||
|
|
||||||
notify_remote_users();
|
notify_remote_users();
|
||||||
}
|
}
|
||||||
|
@ -188,11 +213,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 = view.PseudotextField.getText(); // Read user input
|
String tmpPseudo = view.ChangePseudotextField.getText(); // Read user input
|
||||||
|
|
||||||
if(!(this.validatePseudo(tmpPseudo)) || tmpPseudo.equals(oldPseudo)) {
|
if(!(this.validatePseudo(tmpPseudo)) || tmpPseudo.equals(oldPseudo)) {
|
||||||
view.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 = view.PseudotextField.getText(); // Read user input
|
tmpPseudo = view.ChangePseudotextField.getText(); // Read user input
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.myUser.setPseudo(tmpPseudo);
|
this.myUser.setPseudo(tmpPseudo);
|
||||||
|
@ -221,46 +246,45 @@ public class Controller {
|
||||||
|
|
||||||
// Call broadcast
|
// Call broadcast
|
||||||
InetAddress broadcastIP = InetAddress.getLocalHost(); // change to broadcast
|
InetAddress broadcastIP = InetAddress.getLocalHost(); // change to broadcast
|
||||||
//System.out.println(broadcastIP);
|
//System.out.println(this.myUser.getPortUDPsend());
|
||||||
DatagramSocket dgramSocket = new DatagramSocket(this.myUser.getPortUDPsend(),this.myUser.getAddIP());
|
DatagramSocket dgramSocket = new DatagramSocket(this.myUser.getPortUDPsend(),this.myUser.getAddIP());
|
||||||
byte[] buffer = new byte[256];
|
byte[] buffer = new byte[256];
|
||||||
|
|
||||||
// Création du message à envoyer
|
// Création du message à envoyer
|
||||||
String toSend = this.myUser.getAddIP()+":"+this.myUser.getPortUDPsend()+":test";
|
String toSend = this.myUser.getAddIP()+":"+this.myUser.getPortUDPsend()+":info";
|
||||||
|
|
||||||
// Send to remote user 1
|
// Send to other active user (simulation of broadcast)
|
||||||
DatagramPacket outPacket= new DatagramPacket(toSend.getBytes(), toSend.length(),broadcastIP, portUDPlistening_remoteUsr2);
|
DatagramPacket outPacket = null;
|
||||||
dgramSocket.send(outPacket);
|
int tabBroadcastSize = tabBroadcast.length;
|
||||||
|
for(int i=0;i<tabBroadcastSize;i++) {
|
||||||
|
if(tabBroadcast[i]!=myUser.getPortUDPlistening()) {
|
||||||
|
outPacket= new DatagramPacket(toSend.getBytes(), toSend.length(),broadcastIP, tabBroadcast[i]);
|
||||||
|
dgramSocket.send(outPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Send to remote user 2
|
/*** For 5 seconds wait for answer : validate pseudo & add to userlist ***/
|
||||||
outPacket= new DatagramPacket(toSend.getBytes(), toSend.length(),broadcastIP, portUDPlistening_remoteUsr3);
|
|
||||||
dgramSocket.send(outPacket);
|
|
||||||
|
|
||||||
// Initialisation des variables de la boucle
|
|
||||||
Boolean valid = true;
|
Boolean valid = true;
|
||||||
|
|
||||||
DatagramPacket inPacket;
|
DatagramPacket inPacket;
|
||||||
String response = null;
|
String response = null;
|
||||||
String[] tabresponse= new String [4];
|
String[] tabresponse= new String [4];
|
||||||
dgramSocket.setSoTimeout(1000);
|
dgramSocket.setSoTimeout(1000);
|
||||||
Boolean arecu;
|
Boolean arecu;
|
||||||
|
|
||||||
System.out.print("Wait for pseudo validation ...\n");
|
|
||||||
|
|
||||||
int nbReponse =0;
|
int nbReponse =0;
|
||||||
|
System.out.println("("+myUser.getPseudo()+") Waiting for pseudo validation ...");
|
||||||
Date oldDate = new Date();
|
Date oldDate = new Date();
|
||||||
Date newDate = new Date();
|
Date newDate = new Date();
|
||||||
while( (newDate.getTime()-oldDate.getTime()) < 5000 && valid) {
|
|
||||||
|
|
||||||
|
while( (newDate.getTime()-oldDate.getTime()) < NB_SECOND_WAITING_RESPONSE_BROADCAST*1000 && valid) {
|
||||||
nbReponse++;
|
nbReponse++;
|
||||||
inPacket= new DatagramPacket(buffer, buffer.length);
|
inPacket= new DatagramPacket(buffer, buffer.length);
|
||||||
|
|
||||||
arecu=true;
|
arecu=true;
|
||||||
try{
|
try{
|
||||||
dgramSocket.receive(inPacket);
|
dgramSocket.receive(inPacket);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
arecu=false;
|
arecu=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = inPacket.getData();
|
buffer = inPacket.getData();
|
||||||
response = new String(buffer);
|
response = new String(buffer);
|
||||||
|
|
||||||
|
@ -268,9 +292,6 @@ public class Controller {
|
||||||
// On découpe la réponse en tableau de string ([adresseIP,tcpPort,nickname])
|
// On découpe la réponse en tableau de string ([adresseIP,tcpPort,nickname])
|
||||||
tabresponse = response.split(":");
|
tabresponse = response.split(":");
|
||||||
|
|
||||||
// Affichage de la réponse
|
|
||||||
//System.out.println("Remote user n°"+nbReponse+"\nIP : "+tabresponse[0]+"\nn°Port : "+tabresponse[1]+"\npseudo : "+tabresponse[2]);
|
|
||||||
|
|
||||||
// Si reception on ajoute l'utilisateur à notre liste d'utilisateur distant
|
// Si reception on ajoute l'utilisateur à notre liste d'utilisateur distant
|
||||||
this.myUser.addRemoteUser(InetAddress.getByName(tabresponse[0].split("/")[1]),Integer.parseInt(tabresponse[1]),tabresponse[2]);
|
this.myUser.addRemoteUser(InetAddress.getByName(tabresponse[0].split("/")[1]),Integer.parseInt(tabresponse[1]),tabresponse[2]);
|
||||||
valid= (tmpPseudo.compareTo(tabresponse[2])!=0); // On regarde la différence entre notre pseudo et le pseudo reçu
|
valid= (tmpPseudo.compareTo(tabresponse[2])!=0); // On regarde la différence entre notre pseudo et le pseudo reçu
|
||||||
|
@ -287,13 +308,13 @@ public class Controller {
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** notify_remote_users
|
/** notify_remote_users
|
||||||
* <p>
|
* <p>
|
||||||
* En utilisant le port UDP d'envoi, on envoie en broadcast les informations nous concernant
|
* En utilisant le port UDP d'envoi, on envoie en broadcast les informations nous concernant
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void notify_remote_users() {
|
public void notify_remote_users() {
|
||||||
// Création du socket d'envoi d'information
|
|
||||||
DatagramSocket dgramSocket= null;
|
DatagramSocket dgramSocket= null;
|
||||||
try {
|
try {
|
||||||
dgramSocket= new DatagramSocket(this.myUser.getPortUDPsend(),this.myUser.getAddIP());
|
dgramSocket= new DatagramSocket(this.myUser.getPortUDPsend(),this.myUser.getAddIP());
|
||||||
|
@ -301,32 +322,21 @@ public class Controller {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construction du message à envoyer
|
// Send to other active user (simulation of broadcast)
|
||||||
String toSend = this.myUser.getAddIP().toString()+":"+this.myUser.getPortTCP()+":"+this.myUser.getPseudo()+":test";
|
String toSend = this.myUser.getAddIP().toString()+":"+this.myUser.getPortTCP()+":"+this.myUser.getPseudo()+":notify";
|
||||||
|
|
||||||
DatagramPacket outPacket =null;
|
DatagramPacket outPacket =null;
|
||||||
|
int tabBroadcastSize = tabBroadcast.length;
|
||||||
|
for(int i=0;i<tabBroadcastSize;i++) {
|
||||||
|
if(tabBroadcast[i]!=myUser.getPortUDPlistening()) {
|
||||||
|
outPacket = new DatagramPacket(toSend.getBytes(), toSend.length(),this.myUser.getAddIP(), tabBroadcast[i]);
|
||||||
|
try {
|
||||||
|
dgramSocket.send(outPacket);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Send information to usr2
|
}
|
||||||
if(this.myUser.getPortUDPlistening()!=portUDPlistening_remoteUsr2) {
|
|
||||||
outPacket = new DatagramPacket(toSend.getBytes(), toSend.length(),this.myUser.getAddIP(), portUDPlistening_remoteUsr2);
|
|
||||||
try {
|
|
||||||
dgramSocket.send(outPacket);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Send information to usr3
|
|
||||||
if(this.myUser.getPortUDPlistening()!=portUDPlistening_remoteUsr3) {
|
|
||||||
|
|
||||||
outPacket= new DatagramPacket(toSend.getBytes(), toSend.length(),this.myUser.getAddIP(), portUDPlistening_remoteUsr3);
|
|
||||||
try {
|
|
||||||
dgramSocket.send(outPacket);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dgramSocket.close();
|
dgramSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +352,7 @@ public class Controller {
|
||||||
link=new Socket(c.getRemoteUser().getAddIP(),c.getRemoteUser().getPortTCP()/*, InetAddress.getLocalHost() ,myUser.getPortTCP()*/);
|
link=new Socket(c.getRemoteUser().getAddIP(),c.getRemoteUser().getPortTCP()/*, InetAddress.getLocalHost() ,myUser.getPortTCP()*/);
|
||||||
c.setSocket(link);
|
c.setSocket(link);
|
||||||
// Sending data for identification (TO REMOVE IF != IP)
|
// Sending data for identification (TO REMOVE IF != IP)
|
||||||
sendMessage(new Msg_Text(myUser.getAddIP(),Integer.toString(myUser.getPortTCP())),c);
|
sendInfoProcess(Integer.toString(myUser.getPortTCP()), c); // tell rm session STOP
|
||||||
}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());
|
||||||
}
|
}
|
||||||
|
@ -376,9 +386,10 @@ public class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for history
|
// Look for history
|
||||||
|
|
||||||
int nbMessage = c.getMessages().size();
|
int nbMessage = c.getMessages().size();
|
||||||
for(int i=0;i<nbMessage;i++) {
|
for(int i=0;i<nbMessage;i++) {
|
||||||
history+="\n"+c.getMessages().get(i).getMessage();
|
history+="\n("+c.getMessages().get(i).getDate()+")\n"+c.getMessages().get(i).getAutor().getPseudo()+" : "+c.getMessages().get(i).getMessage();
|
||||||
}
|
}
|
||||||
this.activeChat = c;
|
this.activeChat = c;
|
||||||
|
|
||||||
|
@ -390,13 +401,13 @@ public class Controller {
|
||||||
this.activeChat = null;
|
this.activeChat = null;
|
||||||
}
|
}
|
||||||
public void closeSession(Chat c) {
|
public void closeSession(Chat c) {
|
||||||
sendMessage(new Msg_Text(myUser.getAddIP(),"end"), c); // tell rm session STOP
|
sendInfoProcess("end", c); // tell rm session STOP
|
||||||
JOptionPane.showMessageDialog(null ,"Close session with "+c.getRemoteUser().getPseudo());
|
JOptionPane.showMessageDialog(null ,"Close session with "+c.getRemoteUser().getPseudo());
|
||||||
this.myUser.closeChat(c);
|
this.myUser.closeChat(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void askToSend(String textMessage){
|
public void askToSend(String textMessage){
|
||||||
sendMessage(new Msg_Text(myUser.getAddIP(),textMessage), this.activeChat);
|
sendMessage(new Msg_Text(myUser,textMessage), this.activeChat);
|
||||||
}
|
}
|
||||||
public void sendMessage(Message msg,Chat c) {
|
public void sendMessage(Message msg,Chat c) {
|
||||||
/*** Init send process ***/
|
/*** Init send process ***/
|
||||||
|
@ -408,29 +419,57 @@ public class Controller {
|
||||||
}
|
}
|
||||||
c.addMessage(msg);
|
c.addMessage(msg);
|
||||||
|
|
||||||
/*** Gestion des différentes instance de Message ***/
|
|
||||||
// TODO check if instance of Msg_Text or anything else and threat it given a type
|
// TODO check if instance of Msg_Text or anything else and threat it given a type
|
||||||
String message = (String) msg.getMessage();
|
String message = (String) msg.getMessage();
|
||||||
|
|
||||||
// Date l'envoie du message
|
// Sauvegarde dans la base de données
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy MM dd HH mm ss");
|
DateFormat dateFormat = new SimpleDateFormat("yyyy MM dd HH mm ss");
|
||||||
Date date=new Date();
|
Date date=new Date();
|
||||||
|
|
||||||
// Sauvegarde dans la base de données
|
|
||||||
//this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateFormat.format(date));
|
//this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateFormat.format(date));
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
//out.println(dateFormat.format(date));
|
|
||||||
out.println(message);
|
out.println(message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendInfoProcess(String msg,Chat c) {
|
||||||
|
PrintWriter out=null;
|
||||||
|
try {
|
||||||
|
out = new PrintWriter(c.getUserSocket().getOutputStream(),true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
out.println(msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public String askNewMessage() {
|
public String askNewMessage() {
|
||||||
String message = "";
|
String message = "";
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String [] askUpdateActiveUsers() {
|
||||||
|
String[] pseudotab = new String[myUser.getRemoteUsersList().size()];
|
||||||
|
int size = myUser.getRemoteUsersList().size();
|
||||||
|
for(int i=0; i < size; i++) {
|
||||||
|
pseudotab[i] = myUser.getRemoteUsersList().get(i).getPseudo();
|
||||||
|
}
|
||||||
|
return pseudotab;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void askForClose() {
|
||||||
|
interfaceRunning = false;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
public void close() {
|
||||||
|
if(interfaceRunning) {
|
||||||
|
myUser.closeAllChat();
|
||||||
|
tcp_connect_thread.close();
|
||||||
|
udp_connect_thread.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, InterruptedException {
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
|
|
||||||
|
@ -440,12 +479,15 @@ public class Controller {
|
||||||
|
|
||||||
/************************* INIT *******************************/
|
/************************* INIT *******************************/
|
||||||
/** Création des utilisateurs **/
|
/** Création des utilisateurs **/
|
||||||
// REMOTEUSER_1 - MIKE
|
|
||||||
Controller ctr2 = new Controller(31012,portUDPlistening_remoteUsr2,31022,"Mike",histoire);
|
|
||||||
// REMOTEUSER_2 - ALICE
|
|
||||||
Controller ctr3 = new Controller(31013,portUDPlistening_remoteUsr3,31023,"Alice",histoire);
|
|
||||||
// LOCAL USER
|
// LOCAL USER
|
||||||
Controller ctr1 = new Controller(31011,31001,31021,histoire);
|
Controller ctr1 = new Controller(31011,portUDPlistening_usr1,31021,"Theau",histoire);
|
||||||
|
|
||||||
|
// REMOTEUSER_1 - MIKE
|
||||||
|
Controller ctr2 = new Controller(31012,portUDPlistening_remoteUsr2,31022,"Leonie",histoire);
|
||||||
|
|
||||||
|
// REMOTEUSER_2 - ALICE
|
||||||
|
Controller ctr3 = new Controller(31013,portUDPlistening_remoteUsr3,31023,"Alexandre",histoire);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -476,17 +518,12 @@ public class Controller {
|
||||||
|
|
||||||
/************************* LOOP *******************************/
|
/************************* LOOP *******************************/
|
||||||
|
|
||||||
/** Création de l'interface graphique **/
|
|
||||||
ctr1.interfaceRunning =true;
|
|
||||||
ctr1.view=Interface.createAndShowGUI(ctr1);
|
|
||||||
ctr2.interfaceRunning =true;
|
|
||||||
ctr2.view=Interface.createAndShowGUI(ctr2);
|
|
||||||
ctr3.interfaceRunning =true;
|
|
||||||
ctr3.view=Interface.createAndShowGUI(ctr3);
|
|
||||||
|
|
||||||
/** loop **/
|
/** loop **/
|
||||||
while(ctr1.interfaceRunning) {
|
Boolean running = ctr1.interfaceRunning || ctr2.interfaceRunning || ctr3.interfaceRunning;
|
||||||
//ctr1.view.update(info)
|
while(running) {
|
||||||
|
running = ctr1.interfaceRunning || ctr2.interfaceRunning || ctr3.interfaceRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Fin de la boucle");
|
System.out.println("Fin de la boucle");
|
||||||
|
@ -497,17 +534,14 @@ public class Controller {
|
||||||
|
|
||||||
/** Close thread and socket **/
|
/** Close thread and socket **/
|
||||||
// REMOTEUSER_1 - MIKE
|
// REMOTEUSER_1 - MIKE
|
||||||
ctr2.myUser.closeAllChat();
|
ctr2.close();
|
||||||
ctr2.tcp_connect_thread.close();
|
|
||||||
ctr2.udp_connect_thread.close();
|
|
||||||
// REMOTEUSER_2 - ALICE
|
// REMOTEUSER_2 - ALICE
|
||||||
ctr3.myUser.closeAllChat();
|
ctr3.close();
|
||||||
ctr3.tcp_connect_thread.close();
|
|
||||||
ctr3.udp_connect_thread.close();
|
|
||||||
// LOCAL USER
|
// LOCAL USER
|
||||||
ctr1.myUser.closeAllChat();
|
ctr1.close();
|
||||||
ctr1.tcp_connect_thread.close();
|
|
||||||
ctr1.udp_connect_thread.close();
|
|
||||||
// AFFICHAGE
|
// AFFICHAGE
|
||||||
System.out.println("end program");
|
System.out.println("end program");
|
||||||
JOptionPane.showMessageDialog(null ,"END");
|
JOptionPane.showMessageDialog(null ,"END");
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class Historique {
|
||||||
int nb_changed_rows = stat.executeUpdate("USE tp_servlet_003");
|
int nb_changed_rows = stat.executeUpdate("USE tp_servlet_003");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nb_changed_rows = stat.executeUpdate("CREATE TABLE chat ( user_IPcode1 INTEGER, user_IPcode2 INTEGER ,Message VARCHAR(450) ,temps VARCHAR(450) )");
|
nb_changed_rows = stat.executeUpdate("CREATE TABLE chat ( user_IPcode1 INTEGER, user_IPcode2 INTEGER ,Message VARCHAR(450) ,temps VARCHAR(450) )");
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
package controller;
|
package controller;
|
||||||
|
|
||||||
import model.Chat;
|
import model.Chat;
|
||||||
import model.LocalUser;
|
|
||||||
import model.Msg_Text;
|
import model.Msg_Text;
|
||||||
import model.RemoteUser;
|
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.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -93,28 +88,31 @@ public class ListeningThreadTCPChat extends ListeningThread{
|
||||||
else {
|
else {
|
||||||
c=this.controller.openSession(rm);
|
c=this.controller.openSession(rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** listening tcp message from rm until session is close ***/
|
||||||
|
|
||||||
|
try {
|
||||||
|
String msgToprint;
|
||||||
|
while (!(input=in.readLine()).equals("end")/* && c.getActive()*/) {
|
||||||
|
|
||||||
|
System.out.println("("+this.controller.myUser.getPseudo()+") recoit => "+rm.getPseudo()+" : "+input);
|
||||||
|
Msg_Text message = new Msg_Text(rm,input);
|
||||||
|
c.addMessage(message);
|
||||||
|
if(controller.activeChat==c) {
|
||||||
|
controller.view.notifyNewMessage("("+message.getDate()+")\n"+c.getRemoteUser().getPseudo()+" : "+input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") Remote User unidentifiable => CLOSING CONNECTION");
|
System.out.println("("+this.controller.myUser.getPseudo()+") Remote User unidentifiable => CLOSING CONNECTION");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*** listening tcp message from rm until session is close ***/
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") WAIT FOR NEW MESSAGE FROM "+rm.getPseudo());
|
|
||||||
|
|
||||||
while (!(input=in.readLine()).equals("end")/* && c.getActive()*/) {
|
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") recoit => "+rm.getPseudo()+" : "+input);
|
|
||||||
c.addMessage(new Msg_Text(rm.getAddIP(),input));
|
|
||||||
// TODO Prévenir l'interface de la réception d'un nouveau message
|
|
||||||
controller.view.notifyNewMessage();
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package controller;
|
package controller;
|
||||||
|
|
||||||
import model.LocalUser;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
@ -51,9 +49,8 @@ public class ListeningThreadTCPConnection extends ListeningThread{
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") Server is not listening on port "+this.controller.myUser.getPortTCP());
|
System.out.println("("+this.controller.myUser.getPseudo()+") Server is not listening on port "+this.controller.myUser.getPortTCP());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// TODO changer le true
|
|
||||||
while(true) {
|
while(true) {
|
||||||
System.out.println("("+this.controller.myUser.getPseudo()+") WAITING FOR NEW CONNECTION");
|
System.out.println("("+this.controller.myUser.getPseudo()+") TCP Server waiting for new connection ...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.accept(servSocket);
|
this.accept(servSocket);
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class ListeningThreadUDP extends ListeningThread{
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
// On récupère l'adresse IP et le port TCP de l'utilisateur distant et ajout à la liste de l'utilisateur utilisant ce thread
|
// On récupère l'adresse IP et le port TCP de l'utilisateur distant et ajout à la liste de l'utilisateur utilisant ce thread
|
||||||
this.controller.myUser.addRemoteUser(InetAddress.getByName(tabMsg[0].split("/")[1]),Integer.parseInt(tabMsg[1]),tabMsg[2]);
|
controller.myUser.addRemoteUser(InetAddress.getByName(tabMsg[0].split("/")[1]),Integer.parseInt(tabMsg[1]),tabMsg[2]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -94,6 +94,9 @@ public class ListeningThreadUDP extends ListeningThread{
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if(controller.interfaceRunning) {
|
||||||
|
controller.view.updateActiveUsers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,11 +69,11 @@ public class LocalUser extends User{
|
||||||
RemoteUser tmpRemoteUser = new RemoteUser(remoteUserPseudo,remoteUserIP,remoteUserPortTCP);
|
RemoteUser tmpRemoteUser = new RemoteUser(remoteUserPseudo,remoteUserIP,remoteUserPortTCP);
|
||||||
int index = this.remoteUsersList.indexOf(tmpRemoteUser);
|
int index = this.remoteUsersList.indexOf(tmpRemoteUser);
|
||||||
if(index!=-1) {
|
if(index!=-1) {
|
||||||
System.out.println("("+this.pseudo+") - "+"MAJ, IP(port) of user : "+remoteUserPseudo+" => "+remoteUserIP+"("+remoteUserPortTCP+")");
|
System.out.println("("+this.pseudo+") "+"MAJ, IP(port) : "+remoteUserPseudo+" => "+remoteUserIP+"("+remoteUserPortTCP+")");
|
||||||
this.remoteUsersList.set(index,tmpRemoteUser);
|
this.remoteUsersList.set(index,tmpRemoteUser);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("("+this.pseudo+") - "+"Add new user IP(port) of user : "+remoteUserPseudo+" => "+remoteUserIP+"("+remoteUserPortTCP+")");
|
System.out.println("("+this.pseudo+") "+"Add new user IP(port) : "+remoteUserPseudo+" => "+remoteUserIP+"("+remoteUserPortTCP+")");
|
||||||
this.remoteUsersList.add(tmpRemoteUser);
|
this.remoteUsersList.add(tmpRemoteUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,8 @@ import java.text.SimpleDateFormat;
|
||||||
public abstract class Message {
|
public abstract class Message {
|
||||||
|
|
||||||
/*** ATTRIBUTS ***/
|
/*** ATTRIBUTS ***/
|
||||||
private Date date;
|
private String date;
|
||||||
private InetAddress autorIP;
|
private User autor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of Message
|
* Constructor of Message
|
||||||
* @parametres
|
* @parametres
|
||||||
|
@ -20,25 +19,22 @@ public abstract class Message {
|
||||||
*
|
*
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public Message(InetAddress autorIP) {
|
public Message(User autor) {
|
||||||
this.autorIP = autorIP;
|
this.autor = autor;
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||||
this.date = new Date();
|
this.date = dateFormat.format(new Date());
|
||||||
}
|
}
|
||||||
/*** GETTERS ***/
|
/*** GETTERS ***/
|
||||||
public Date getDate() {
|
public String getDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
public InetAddress getAutorIP() {
|
public User getAutor() {
|
||||||
return autorIP;
|
return autor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** SETTERS ***/
|
/*** SETTERS ***/
|
||||||
public void setDate(Date date) {
|
public void setAutorIP(User autor) {
|
||||||
this.date = date;
|
this.autor = autor;
|
||||||
}
|
|
||||||
public void setAutorIP(InetAddress autorIP) {
|
|
||||||
this.autorIP = autorIP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ public class Msg_Text extends Message{
|
||||||
/*** ATTRIBUT ***/
|
/*** ATTRIBUT ***/
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
public Msg_Text(InetAddress autorIP,String text) {
|
public Msg_Text(User autor,String text) {
|
||||||
super(autorIP);
|
super(autor);
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.awt.event.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import controller.Controller;
|
import controller.Controller;
|
||||||
import model.RemoteUser;
|
|
||||||
|
|
||||||
public class Interface extends JFrame implements ActionListener, WindowListener {
|
public class Interface extends JFrame implements ActionListener, WindowListener {
|
||||||
|
|
||||||
|
@ -18,14 +17,15 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
public Controller controller;
|
public Controller controller;
|
||||||
|
|
||||||
public JLabel Pseudolabel;
|
public JLabel Pseudolabel;
|
||||||
public JTextField PseudotextField;
|
public JLabel ChangePseudolabel;
|
||||||
|
public JTextField ChangePseudotextField;
|
||||||
|
|
||||||
public JTextArea MessagetextArea;
|
public JTextArea MessagetextArea;
|
||||||
public JTextField MessagetextField;
|
public JTextField MessagetextField;
|
||||||
public JScrollPane scrollpane;
|
public JScrollPane scrollpane;
|
||||||
|
|
||||||
public JButton RemoteUserButton;
|
public JButton RemoteUserButton;
|
||||||
public JComboBox RemoteUserbox;
|
public JComboBox<String> RemoteUserbox;
|
||||||
public JButton CloseConversationButton;
|
public JButton CloseConversationButton;
|
||||||
|
|
||||||
//Specifies the look and feel to use. Valid values:
|
//Specifies the look and feel to use. Valid values:
|
||||||
|
@ -47,53 +47,89 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
public Component createComponents() {
|
public Component createComponents() {
|
||||||
|
|
||||||
//Pseudo setup
|
//Pseudo setup
|
||||||
PseudotextField = new JTextField();
|
JPanel changePseudoPanel = new JPanel(new GridLayout(1, 0));
|
||||||
PseudotextField.setColumns(10);
|
ChangePseudolabel = new JLabel("Change nickname : ");
|
||||||
PseudotextField.addActionListener(this);
|
changePseudoPanel.add(ChangePseudolabel);
|
||||||
Pseudolabel = new JLabel("Your current username is: " + controller.getMyUser().getPseudo());
|
ChangePseudotextField = new JTextField();
|
||||||
Pseudolabel.setLabelFor(PseudotextField);
|
ChangePseudotextField.setColumns(10);
|
||||||
|
ChangePseudotextField.addActionListener(this);
|
||||||
|
changePseudoPanel.add(ChangePseudotextField);
|
||||||
|
|
||||||
|
Pseudolabel = new JLabel("Nickname : "+controller.getMyUser().getPseudo());
|
||||||
|
Pseudolabel.setLabelFor(ChangePseudotextField);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Remote user list setup
|
//Remote user list setup
|
||||||
RemoteUserButton = new JButton("Click to get Remote User list");
|
RemoteUserButton = new JButton("Start session");
|
||||||
RemoteUserButton.addActionListener(this);
|
RemoteUserButton.addActionListener(this);
|
||||||
|
|
||||||
|
|
||||||
|
// Remote user list
|
||||||
//Converts the Userlist to a Pseudotab for treatment in actionPerformed
|
//Converts the Userlist to a Pseudotab for treatment in actionPerformed
|
||||||
String[] pseudotab = new String[controller.getMyUser().getRemoteUsersList().size()];
|
String[] pseudotab = controller.askUpdateActiveUsers();
|
||||||
for(int i=0; i < controller.getMyUser().getRemoteUsersList().size(); i++) {
|
RemoteUserbox = new JComboBox<String>(pseudotab);
|
||||||
pseudotab[i] = "(" + Integer.toString(i) + "): " + controller.getMyUser().getRemoteUsersList().get(i).getPseudo();
|
|
||||||
}
|
|
||||||
RemoteUserbox = new JComboBox(pseudotab);
|
|
||||||
RemoteUserbox.setEditable(true);
|
RemoteUserbox.setEditable(true);
|
||||||
RemoteUserbox.addActionListener(this);
|
RemoteUserbox.addActionListener(this);
|
||||||
RemoteUserbox.setVisible(false);
|
RemoteUserbox.setVisible(false);
|
||||||
CloseConversationButton = new JButton("Click to close active chat");
|
|
||||||
|
// Close session
|
||||||
|
CloseConversationButton = new JButton("Close session");
|
||||||
CloseConversationButton.addActionListener(this);
|
CloseConversationButton.addActionListener(this);
|
||||||
CloseConversationButton.setVisible(false);
|
CloseConversationButton.setVisible(false);
|
||||||
|
|
||||||
|
JPanel userListsPanel = new JPanel(new GridLayout(1, 0));
|
||||||
|
|
||||||
|
userListsPanel.add(RemoteUserButton);
|
||||||
|
userListsPanel.add(RemoteUserbox);
|
||||||
|
userListsPanel.add(CloseConversationButton);
|
||||||
|
|
||||||
|
|
||||||
//Messages setup
|
//Messages setup
|
||||||
MessagetextField = new JTextField();
|
MessagetextField = new JTextField();
|
||||||
MessagetextField.setColumns(10);
|
MessagetextField.setColumns(10);
|
||||||
MessagetextField.addActionListener(this);
|
MessagetextField.addActionListener(this);
|
||||||
MessagetextArea = new JTextArea("Message field: ");
|
MessagetextArea = new JTextArea("Chat");
|
||||||
scrollpane = new JScrollPane();
|
scrollpane = new JScrollPane();
|
||||||
scrollpane.getViewport().add(MessagetextArea);
|
scrollpane.getViewport().add(MessagetextArea);
|
||||||
scrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
scrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
scrollpane.setPreferredSize(new Dimension(600,60));
|
||||||
MessagetextField.setVisible(false);
|
MessagetextField.setVisible(false);
|
||||||
MessagetextArea.setVisible(false);
|
MessagetextArea.setVisible(false);
|
||||||
scrollpane.setVisible(false);
|
scrollpane.setVisible(false);
|
||||||
|
// Create a placeholder on JTextField
|
||||||
|
MessagetextField.addFocusListener(new FocusListener() {
|
||||||
|
@Override
|
||||||
|
public void focusGained(FocusEvent e) {
|
||||||
|
if (MessagetextField.getText().equals("Your message")) {
|
||||||
|
MessagetextField.setText("");
|
||||||
|
MessagetextField.setForeground(Color.BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void focusLost(FocusEvent e) {
|
||||||
|
if (MessagetextField.getText().isEmpty()) {
|
||||||
|
MessagetextField.setForeground(Color.GRAY);
|
||||||
|
MessagetextField.setText("Your message");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An easy way to put space between a top-level container
|
* An easy way to put space between a top-level container
|
||||||
* and its contents is to put the contents in a JPanel
|
* and its contents is to put the contents in a JPanel
|
||||||
* that has an "empty" border.
|
* that has an "empty" border.
|
||||||
*/
|
*/
|
||||||
JPanel pane = new JPanel(new GridLayout(0, 2));
|
JPanel header = new JPanel(new GridLayout(0, 1));
|
||||||
pane.add(Pseudolabel);
|
header.add(Pseudolabel);
|
||||||
pane.add(PseudotextField);
|
header.add(changePseudoPanel);
|
||||||
pane.add(RemoteUserButton);
|
header.add(userListsPanel);
|
||||||
pane.add(RemoteUserbox);
|
|
||||||
pane.add(scrollpane);
|
JPanel pane = new JPanel(new BorderLayout());
|
||||||
pane.add(MessagetextField);
|
pane.add(header,BorderLayout.NORTH);
|
||||||
pane.add(CloseConversationButton);
|
pane.add(scrollpane,BorderLayout.CENTER);
|
||||||
|
pane.add(MessagetextField,BorderLayout.SOUTH);
|
||||||
pane.setBorder(BorderFactory.createEmptyBorder(
|
pane.setBorder(BorderFactory.createEmptyBorder(
|
||||||
30, //top
|
30, //top
|
||||||
30, //left
|
30, //left
|
||||||
|
@ -105,8 +141,8 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if(e.getSource() == PseudotextField) { //Changing pseudo
|
if(e.getSource() == ChangePseudotextField) { //Changing pseudo
|
||||||
String Textinput = PseudotextField.getText();
|
String Textinput = ChangePseudotextField.getText();
|
||||||
Pseudolabel.setText("Your current username is: " + Textinput);
|
Pseudolabel.setText("Your current username is: " + Textinput);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -117,7 +153,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
}
|
}
|
||||||
}else if(e.getSource() == MessagetextField){ //Messages
|
}else if(e.getSource() == MessagetextField){ //Messages
|
||||||
String Textinput = MessagetextField.getText();
|
String Textinput = MessagetextField.getText();
|
||||||
MessagetextArea.setText(MessagetextArea.getText() + controller.getMyUser().getPseudo() + ": " + Textinput + "\n");
|
MessagetextArea.setText(MessagetextArea.getText() + "\n" + controller.getMyUser().getPseudo() + " : " + Textinput );
|
||||||
MessagetextField.setText("");
|
MessagetextField.setText("");
|
||||||
controller.askToSend(Textinput); // ask to send to controller
|
controller.askToSend(Textinput); // ask to send to controller
|
||||||
|
|
||||||
|
@ -129,15 +165,16 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
scrollpane.setVisible(false);
|
scrollpane.setVisible(false);
|
||||||
MessagetextField.setVisible(false);
|
MessagetextField.setVisible(false);
|
||||||
CloseConversationButton.setVisible(false);
|
CloseConversationButton.setVisible(false);
|
||||||
}else { // Choice in remote user list
|
}else if(e.getSource() == RemoteUserbox){ // Choice in remote user list
|
||||||
|
|
||||||
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 = RemoteUserbox.getSelectedIndex();
|
||||||
|
//String.valueOf(((String) cb.getSelectedItem()).charAt(1)));
|
||||||
|
|
||||||
// start or switch chat => get history
|
// start or switch chat => get history
|
||||||
String history = controller.askOpenSession(selectedUsernb);
|
String history = controller.askOpenSession(selectedUsernb);
|
||||||
// display it
|
// display it
|
||||||
MessagetextArea.setText("Message:"+history);
|
MessagetextArea.setText(history);
|
||||||
MessagetextField.setVisible(true);
|
MessagetextField.setVisible(true);
|
||||||
scrollpane.setVisible(true);
|
scrollpane.setVisible(true);
|
||||||
MessagetextArea.setVisible(true);
|
MessagetextArea.setVisible(true);
|
||||||
|
@ -198,14 +235,15 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
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.setPreferredSize(new Dimension(400,300));
|
||||||
|
|
||||||
//Ends all running background tasks upon closing the window
|
//Ends all running background tasks upon closing the window
|
||||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
||||||
System.out.println("Window has been closed");
|
System.out.println("("+controller.getMyUser().getPseudo()+") Window has been closed");
|
||||||
app.controller.interfaceRunning = false;
|
controller.askForClose();
|
||||||
System.exit(0);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -225,14 +263,14 @@ public class Interface extends JFrame implements ActionListener, WindowListener
|
||||||
public void windowClosing(WindowEvent e) {}
|
public void windowClosing(WindowEvent e) {}
|
||||||
|
|
||||||
|
|
||||||
public void notifyNewMessage() {
|
public void notifyNewMessage(String msg) {
|
||||||
String newMessage = controller.askNewMessage();
|
MessagetextArea.setText(MessagetextArea.getText() + "\n" + msg);
|
||||||
//TOCHECK maybe better way to do it
|
|
||||||
if(newMessage!="") {
|
|
||||||
//TODO afficher le message
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateActiveUsers() {
|
||||||
|
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>( controller.askUpdateActiveUsers() );
|
||||||
|
RemoteUserbox.setModel( model );
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
Loading…
Reference in a new issue