KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > threads > AddUserListInChanThread


1 package zirc.threads ;
2
3 import java.util.* ;
4 import javax.swing.* ;
5 import zirc.base.* ;
6 import zirc.gui.* ;
7
8 //zIrc, irc client.
9
// Copyright (C) 2004 CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com
10
//
11
// This program is free software; you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your option) any later version.
15
//
16
// This program is distributed in the hope that it will be useful,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
// GNU General Public License for more details.
20

21 /**
22  * <p>Title: thread qui gere la commande LIST</p>
23  * <p>Description: traite le message MODE</p>
24  * <p>Copyright: Copyright (c) 2004</p>
25  * <p>Company: CoolBytes(Stephane Claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com</p>
26  * @version 1.0
27  */

28
29 public class AddUserListInChanThread extends PseudoThread
30 {
31   private ChatFrame chatFrame ;
32   private String JavaDoc users ;
33
34   /**
35    * AddUsersInChanThread
36    * constructeur par parametres
37    *
38    * @param _chatFrame ChatFrame
39    * @param _users String
40    */

41   public AddUserListInChanThread(ChatFrame _chatFrame, String JavaDoc _users)
42   {
43     chatFrame = _chatFrame ;
44     users = _users ;
45   }
46
47   //:zuzu!origin@AAB120F.869FB0FF.CA7F87DF.IP JOIN :#Dialogues
48
//:courbevoie.fr.epiknet.org 353 zuzu = #Dialogues :zuzu scott coeur uR_NaMMu Ades95 Athalante bluc Lullaby urtia jeandeDIEU +korben[AwaY] girl-62 DeFecTeD Cornellius animateurradio_scotty DJ_Depannage`oqp Fenix Melodie41 MK @Exit[aw] davidpulp @Gou[away] LaC-PaLa hein +BENHUR[plu_la] +k|aw apupersonne brun_yx_verts @Sphinx MlleSexy +DataStats02 +eat +BigBrother une_merdouille_pala Pandore +Puppy[-Aw-] Pwals Al_doc edouardito Bob_le_Pointu +Phantasia bArAkA
49
//:courbevoie.fr.epiknet.org 353 zuzu = #Dialogues :Ray[ILJ]`AwAy platon
50
//:courbevoie.fr.epiknet.org 366 zuzu #Dialogues :End of /NAMES list.
51

52   public void go()
53   {
54
55     //le nom en cours de traitement
56
String JavaDoc userName ;
57
58     //cet objet contient l utilisateur
59
ChanUser userFinal ;
60
61     StringTokenizer str = new StringTokenizer(users, " ") ;
62
63     ChanUser vectUsers[] = new ChanUser[str.countTokens()] ;
64     int i = 0 ;
65
66     //on passe les lignees
67
while (str.hasMoreTokens())
68     {
69       userName = str.nextToken() ;
70
71       //test (a peu près dans l'ordre de probabilité)
72
if (userName.charAt(0) == '+')
73       {
74         userFinal = new ChanUser(userName.substring(1), ChanUser.VOICE) ;
75       }
76       else
77       {
78         if (userName.charAt(0) == '@')
79         {
80           userFinal = new ChanUser(userName.substring(1), ChanUser.OP) ;
81         }
82         else
83         {
84           if (userName.charAt(0) == '%')
85           {
86             userFinal = new ChanUser(userName.substring(1), ChanUser.HALFOP) ;
87           }
88           else
89           {
90             userFinal = new ChanUser(userName, ChanUser.NORM) ;
91
92           }
93         }
94       }
95
96       //ajouter l'individu a l'array d'users
97
vectUsers[i] = userFinal ;
98       i++ ;
99     }
100
101     //trier le vecteur
102
sort(vectUsers) ;
103
104     //synchroniser son contenu avec celui du listmodel
105
addUsers(vectUsers) ;
106
107     isFinished = true ;
108
109   }
110
111   public void sort(ChanUser[] _vect)
112   {
113     Arrays.sort(_vect) ;
114   }
115
116   public void addUsers(ChanUser[] _vect)
117   {
118     //avoir le listmodel de la chatframe
119
DefaultListModel lm = chatFrame.getListModel() ;
120
121     //vider le listmodel
122
lm.clear() ;
123
124     //ajouter les différents users l un apres l'autre
125
//
126
//!!!!AZUUU SURTOUT ON MET PAS les éléments dans l'ordre INVERSE ou alors
127
//C'est le comparateur qu'il faut changer!
128
//
129
//Si tu insères en inverse CELA perturbe vachement la recherche binaire!!!
130
//puisque lorsque tu fais un Listmodel.toArray() ca te renvoie les éléments
131
//dans un ORDRE DIFFERENT de celui qui a été renvoyé par ton comparateur.
132
//J'ai perdu une demi-journée à savoir que ca venait de ca!!!!!!!!!!
133

134     for (int i = 0 ; i < _vect.length ; i++)
135     {
136       lm.addElement(_vect[i]) ;
137     }
138
139     System.err.println("Done") ;
140     chatFrame.getUserList().validate() ;
141   }
142
143 }
144
Popular Tags