KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > plugin > JContactListItem


1 /*
2     =========================================================================
3     Package plugin - Plugin management
4
5     This module is developed and maintained by PlanetaMessenger.org.
6     Specs, New and updated versions can be found in
7     http://www.planetamessenger.org
8     If you want contact the Team please send a email to Project Manager
9     Leidson Campos Alves Ferreira at leidson@planetamessenger.org
10
11     Copyright (C) since 2001 by PlanetaMessenger.org
12     
13     This library is free software; you can redistribute it and/or
14     modify it under the terms of the GNU Lesser General Public
15     License as published by the Free Software Foundation; either
16     version 2.1 of the License, or (at your option) any later version.
17
18     This library is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21     Lesser General Public License for more details.
22
23     You should have received a copy of the GNU Lesser General Public
24     License along with this library; if not, write to the Free Software
25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27     =========================================================================
28 */

29 /**
30  *
31  * $Id: JContactListItem.java,v 1.9 2007/01/28 17:39:21 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.9 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.plugin;
40
41
42 public class JContactListItem implements java.lang.Comparable JavaDoc {
43
44   static public final int CONTACT_IN_LIST = 0;
45   static public final int CONTACT_NOT_IN_LIST = 1;
46
47   java.lang.String JavaDoc strNickName = "";
48   java.lang.String JavaDoc strUserId = "";
49   java.lang.String JavaDoc strFirstName = "";
50   java.lang.String JavaDoc strLastName = "";
51   java.lang.String JavaDoc strEmail = "";
52   java.lang.String JavaDoc strNotes = "";
53
54   int nPluginId = -1;
55   int nGender = -1;
56   int nGroupId = -1;
57   int nAge = 0;
58   int nContactFlag = CONTACT_IN_LIST;
59   boolean bVisible = true;
60   boolean bBlocked = false;
61   int nOnlineStatus = JPlugin.STATUS_OFFLINE;
62   int nCurrentStatus = JPlugin.STATUS_OFFLINE;
63
64   
65
66   /**
67    * Constructs and initializes all
68    * contactitem class data.
69    */

70   public JContactListItem() {
71     
72   }
73
74   /**
75    * Constructs and initializes all
76    * contactitem class data.
77    * @param nPluginId The new PluginId of this class;
78    * @param strUserId The item User Id;
79    * @param strText The item nick name;
80    */

81   public JContactListItem( int nPluginId, java.lang.String JavaDoc strUserId, java.lang.String JavaDoc strNickName ) {
82    
83     this();
84     
85     this.strUserId = strUserId;
86     this.nPluginId = nPluginId;
87     this.strNickName = strNickName;
88   }
89
90   /**
91    * Sets the ItemId of this object.
92    * @param strUserId The user id to assign to this item;
93    */

94   public void setUserId( java.lang.String JavaDoc strUserId ) {
95     
96     this.strUserId = strUserId;
97   }
98
99   /**
100    * Returns the user Id of this object;
101    */

102   public java.lang.String JavaDoc getUserId() {
103     
104     return strUserId;
105   }
106
107   /**
108    * Sets the PluginId of this object;
109    * @param nPluginId The new PluginId of this class;
110    */

111   public void setPluginId( int nPluginId ) {
112     
113     this.nPluginId = nPluginId;
114   }
115
116   /**
117    * Returns the PluginId of this
118    * class;
119    */

120   public int getPluginId() {
121     
122     return nPluginId;
123   }
124
125   /**
126    * Sets the new nickname of this item.
127    * o strNickName - The new nickname of this item;
128    */

129   public void setNickName( java.lang.String JavaDoc strNickName ) {
130     
131     this.strNickName = strNickName;
132   }
133
134   /**
135    * Returns the NickName of this item;
136    */

137   public java.lang.String JavaDoc getNickName() {
138     
139     return strNickName;
140   }
141   
142   /**
143    * Set the object's first name;
144    * @param strUserName The item first name;
145    */

146   public void setFirstName( java.lang.String JavaDoc strFirstName ) {
147
148     this.strFirstName = strFirstName;
149   }
150
151   /**
152    * Get the object's first name.
153    */

154   public java.lang.String JavaDoc getFirstName() {
155     
156     return strFirstName;
157   }
158
159   /**
160    * Set the object's user last name;
161    * @param strUserName The user last name;
162    */

163   public void setLastName( java.lang.String JavaDoc strLastName ) {
164
165     this.strLastName = strLastName;
166   }
167
168   /**
169    * Get the object's user last name.
170    */

171   public java.lang.String JavaDoc getLastName() {
172     
173     return strLastName;
174   }
175   
176   /**
177    * Set the user email.
178    * @param strEmail The user email;
179    */

180   public void setEmail( java.lang.String JavaDoc strEmail ) {
181     
182     this.strEmail = strEmail;
183   }
184
185   /**
186    * Get the object user email.
187    */

188   public java.lang.String JavaDoc getEmail() {
189     
190     return strEmail;
191   }
192   
193   /**
194    * Set the contact gender.
195    * @param nGender The new gender value;
196    * -1 None;
197    * 0 Male;
198    * 1 Female;
199    */

200   public void setGender( int nGender ) {
201     
202     this.nGender = nGender;
203   }
204   
205   /**
206    * Return the contact gender.
207    */

208   public int getGender() {
209     
210     return nGender;
211   }
212   
213   /**
214    * Set the contact age.
215    * @param nAge The contact age;
216    */

217   public void setAge( int nAge ) {
218     
219     this.nAge = nAge;
220   }
221   
222   /**
223    * Get the contact age.
224    */

225   public int getAge() {
226    
227     return nAge;
228   }
229   
230   /**
231    * Set the contact visibility flag.
232    * @param bVisible The new user visibility;
233    */

234   public void setVisible( boolean bVisible ) {
235    
236     this.bVisible = bVisible;
237   }
238   
239   /**
240    * Get the contact visibility flag.
241    */

242   public boolean getVisible() {
243    
244     return bVisible;
245   }
246   
247   /**
248    * Set the contact blocked status.
249    * @param bVisible The new user blocked status;
250    */

251   public void setBlocked( boolean bBlocked ) {
252    
253     this.bBlocked = bBlocked;
254   }
255   
256   /**
257    * Get the contact blocked status.
258    */

259   public boolean getBlocked() {
260    
261     return bBlocked;
262   }
263   
264   /**
265    * Set the contact contact Notes.
266    * @param strNotes The contact notes;
267    */

268   public void setNotes( java.lang.String JavaDoc strNotes ) {
269    
270     this.strNotes = strNotes;
271   }
272   
273   /**
274    * Get the contact notes.
275    */

276   public java.lang.String JavaDoc getNotes() {
277    
278     return strNotes;
279   }
280   
281   /**
282    * Set the contact group.
283    * @param nAge The contact group;
284    */

285   public void setGroupId( int nGroupId ) {
286     
287     this.nGroupId = nGroupId;
288   }
289   
290   /**
291    * Get the contact group;
292    */

293   public int getGroupId() {
294    
295     return nGroupId;
296   }
297   
298   /**
299    * Set the contact flag used for general
300    * purposes.<br>
301    * @param nContactFlag The new contact flag;
302    */

303   public void setContactFlag( int nContactFlag ) {
304    
305     this.nContactFlag = nContactFlag;
306   }
307   
308   /**
309    * Return the contact flag used for general
310    * purposes;<br>
311    */

312   public int getContactFlag() {
313     
314     return nContactFlag;
315   }
316   
317   
318   /**
319    * Verify if the contact is a enabled contact in contact list.
320    */

321   public boolean isContact() {
322
323     return ( nContactFlag == CONTACT_IN_LIST );
324   }
325
326   /**
327    * Set the item status.
328    * @param nNewStatus The new item status;
329    */

330   public void setStatus( int nNewStatus ) {
331
332     if( ( nNewStatus != JPlugin.STATUS_MESSAGE ) &&
333         ( nNewStatus != JPlugin.STATUS_URL ) )
334       nOnlineStatus = nNewStatus;
335
336     if( ( nCurrentStatus != JPlugin.STATUS_MESSAGE ) &&
337         ( nCurrentStatus != JPlugin.STATUS_URL ) )
338       nCurrentStatus = nNewStatus;
339   }
340
341   /**
342    * Get the current item status.
343    */

344   public int getStatus() {
345
346     return ( nCurrentStatus != nOnlineStatus ? nCurrentStatus : nOnlineStatus );
347   }
348
349   /**
350    * Return the active onLine Status.
351    */

352   public int getOnlineStatus() {
353     
354     return nOnlineStatus;
355   }
356
357   /**
358    * Restore the real contact status.
359    * Used internally by contact list objet (Call directly
360    * this method only when you really know what you're
361    * doing;
362    */

363   public void restoreRealStatus() {
364     
365     nCurrentStatus = nOnlineStatus;
366   }
367   
368   /**
369    * Copy data from object specified by parameter.<br>
370    * @param item The item to copy.<br>
371    */

372   public void copy( JContactListItem item ) {
373
374     strNickName = item.strNickName;
375     strUserId = item.strUserId;
376     strFirstName = item.strFirstName;
377     strLastName = item.strLastName;
378     strEmail = item.strEmail;
379     strNotes = item.strNotes;
380     nPluginId = item.nPluginId;
381     nGender = item.nGender;
382     nGroupId = item.nGroupId;
383     nAge = item.nAge;
384     nContactFlag = item.nContactFlag;
385     bVisible = item.bVisible;
386     bBlocked = item.bBlocked;
387     nOnlineStatus = item.nOnlineStatus;
388     nCurrentStatus = item.nCurrentStatus;
389   }
390
391   /**
392    * Implements the comparision method
393    * for this JContactItem class.
394    * @param obj The another JContactItem
395    * object to compare;
396    */

397   public boolean equals( Object JavaDoc obj ) {
398     
399     JContactListItem item = ( JContactListItem ) obj;
400     
401     
402     if( strUserId.equals( item.strUserId ) && ( nPluginId == item.nPluginId ) )
403       return true;
404     else
405       return false;
406   }
407
408   /**
409    * Implements the comparable interface
410    * method for comparision in the contact
411    * list items engine.
412    * This compare function sort the contact
413    * list items following the contact list
414    * rules (online, offline, messages, ...)
415    * @param obj The object that will be compared
416    * with this object;
417    */

418   public int compareTo( Object JavaDoc obj ) {
419     
420     JContactListItem item = ( JContactListItem ) obj;
421     
422     
423     if( item.getPluginId() == -1 )
424       return 1;
425     else
426       if( ( item.getPluginId() == -2 ) && ( getOnlineStatus() == JPlugin.STATUS_OFFLINE ) )
427         return 1;
428       else
429         if( ( item.getStatus() >= JPlugin.STATUS_URL ) &&
430             ( item.getOnlineStatus() > JPlugin.STATUS_OFFLINE ) &&
431             ( getPluginId() != -1 ) && ( getPluginId() != -2 ) &&
432             ( getOnlineStatus() > JPlugin.STATUS_OFFLINE ) &&
433             ( getStatus() < JPlugin.STATUS_URL ) )
434           return 1;
435         else
436           if( ( getStatus() >= JPlugin.STATUS_URL ) &&
437               ( getOnlineStatus() > JPlugin.STATUS_OFFLINE ) &&
438               ( item.getPluginId() != -1 ) && ( item.getPluginId() != -2 ) &&
439               ( item.getOnlineStatus() > JPlugin.STATUS_OFFLINE ) &&
440               ( item.getStatus() < JPlugin.STATUS_URL ) )
441             return -1;
442           else
443             if( ( item.getOnlineStatus() > JPlugin.STATUS_OFFLINE ) &&
444                 ( getOnlineStatus() == JPlugin.STATUS_OFFLINE ) &&
445                 ( getPluginId() != -1 ) )
446               return 1;
447             else
448               if( ( item.getStatus() >= JPlugin.STATUS_URL ) &&
449                   ( item.getOnlineStatus() == JPlugin.STATUS_OFFLINE ) &&
450                   ( getOnlineStatus() == JPlugin.STATUS_OFFLINE ) &&
451                   ( getPluginId() != -1 ) && ( getPluginId() != -2 ) )
452                 return 1;
453
454     return 0;
455   }
456
457   /**
458    * Overloads the toString method to
459    * show the new String representation
460    * of this class.
461    */

462   public java.lang.String JavaDoc toString() {
463     
464     return strNickName;
465   }
466 }
467
468 // JContactListItem class
Popular Tags