diff --git a/POO/src/communication/filetransfer/FileTransferUtils.java b/POO/src/communication/filetransfer/FileTransferUtils.java index b37f5bd..cd561ac 100644 --- a/POO/src/communication/filetransfer/FileTransferUtils.java +++ b/POO/src/communication/filetransfer/FileTransferUtils.java @@ -109,4 +109,12 @@ public class FileTransferUtils { BufferedImage image = gc.createCompatibleImage(w, h); return image; } + + public static void createDownloads() { + File downloads = new File(FileTransferUtils.DOWNLOADS_RELATIVE_PATH); + + if(!downloads.exists()) { + downloads.mkdir(); + } + } } diff --git a/POO/src/communication/tcp/TCPServer.java b/POO/src/communication/tcp/TCPServer.java index dbd1d34..bdbb16f 100644 --- a/POO/src/communication/tcp/TCPServer.java +++ b/POO/src/communication/tcp/TCPServer.java @@ -10,12 +10,15 @@ import observers.ObserverInputMessage; public class TCPServer extends Thread { + + //**** + public static int PORT_SERVER = 7000; private ServerSocket sockListenTCP; private ObserverInputMessage obs; public TCPServer(int port) throws UnknownHostException, IOException { - this.sockListenTCP = new ServerSocket(port, 5, InetAddress.getLocalHost()); + this.sockListenTCP = new ServerSocket(port, 50, InetAddress.getLocalHost()); } @Override diff --git a/POO/src/communication/udp/CommunicationUDP.java b/POO/src/communication/udp/CommunicationUDP.java index 3cc64f7..91eec76 100644 --- a/POO/src/communication/udp/CommunicationUDP.java +++ b/POO/src/communication/udp/CommunicationUDP.java @@ -2,6 +2,7 @@ package communication.udp; import java.io.IOException; import java.net.InetAddress; +import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; @@ -12,6 +13,11 @@ import observers.ObserverUserList; public class CommunicationUDP extends Thread { + // **** + protected static int PORT_SERVEUR = 3000; + // **** + protected static int PORT_CLIENT = 2000; + private UDPClient client; private UDPServer server; private int portServer; @@ -27,6 +33,14 @@ public class CommunicationUDP extends Thread { this.client = new UDPClient(portClient); } + // **** + public CommunicationUDP() throws SocketException, UnknownHostException { + this.portServer = PORT_SERVEUR; + this.server = new UDPServer(portServer, this); + this.server.start(); + this.client = new UDPClient(PORT_CLIENT); + } + private ArrayList getArrayListFromArray(int ports[]) { ArrayList tmp = new ArrayList(); for (int port : ports) { @@ -41,27 +55,27 @@ public class CommunicationUDP extends Thread { this.observer = obs; } - //-------------- USER LIST UPDATE FUNCTION --------------// + // -------------- USER LIST UPDATE FUNCTION --------------// protected synchronized void addUser(String idClient, String pseudoClient, InetAddress ipClient, int port) throws IOException { users.add(new Utilisateur(idClient, pseudoClient, ipClient, port)); - observer.updateList(this, users); + this.sendUpdate(); } protected synchronized void changePseudoUser(String idClient, String pseudoClient, InetAddress ipClient, int port) { int index = getIndexFromID(idClient); users.get(index).setPseudo(pseudoClient); - observer.updateList(this, users); + this.sendUpdate(); } protected synchronized void removeUser(String idClient, String pseudoClient, InetAddress ipClient, int port) { - int index = getIndexFromIP(ipClient); + int index = getIndexFromID(idClient); if (index != -1) { users.remove(index); } - observer.updateList(this, users); + this.sendUpdate(); } public void removeAll() { @@ -71,7 +85,7 @@ public class CommunicationUDP extends Thread { } } - //-------------- CHECKERS --------------// + // -------------- CHECKERS --------------// protected boolean containsUserFromID(String id) { for (Utilisateur u : users) { @@ -92,7 +106,7 @@ public class CommunicationUDP extends Thread { return false; } - //-------------- GETTERS --------------// + // -------------- GETTERS --------------// public Utilisateur getUserFromPseudo(String pseudo) { for (int i = 0; i < users.size(); i++) { @@ -112,19 +126,8 @@ public class CommunicationUDP extends Thread { return -1; } - private int getIndexFromIP(InetAddress ip) { - for (int i = 0; i < users.size(); i++) { - if (users.get(i).getIp().equals(ip)) { - return i; - } - } - return -1; - } - - - - //-------------- SEND MESSAGES --------------// - + // -------------- SEND MESSAGES --------------// + public void sendMessageConnecte() throws UnknownHostException, IOException { for (int port : this.portOthers) { try { @@ -145,15 +148,10 @@ public class CommunicationUDP extends Thread { Utilisateur self = Utilisateur.getSelf(); - String pseudoSelf = self.getPseudo(); - String idSelf = self.getId(); - int portSelf = self.getPort(); - - Message msout = null; try { - msout = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, pseudoSelf, idSelf, portSelf); + Message msgOut = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, self.getPseudo(), self.getId(), self.getPort()); for (int port : this.portOthers) { - this.client.sendMessageUDP_local(msout, port, InetAddress.getLocalHost()); + this.client.sendMessageUDP_local(msgOut, port, InetAddress.getLocalHost()); } } catch (Exception e) { e.printStackTrace(); @@ -167,9 +165,9 @@ public class CommunicationUDP extends Thread { Utilisateur self = Utilisateur.getSelf(); try { - Message msout = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, self.getPseudo(), self.getId(), + Message msgOut = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, self.getPseudo(), self.getId(), self.getPort()); - this.client.sendMessageUDP_local(msout, portOther, InetAddress.getLocalHost()); + this.client.sendMessageUDP_local(msgOut, portOther, InetAddress.getLocalHost()); } catch (MauvaisTypeMessageException e) { e.printStackTrace(); } @@ -180,32 +178,26 @@ public class CommunicationUDP extends Thread { // This allows the receivers' agent (portOthers) to delete the entry // corresponding to this agent public void sendMessageDelete() throws UnknownHostException, IOException { - for (int port : this.portOthers) { - try { - this.client.sendMessageUDP_local(new MessageSysteme(Message.TypeMessage.JE_SUIS_DECONNECTE), port, - InetAddress.getLocalHost()); - } catch (MauvaisTypeMessageException e) { + Utilisateur self = Utilisateur.getSelf(); + try { + + Message msgOut = new MessageSysteme(Message.TypeMessage.JE_SUIS_DECONNECTE, self.getPseudo(), self.getId(), self.getPort()); + for (int port : this.portOthers) { + this.client.sendMessageUDP_local(msgOut, port, InetAddress.getLocalHost()); } + + } catch (MauvaisTypeMessageException e) { + + } + } + + + private void sendUpdate() { + if(this.observer != null) { + this.observer.updateList(this, users); } } - // Pas encore adapte message -// private void sendIDPseudo_broadcast(String prefixe) throws UnknownHostException, IOException { -// Utilisateur self = Utilisateur.getSelf(); -// String idSelf = self.getId(); -// String pseudoSelf = self.getPseudo(); -// -// String message = prefixe+","+idSelf + "," + pseudoSelf; -// -// -// this.client.sendMessageUDP_broadcast(message, this.portServer); -// -// } - -// public synchronized void createSenderUDP(int port, Mode mode) throws SocketException { -// new SenderUDP(mode, port).start(); -// } - public void destroyAll() { this.client.destroyAll(); this.server.interrupt(); diff --git a/POO/src/communication/udp/UDPClient.java b/POO/src/communication/udp/UDPClient.java index 12224af..54839df 100644 --- a/POO/src/communication/udp/UDPClient.java +++ b/POO/src/communication/udp/UDPClient.java @@ -21,6 +21,8 @@ public class UDPClient { InetAddress localHost = InetAddress.getLocalHost(); NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); this.broadcast = networkInterface.getInterfaceAddresses().get(0).getBroadcast(); + System.out.println(this.broadcast); + System.out.println(InetAddress.getLocalHost()); } @@ -32,12 +34,6 @@ public class UDPClient { } -// protected void sendMessageUDP_broadcast(String message, int port) throws IOException{ -// String messageString=message.toString(); -// DatagramPacket outpacket = new DatagramPacket(messageString.getBytes(), messageString.length(), this.broadcast, port); -// this.sockUDP.send(outpacket); -// } - protected void destroyAll() { this.sockUDP.close(); this.sockUDP = null; diff --git a/POO/src/communication/udp/UDPServer.java b/POO/src/communication/udp/UDPServer.java index 046d285..529d303 100644 --- a/POO/src/communication/udp/UDPServer.java +++ b/POO/src/communication/udp/UDPServer.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.SocketException; + import main.Utilisateur; import messages.*; @@ -36,26 +37,23 @@ public class UDPServer extends Thread { case JE_SUIS_CONNECTE: if (Utilisateur.getSelf() != null) { - // System.out.println("first co"); + int portClient = inPacket.getPort(); - int portServer = portClient + 1; - + int portServer = portClient+1; this.commUDP.sendMessageInfoPseudo(portServer); } break; case INFO_PSEUDO: + MessageSysteme m = (MessageSysteme) msg; - if (this.commUDP.containsUserFromID(((MessageSysteme) msg).getId())) { - this.commUDP.changePseudoUser(((MessageSysteme) msg).getId(), - ((MessageSysteme) msg).getPseudo(), inPacket.getAddress(), - ((MessageSysteme) msg).getPort()); + if (this.commUDP.containsUserFromID(m.getId())) { + this.commUDP.changePseudoUser(m.getId(), m.getPseudo(), inPacket.getAddress(), m.getPort()); } else { - this.commUDP.addUser(((MessageSysteme) msg).getId(), ((MessageSysteme) msg).getPseudo(), - inPacket.getAddress(), ((MessageSysteme) msg).getPort()); - System.out.println(((MessageSysteme) msg).getId() + ", " + ((MessageSysteme) msg).getPseudo()); + this.commUDP.addUser(m.getId(), m.getPseudo(), inPacket.getAddress(), m.getPort()); + System.out.println(m.getId() + ", " + m.getPseudo()); } break; diff --git a/POO/src/connexion/ControleurConnexion.java b/POO/src/connexion/ControleurConnexion.java index b641d8f..c8613db 100644 --- a/POO/src/connexion/ControleurConnexion.java +++ b/POO/src/connexion/ControleurConnexion.java @@ -5,16 +5,13 @@ import java.awt.event.ActionListener; import java.io.IOException; import java.net.UnknownHostException; import java.sql.SQLException; -import java.util.ArrayList; -import communication.*; import communication.udp.CommunicationUDP; import database.SQLiteManager; import main.Utilisateur; -import observers.ObserverUserList; import standard.VueStandard; -public class ControleurConnexion implements ActionListener, ObserverUserList{ +public class ControleurConnexion implements ActionListener{ private enum Etat {DEBUT, ID_OK}; @@ -22,37 +19,43 @@ public class ControleurConnexion implements ActionListener, ObserverUserList{ private Etat etat; private CommunicationUDP comUDP; private int portTCP; - private int num; private String username; private SQLiteManager sqlManager; + private VueStandard vueStd; public ControleurConnexion(VueConnexion vue, int numtest) { this.vue = vue; this.etat = Etat.DEBUT; - this.num = numtest; this.username = ""; this.sqlManager = new SQLiteManager(0); + this.vueStd = null; //Pour les tests, changer pour un truc plus général quand on change CommunicationUDP + + int[] portServer = {2209, 2309, 2409, 2509}; try { switch(numtest) { case 0 : - this.comUDP = new CommunicationUDP(2208, 2209, new int[] {2309, 2409}); + this.comUDP = new CommunicationUDP(2208, 2209, portServer); this.portTCP = 7010; break; case 1 : - this.comUDP = new CommunicationUDP(2308, 2309, new int[] {2209, 2409}); + this.comUDP = new CommunicationUDP(2308, 2309, portServer); this.portTCP = 7020; break; case 2 : - this.comUDP = new CommunicationUDP(2408, 2409, new int[] {2209, 2309}); + this.comUDP = new CommunicationUDP(2408, 2409, portServer); this.portTCP = 7030; break; + case 3 : + this.comUDP = new CommunicationUDP(2508, 2509, portServer); + this.portTCP = 7040; + break; default : - this.comUDP = new CommunicationUDP(2408, 2409, new int[] {2209, 2309}); + this.comUDP = new CommunicationUDP(2408, 2409, portServer); this.portTCP = 7040; } +// - this.comUDP.setObserver(this); } catch (IOException e) { e.printStackTrace(); } @@ -99,11 +102,17 @@ public class ControleurConnexion implements ActionListener, ObserverUserList{ //Mise en place de la demande du pseudo this.vue.setConnexionInfo(""); + this.vue.removePasswordPanel(); + this.vue.setTextUsernameField("Veuillez entrer votre pseudonyme"); this.vue.resetUsernameField(); inputOK=false; } - else this.vue.setConnexionInfo("Identifiant ou mot de passe invalide, veuillez réessayer"); + else { + this.vue.setConnexionInfo("Identifiant ou mot de passe invalide, veuillez réessayer"); + this.vue.resetPasswordField(); + } + } else { pseudo = vue.getUsernameValue(); @@ -125,17 +134,16 @@ public class ControleurConnexion implements ActionListener, ObserverUserList{ try { this.comUDP.sendMessageInfoPseudo(); } catch (UnknownHostException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } + try { - this.vue.close(); - new VueStandard("Standard", this.comUDP, this.portTCP, this.sqlManager, this.num); + this.resetView(); + this.vue.setVisible(false); + this.setVueStandard(); } catch (IOException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } } @@ -143,10 +151,25 @@ public class ControleurConnexion implements ActionListener, ObserverUserList{ } } - @Override - public void updateList(Object o, ArrayList userList) { - // TODO Auto-generated method stub + + private void setVueStandard() throws IOException { + if(this.vueStd == null) { + this.vueStd = new VueStandard("Standard", this.comUDP, this.portTCP, this.sqlManager, this.vue); + + }else { + this.vueStd.initControleur(); + this.vueStd.setPseudoSelf(); + this.vueStd.setVisible(true); + } + } + + private void resetView() { + this.etat = Etat.DEBUT; + this.vue.addPasswordPanel(); + this.vue.resetPasswordField(); + this.vue.resetUsernameField(); + this.vue.setTextUsernameField("Nom d'utilisateur"); + this.vue.setConnexionInfo(""); } - } diff --git a/POO/src/connexion/VueConnexion.java b/POO/src/connexion/VueConnexion.java index d9064ef..e5ec22d 100644 --- a/POO/src/connexion/VueConnexion.java +++ b/POO/src/connexion/VueConnexion.java @@ -4,6 +4,7 @@ package connexion; import java.awt.*; import javax.swing.*; +import database.SQLiteManager; import main.Vue; public class VueConnexion extends Vue { @@ -16,6 +17,8 @@ public class VueConnexion extends Vue { private JLabel labelUsername; private JLabel labelPassword; private JLabel connexionInfo; + private JPanel main; + private JPanel panelPassword; //Controleur private ControleurConnexion controle; @@ -36,6 +39,9 @@ public class VueConnexion extends Vue { //Regle le bouton par défaut this.getRootPane().setDefaultButton(boutonValider); + this.inputUsername.setText(SQLiteManager.hardcodedNames[numtest]+numtest); + this.inputPassword.setText("aze1$"+SQLiteManager.hardcodedNames[numtest].charAt(0)+numtest); + //Affiche la fenetre this.setVisible(true); } @@ -43,9 +49,9 @@ public class VueConnexion extends Vue { private void ajouterElements() { //Creation panel - JPanel main = new JPanel(new GridLayout(4,1)); + main = new JPanel(new GridLayout(4,1)); JPanel panelUsername = new JPanel(new GridLayout(1, 2)); - JPanel panelPassword = new JPanel(new GridLayout(1, 2)); + this.panelPassword = new JPanel(new GridLayout(1, 2)); //Cree les elements this.connexionInfo = new JLabel(""); @@ -68,15 +74,18 @@ public class VueConnexion extends Vue { boutonValider.addActionListener(controle); //Ajoute les elements - panelUsername.add(this.inputUsername); panelUsername.add(this.labelUsername); + panelUsername.add(this.inputUsername); + + + this.panelPassword.add(this.labelPassword); + this.panelPassword.add(this.inputPassword); + - panelPassword.add(this.inputPassword); - panelPassword.add(this.labelPassword); main.add(connexionInfo); main.add(panelUsername); - main.add(panelPassword); + main.add(this.panelPassword); main.add(boutonValider); this.add(main); @@ -104,6 +113,14 @@ public class VueConnexion extends Vue { protected void resetUsernameField() { this.inputUsername.setText(""); } + + protected void removePasswordPanel() { + this.main.remove(2); + } + + protected void addPasswordPanel() { + this.main.add(this.panelPassword, 2); + } protected void resetPasswordField() { this.inputPassword.setText(""); diff --git a/POO/src/database/SQLiteManager.java b/POO/src/database/SQLiteManager.java index 4b77007..707a4ba 100644 --- a/POO/src/database/SQLiteManager.java +++ b/POO/src/database/SQLiteManager.java @@ -1,7 +1,6 @@ package database; import java.io.File; -import java.lang.reflect.Array; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -32,6 +31,9 @@ public class SQLiteManager { private static final String DATABASE_RELATIVE_PATH = "../database"; + public static String[] hardcodedNames = {"Olivia","Liam","Benjamin","Sophia","Charlotte","Noah","Elijah","Isabella", + "Oliver","Emma","William","Amelia","Evelyn","James","Mia","Ava","Lucas","Mason","Ethan","Harper"}; + private Connection connec; private int numDatabase; private SecretKey dbDataKey; @@ -549,7 +551,7 @@ public class SQLiteManager { String pwdPrefix = "aze1$"; - SQLiteManager sqlManager = new SQLiteManager(0); + SQLiteManager sqlManager = new SQLiteManager(1); for(int i=0; i idsSessionEnCours; private SQLiteManager sqlManager; + private VueConnexion vueConnexion; - public ControleurStandard(VueStandard vue, CommunicationUDP commUDP, int portServerTCP, SQLiteManager sqlManager, int num) - throws IOException { + public ControleurStandard(VueStandard vue, CommunicationUDP commUDP, int portServerTCP, SQLiteManager sqlManager, + VueConnexion vueConnexion) throws IOException { this.vue = vue; + this.vue.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - this.num = num; + this.vueConnexion = vueConnexion; + this.tcpServ = new TCPServer(portServerTCP); + this.tcpServ.addObserver(this); this.tcpServ.start(); this.commUDP = commUDP; - this.commUDP.setObserver(this); - this.commUDP.sendMessageConnecte(); - this.commUDP.sendMessageInfoPseudo(); - + this.idsSessionEnCours = new ArrayList(); this.sqlManager = sqlManager; - - this.modifPseudo = ModifPseudo.TERMINE; } // ---------- LISTSELECTION LISTENER OPERATIONS ----------// @@ -86,11 +86,16 @@ public class ControleurStandard implements ActionListener, ListSelectionListener System.out.println("choix : " + choix); if (choix == 0) { + + int port = other.getPort(); + + System.out.println("port = " + port); try { Socket socketComm = new Socket(InetAddress.getLocalHost(), port); + this.sendMessage(socketComm, Utilisateur.getSelf().getPseudo()); String reponse = this.readMessage(socketComm); @@ -145,7 +150,6 @@ public class ControleurStandard implements ActionListener, ListSelectionListener try { this.commUDP.sendMessageInfoPseudo(); } catch (IOException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } @@ -163,15 +167,7 @@ public class ControleurStandard implements ActionListener, ListSelectionListener // Cas deconnexion else if ((JButton) e.getSource() == this.vue.getButtonDeconnexion()) { try { - this.commUDP.sendMessageDelete(); - this.commUDP.removeAll(); - this.commUDP.destroyAll(); - this.vue.removeAllUsers(); - Utilisateur.resetSelf(); - - vue.dispose(); - - new VueConnexion(this.num); + this.setVueConnexion(); } catch (IOException e1) { e1.printStackTrace(); @@ -191,9 +187,8 @@ public class ControleurStandard implements ActionListener, ListSelectionListener public void windowClosing(WindowEvent e) { try { - this.commUDP.sendMessageDelete(); + this.setVueConnexion(); } catch (IOException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } @@ -207,7 +202,6 @@ public class ControleurStandard implements ActionListener, ListSelectionListener @Override public void windowClosed(WindowEvent e) { - // TODO Auto-generated method stub } @@ -307,6 +301,25 @@ public class ControleurStandard implements ActionListener, ListSelectionListener int index = this.vue.removeSession(session); this.idsSessionEnCours.remove(index); } + + private void setVueConnexion() throws UnknownHostException, IOException { + this.commUDP.sendMessageDelete(); + this.vue.removeAllUsers(); + this.vue.closeAllSession(); + this.idsSessionEnCours.clear(); + Utilisateur.resetSelf(); + this.commUDP.setObserver(null); + + this.vue.setVisible(false); + this.vueConnexion.setVisible(true); + } + + protected void init() throws UnknownHostException, IOException { + this.commUDP.setObserver(this); + this.commUDP.sendMessageConnecte(); + this.commUDP.sendMessageInfoPseudo(); + this.modifPseudo = ModifPseudo.TERMINE; + } } \ No newline at end of file diff --git a/POO/src/standard/VueStandard.java b/POO/src/standard/VueStandard.java index 183ff9b..11c0995 100644 --- a/POO/src/standard/VueStandard.java +++ b/POO/src/standard/VueStandard.java @@ -7,7 +7,9 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.IOException; +import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Iterator; import javax.swing.AbstractButton; import javax.swing.BorderFactory; @@ -25,6 +27,7 @@ import javax.swing.ScrollPaneConstants; import javax.swing.plaf.basic.BasicButtonUI; import communication.udp.CommunicationUDP; +import connexion.VueConnexion; import database.SQLiteManager; import main.Utilisateur; import main.Vue; @@ -48,12 +51,13 @@ public class VueStandard extends Vue { private ArrayList sessions; private DefaultListModel userList = new DefaultListModel(); - public VueStandard(String title, CommunicationUDP commUDP, int portServerTCP, SQLiteManager sqlManager, int num) throws IOException { + public VueStandard(String title, CommunicationUDP commUDP, int portServerTCP, SQLiteManager sqlManager, VueConnexion vueConnexion) throws IOException { super(title); this.tabButtons = new ArrayList(); this.sessions = new ArrayList(); - this.c = new ControleurStandard(this, commUDP, portServerTCP, sqlManager, num); + this.c = new ControleurStandard(this, commUDP, portServerTCP, sqlManager, vueConnexion); + this.c.init(); getContentPane().setLayout(new GridBagLayout()); @@ -118,6 +122,11 @@ public class VueStandard extends Vue { this.seDeconnecter = new JButton("Se Déconnecter"); this.seDeconnecter.addActionListener(this.c); deconnexion.add(this.seDeconnecter); + + if(Utilisateur.getSelf().getId() == "admin") { + JButton addNewUser = new JButton("Ajouter un nouvel utilisateur"); + deconnexion.add(addNewUser); + } // --------Ajout à la vue--------// left.add(self, BorderLayout.PAGE_START); @@ -185,6 +194,10 @@ public class VueStandard extends Vue { protected void setDisplayedPseudo(String pseudo) { this.pseudoSelf.setText(pseudo); } + + public void setPseudoSelf() { + this.setDisplayedPseudo(Utilisateur.getSelf().getPseudo()); + } // ------------ JOPTIONS -------------// @@ -237,18 +250,6 @@ public class VueStandard extends Vue { return index; } - protected int removeSession(VueSession vue) { - int index = this.sessions.indexOf(vue); - - vue.destroyAll(); - - this.zoneSessions.remove(vue); - this.sessions.remove(index); - this.tabButtons.remove(index); - - return index; - } - protected void addSession(String pseudo, VueSession session) { JPanel tabTitle = new JPanel(); @@ -266,12 +267,41 @@ public class VueStandard extends Vue { session.requestFocus(); } + + protected synchronized int removeSession(VueSession vue) { + int index = this.sessions.indexOf(vue); + + vue.destroyAll(); + + this.zoneSessions.remove(vue); + this.sessions.remove(index); + this.tabButtons.remove(index); + + return index; + } + + protected void closeAllSession() { + Iterator it = this.sessions.iterator(); + while(it.hasNext()) { + VueSession session = it.next(); + this.zoneSessions.remove(session); + session.destroyAll(); + it.remove(); + } + + this.tabButtons.clear(); + } + // ------------ OTHERS -------------// protected void removeAllUsers() { this.userList.removeAllElements(); } + + public void initControleur() throws UnknownHostException, IOException { + this.c.init(); + } // ------------- PRIVATE CLASSES FOR THE TABS BUTTON -------------// private class TabButton extends JButton {