diff --git a/Projet_POO/src/defaut/Main.java b/Projet_POO/src/defaut/Main.java index 97e6617..39fb19f 100644 --- a/Projet_POO/src/defaut/Main.java +++ b/Projet_POO/src/defaut/Main.java @@ -14,7 +14,7 @@ public class Main { //GestionnaireHistorique.instance().recuperer("z", "user"); //on lance le server d'écoute de cmd - GestionnaireListeUtilisateur.instance().ecoute2(2001); //enlever le 2, debug //TODO PORT = 2001 à 2009 + GestionnaireListeUtilisateur.instance().ecoute2(2002); //enlever le 2, debug //TODO PORT = 2001 à 2009 //on crée manuellement des utilisateurs GestionnaireListeUtilisateur.instance().envoie2("add$$$77$$$Moi$$$LocalHost$$$true"); diff --git a/Projet_POO/src/liste/TraitementCmdListe.java b/Projet_POO/src/liste/TraitementCmdListe.java index 079ec15..b8be538 100644 --- a/Projet_POO/src/liste/TraitementCmdListe.java +++ b/Projet_POO/src/liste/TraitementCmdListe.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.concurrent.Semaphore; import nom.GestionnaireNom; -import ui.ListUI2; +import ui.ListUI; public class TraitementCmdListe implements Runnable{ @@ -119,7 +119,7 @@ public class TraitementCmdListe implements Runnable{ } //mise à jour des graphismes - ListUI2.update(); + ListUI.update(); } @@ -136,6 +136,6 @@ public class TraitementCmdListe implements Runnable{ } //mise à jour des graphismes - ListUI2.update(); + ListUI.update(); } } diff --git a/Projet_POO/src/nom/GestionnaireNom.java b/Projet_POO/src/nom/GestionnaireNom.java index b1f47c0..8a6d7c2 100644 --- a/Projet_POO/src/nom/GestionnaireNom.java +++ b/Projet_POO/src/nom/GestionnaireNom.java @@ -11,7 +11,7 @@ public class GestionnaireNom{ private String idUtilisateur; private String nomUtilisateur; static private String ipUtilisateur; - private boolean dansReseau; + private boolean dansReseau = true; private String statut = "online"; diff --git a/Projet_POO/src/ui/ListUI.java b/Projet_POO/src/ui/ListUI.java index 698cfd6..82160d8 100644 --- a/Projet_POO/src/ui/ListUI.java +++ b/Projet_POO/src/ui/ListUI.java @@ -26,7 +26,13 @@ import java.util.ArrayList; import clavardage.gestionnaireClavardage; import liste.GestionnaireListeUtilisateur; import nom.GestionnaireNom; +import servlet.Post; import liste.TypeListeUtilisateur; +import javax.swing.JComboBox; +import javax.swing.DefaultComboBoxModel; +import java.awt.event.ItemListener; +import java.io.IOException; +import java.awt.event.ItemEvent; @@ -36,8 +42,9 @@ public class ListUI extends JFrame implements Runnable{ private static final long serialVersionUID = 42L; private JPanel contentPane; - public static JList list = new JList(); - private JList list2 = new JList(); + private JComboBox comboBox = new JComboBox(); + + private static JList list = new JList(); /** @@ -51,24 +58,29 @@ public class ListUI extends JFrame implements Runnable{ list.setCellRenderer(new DefaultListCellRenderer() { + private static final long serialVersionUID = 1L; - @Override + @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof String) { - String nextUser = (String) value; - setText(nextUser); - if (nextUser.equals("Toto")) { - setBackground(Color.GREEN); - } else { - setBackground(Color.RED); - } - if (isSelected) { - setBackground(getBackground().darker()); + if (value instanceof TypeListeUtilisateur) { + TypeListeUtilisateur nextUser = (TypeListeUtilisateur) value; + setText(nextUser.nom); + if (nextUser.statut != null) { + if (nextUser.statut.equals("online")) { + setBackground(Color.GREEN); + } else if (nextUser.statut.equals("occupied")) { + setBackground(Color.RED); + } else { + setBackground(Color.GRAY); + } + if (isSelected) { + setBackground(getBackground().darker()); + } } } else { - setText("whodat?"); + setText("ERROR"); } return c; } @@ -77,7 +89,7 @@ public class ListUI extends JFrame implements Runnable{ } catch (Exception e) { - System.out.println("Erreur : run ListUI"); + System.out.println("Erreur : run ListUI2"); e.printStackTrace(); dispose(); } @@ -128,7 +140,7 @@ public class ListUI extends JFrame implements Runnable{ scrollPane.setViewportView(list); */ - listeInitial(); + //listeInitiale(); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scrollPane.setViewportView(list); @@ -174,6 +186,22 @@ public class ListUI extends JFrame implements Runnable{ nameLabel.setBounds(10, 227, 119, 23); contentPane.add(nameLabel); + // combobox + comboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if(e.getStateChange() == ItemEvent.SELECTED) { + actionComboBox(); + + } + } + }); + // combobox (suite) + comboBox.setMaximumRowCount(3); + comboBox.setModel(new DefaultComboBoxModel(new String[] {"online", "occupied", "offline"})); + comboBox.setSelectedIndex(0); + comboBox.setBounds(335, 194, 89, 22); + contentPane.add(comboBox); + this.addWindowListener(new java.awt.event.WindowAdapter() { @Override @@ -207,8 +235,8 @@ public class ListUI extends JFrame implements Runnable{ // Lance une communication avce l'Utilisateur voulu public void connect() { try{ - String nom = (String) list.getSelectedValue(); - if (nom != null) { + if (list.getSelectedValue() != null) { + String nom = list.getSelectedValue().nom; gestionnaireClavardage gc = gestionnaireClavardage.instance(); gc.createSession(nom); } @@ -220,13 +248,13 @@ public class ListUI extends JFrame implements Runnable{ } //mise en place de la liste de base - public void listeInitial() { + public void listeInitiale() { ArrayList listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur(); - DefaultListModel defaultListModel = new DefaultListModel(); + DefaultListModel defaultListModel = new DefaultListModel(); for (int i=0; i listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur(); - DefaultListModel defaultListModel = new DefaultListModel(); + DefaultListModel defaultListModel = new DefaultListModel(); for (int i=0; i comboBox = new JComboBox(); - - private static JList list = new JList(); - - - /** - * Run - */ - - public void run() { - try { - ListUI2 frame = new ListUI2(); - frame.setVisible(true); - - - list.setCellRenderer(new DefaultListCellRenderer() { - private static final long serialVersionUID = 1L; - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, - boolean isSelected, boolean cellHasFocus) { - Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof TypeListeUtilisateur) { - TypeListeUtilisateur nextUser = (TypeListeUtilisateur) value; - setText(nextUser.nom); - if (nextUser.statut != null) { - if (nextUser.statut.equals("online")) { - setBackground(Color.GREEN); - } else if (nextUser.statut.equals("occupied")) { - setBackground(Color.RED); - } else { - setBackground(Color.GRAY); - } - if (isSelected) { - setBackground(getBackground().darker()); - } - } - } else { - setText("ERROR"); - } - return c; - } - - }); - - - } catch (Exception e) { - System.out.println("Erreur : run ListUI2"); - e.printStackTrace(); - dispose(); - } - } - - - - /** - * Constructeur - */ - - public ListUI2() { - // Titre - setTitle("List : " + GestionnaireNom.instance().getId()); - - // Operation par défaut - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - //Dimension - setBounds(100, 100, 450, 300); - - // JPanel - contentPane = new JPanel(); - contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); - setContentPane(contentPane); - contentPane.setLayout(null); - - - //JScrollPane - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setBounds(67, 23, 303, 158); - contentPane.add(scrollPane); - /* - - //list ? - list = new JList(); - list.setModel(new AbstractListModel() { - private static final long serialVersionUID = 41L; - - public String[] values = new String[] {"A", "B", "C"}; - public int getSize() { - return values.length; - } - public String getElementAt(int index) { - return values[index]; - } - }); - scrollPane.setViewportView(list); - */ - - //listeInitiale(); - - list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - scrollPane.setViewportView(list); - - - - - - - - // Bouton Rename - JButton renameButton = new JButton("Rename"); - renameButton.addActionListener(new ActionListener() { // Appuyer - public void actionPerformed(ActionEvent arg0) { - Thread t = new Thread(new NomUI()); - t.start(); - dispose(); - } - }); - // Bouton Rename (suite) - renameButton.setBounds(335, 227, 89, 23); - contentPane.add(renameButton); - - // Bouton Connect - JButton connectButton = new JButton("Connect"); - connectButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { //Appuyer - connect(); - - } - }); - // Buton Connect (suite) - connectButton.setBounds(156, 192, 89, 23); - contentPane.add(connectButton); - - // idLabel - JLabel idLabel = new JLabel("ID : " + GestionnaireNom.instance().getId() ); - idLabel.setBounds(10, 202, 78, 23); - contentPane.add(idLabel); - - // nameLabel - JLabel nameLabel = new JLabel("Username : " + GestionnaireNom.instance().getNom() ); - nameLabel.setBounds(10, 227, 119, 23); - contentPane.add(nameLabel); - - // combobox - comboBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - if(e.getStateChange() == ItemEvent.SELECTED) { - actionComboBox(); - - } - } - }); - // combobox (suite) - comboBox.setMaximumRowCount(3); - comboBox.setModel(new DefaultComboBoxModel(new String[] {"online", "occupied", "offline"})); - comboBox.setSelectedIndex(0); - comboBox.setBounds(335, 194, 89, 22); - contentPane.add(comboBox); - - - this.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosing(java.awt.event.WindowEvent windowEvent) { - ListUI2 window = (ListUI2) windowEvent.getSource(); - - GestionnaireNom.instance().supprimer2(); //TODO enlever 2 //debug - } - }); - } - - - - /** - * Méthode - */ - - - - // à améliorer ... (suppression ?) - public void ajouterNomListe(DefaultTableModel dtm, ArrayList liste) { - for (String t : liste) { - if (!t.equals(GestionnaireNom.instance().getNom())) { - dtm.addRow(new Object[] {t}); - - } - } - - } - - // Lance une communication avce l'Utilisateur voulu - public void connect() { - try{ - String nom = (String) list.getSelectedValue().nom; - if (nom != null) { - gestionnaireClavardage gc = gestionnaireClavardage.instance(); - gc.createSession(nom); - } - }catch (Exception e) { - System.out.println("Erreur : connect ListUI"); - e.printStackTrace(); - } - - } - - //mise en place de la liste de base - public void listeInitiale() { - - ArrayList listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur(); - DefaultListModel defaultListModel = new DefaultListModel(); - for (int i=0; i listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur(); - DefaultListModel defaultListModel = new DefaultListModel(); - for (int i=0; i