ajout selection remoteuser

This commit is contained in:
Alexandre Gonzalvez 2020-12-16 12:22:58 +01:00
parent 89b3f1aa97
commit e748951c79
2 changed files with 70 additions and 53 deletions

View file

@ -363,7 +363,7 @@ public class Controller {
date = new Date();
date1.setTime(date);
dateString=date1.toString();
this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateString );
//this.getHistory().saveMessage(getMyUser(), c.getRemoteUser(),message ,dateString );
/*
System.out.println(this.getHistory());
@ -378,7 +378,7 @@ public class Controller {
//this.getHistory().saveMessage(this.myUser, c.getRemoteUser(),message ,dateString);
// Envoie du message (avec la date)
//DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
out.println(dateString);
out.println(message);
}
@ -489,60 +489,70 @@ public class Controller {
/*************************************************************************************************************************/
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("start program");
System.out.println("start program");
Historique histoire=new Historique();
Historique histoire=new Historique();
/** 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
Controller ctr1 = new Controller(31011,31001,31021,histoire);
/** 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
Controller ctr1 = new Controller(31011,31001,31021,histoire);
/** Création de l'interface graphique **/
ctr1.hisView=Interface.createAndShowGUI(ctr1);
/** Création de l'interface graphique **/
Boolean interfaceRunning = true;
ctr1.hisView=Interface.createAndShowGUI(ctr1);
/** Simulation of a session **/
// SELECT REMOTE USER
Chat chatwithrm0 = ctr1.myUser.addChats(ctr1.myUser.getRemoteUsersList().get(0));
// AFFICHAGE REMOTE USER CHOISIE
System.out.println("("+ctr1.myUser.getPseudo()+" ) OPEN SESSION WITH "+ctr1.myUser.getRemoteUsersList().get(0).getPseudo());
// OPEN SESSION
ctr1.openSession(chatwithrm0);
// SEND MESSAGE
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"test"), chatwithrm0);
// CLOSE SESSION
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"end"), chatwithrm0);
ctr1.closeSession(chatwithrm0);
/** Simulation of a session **/
/** Unused function **/
// MANUAL SELECTION OF ACTIVE USER
//ctr1.selectActiveUser();
// CHANGE USER NICKNAME
//ctr1.changePseudo();
// SELECT REMOTE USER
Chat chatwithrm0 = ctr1.myUser.addChats(ctr1.myUser.getRemoteUsersList().get(0));
// AFFICHAGE REMOTE USER CHOISIE
System.out.println("("+ctr1.myUser.getPseudo()+" ) OPEN SESSION WITH "+ctr1.myUser.getRemoteUsersList().get(0).getPseudo());
// OPEN SESSION
ctr1.openSession(chatwithrm0);
// SEND MESSAGE
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"test"), chatwithrm0);
// CLOSE SESSION
ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"end"), chatwithrm0);
ctr1.closeSession(chatwithrm0);
/** Close thread and socket **/
// SLEEP 5 SEC
System.out.println("Sleep mode for 5 seconds ...");
Thread.sleep(5000);
// REMOTEUSER_1 - MIKE
ctr2.myUser.closeAllRemainingChatSocket();
ctr2.tcp_connect_thread.close();
ctr2.udp_connect_thread.close();
// REMOTEUSER_2 - ALICE
ctr3.myUser.closeAllRemainingChatSocket();
ctr3.tcp_connect_thread.close();
ctr3.udp_connect_thread.close();
// LOCAL USER
ctr1.myUser.closeAllRemainingChatSocket();
ctr1.tcp_connect_thread.close();
ctr1.udp_connect_thread.close();
// AFFICHAGE
System.out.println("end program");
JOptionPane.showMessageDialog(null ,"END");
/** Unused function **/
// MANUAL SELECTION OF ACTIVE USER
//ctr1.selectActiveUser();
// CHANGE USER NICKNAME
//ctr1.changePseudo();
/*
while(interfaceRunning) {
}*/
/** Close thread and socket **/
// SLEEP 20 SEC
System.out.println("Sleep mode for 20 seconds ...");
Thread.sleep(20000);
// REMOTEUSER_1 - MIKE
ctr2.myUser.closeAllRemainingChatSocket();
ctr2.tcp_connect_thread.close();
ctr2.udp_connect_thread.close();
// REMOTEUSER_2 - ALICE
ctr3.myUser.closeAllRemainingChatSocket();
ctr3.tcp_connect_thread.close();
ctr3.udp_connect_thread.close();
// LOCAL USER
ctr1.myUser.closeAllRemainingChatSocket();
ctr1.tcp_connect_thread.close();
ctr1.udp_connect_thread.close();
// AFFICHAGE
System.out.println("end program");
JOptionPane.showMessageDialog(null ,"END");
}
}

View file

@ -101,8 +101,10 @@ public class Interface implements ActionListener {
}else {
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)));
System.out.println("selectedUsernb: " + selectedUsernb); //Test pour voir si ça marche
//System.out.println("selectedUsernb: " + selectedUsernb); //Test pour voir si ça marche
//TODO Utiliser ce selectedUsernb pour faire le lien avec openSession de Controller
hisController.openSession(hisController.getMyUser().addChats(hisController.getMyUser().getRemoteUsersList().get(selectedUsernb)));
}
}
@ -157,6 +159,8 @@ public class Interface implements ActionListener {
JFrame frame = new JFrame("SwingApplication");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Interface app = new Interface(controller);
Component contents = app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
@ -167,6 +171,9 @@ public class Interface implements ActionListener {
return app;
}
/*
public static void main(String[] args) throws IOException {
//Schedule a job for the event-dispatching thread: