1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail/IM me at jeti@jabber.org |
---|
21 | * |
---|
22 | */ |
---|
23 | |
---|
24 | package nu.fw.jeti.backend.roster; |
---|
25 | |
---|
26 | import java.util.ArrayList; |
---|
27 | import java.util.Collections; |
---|
28 | import java.util.Iterator; |
---|
29 | import java.util.List; |
---|
30 | |
---|
31 | import nu.fw.jeti.jabber.JIDStatus; |
---|
32 | |
---|
33 | /** |
---|
34 | * <p>Copyright: Copyright (c) 2001</p> |
---|
35 | * @author E.S. de Boer |
---|
36 | */ |
---|
37 | |
---|
38 | public class PrimaryJIDStatus implements Comparable //implements JIDStatus |
---|
39 | {//contains secondary jidstatussen (resource + same nick) |
---|
40 | private JIDStatus primaryJIDStatus; |
---|
41 | private List jidStatussen; |
---|
42 | private String nick; |
---|
43 | private boolean online=false; |
---|
44 | |
---|
45 | |
---|
46 | public PrimaryJIDStatus(String nick,JIDStatus primaryJIDStatus) |
---|
47 | { |
---|
48 | this.nick = nick; |
---|
49 | this.primaryJIDStatus = primaryJIDStatus; |
---|
50 | } |
---|
51 | |
---|
52 | // public boolean isEmpty() |
---|
53 | // { |
---|
54 | // return isEmpty; |
---|
55 | // } |
---|
56 | |
---|
57 | public boolean hasMultiple() |
---|
58 | { |
---|
59 | return jidStatussen != null; |
---|
60 | } |
---|
61 | |
---|
62 | public boolean isAJIDstatusOffline() |
---|
63 | { |
---|
64 | if(!primaryJIDStatus.isOnline()) return true; |
---|
65 | if(jidStatussen == null) return false; |
---|
66 | for(Iterator i = jidStatussen.iterator();i.hasNext();) |
---|
67 | { |
---|
68 | if(!((JIDStatus)i.next()).isOnline()) return true; |
---|
69 | } |
---|
70 | return false; |
---|
71 | } |
---|
72 | |
---|
73 | public boolean multipleJIDstatusOnline() |
---|
74 | { |
---|
75 | if(!primaryJIDStatus.isOnline()) return false; |
---|
76 | if(jidStatussen == null) return false; |
---|
77 | for(Iterator i = jidStatussen.iterator();i.hasNext();) |
---|
78 | { |
---|
79 | if(((JIDStatus)i.next()).isOnline()) return true; |
---|
80 | } |
---|
81 | return false; |
---|
82 | } |
---|
83 | |
---|
84 | public void addJIDStatus(JIDStatus jidStatus) |
---|
85 | { |
---|
86 | // if(primaryJIDStatus == null) |
---|
87 | // { |
---|
88 | // primaryJIDStatus = jidStatus; |
---|
89 | // //return true; |
---|
90 | // } |
---|
91 | // else |
---|
92 | // { |
---|
93 | if(jidStatussen == null) jidStatussen = new ArrayList(8); |
---|
94 | jidStatussen.add(jidStatus); |
---|
95 | Collections.sort(jidStatussen); |
---|
96 | //return false; |
---|
97 | //} |
---|
98 | } |
---|
99 | |
---|
100 | public boolean removeJIDStatus(JIDStatus jidStatus) |
---|
101 | {//returns true if primaryJIDStatus is now empty |
---|
102 | if(primaryJIDStatus == jidStatus) |
---|
103 | { |
---|
104 | if(jidStatussen == null) |
---|
105 | { |
---|
106 | //primaryJIDStatus = null; |
---|
107 | return true; |
---|
108 | } |
---|
109 | else if(jidStatussen.size() == 1) |
---|
110 | { |
---|
111 | primaryJIDStatus = (JIDStatus)jidStatussen.get(0); |
---|
112 | jidStatussen =null; |
---|
113 | } |
---|
114 | else |
---|
115 | {//jidstatussen sorted so first will be new primary |
---|
116 | primaryJIDStatus = (JIDStatus)jidStatussen.remove(0); |
---|
117 | } |
---|
118 | return false; |
---|
119 | } |
---|
120 | jidStatussen.remove(jidStatus); |
---|
121 | if (jidStatussen.size() == 0) jidStatussen = null; |
---|
122 | return false; |
---|
123 | } |
---|
124 | |
---|
125 | public void updatePresence(SecondaryJIDStatus jidStatus) |
---|
126 | { |
---|
127 | if(jidStatussen != null) Collections.sort(jidStatussen); |
---|
128 | if(jidStatus == primaryJIDStatus) |
---|
129 | {//check of secondery jids better then primary |
---|
130 | if(jidStatussen == null) return; |
---|
131 | |
---|
132 | //jidstatussen sorted so only first checked |
---|
133 | checkVolgorde((JIDStatus) getJIDStatus(0)); |
---|
134 | /* |
---|
135 | for(Iterator i = jidStatussen.iterator();i.hasNext();) |
---|
136 | { |
---|
137 | JIDStatus2 temp = (JIDStatus2)i.next(); |
---|
138 | checkVolgorde(jidGroup, temp, backend); |
---|
139 | } |
---|
140 | */ |
---|
141 | } |
---|
142 | else checkVolgorde(jidStatus); |
---|
143 | } |
---|
144 | |
---|
145 | public void updateOnline() |
---|
146 | { |
---|
147 | online = primaryJIDStatus.isOnline(); |
---|
148 | } |
---|
149 | |
---|
150 | private void checkVolgorde(JIDStatus jidStatus) |
---|
151 | { |
---|
152 | if(primaryJIDStatus.compareTo(jidStatus) > 0) |
---|
153 | { |
---|
154 | int index = jidStatussen.indexOf(jidStatus); |
---|
155 | jidStatussen.set(index,primaryJIDStatus); |
---|
156 | primaryJIDStatus = jidStatus; |
---|
157 | Collections.sort(jidStatussen);//sort new list |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | public JIDStatus getJIDPrimaryStatus() |
---|
162 | { |
---|
163 | // if(primaryJIDStatus == null) |
---|
164 | // {//jidstatus is removed from group before from gui so use a dummy until removed from gui |
---|
165 | // //System.out.println("Primary jids null"); |
---|
166 | // return new NormalJIDStatus(new JID("test","test") ,nick); |
---|
167 | // } |
---|
168 | return primaryJIDStatus; |
---|
169 | } |
---|
170 | |
---|
171 | public Object getJIDStatus(int index) |
---|
172 | { |
---|
173 | return jidStatussen.get(index); |
---|
174 | } |
---|
175 | |
---|
176 | public int indexOfJIDStatus(Object jidStatus) |
---|
177 | { |
---|
178 | return jidStatussen.indexOf(jidStatus); |
---|
179 | } |
---|
180 | |
---|
181 | public int size() |
---|
182 | { |
---|
183 | if(jidStatussen == null) return 0; |
---|
184 | return jidStatussen.size(); |
---|
185 | } |
---|
186 | |
---|
187 | public Iterator getOtherJidStatussen() |
---|
188 | { |
---|
189 | return new ArrayList(jidStatussen).iterator(); |
---|
190 | } |
---|
191 | |
---|
192 | public String toString() |
---|
193 | { |
---|
194 | //return nick;// |
---|
195 | return primaryJIDStatus.toString(); |
---|
196 | } |
---|
197 | |
---|
198 | public int compareTo(Object o) |
---|
199 | {//compare jid |
---|
200 | //if(nickname==null) return -1; |
---|
201 | return nick.compareTo(((PrimaryJIDStatus)o).nick); |
---|
202 | } |
---|
203 | |
---|
204 | //-------------------JIStatus implementation--------------------\\ |
---|
205 | |
---|
206 | // public JID getJID(){return primaryJIDStatus.getJID();} |
---|
207 | // |
---|
208 | // public JID getCompleteJID(){return primaryJIDStatus.getCompleteJID();} |
---|
209 | // |
---|
210 | public boolean isOnline() |
---|
211 | { |
---|
212 | return online; |
---|
213 | } |
---|
214 | // |
---|
215 | // public int getShow() |
---|
216 | // { |
---|
217 | // return primaryJIDStatus.getShow(); |
---|
218 | // } |
---|
219 | // |
---|
220 | // public String getStatus() |
---|
221 | // { |
---|
222 | // return primaryJIDStatus.getStatus(); |
---|
223 | // } |
---|
224 | // |
---|
225 | public String getNick() |
---|
226 | { |
---|
227 | return nick; |
---|
228 | } |
---|
229 | // |
---|
230 | // public String getType() |
---|
231 | // { |
---|
232 | // return primaryJIDStatus.getType(); |
---|
233 | // } |
---|
234 | // |
---|
235 | // public String getSubscription(){return primaryJIDStatus.getSubscription();} |
---|
236 | // |
---|
237 | // public String getWaiting() |
---|
238 | // { |
---|
239 | // return primaryJIDStatus.getWaiting(); |
---|
240 | // } |
---|
241 | // |
---|
242 | // public StringArray getGroupsCopy(){return primaryJIDStatus.getGroupsCopy();} |
---|
243 | // |
---|
244 | // public int groupCount(){return primaryJIDStatus.groupCount();} |
---|
245 | // |
---|
246 | // public boolean isGroupPresent(String group){return primaryJIDStatus.isGroupPresent(group);} |
---|
247 | } |
---|
248 | /* |
---|
249 | * Overrides for emacs |
---|
250 | * Local variables: |
---|
251 | * tab-width: 4 |
---|
252 | * End: |
---|
253 | */ |
---|