correctif
This commit is contained in:
parent
dac29b05e8
commit
d186fd2a22
7 changed files with 77 additions and 330 deletions
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
||||
|
|
|
@ -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<String> list = new JList<String>();
|
||||
private JList<TypeListeUtilisateur> list2 = new JList<TypeListeUtilisateur>();
|
||||
private JComboBox<String> comboBox = new JComboBox<String>();
|
||||
|
||||
private static JList<TypeListeUtilisateur> list = new JList<TypeListeUtilisateur>();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -51,24 +58,29 @@ public class ListUI extends JFrame implements Runnable{
|
|||
|
||||
|
||||
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 String) {
|
||||
String nextUser = (String) value;
|
||||
setText(nextUser);
|
||||
if (nextUser.equals("Toto")) {
|
||||
if (value instanceof TypeListeUtilisateur) {
|
||||
TypeListeUtilisateur nextUser = (TypeListeUtilisateur) value;
|
||||
setText(nextUser.nom);
|
||||
if (nextUser.statut != null) {
|
||||
if (nextUser.statut.equals("online")) {
|
||||
setBackground(Color.GREEN);
|
||||
} else {
|
||||
} 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<TypeListeUtilisateur> listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur();
|
||||
DefaultListModel<String> defaultListModel = new DefaultListModel<String>();
|
||||
DefaultListModel<TypeListeUtilisateur> defaultListModel = new DefaultListModel<TypeListeUtilisateur>();
|
||||
for (int i=0; i<listeUtilisateur.size(); i++){
|
||||
if(!listeUtilisateur.get(i).nom.equals(GestionnaireNom.instance().getNom())) {
|
||||
defaultListModel.addElement(listeUtilisateur.get(i).nom);
|
||||
defaultListModel.addElement(listeUtilisateur.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -240,14 +268,32 @@ public class ListUI extends JFrame implements Runnable{
|
|||
public static void update() { //TODO à refaire en plus jolie (observer ou autre)
|
||||
|
||||
ArrayList<TypeListeUtilisateur> listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur();
|
||||
DefaultListModel<String> defaultListModel = new DefaultListModel<String>();
|
||||
DefaultListModel<TypeListeUtilisateur> defaultListModel = new DefaultListModel<TypeListeUtilisateur>();
|
||||
for (int i=0; i<listeUtilisateur.size(); i++){
|
||||
if(!listeUtilisateur.get(i).nom.equals(GestionnaireNom.instance().getNom())) {
|
||||
defaultListModel.addElement(listeUtilisateur.get(i).nom);
|
||||
defaultListModel.addElement(listeUtilisateur.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
list.setModel(defaultListModel);
|
||||
}
|
||||
|
||||
|
||||
// action ComboBox
|
||||
private void actionComboBox() {
|
||||
String item = (String) comboBox.getSelectedItem();
|
||||
System.out.println(item); // debug
|
||||
GestionnaireNom.instance().setStatut(item);
|
||||
// on envoie l'info à la servlet
|
||||
try {
|
||||
Post.sendPOST("nom$$$" + GestionnaireNom.instance().getId() + "$$$" + GestionnaireNom.instance().getNom()+ "$$$"
|
||||
+ GestionnaireNom.instance().getIp() + "$$$" + GestionnaireNom.instance().getDansReseau() + "$$$"
|
||||
+ GestionnaireNom.instance().getStatut() );
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,299 +0,0 @@
|
|||
package ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
//import javax.swing.AbstractListModel;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
public class ListUI2 extends JFrame implements Runnable{
|
||||
|
||||
private static final long serialVersionUID = 42L;
|
||||
|
||||
private JPanel contentPane;
|
||||
private JComboBox<String> comboBox = new JComboBox<String>();
|
||||
|
||||
private static JList<TypeListeUtilisateur> list = new JList<TypeListeUtilisateur>();
|
||||
|
||||
|
||||
/**
|
||||
* 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<String>();
|
||||
list.setModel(new AbstractListModel<String>() {
|
||||
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<String> 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<TypeListeUtilisateur> listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur();
|
||||
DefaultListModel<TypeListeUtilisateur> defaultListModel = new DefaultListModel<TypeListeUtilisateur>();
|
||||
for (int i=0; i<listeUtilisateur.size(); i++){
|
||||
if(!listeUtilisateur.get(i).nom.equals(GestionnaireNom.instance().getNom())) {
|
||||
defaultListModel.addElement(listeUtilisateur.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
list.setModel(defaultListModel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// mise à jour des graphismes
|
||||
public static void update() { //TODO à refaire en plus jolie (observer ou autre)
|
||||
|
||||
ArrayList<TypeListeUtilisateur> listeUtilisateur = GestionnaireListeUtilisateur.instance().getListeUtilisateur();
|
||||
DefaultListModel<TypeListeUtilisateur> defaultListModel = new DefaultListModel<TypeListeUtilisateur>();
|
||||
for (int i=0; i<listeUtilisateur.size(); i++){
|
||||
if(!listeUtilisateur.get(i).nom.equals(GestionnaireNom.instance().getNom())) {
|
||||
defaultListModel.addElement(listeUtilisateur.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
list.setModel(defaultListModel);
|
||||
}
|
||||
|
||||
|
||||
// action ComboBox
|
||||
private void actionComboBox() {
|
||||
String item = (String) comboBox.getSelectedItem();
|
||||
System.out.println(item); // debug
|
||||
GestionnaireNom.instance().setStatut(item);
|
||||
// on envoie l'info à la servlet
|
||||
try {
|
||||
Post.sendPOST("nom$$$" + GestionnaireNom.instance().getId() + "$$$" + GestionnaireNom.instance().getNom()+ "$$$"
|
||||
+ GestionnaireNom.instance().getIp() + "$$$" + GestionnaireNom.instance().getDansReseau() + "$$$"
|
||||
+ GestionnaireNom.instance().getStatut() );
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -202,7 +202,6 @@ public class Login_RegisterUI extends JFrame implements Runnable{
|
|||
|
||||
// inCheckBox
|
||||
JCheckBox inCheckBox = new JCheckBox("I am inside the network");
|
||||
GestionnaireNom.instance().setDansReseau(inCheckBox.isSelected());
|
||||
inCheckBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) { //action
|
||||
GestionnaireNom.instance().setDansReseau(inCheckBox.isSelected());
|
||||
|
@ -213,6 +212,7 @@ public class Login_RegisterUI extends JFrame implements Runnable{
|
|||
inCheckBox.setSelected(true);
|
||||
inCheckBox.setBounds(141, 162, 157, 23);
|
||||
contentPane.add(inCheckBox);
|
||||
GestionnaireNom.instance().setDansReseau(inCheckBox.isSelected());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ public class NomUI extends JFrame implements Runnable{
|
|||
if( (GestionnaireNom.instance().getNom() != null) && ( nom.isBlank() || nom.equals(GestionnaireNom.instance().getNom()) ) ) {
|
||||
dispose();
|
||||
|
||||
Thread t = new Thread(new ListUI2());
|
||||
Thread t = new Thread(new ListUI());
|
||||
t.start();
|
||||
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public class NomUI extends JFrame implements Runnable{
|
|||
}
|
||||
dispose();
|
||||
|
||||
Thread t = new Thread(new ListUI2());
|
||||
Thread t = new Thread(new ListUI());
|
||||
t.start();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue