Correction : Un utilisateur ne peut pas communiquer plusieurs fois en même temps avec la même personne
This commit is contained in:
parent
f56866329d
commit
7103a2b584
7 changed files with 62 additions and 34 deletions
|
@ -1,5 +1,30 @@
|
||||||
|
chatapp/Model/Utilisateur.java
|
||||||
|
chatapp.Model.Utilisateur
|
||||||
chatapp/Launcher.java
|
chatapp/Launcher.java
|
||||||
chatapp.Launcher
|
chatapp.Launcher
|
||||||
|
chatapp/Model/MessageHorodate.java
|
||||||
|
chatapp.Model.MessageHorodate
|
||||||
|
chatapp/Model/DataBase.java
|
||||||
|
chatapp.Model.DataBase
|
||||||
|
chatapp/Model/ListUtilisateurs.java
|
||||||
|
chatapp.Model.ListUtilisateurs
|
||||||
|
chatapp/Protocol/SessionClavardage.java
|
||||||
|
chatapp.Protocol.SessionClavardage
|
||||||
|
chatapp/Protocol/HttpEchange.java
|
||||||
|
chatapp.Protocol.HttpEchange
|
||||||
|
chatapp/View/View_Menu.java
|
||||||
|
chatapp.View.View_Menu
|
||||||
|
chatapp/View/ChangementPseudo.java
|
||||||
|
chatapp.View.ChangementPseudo
|
||||||
|
chatapp/Protocol/RunnerEcouteUDP.java
|
||||||
|
chatapp.Protocol.RunnerEcouteUDP
|
||||||
|
chatapp/Protocol/UDPEchange.java
|
||||||
|
chatapp.Protocol.RunnerUDP
|
||||||
|
chatapp.Protocol.UDPEchange
|
||||||
|
chatapp/Main.java
|
||||||
|
chatapp.Main
|
||||||
|
chatapp/View/View_Utilisateurs.java
|
||||||
|
chatapp.View.View_Utilisateurs
|
||||||
chatapp/View/ConnexionScreen.java
|
chatapp/View/ConnexionScreen.java
|
||||||
chatapp.View.ConnexionScreen
|
chatapp.View.ConnexionScreen
|
||||||
chatapp/Protocol/RunnerEcouteTCP.java
|
chatapp/Protocol/RunnerEcouteTCP.java
|
||||||
|
@ -9,33 +34,8 @@ chatapp/View/FenetreSession.java
|
||||||
chatapp.View.FenetreSession$1
|
chatapp.View.FenetreSession$1
|
||||||
chatapp/Controller/ChatApp.java
|
chatapp/Controller/ChatApp.java
|
||||||
chatapp.Controller.ChatApp
|
chatapp.Controller.ChatApp
|
||||||
chatapp/Model/DataBase.java
|
|
||||||
chatapp.Model.DataBase
|
|
||||||
chatapp/View/ChangementPseudo.java
|
|
||||||
chatapp.View.ChangementPseudo
|
|
||||||
chatapp/Protocol/RunnerEcouteUDP.java
|
|
||||||
chatapp.Protocol.RunnerEcouteUDP
|
|
||||||
chatapp/Model/ListUtilisateurs.java
|
|
||||||
chatapp.Model.ListUtilisateurs
|
|
||||||
chatapp/Protocol/UDPEchange.java
|
|
||||||
chatapp.Protocol.RunnerUDP
|
|
||||||
chatapp.Protocol.UDPEchange
|
|
||||||
chatapp/Model/MessageHorodate.java
|
|
||||||
chatapp.Model.MessageHorodate
|
|
||||||
chatapp/Main.java
|
|
||||||
chatapp.Main
|
|
||||||
chatapp/View/Clavardage.java
|
chatapp/View/Clavardage.java
|
||||||
chatapp.View.Clavardage
|
chatapp.View.Clavardage
|
||||||
chatapp.View.Clavardage$1
|
chatapp.View.Clavardage$1
|
||||||
chatapp/Protocol/SessionClavardage.java
|
|
||||||
chatapp.Protocol.SessionClavardage
|
|
||||||
chatapp/View/View_Utilisateurs.java
|
|
||||||
chatapp.View.View_Utilisateurs
|
|
||||||
chatapp/Model/Utilisateur.java
|
|
||||||
chatapp.Model.Utilisateur
|
|
||||||
chatapp/View/View_Menu.java
|
|
||||||
chatapp.View.View_Menu
|
|
||||||
chatapp/Protocol/HttpEchange.java
|
|
||||||
chatapp.Protocol.HttpEchange
|
|
||||||
chatapp/View/DemarrerSession.java
|
chatapp/View/DemarrerSession.java
|
||||||
chatapp.View.DemarrerSession
|
chatapp.View.DemarrerSession
|
||||||
|
|
|
@ -6,10 +6,12 @@ import chatapp.Model.Utilisateur;
|
||||||
import chatapp.Protocol.*;
|
import chatapp.Protocol.*;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p> Controller de l'application. C'est par cette méthode que chaque connexion et chaque session sont entamées.
|
* <p> Controller de l'application. C'est par cette méthode que chaque connexion et chaque session sont entamées.
|
||||||
|
@ -41,6 +43,7 @@ public class ChatApp implements PropertyChangeListener {
|
||||||
private RunnerEcouteUDP runnerEcouteUDP;
|
private RunnerEcouteUDP runnerEcouteUDP;
|
||||||
private boolean connecte;
|
private boolean connecte;
|
||||||
//private DataBase db;
|
//private DataBase db;
|
||||||
|
public ArrayList<String> ListeCommunication = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p> Getter : Connecte
|
* <p> Getter : Connecte
|
||||||
|
@ -407,4 +410,22 @@ public class ChatApp implements PropertyChangeListener {
|
||||||
public void setExterne(boolean externe) {
|
public void setExterne(boolean externe) {
|
||||||
isExterne = externe;
|
isExterne = externe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Un utilisateur ne peut pas ouvrir plusieurs sessions de clavardage avec le même utilisateur.
|
||||||
|
* <br> Cette methode compare les communications en cours pour retourner une liste d'utilisateurs avec
|
||||||
|
* lesquels les communications sont possibles
|
||||||
|
* </p>
|
||||||
|
* @return Une liste d'utilisateurs avec lesquels il peut communiquer
|
||||||
|
*/
|
||||||
|
public ArrayList<Utilisateur> createListeCommunicationPossible(){
|
||||||
|
ArrayList<Utilisateur> communication = new ArrayList<>();
|
||||||
|
for ( Utilisateur element : this.actifUsers.getActifUsers()){
|
||||||
|
if ( ! this.ListeCommunication.contains(element.getId())){
|
||||||
|
communication.add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return communication;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class Main extends Application {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
Rectangle2D tailleEcran = Screen.getPrimary().getBounds();
|
//Rectangle2D tailleEcran = Screen.getPrimary().getBounds();
|
||||||
this.chatapp = ChatApp.getInstance("Null",1234,this);
|
this.chatapp = ChatApp.getInstance("Null",1234,this);
|
||||||
FXMLLoader fichier = new FXMLLoader(getClass().getResource("/fenetres/ConnexionScreen.fxml"));
|
FXMLLoader fichier = new FXMLLoader(getClass().getResource("/fenetres/ConnexionScreen.fxml"));
|
||||||
Scene scene1 = new Scene(fichier.load(),600,400);
|
Scene scene1 = new Scene(fichier.load(),600,400);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package chatapp.Model;
|
package chatapp.Model;
|
||||||
|
|
||||||
|
import chatapp.Controller.ChatApp;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -28,6 +30,7 @@ public class ListUtilisateurs {
|
||||||
public synchronized void addList(Utilisateur u) {
|
public synchronized void addList(Utilisateur u) {
|
||||||
if (! this.appartient(u)){
|
if (! this.appartient(u)){
|
||||||
this.actifUsers.add(u);
|
this.actifUsers.add(u);
|
||||||
|
//ListeCommunicationPossible.add(u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,9 @@ public class SessionClavardage extends Thread {
|
||||||
if(this.app.isExterne()){
|
if(this.app.isExterne()){
|
||||||
isExterne="true"; // on indiquera dans le message si l'on est externe ou interne
|
isExterne="true"; // on indiquera dans le message si l'on est externe ou interne
|
||||||
}
|
}
|
||||||
|
System.out.println("Ajout d'un utilisateur dans communication");
|
||||||
|
app.ListeCommunication.add(getU2().getId());
|
||||||
|
System.out.println(app.ListeCommunication.size());
|
||||||
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),isExterne,3);
|
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),isExterne,3);
|
||||||
try {
|
try {
|
||||||
getOut().writeObject(msgh.toString());
|
getOut().writeObject(msgh.toString());
|
||||||
|
@ -165,12 +168,14 @@ public class SessionClavardage extends Thread {
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
try {
|
||||||
plaintext = (String) getIn().readObject();
|
plaintext = (String) getIn().readObject();
|
||||||
|
System.out.println("Message reçu");
|
||||||
msg = MessageHorodate.stringToMessageHorodate(plaintext);
|
msg = MessageHorodate.stringToMessageHorodate(plaintext);
|
||||||
|
System.out.println(msg.getMessage());
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
pcs.firePropertyChange("FinDeLaSession", false, true);
|
pcs.firePropertyChange("FinDeLaSession", false, true);
|
||||||
|
app.ListeCommunication.remove(u2.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(msg.getType() == 2) {
|
if(msg.getType() == 2) {
|
||||||
|
@ -180,11 +185,13 @@ public class SessionClavardage extends Thread {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
app.ListeCommunication.remove(u2.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(msg.getType() == 3) {
|
else if(msg.getType() == 3) {
|
||||||
System.out.println("Session Initiee");
|
System.out.println("Session Initiee");
|
||||||
this.u2 = msg.getSource() ;
|
this.u2 = msg.getSource() ;
|
||||||
|
app.ListeCommunication.add(u2.getId());
|
||||||
Platform.runLater( () ->
|
Platform.runLater( () ->
|
||||||
new FenetreSession(this)
|
new FenetreSession(this)
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,7 @@ package chatapp.View;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import chatapp.Controller.ChatApp;
|
import chatapp.Controller.ChatApp;
|
||||||
|
@ -45,9 +46,7 @@ public class DemarrerSession {
|
||||||
* @param event L'utilisateur vient de selectionner un utilisateur
|
* @param event L'utilisateur vient de selectionner un utilisateur
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void demarrerSessionAvec(ActionEvent event) {
|
void demarrerSessionAvec(ActionEvent event) { chatApp.demarrerSession(choixContact.getValue()); }
|
||||||
chatApp.demarrerSession(choixContact.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p> Handler permettant de retourner au menu principal sur pression du MenuButton</p>
|
* <p> Handler permettant de retourner au menu principal sur pression du MenuButton</p>
|
||||||
|
@ -73,10 +72,9 @@ public class DemarrerSession {
|
||||||
@FXML // This method is called by the FXMLLoader when initialization is complete
|
@FXML // This method is called by the FXMLLoader when initialization is complete
|
||||||
void initialize() {
|
void initialize() {
|
||||||
this.chatApp = ChatApp.getInstance();
|
this.chatApp = ChatApp.getInstance();
|
||||||
ListUtilisateurs utils = chatApp.getActifUsers();
|
ArrayList<Utilisateur> Com = chatApp.createListeCommunicationPossible();
|
||||||
for(Utilisateur u : utils.getActifUsers()){
|
for(Utilisateur u : Com ){
|
||||||
choixContact.getItems().add(u.getPseudo());
|
choixContact.getItems().add(u.getPseudo());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ public class View_Utilisateurs {
|
||||||
@FXML // This method is called by the FXMLLoader when initialization is complete
|
@FXML // This method is called by the FXMLLoader when initialization is complete
|
||||||
void initialize() {
|
void initialize() {
|
||||||
ListUtilisateurs utilisateurs = ChatApp.getInstance().getActifUsers();
|
ListUtilisateurs utilisateurs = ChatApp.getInstance().getActifUsers();
|
||||||
|
|
||||||
ListeUtilisateurs.setText("");
|
ListeUtilisateurs.setText("");
|
||||||
for(Utilisateur elem : utilisateurs.getActifUsers()) {
|
for(Utilisateur elem : utilisateurs.getActifUsers()) {
|
||||||
ListeUtilisateurs.appendText( " - " +elem.getPseudo() + '\n');
|
ListeUtilisateurs.appendText( " - " +elem.getPseudo() + '\n');
|
||||||
|
|
Loading…
Reference in a new issue