Merge branch view
This commit is contained in:
commit
220c585537
12 changed files with 620 additions and 93 deletions
|
@ -1,6 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<<<<<<< HEAD
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
=======
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-13">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="jgoodies-forms-1.8.0.jar" sourcepath="jgoodies-forms-1.8.0-sources.jar"/>
|
||||||
|
>>>>>>> View
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
BIN
Implementation/jgoodies-forms-1.8.0-sources.jar
Normal file
BIN
Implementation/jgoodies-forms-1.8.0-sources.jar
Normal file
Binary file not shown.
BIN
Implementation/jgoodies-forms-1.8.0.jar
Normal file
BIN
Implementation/jgoodies-forms-1.8.0.jar
Normal file
Binary file not shown.
|
@ -64,13 +64,14 @@ public class ChatApp {
|
||||||
* Envoie en broadcast ses informations utilisateurs et son nouveau pseudo
|
* Envoie en broadcast ses informations utilisateurs et son nouveau pseudo
|
||||||
*
|
*
|
||||||
* @param nouveau correspond au nouveau pseudo
|
* @param nouveau correspond au nouveau pseudo
|
||||||
|
* @return False si modiferPseudo a echoue, True sinon
|
||||||
*/
|
*/
|
||||||
public void modifierPseudo(String nouveau) throws IOException {
|
public Boolean modifierPseudo(String nouveau) throws IOException {
|
||||||
// Message que l'on envoie à tous les utilisateurs actifs
|
// Message que l'on envoie à tous les utilisateurs actifs
|
||||||
String broadcastMessage = "Demande Modification Pseudo\n" + this.getMe().toString() + "\n" + nouveau + "\n";
|
String broadcastMessage = "Demande Modification Pseudo\n" + this.getMe().toString() + "\n" + nouveau + "\n";
|
||||||
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(2000);
|
||||||
/* L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
/* L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
||||||
* pour savoir si son pseudo est accepte
|
* pour savoir si son pseudo est accepte
|
||||||
*/
|
*/
|
||||||
|
@ -87,11 +88,12 @@ public class ChatApp {
|
||||||
this.getMe().setPseudo(nouveau);
|
this.getMe().setPseudo(nouveau);
|
||||||
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
||||||
this.getActifUsers().afficherListeUtilisateurs();
|
this.getActifUsers().afficherListeUtilisateurs();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println("Connexion echoue");
|
System.out.println("Echec Modification pseudo");
|
||||||
System.exit(1) ; // A MODIFIER NORMALEMENT ON LUI DEMANDE DE CHOISIR UN NV MDP
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,24 +101,26 @@ public class ChatApp {
|
||||||
/**
|
/**
|
||||||
* Methode appelee lors de la connexion d'un nouvel utilisateur.
|
* Methode appelee lors de la connexion d'un nouvel utilisateur.
|
||||||
* Il va prevenir les utilisateurs du reseau de son arrivee.
|
* Il va prevenir les utilisateurs du reseau de son arrivee.
|
||||||
*
|
* @return False si Connexion a echoue, True sinon
|
||||||
*/
|
*/
|
||||||
public void connexion() throws IOException {
|
public Boolean connexion() throws IOException {
|
||||||
// Message que l'on envoie à tous les utilisateurs actifs
|
// Message que l'on envoie à tous les utilisateurs actifs
|
||||||
String broadcastMessage = "Connexion\n" + this.getMe().toString() ;
|
String broadcastMessage = "Connexion\n" + this.getMe().toString() ;
|
||||||
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000); // L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
Thread.sleep(2000); // L'utilisateur doit attendre la reponse de tous les utilisateurs connectes
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (UDPEchange.getConnecte()) {
|
if (UDPEchange.getConnecte()) {
|
||||||
System.out.println("Connexion reussie");
|
System.out.println("Connexion reussie");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println("Connexion echoue");
|
System.out.println("Connexion echoue");
|
||||||
System.exit(1) ; // A MODIFIER NORMALEMENT ON LUI DEMANDE DE CHOISIR UN NV MDP
|
UDPEchange.setConnecte(true);
|
||||||
|
return false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +133,7 @@ public class ChatApp {
|
||||||
// Message que l'on envoie à tous les utilisateurs actifs
|
// Message que l'on envoie à tous les utilisateurs actifs
|
||||||
String broadcastMessage = "Deconnexion\n" + this.getMe().toString() ;
|
String broadcastMessage = "Deconnexion\n" + this.getMe().toString() ;
|
||||||
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
UDPEchange.EnvoiBroadcast(broadcastMessage);
|
||||||
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -99,11 +99,14 @@ public class ListUtilisateurs {
|
||||||
* Méthode affichant la liste des utilisateurs actifs
|
* Méthode affichant la liste des utilisateurs actifs
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void afficherListeUtilisateurs() {
|
public String afficherListeUtilisateurs() {
|
||||||
System.out.println ("Liste des utilisateurs actifs : ");
|
System.out.println ("Liste des utilisateurs actifs : ");
|
||||||
|
String Utilisateur = "" ;
|
||||||
for(Utilisateur elem: this.actifUsers)
|
for(Utilisateur elem: this.actifUsers)
|
||||||
{
|
{
|
||||||
System.out.println (elem.toString());
|
System.out.println (elem.toString());
|
||||||
}
|
Utilisateur += (elem + "\n");
|
||||||
|
}
|
||||||
|
return Utilisateur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
49
Implementation/src/Modification_Pseudo.java
Normal file
49
Implementation/src/Modification_Pseudo.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
public class Modification_Pseudo extends JPanel{
|
||||||
|
ChatApp app;
|
||||||
|
public Modification_Pseudo(String name, ChatApp app) {
|
||||||
|
this.app = app ;
|
||||||
|
JLabel Text = new JLabel("Entrez un nouveau nom d'utilisateur!", SwingConstants.CENTER);
|
||||||
|
JTextField pseudofield = new JTextField(2); // Zone d'insertion de texte
|
||||||
|
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||||
|
//Ajout d'un bouton Valider
|
||||||
|
JButton Valider = new JButton("Valider");
|
||||||
|
this.getRootPane().setDefaultButton(Valider);
|
||||||
|
//Listen to events from the Valider button.
|
||||||
|
Valider.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
String nouveau = pseudofield.getText();
|
||||||
|
try {
|
||||||
|
Boolean resultat = app.modifierPseudo(nouveau);
|
||||||
|
if(resultat) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//JOptionPane.showMessageDialog(this, "Echec de modification de pseudo, " + nouveau +" deja pris", JOptionPane.WARNING_MESSAGE);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.add(home);
|
||||||
|
this.add(Text);
|
||||||
|
this.add(BorderLayout.CENTER,pseudofield);
|
||||||
|
this.add(BorderLayout.SOUTH,Valider);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,84 +0,0 @@
|
||||||
import java.awt.GridLayout;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JMenu;
|
|
||||||
import javax.swing.JMenuBar;
|
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
|
|
||||||
public class View extends JFrame {
|
|
||||||
|
|
||||||
public View() {
|
|
||||||
//créer une instance JFrame
|
|
||||||
super("ChatApp-AL-NM");
|
|
||||||
|
|
||||||
// creation d'un label qui contiendra un txt au centre
|
|
||||||
JLabel label = new JLabel("Bonjour, Entrez un nom d'utilisateur!", JLabel.CENTER);
|
|
||||||
|
|
||||||
// Définissez le panel (conteneur de différents composants)
|
|
||||||
JPanel panel = new JPanel();
|
|
||||||
// Définir le bouton
|
|
||||||
JButton btn1 = new JButton("Connexion");
|
|
||||||
// Ajouter le bouton au frame
|
|
||||||
panel.add(btn1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************/
|
|
||||||
//L'en-têtes du JTable
|
|
||||||
String[] column = {"Pseudo", "port", "IP", "ID"};
|
|
||||||
|
|
||||||
//Les lignes du JTable
|
|
||||||
String[][] data = {
|
|
||||||
{"Auriane", "3000", "MBP-de-Auriane/192.168.1.43 ", "MBP-de-Auriane"},
|
|
||||||
{"Nabil", "4000", "LAPTOP-1JO2SHBG/192.168.1.72", "LAPTOP-1JO2SHBG"}
|
|
||||||
};
|
|
||||||
// Créer le JTable
|
|
||||||
JTable table = new JTable(data, column);
|
|
||||||
JScrollPane scroll = new JScrollPane(table);
|
|
||||||
// Ajout de la JTable
|
|
||||||
this.add(scroll);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Définir le menu principal
|
|
||||||
JMenuBar menu = new JMenuBar();
|
|
||||||
JMenu pseudo= new JMenu("Modifier Pseudo");
|
|
||||||
JMenu clavardage = new JMenu("Clavardage");
|
|
||||||
JMenu deconnexion = new JMenu("Deconnexion");
|
|
||||||
// Définir le sous-menu pour Clavardage
|
|
||||||
JMenuItem actifs = new JMenuItem("Connaitre utilisateur actifs");
|
|
||||||
JMenuItem session = new JMenuItem("Demarrer session");
|
|
||||||
|
|
||||||
clavardage.add(actifs);
|
|
||||||
clavardage.add(session);
|
|
||||||
|
|
||||||
menu.add(pseudo);
|
|
||||||
menu.add(clavardage);
|
|
||||||
menu.add(deconnexion);
|
|
||||||
|
|
||||||
|
|
||||||
// Ajouter label, menu et panel au frame
|
|
||||||
this.setLayout(new GridLayout(8, 1));
|
|
||||||
this.add(menu);
|
|
||||||
this.add(label);
|
|
||||||
this.add(panel);
|
|
||||||
|
|
||||||
// fixer les dimensions de la fenêtre
|
|
||||||
this.pack();
|
|
||||||
this.setSize(500, 500);
|
|
||||||
//sortir quand l’utilisateur ferme le frame
|
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
// rendre la fenêtre visible :
|
|
||||||
this.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main (String[] args) {
|
|
||||||
JFrame frame = new View();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
127
Implementation/src/View_Accueil.java
Normal file
127
Implementation/src/View_Accueil.java
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
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.io.IOException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Classe represenyant la fenetre d'accueil pour la connexion d'un utilisateur.
|
||||||
|
*/
|
||||||
|
public class View_Accueil implements ActionListener{
|
||||||
|
JFrame frame;
|
||||||
|
JPanel panel;
|
||||||
|
JTextField pseudofield;
|
||||||
|
JLabel Text;
|
||||||
|
JButton Connexion;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructeur d'une fenetre d'affichage pour la connexion d'un utilisateur.
|
||||||
|
* Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo.
|
||||||
|
*/
|
||||||
|
public View_Accueil () {
|
||||||
|
//creer une instance JFrame
|
||||||
|
frame = new JFrame("ChatApp-AL-NM");
|
||||||
|
//sortir quand l’utilisateur ferme le frame
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
// fixer les dimensions de la fenetre
|
||||||
|
frame.setSize(new Dimension(120, 40));
|
||||||
|
//Creer le JPanel
|
||||||
|
panel = new JPanel(new GridLayout(3,1));
|
||||||
|
//Ajouter les elements
|
||||||
|
this.addWidgets();
|
||||||
|
//Set the default button.
|
||||||
|
frame.getRootPane().setDefaultButton(Connexion);
|
||||||
|
//Ajouter le panel a la window
|
||||||
|
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||||
|
//L'utilisateur ne pourra pas aggrandir la fenetre
|
||||||
|
this.frame.setResizable(false);
|
||||||
|
//Afficher la fenetre
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creer et ajouter les outils de la fenetre
|
||||||
|
*/
|
||||||
|
private void addWidgets() {
|
||||||
|
// Créer Zone d'insertion de texte pour le pseudo
|
||||||
|
this.pseudofield = new JTextField(2);
|
||||||
|
// creation d'un label qui contiendra un txt au centre
|
||||||
|
this.Text = new JLabel("Bonjour, Entrez un nom d'utilisateur!", SwingConstants.CENTER);
|
||||||
|
//Ajout d'un bouton Connexion
|
||||||
|
this.Connexion = new JButton("Connexion");
|
||||||
|
//On associe au bouton Connexion des actions a realiser
|
||||||
|
this.Connexion.addActionListener(this);
|
||||||
|
// On ajouter les differents elements au panel
|
||||||
|
panel.add(pseudofield);
|
||||||
|
panel.add(Text);
|
||||||
|
panel.add(Connexion);
|
||||||
|
//ajouter un effet de bord transparent au composant Jlabel
|
||||||
|
Text.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definir des traitements en réponse à un clic sur le bouton connexion
|
||||||
|
* @param event Un clic sur le bouton connexion
|
||||||
|
*/
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
// on recupere le texte entree dans la zone de saisie
|
||||||
|
String pseudo = pseudofield.getText();
|
||||||
|
// On crée un objet de type ChatApp
|
||||||
|
ChatApp app = new ChatApp(pseudo, 3000) ;
|
||||||
|
// on crée un thread qui va ecouter les connexions entrantes
|
||||||
|
ExecutorService execUDP = Executors.newFixedThreadPool(1000);
|
||||||
|
execUDP.submit(new RunnerEcouteUDP(app));
|
||||||
|
Boolean connexion = false ;
|
||||||
|
try {
|
||||||
|
// on tente une connexion avec ce pseudo
|
||||||
|
connexion = app.connexion();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// Dans les deux cas de figures (reussite ou echec) on affiche un pop-up pour expliquer la situation
|
||||||
|
if(connexion) {
|
||||||
|
// La connexion a reussi
|
||||||
|
JOptionPane.showMessageDialog(frame, "Bonjour " + pseudo) ;
|
||||||
|
frame.dispose();
|
||||||
|
// on lance une nouvelle fenetre de type View_Menu
|
||||||
|
View_Menu fenetreCourante= new View_Menu(app);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// La connexion a echoue, il est possible de rentrer un nouveau pseudo
|
||||||
|
JOptionPane.showMessageDialog(frame, "Echec de Connexion , ce pseudo est deja pris !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createAndShowGUI() {
|
||||||
|
// Etre certain d'avoir une joli fenetre
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||||
|
// On crée une fentre d'acceuil
|
||||||
|
View_Accueil fenetre = new View_Accueil();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//Schedule a job for the event-dispatching thread:
|
||||||
|
//creating and showing this application's GUI.
|
||||||
|
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
createAndShowGUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
165
Implementation/src/View_Clavardage.java
Normal file
165
Implementation/src/View_Clavardage.java
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
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.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 com.jgoodies.forms.layout.FormLayout;
|
||||||
|
import com.jgoodies.forms.layout.ColumnSpec;
|
||||||
|
import com.jgoodies.forms.layout.RowSpec;
|
||||||
|
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 View_Clavardage {
|
||||||
|
JFrame frame ;
|
||||||
|
ChatApp app;
|
||||||
|
Utilisateur destination ; // Celui avec qui on va discuter
|
||||||
|
Utilisateur source; //Nous
|
||||||
|
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 View_Clavardage(ChatApp app, String User2) {
|
||||||
|
this.app = app ;
|
||||||
|
this.frame = new JFrame("ChatApp-AL-NM");
|
||||||
|
this.source = this.app.getMe();
|
||||||
|
this.destination = Utilisateur.stringToUtilisateur(User2);
|
||||||
|
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){
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
addWidgets();
|
||||||
|
frame.addWindowListener( wa ) ;
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creer et ajouter les outils de la fenetre
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
send.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
//UTILISER TCPENVOI
|
||||||
|
String AEnvoyer = textAreaSaisie.getText();
|
||||||
|
textAreaAffichage.append(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);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
253
Implementation/src/View_Menu.java
Normal file
253
Implementation/src/View_Menu.java
Normal file
|
@ -0,0 +1,253 @@
|
||||||
|
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.KeyEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.ComponentOrientation;
|
||||||
|
import java.awt.SystemColor;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Classe representant la fenetre de menu. Lance apres la connexion d'un utilisateur
|
||||||
|
*/
|
||||||
|
public class View_Menu {
|
||||||
|
JFrame frame;
|
||||||
|
JPanel panel;
|
||||||
|
JMenuBar menu;
|
||||||
|
ChatApp app;
|
||||||
|
JLabel jlabel;
|
||||||
|
JLabel Txt;
|
||||||
|
WindowAdapter wa ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public View_Menu(ChatApp app) {
|
||||||
|
this.app = app ;
|
||||||
|
//creer une instance JFrame
|
||||||
|
frame = new JFrame("ChatApp-AL-NM");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
// fixer les dimensions de la fenetre
|
||||||
|
frame.setSize(new Dimension(394, 344));
|
||||||
|
// Lorsque l'utilisateur souhaite quitter la fenetre on affiche un pop-up pour verifier son choix
|
||||||
|
wa = new WindowAdapter(){
|
||||||
|
public void windowClosing(WindowEvent e){
|
||||||
|
int reponse = showConfirmDialog();
|
||||||
|
if (reponse==0){
|
||||||
|
try {
|
||||||
|
// on deconnecte l'app avant de quitter
|
||||||
|
// Tout les utilisateurs sont donc prevenus du depart
|
||||||
|
app.deconnexion();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
frame.addWindowListener( wa ) ;
|
||||||
|
// Menu pour les differentes actions réalisables
|
||||||
|
menu = new JMenuBar();
|
||||||
|
//Creation d'un JPanel
|
||||||
|
panel = new JPanel(new GridLayout(3,1));
|
||||||
|
panel.setForeground(SystemColor.menuText);
|
||||||
|
// Ajouter tout les elements a la fenetre
|
||||||
|
this.addWidgets();
|
||||||
|
// ajouter le panel a la fenetre
|
||||||
|
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||||
|
// Afficher la fenetre
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methode static creant un pop-up demandant a l'utilisateur si il souhaite vraiment quitter.
|
||||||
|
*/
|
||||||
|
static int showConfirmDialog(){
|
||||||
|
return JOptionPane.showConfirmDialog(
|
||||||
|
null,
|
||||||
|
"Voulez-vous vraiment quitter?",
|
||||||
|
"Quitter",
|
||||||
|
JOptionPane.YES_NO_OPTION);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creer et ajouter les outils de la fenetre
|
||||||
|
*/
|
||||||
|
private void addWidgets() {
|
||||||
|
// On ajoute une jolie icone
|
||||||
|
jlabel = new JLabel(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Logo.png"), JLabel.CENTER);
|
||||||
|
|
||||||
|
Txt = new JLabel("Menu principal de " + app.getMe().getPseudo());
|
||||||
|
Txt.setFont(new Font("Tamil MN", Font.PLAIN, 30));
|
||||||
|
Txt.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
|
||||||
|
//On cree une item Actions que l'on ajoutera a la bar de menu
|
||||||
|
JMenu Actions = new JMenu("Actions");
|
||||||
|
Actions.setForeground(Color.WHITE);
|
||||||
|
Actions.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
// Définir le sous-menu pour Actions
|
||||||
|
JMenuItem actifs = new JMenuItem("Utilisateurs actifs");
|
||||||
|
JMenuItem session = new JMenuItem("Session de Clavardage");
|
||||||
|
JMenuItem pseudo = new JMenuItem("Modifier Pseudo");
|
||||||
|
JMenuItem deconnexion = new JMenuItem("Deconnexion");
|
||||||
|
// Ajouter les sous items a actions
|
||||||
|
Actions.add(actifs);
|
||||||
|
Actions.add(session);
|
||||||
|
Actions.add(pseudo);
|
||||||
|
Actions.add(deconnexion);
|
||||||
|
// On ajoute l'item Action dans la bar de menu
|
||||||
|
menu.add(Actions);
|
||||||
|
// On ajouter les differents elements au panel
|
||||||
|
panel.add(BorderLayout.NORTH , menu);
|
||||||
|
panel.add(BorderLayout.CENTER, jlabel);
|
||||||
|
panel.add(BorderLayout.SOUTH , Txt );
|
||||||
|
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//**************************************** Actions lorsque l'on clique sur actifs **********************************
|
||||||
|
//******************************************************************************************************************
|
||||||
|
actifs.addActionListener( new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
JPanel panel1 = new JPanel();
|
||||||
|
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||||
|
|
||||||
|
JTextArea textArea = new JTextArea(20,20);
|
||||||
|
textArea.insert("Liste Utilisateurs Actifs \n",0);
|
||||||
|
JScrollPane scrollPane = new JScrollPane(textArea);
|
||||||
|
|
||||||
|
String utilisateurs = app.getActifUsers().afficherListeUtilisateurs();
|
||||||
|
for(String elem : utilisateurs.split("\n")) {
|
||||||
|
textArea.append( " - " +Utilisateur.stringToUtilisateur(elem).getPseudo() + '\n');
|
||||||
|
}
|
||||||
|
panel1.add(textArea);
|
||||||
|
home.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
frame.dispose();
|
||||||
|
new View_Menu(app);
|
||||||
|
} });
|
||||||
|
textArea.setEditable(false);
|
||||||
|
frame.getContentPane().removeAll();
|
||||||
|
frame.getContentPane().add(BorderLayout.CENTER, panel1);
|
||||||
|
frame.getContentPane().add(BorderLayout.NORTH , home);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}});
|
||||||
|
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//**************************************** Actions lorsque l'on clique sur Session *********************************
|
||||||
|
//******************************************************************************************************************
|
||||||
|
session.addActionListener( new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||||
|
home.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
frame.dispose();
|
||||||
|
new View_Menu(app);
|
||||||
|
} });
|
||||||
|
String utilisateurs = app.getActifUsers().afficherListeUtilisateurs();
|
||||||
|
Vector<String> vector = new Vector<String>();
|
||||||
|
for(String elem : utilisateurs.split("\n")) {
|
||||||
|
vector.add(elem);
|
||||||
|
}
|
||||||
|
// Créer une liste déroulante
|
||||||
|
JComboBox cb = new JComboBox(vector);
|
||||||
|
cb.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
Object selected = cb.getSelectedItem();
|
||||||
|
new View_Clavardage(app, selected.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JPanel panel1 = new JPanel(new GridLayout(2,1));
|
||||||
|
panel1.add(home);
|
||||||
|
panel1.add(cb);
|
||||||
|
frame.getContentPane().removeAll();
|
||||||
|
frame.getContentPane().add(panel1,BorderLayout.CENTER);
|
||||||
|
frame.setVisible(true);
|
||||||
|
} });
|
||||||
|
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//**************************************** Actions lorsque l'on clique sur Pseudo **********************************
|
||||||
|
//******************************************************************************************************************
|
||||||
|
pseudo.addActionListener( new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
JLabel Text = new JLabel("Entrez un nouveau nom d'utilisateur!", SwingConstants.CENTER);
|
||||||
|
JTextField pseudofield = new JTextField(2); // Zone d'insertion de texte
|
||||||
|
JButton home = new JButton(new ImageIcon("/Users/auriane/Desktop/ChatApp-AL-NM/Implementation/src/images/Home.png"));
|
||||||
|
home.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
frame.dispose();
|
||||||
|
new View_Menu(app);
|
||||||
|
} });
|
||||||
|
//Ajout d'un bouton Valider
|
||||||
|
JButton Valider = new JButton("Valider");
|
||||||
|
frame.getRootPane().setDefaultButton(Valider);
|
||||||
|
//Listen to events from the Valider button.
|
||||||
|
Valider.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
String nouveau = pseudofield.getText();
|
||||||
|
try {
|
||||||
|
Boolean resultat = app.modifierPseudo(nouveau);
|
||||||
|
if(resultat) {
|
||||||
|
JOptionPane.showMessageDialog(frame, "Modification pseudo Reussi");
|
||||||
|
frame.dispose();
|
||||||
|
new View_Menu(app);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(frame, "Echec Modification pseudo ");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JPanel panel1 = new JPanel(new GridLayout(4,1));
|
||||||
|
panel1.add(home);
|
||||||
|
panel1.add(Text);
|
||||||
|
panel1.add(pseudofield);
|
||||||
|
panel1.add(Valider);
|
||||||
|
frame.getContentPane().removeAll();
|
||||||
|
frame.getContentPane().add(panel1,BorderLayout.CENTER);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}});
|
||||||
|
//******************************************************************************************************************
|
||||||
|
//**************************************** Actions lorsque l'on clique sur Deconnexion *****************************
|
||||||
|
//******************************************************************************************************************
|
||||||
|
deconnexion.addActionListener( new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||||
|
} });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
BIN
Implementation/src/images/Home.png
Normal file
BIN
Implementation/src/images/Home.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
BIN
Implementation/src/images/Logo.png
Normal file
BIN
Implementation/src/images/Logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
Loading…
Reference in a new issue