KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > threads > ChangeUserNickThread


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

22 /**
23  * <p>Title: ChangeUserNickThread</p>
24  * <p>Description: thread qui gere le changement de nick</p>
25  * <p>Copyright: Copyright (c) 2004</p>
26  * <p>Company: CoolBytes(Stephane Claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com</p>
27  * @version 1.0
28  */

29
30
31 public class ChangeUserNickThread extends PseudoThread
32 {
33
34   private ChanUser OldUser ;
35   private String JavaDoc newNick ;
36   private IRCconnexion ircChat ;
37
38   public ChangeUserNickThread(IRCconnexion _ircChat, String JavaDoc _oldNick, String JavaDoc _newNick)
39   {
40     OldUser = new ChanUser(_oldNick, ChanUser.NORM) ;
41     newNick = _newNick ;
42     ircChat = _ircChat ;
43   }
44
45   public void go()
46   {
47     //
48
//ici on fait recherche binaire pour inserer le user a la bonne place
49
//
50
ChatFrame crm ;
51     PrivateFrame prm ;
52     ChanUser machin ;
53     ArrayList Frm = ircChat.getAllChatFrames() ;
54     DefaultListModel lm ;
55     int i ;
56     int ind ;
57
58     //
59
//parcourir les listmodels chan
60
//
61

62     /* public static final int OP = 0 ;
63        public static final int HALFOP = 1 ;
64        public static final int VOICE = 2 ;
65        public static final int NORM = 3 ;
66      */

67     for (i = 0 ; i < Frm.size() ; i++)
68     {
69       crm = (ChatFrame)(Frm.get(i)) ;
70       lm = crm.getListModel() ;
71
72       ind = Arrays.binarySearch(lm.toArray(), new ChanUser(OldUser.getNameAvecRank(), ChanUser.OP)) ;
73       if (ind < 0)
74       {
75         ind = Arrays.binarySearch(lm.toArray(), new ChanUser(OldUser.getNameAvecRank(), ChanUser.HALFOP)) ;
76       }
77       if (ind < 0)
78       {
79         ind = Arrays.binarySearch(lm.toArray(), new ChanUser(OldUser.getNameAvecRank(), ChanUser.VOICE)) ;
80       }
81       if (ind < 0)
82       {
83         ind = Arrays.binarySearch(lm.toArray(), new ChanUser(OldUser.getNameAvecRank(), ChanUser.NORM)) ;
84       }
85
86       if (ind >= 0)
87       {
88         machin = (ChanUser)(lm.get(ind)) ;
89         lm.removeElementAt(ind) ;
90
91         machin.setName(newNick) ;
92
93         //résinsertion sociale lol
94
crm.addNewUserInChan(machin) ;
95
96         new MSGinfo(ircChat, crm, OldUser.getNameSansRank() + " se nomme à présent " + newNick).affiche() ;
97       }
98     }
99
100     //
101
//les privés...
102
//
103
Frm = ircChat.getAllPrivateFrames() ;
104
105     for (i = 0 ; i < Frm.size() ; i++)
106     {
107       prm = (PrivateFrame)(Frm.get(i)) ;
108       if (prm.getCorrespondant().equalsIgnoreCase(OldUser.getNameSansRank()))
109       {
110         prm.setCorrespondant(newNick) ;
111         new MSGinfo(ircChat, prm, OldUser.getNameSansRank() + " se nomme à présent " + newNick).affiche() ;
112       }
113     }
114
115     isFinished = true ;
116   }
117
118 }
119
Popular Tags