KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > threads > AddUserInChanThread


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: AddUserInChanThread</p>
23  * <p>Description: thread qui ajoute un user dans un chan</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
30 public class AddUserInChanThread extends PseudoThread
31 {
32   private ChatFrame chatFrame ;
33   private ChanUser user ;
34
35   /**
36    * AddUserInChanThread
37    * constructeur par parametres
38    *
39    * @param _chatFrame ChatFrame
40    * @param _user String
41    */

42   public AddUserInChanThread(ChatFrame _chatFrame, String JavaDoc _user)
43   {
44     chatFrame = _chatFrame ;
45     user = new ChanUser(_user, ChanUser.NORM) ;
46   }
47
48   public AddUserInChanThread(ChatFrame _chatFrame, ChanUser _user)
49   {
50     chatFrame = _chatFrame ;
51     user = _user ;
52   }
53
54   /**
55    * run
56    * va effectuer une recherche binaire dans le listmodel de la jlist du
57    * ChatFrame et inserer le nouveau user. Le run met aussi a jour les
58    * differents arrayy de users
59    */

60   public void go()
61   {
62     //
63
//ici on fait recherche binaire pour inserer le user a la bonne place
64
//
65

66     //AZUU si tu dois utiliser un objet étranger a la classe plusieurs fois.
67
//déclare une référence au lieu d'appeler 5 fois le Getters.
68
//ça gagne en lisibilité.
69
DefaultListModel lm = chatFrame.getListModel() ;
70
71     int posToInsert = Math.abs(Arrays.binarySearch(lm.toArray(), user)) - 1 ;
72     try
73     {
74       lm.add(posToInsert, user) ;
75     }
76     catch (ArrayIndexOutOfBoundsException JavaDoc ex)
77     {
78       lm.add(lm.size(), user) ;
79       ex.printStackTrace() ;
80     }
81
82     isFinished = true ;
83   }
84
85 }
86
Popular Tags