Jämför commits
8 commits
Upphovsman | SHA1 | Datum | |
---|---|---|---|
|
558bc8beda | ||
|
508a1b89e8 | ||
|
f9fa379fc3 | ||
|
711cc37040 | ||
|
2caf30da03 | ||
|
65c729b9aa | ||
|
6aa087f1bc | ||
|
b3f0a3220c |
15 ändrade filer med 553 tillägg och 19 borttagningar
84
Implementation/.gitignore
vendored
84
Implementation/.gitignore
vendored
|
@ -1 +1,85 @@
|
||||||
|
##############################
|
||||||
|
## Java
|
||||||
|
##############################
|
||||||
|
.mtj.tmp/
|
||||||
|
*.class
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
*.nar
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## Maven
|
||||||
|
##############################
|
||||||
|
target/
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
pom.xml.bak
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## Gradle
|
||||||
|
##############################
|
||||||
/bin/
|
/bin/
|
||||||
|
bin/
|
||||||
|
build/
|
||||||
|
.gradle
|
||||||
|
.gradletasknamecache
|
||||||
|
gradle-app.setting
|
||||||
|
!gradle-wrapper.jar
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## IntelliJ
|
||||||
|
##############################
|
||||||
|
out/
|
||||||
|
.idea/
|
||||||
|
.idea_modules/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## Eclipse
|
||||||
|
##############################
|
||||||
|
.settings/
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
.metadata
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.loadpath
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## NetBeans
|
||||||
|
##############################
|
||||||
|
nbproject/private/
|
||||||
|
build/
|
||||||
|
nbbuild/
|
||||||
|
dist/
|
||||||
|
nbdist/
|
||||||
|
nbactions.xml
|
||||||
|
nb-configuration.xml
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## Visual Studio Code
|
||||||
|
##############################
|
||||||
|
.vscode/
|
||||||
|
.code-workspace
|
||||||
|
|
||||||
|
##############################
|
||||||
|
## OS X
|
||||||
|
##############################
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import src.Protocoles.*;
|
import src.Protocoles.*;
|
||||||
|
import src.Model.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -23,7 +24,7 @@ import src.Protocoles.*;
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ChatApp {
|
public class ChatApp extends Thread{
|
||||||
|
|
||||||
/* Liste des utilisateurs actifs */
|
/* Liste des utilisateurs actifs */
|
||||||
private ListUtilisateurs actifUsers ;
|
private ListUtilisateurs actifUsers ;
|
||||||
|
@ -196,11 +197,9 @@ public class ChatApp {
|
||||||
return h ;
|
return h ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args) throws IOException {
|
public static void main (String[] args) throws IOException {
|
||||||
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
|
ChatApp app = new ChatApp(args[0],Integer.parseInt(args[1])) ;
|
||||||
|
System.out.println("On lance le chatapp");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||||
|
@ -211,6 +210,7 @@ public class ChatApp {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
ExecutorService execTCP = Executors.newFixedThreadPool(1000);
|
ExecutorService execTCP = Executors.newFixedThreadPool(1000);
|
||||||
|
System.out.println("On lance l'écoute TCP de chatapp");
|
||||||
execTCP.submit(new RunnerEcouteTCP(app));
|
execTCP.submit(new RunnerEcouteTCP(app));
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package src.Controller;
|
package src.Model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package src.Controller;
|
package src.Model;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ListUtilisateurs {
|
public class ListUtilisateurs {
|
||||||
|
@ -37,6 +38,16 @@ public class ListUtilisateurs {
|
||||||
return null ;
|
return null ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Utilisateur getIPList(InetAddress ip) throws Exception {
|
||||||
|
for(Utilisateur elem: this.actifUsers)
|
||||||
|
{
|
||||||
|
if (elem.getIp().equals(ip) ) {
|
||||||
|
return elem ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception("No such user with this IP address") ;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprimer de la liste des utilisateurs actifs 'actifUsers' un certain utilisateur
|
* Supprimer de la liste des utilisateurs actifs 'actifUsers' un certain utilisateur
|
||||||
*
|
*
|
|
@ -1,16 +1,16 @@
|
||||||
package src.Controller;
|
package src.Model;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.io.Serializable;
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Classe representant les messages envoyés en TCP lors d'une session de clavardage
|
* Classe representant les messages envoyés en TCP lors d'une session de clavardage
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class MessageHorodate {
|
public class MessageHorodate implements Serializable {
|
||||||
private Utilisateur destinataire ;
|
private Utilisateur destinataire ;
|
||||||
private Utilisateur source ;
|
private Utilisateur source ;
|
||||||
private Date dateHorodatage ;
|
private Date dateHorodatage ;
|
|
@ -1,4 +1,4 @@
|
||||||
package src.Controller;
|
package src.Model;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
@ -13,6 +13,7 @@ import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
import src.Controller.ChatApp;
|
||||||
|
|
||||||
public class Modification_Pseudo extends JPanel{
|
public class Modification_Pseudo extends JPanel{
|
||||||
ChatApp app;
|
ChatApp app;
|
|
@ -1,4 +1,4 @@
|
||||||
package src.Controller;
|
package src.Model;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
|
@ -1,16 +1,62 @@
|
||||||
package src.Protocoles;
|
package src.Protocoles;
|
||||||
|
|
||||||
import src.Controller.ChatApp;
|
import src.Controller.ChatApp;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.beans.PropertyChangeSupport;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class RunnerEcouteTCP implements Runnable {
|
public class RunnerEcouteTCP extends Thread {
|
||||||
ChatApp app ;
|
public ChatApp app ;
|
||||||
|
private PropertyChangeSupport pcs;
|
||||||
|
private ArrayList<SessionClavardage> ListeSessions = new ArrayList<SessionClavardage>();
|
||||||
public RunnerEcouteTCP(ChatApp app) {
|
public RunnerEcouteTCP(ChatApp app) {
|
||||||
this.app = app ;
|
this.app = app ;
|
||||||
|
this.pcs = new PropertyChangeSupport(this);
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addPropertyChangeListener(PropertyChangeListener pcl) {
|
||||||
|
this.pcs.addPropertyChangeListener("NouvelleSession",pcl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Méthode pour qu'un objet de la classe ChatApp soit constamment en écoute de potentielles connexions
|
||||||
|
* @param app L'utilisateur en écoute de potentielles communications
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public void ecouteTCP(ChatApp app) {
|
||||||
|
ServerSocket ss = null;
|
||||||
|
System.out.println("Ecoute TCP activee");
|
||||||
|
try {
|
||||||
|
ss = new ServerSocket(5000); // On ecoute sur le port 5000
|
||||||
|
System.out.println("Socket d'ecoute cree");
|
||||||
|
while(true) { // Ecoute en boucle
|
||||||
|
System.out.println("Attente Session de clavardage");
|
||||||
|
Socket link = ss.accept(); // Blocante
|
||||||
|
SessionClavardage session = new SessionClavardage(link,app);
|
||||||
|
this.ListeSessions.add(session);
|
||||||
|
pcs.firePropertyChange("NouvelleSession",false,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SessionClavardage getSessionClavardage() {
|
||||||
|
return(this.ListeSessions.remove(0));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
ecouteTCP(this.app);
|
||||||
|
|
||||||
TCPEchange.ecouteTCP(app);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
168
Implementation/src/Protocoles/SessionClavardage.java
Normal file
168
Implementation/src/Protocoles/SessionClavardage.java
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
package src.Protocoles;
|
||||||
|
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.beans.PropertyChangeSupport;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import src.Controller.ChatApp;
|
||||||
|
import src.Model.MessageHorodate;
|
||||||
|
import src.Model.Utilisateur;
|
||||||
|
|
||||||
|
public class SessionClavardage extends Thread {
|
||||||
|
private Socket link;
|
||||||
|
private ChatApp app;
|
||||||
|
private Utilisateur u2;
|
||||||
|
private ObjectOutputStream out;
|
||||||
|
private ObjectInputStream in;
|
||||||
|
private PropertyChangeSupport pcs;
|
||||||
|
private ArrayList<MessageHorodate> derniersMsg; // on met temporairement les derniers msgs pour éviter les pb de synchro inter-threads
|
||||||
|
|
||||||
|
public SessionClavardage(Socket link, ChatApp app) {
|
||||||
|
this.setLink(link);
|
||||||
|
this.setApp(app);
|
||||||
|
try {
|
||||||
|
this.setU2(app.getActifUsers().getIPList(link.getInetAddress()));
|
||||||
|
this.setOut(new ObjectOutputStream(link.getOutputStream()));
|
||||||
|
this.setIn(new ObjectInputStream(link.getInputStream()));
|
||||||
|
}catch(Exception e) {
|
||||||
|
e.getStackTrace();
|
||||||
|
}
|
||||||
|
this.derniersMsg = new ArrayList<MessageHorodate>();
|
||||||
|
this.pcs = new PropertyChangeSupport(this);
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SessionClavardage(Utilisateur u2, ChatApp app) {
|
||||||
|
this.setU2(u2);
|
||||||
|
this.setApp(app);
|
||||||
|
try {
|
||||||
|
Socket s = new Socket(u2.getIp(),5000);
|
||||||
|
this.setOut(new ObjectOutputStream(s.getOutputStream()));
|
||||||
|
this.setIn(new ObjectInputStream(s.getInputStream()));
|
||||||
|
this.setLink(s);
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
this.derniersMsg = new ArrayList<MessageHorodate>();
|
||||||
|
this.pcs = new PropertyChangeSupport(this);
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addPropertyChangeListener(PropertyChangeListener pcl){
|
||||||
|
this.pcs.addPropertyChangeListener("MessageRecu",pcl);
|
||||||
|
this.pcs.addPropertyChangeListener("FinDeLaSession",pcl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void arretSession() {
|
||||||
|
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),".",2);
|
||||||
|
try {
|
||||||
|
getOut().writeObject(msgh.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
link.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void envoiMsg(String msg) {
|
||||||
|
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),msg,1);
|
||||||
|
try {
|
||||||
|
getOut().writeObject(msgh.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageHorodate getDernierMsg() {
|
||||||
|
return this.derniersMsg.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
String plaintext = null;
|
||||||
|
MessageHorodate msg = null;
|
||||||
|
while(true) {
|
||||||
|
try {
|
||||||
|
plaintext = (String) getIn().readObject();
|
||||||
|
msg = MessageHorodate.stringToMessageHorodate(plaintext);
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
pcs.firePropertyChange("FinDeLaSession", false, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(msg.getType() == 2) {
|
||||||
|
pcs.firePropertyChange("FinDeLaSession", false, true);
|
||||||
|
try {
|
||||||
|
link.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
derniersMsg.add(msg);
|
||||||
|
pcs.firePropertyChange("MessageRecu",false,true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectOutputStream getOut() {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOut(ObjectOutputStream out) {
|
||||||
|
this.out = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectInputStream getIn() {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIn(ObjectInputStream in) {
|
||||||
|
this.in = in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Socket getLink() {
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLink(Socket link) {
|
||||||
|
this.link = link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatApp getApp() {
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApp(ChatApp app) {
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Utilisateur getU2() {
|
||||||
|
return u2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setU2(Utilisateur u2) {
|
||||||
|
this.u2 = u2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import src.Controller.*;
|
import src.Controller.*;
|
||||||
|
import src.Model.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import src.Controller.*;
|
import src.Controller.*;
|
||||||
|
import src.Model.*;
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Classe representant les echanges UDP entre utilisateurs.
|
* Classe representant les echanges UDP entre utilisateurs.
|
||||||
|
@ -27,6 +28,7 @@ public class UDPEchange {
|
||||||
private static Boolean Connecte = true;
|
private static Boolean Connecte = true;
|
||||||
// True si l'utilisateur peut se connecter avec ce nom d'utilisateur , False sinon
|
// True si l'utilisateur peut se connecter avec ce nom d'utilisateur , False sinon
|
||||||
|
|
||||||
|
private static Boolean EcouteEnCours = false;
|
||||||
/**
|
/**
|
||||||
* Getter
|
* Getter
|
||||||
* @return le boolean connecte (True s'il peut se connecter avec ce nom d'utilisateur , False sinon)
|
* @return le boolean connecte (True s'il peut se connecter avec ce nom d'utilisateur , False sinon)
|
||||||
|
|
191
Implementation/src/View/ViewSession.java
Normal file
191
Implementation/src/View/ViewSession.java
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
package src.View;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import src.Controller.*;
|
||||||
|
import src.Model.MessageHorodate;
|
||||||
|
import src.Model.Utilisateur;
|
||||||
|
import src.Protocoles.SessionClavardage;
|
||||||
|
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Classe representant la fenetre pour chaque session de clavardage.
|
||||||
|
*/
|
||||||
|
public class ViewSession implements PropertyChangeListener{
|
||||||
|
JFrame frame ;
|
||||||
|
ChatApp app;
|
||||||
|
Utilisateur destination ; // Celui avec qui on va discuter
|
||||||
|
Utilisateur source; //Nous
|
||||||
|
SessionClavardage session;
|
||||||
|
WindowAdapter wa ;
|
||||||
|
JPanel panel ;
|
||||||
|
JTextArea textAreaAffichage ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructeur d'une fenetre de session de clavardage.
|
||||||
|
* @param app Un objet de type ChatApp pour posseder toutes les informations de l'utilisateur
|
||||||
|
* @param User2 L'utilisateur avec qui l'on souhaite discuter et passer en parametre sous forme de String
|
||||||
|
*/
|
||||||
|
public ViewSession(SessionClavardage session) {
|
||||||
|
this.session = session;
|
||||||
|
|
||||||
|
this.app = session.getApp() ;
|
||||||
|
this.frame = new JFrame("ChatApp-AL-NM");
|
||||||
|
this.source = this.app.getMe();
|
||||||
|
this.destination = session.getU2();
|
||||||
|
this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
// fixer les dimensions de la fenetre
|
||||||
|
this.frame.setSize(new Dimension(394, 344));
|
||||||
|
this.frame.setResizable(false);
|
||||||
|
wa = new WindowAdapter(){
|
||||||
|
public void windowClosing(WindowEvent e){
|
||||||
|
int reponse = View_Menu.showConfirmDialog();
|
||||||
|
if (reponse==0){
|
||||||
|
session.arretSession();
|
||||||
|
frame.dispose();
|
||||||
|
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
addWidgets();
|
||||||
|
frame.addWindowListener( wa ) ;
|
||||||
|
frame.setVisible(true);
|
||||||
|
session.addPropertyChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creer et ajouter les outils de la fenetre
|
||||||
|
*/
|
||||||
|
public void propertyChange(PropertyChangeEvent pce) {
|
||||||
|
switch(pce.getPropertyName()) {
|
||||||
|
case "MessageRecu":
|
||||||
|
MessageHorodate msgh = session.getDernierMsg();
|
||||||
|
textAreaAffichage.append(msgh.getMessage());
|
||||||
|
case "FinDeLaSession":
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void addWidgets() {
|
||||||
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||||
|
gridBagLayout.columnWidths = new int[]{394, 0};
|
||||||
|
gridBagLayout.rowHeights = new int[]{16, 220, 74, 0};
|
||||||
|
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||||
|
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||||
|
this.frame.getContentPane().setLayout(gridBagLayout);
|
||||||
|
this.panel = new JPanel();
|
||||||
|
// Zone pour ecrire de nouveau message
|
||||||
|
JTextArea textAreaSaisie = new JTextArea(5,3);
|
||||||
|
textAreaSaisie.setLineWrap(true);
|
||||||
|
textAreaSaisie.setForeground(Color.LIGHT_GRAY);
|
||||||
|
textAreaSaisie.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
|
||||||
|
textAreaSaisie.setText("Entrer du texte ici !!!");
|
||||||
|
JScrollPane scrollPane = new JScrollPane(textAreaSaisie);
|
||||||
|
// Creation d'un bouton envoye
|
||||||
|
JButton send = new JButton("Envoye");
|
||||||
|
frame.getRootPane().setDefaultButton(send);
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//**************************************** GERER LES ECHANGES ENTRE UTILISATEURS ***********************************
|
||||||
|
//******************************************************************************************************************
|
||||||
|
send.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
//UTILISER TCPENVOI
|
||||||
|
String AEnvoyer = textAreaSaisie.getText();
|
||||||
|
textAreaAffichage.append(AEnvoyer);
|
||||||
|
session.envoiMsg(AEnvoyer);
|
||||||
|
textAreaSaisie.setText("");
|
||||||
|
}});
|
||||||
|
// Creation d'un bouton vider la zone de saisie de texte
|
||||||
|
JButton reset = new JButton("Vider");
|
||||||
|
reset.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
textAreaSaisie.setText("");
|
||||||
|
}});
|
||||||
|
JLabel titre = new JLabel("Chat avec "+ this.destination.getPseudo(),SwingConstants.CENTER);
|
||||||
|
GridBagConstraints gbc_titre = new GridBagConstraints();
|
||||||
|
gbc_titre.anchor = GridBagConstraints.NORTH;
|
||||||
|
gbc_titre.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_titre.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_titre.gridx = 0;
|
||||||
|
gbc_titre.gridy = 0;
|
||||||
|
frame.getContentPane().add(titre, gbc_titre);
|
||||||
|
// Zone d'affichage de l'historique
|
||||||
|
this.textAreaAffichage = new JTextArea(10,5);
|
||||||
|
textAreaAffichage.setLineWrap(true);
|
||||||
|
this.textAreaAffichage.setText("");
|
||||||
|
JScrollPane scrollPaneAffichage = new JScrollPane(this.textAreaAffichage);
|
||||||
|
this.textAreaAffichage.setEditable(false); // il sert juste a afficher
|
||||||
|
GridBagConstraints gbc_textAreaAffichage = new GridBagConstraints();
|
||||||
|
gbc_textAreaAffichage.fill = GridBagConstraints.BOTH;
|
||||||
|
gbc_textAreaAffichage.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_textAreaAffichage.gridx = 0;
|
||||||
|
gbc_textAreaAffichage.gridy = 1;
|
||||||
|
frame.getContentPane().add(scrollPaneAffichage, gbc_textAreaAffichage);
|
||||||
|
panel.add(BorderLayout.CENTER, scrollPane);
|
||||||
|
panel.add(BorderLayout.SOUTH,send);
|
||||||
|
panel.add(BorderLayout.SOUTH,reset);
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||||
|
//Add the panel to the window.
|
||||||
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||||
|
gbc_panel.anchor = GridBagConstraints.NORTH;
|
||||||
|
gbc_panel.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_panel.gridx = 0;
|
||||||
|
gbc_panel.gridy = 2;
|
||||||
|
frame.getContentPane().add(panel, gbc_panel);
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*JTextArea textAreaAffichage = new JTextArea(10,5);
|
||||||
|
textAreaAffichage.setEditable(false);
|
||||||
|
JTextArea textAreaSaisie = new JTextArea(10,5);
|
||||||
|
textAreaSaisie.setForeground(Color.LIGHT_GRAY);
|
||||||
|
textAreaSaisie.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
|
||||||
|
textAreaSaisie.setText("Entrer du texte ici !!!");
|
||||||
|
JScrollPane scrollPane = new JScrollPane(textAreaSaisie);
|
||||||
|
JButton send = new JButton("Envoye");
|
||||||
|
frame.getRootPane().setDefaultButton(send);
|
||||||
|
send.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
//UTILISER TCPENVOI
|
||||||
|
textAreaSaisie.setText("");
|
||||||
|
}});
|
||||||
|
JButton reset = new JButton("Vider");
|
||||||
|
reset.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
textAreaSaisie.setText("");
|
||||||
|
}});
|
||||||
|
JLabel titre = new JLabel("Chat avec "+ this.destination.getPseudo(),SwingConstants.CENTER);
|
||||||
|
panel.add(BorderLayout.CENTER, scrollPane);
|
||||||
|
//panel.add(scrollPane);
|
||||||
|
panel.add(BorderLayout.SOUTH,send);
|
||||||
|
panel.add(BorderLayout.SOUTH,reset);
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||||
|
//Add the panel to the window.
|
||||||
|
frame.getContentPane().add(BorderLayout.SOUTH, panel);
|
||||||
|
frame.getContentPane().add(BorderLayout.CENTER, textAreaAffichage);
|
||||||
|
frame.getContentPane().add(BorderLayout.NORTH, titre);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -88,10 +88,15 @@ public class View_Accueil implements ActionListener{
|
||||||
// on recupere le texte entree dans la zone de saisie
|
// on recupere le texte entree dans la zone de saisie
|
||||||
String pseudo = pseudofield.getText();
|
String pseudo = pseudofield.getText();
|
||||||
// On crée un objet de type ChatApp
|
// On crée un objet de type ChatApp
|
||||||
ChatApp app = new ChatApp(pseudo, 3000) ;
|
System.out.println("Lancement du ChatApp");
|
||||||
|
ChatApp app = new ChatApp(pseudo, 1234) ;
|
||||||
// on crée un thread qui va ecouter les connexions entrantes
|
// on crée un thread qui va ecouter les connexions entrantes
|
||||||
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||||
|
System.out.println("Lancement de UDP");
|
||||||
execUDP.submit(new RunnerEcouteUDP(app));
|
execUDP.submit(new RunnerEcouteUDP(app));
|
||||||
|
/*ExecutorService execTCP = Executors.newFixedThreadPool(1000);
|
||||||
|
System.out.println("On lance l'écoute TCP de chatapp");
|
||||||
|
execTCP.submit(new RunnerEcouteTCP(app));*/
|
||||||
Boolean connexion = false ;
|
Boolean connexion = false ;
|
||||||
try {
|
try {
|
||||||
// on tente une connexion avec ce pseudo
|
// on tente une connexion avec ce pseudo
|
||||||
|
|
|
@ -19,6 +19,7 @@ import javax.swing.JTextArea;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import src.Controller.*;
|
import src.Controller.*;
|
||||||
|
import src.Model.Utilisateur;
|
||||||
|
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
@ -85,6 +86,9 @@ public class View_Clavardage {
|
||||||
// Creation d'un bouton envoye
|
// Creation d'un bouton envoye
|
||||||
JButton send = new JButton("Envoye");
|
JButton send = new JButton("Envoye");
|
||||||
frame.getRootPane().setDefaultButton(send);
|
frame.getRootPane().setDefaultButton(send);
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//**************************************** GERER LES ECHANGES ENTRE UTILISATEURS ***********************************
|
||||||
|
//******************************************************************************************************************
|
||||||
send.addActionListener(new ActionListener(){
|
send.addActionListener(new ActionListener(){
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
//UTILISER TCPENVOI
|
//UTILISER TCPENVOI
|
||||||
|
|
|
@ -9,6 +9,8 @@ import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
@ -35,6 +37,9 @@ import javax.swing.JTextField;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import src.Controller.*;
|
import src.Controller.*;
|
||||||
|
import src.Model.Utilisateur;
|
||||||
|
import src.Protocoles.RunnerEcouteTCP;
|
||||||
|
import src.Protocoles.SessionClavardage;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
@ -44,7 +49,7 @@ import java.awt.SystemColor;
|
||||||
/*
|
/*
|
||||||
* Classe representant la fenetre de menu. Lance apres la connexion d'un utilisateur
|
* Classe representant la fenetre de menu. Lance apres la connexion d'un utilisateur
|
||||||
*/
|
*/
|
||||||
public class View_Menu {
|
public class View_Menu implements PropertyChangeListener{
|
||||||
JFrame frame;
|
JFrame frame;
|
||||||
JPanel panel;
|
JPanel panel;
|
||||||
JMenuBar menu;
|
JMenuBar menu;
|
||||||
|
@ -52,7 +57,7 @@ public class View_Menu {
|
||||||
JLabel jlabel;
|
JLabel jlabel;
|
||||||
JLabel Txt;
|
JLabel Txt;
|
||||||
WindowAdapter wa ;
|
WindowAdapter wa ;
|
||||||
|
private RunnerEcouteTCP ecouteTCP;
|
||||||
/*
|
/*
|
||||||
* Constructeur d'une fenetre de menu apres la connexion d'un utilisateur.
|
* Constructeur d'une fenetre de menu apres la connexion d'un utilisateur.
|
||||||
* @param app Un objet de type ChatApp pour posseder toutes les informations de l'utilisateur
|
* @param app Un objet de type ChatApp pour posseder toutes les informations de l'utilisateur
|
||||||
|
@ -92,8 +97,12 @@ public class View_Menu {
|
||||||
// Afficher la fenetre
|
// Afficher la fenetre
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
ecouteTCP.start();
|
||||||
|
this.ecouteTCP.addPropertyChangeListener(this); //TODO Problem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode static creant un pop-up demandant a l'utilisateur si il souhaite vraiment quitter.
|
* Methode static creant un pop-up demandant a l'utilisateur si il souhaite vraiment quitter.
|
||||||
*/
|
*/
|
||||||
|
@ -186,7 +195,8 @@ public class View_Menu {
|
||||||
cb.addActionListener(new ActionListener() {
|
cb.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
Object selected = cb.getSelectedItem();
|
Object selected = cb.getSelectedItem();
|
||||||
new View_Clavardage(app, selected.toString());
|
SessionClavardage session = new SessionClavardage(Utilisateur.stringToUtilisateur(selected.toString()),app);
|
||||||
|
new ViewSession(session);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -252,5 +262,16 @@ public class View_Menu {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent pce) {
|
||||||
|
switch(pce.getPropertyName()) {
|
||||||
|
case "NouvelleSession":
|
||||||
|
SessionClavardage session = this.ecouteTCP.getSessionClavardage();
|
||||||
|
session.addPropertyChangeListener(this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Laddar…
Referens i nytt ärende