KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ContactListItem


1 import org.jivesoftware.smack.packet.*;
2
3 /** A contact list item.
4 * Appears in the JTree of JContactsPanel in the Main frame.
5 * May be a group, a contact or a service.*/

6 public final class ContactListItem{
7     
8     public static final int USER=0;
9     public static final int GROUP=1;
10     public static final int SERVICE=99; //other jabber services
11
private String JavaDoc protocol="jabber";
12     private RosterPacket.ItemType subscription=null; // subscription info
13
private Presence presence=null;
14     private int type;
15     private String JavaDoc label; // Text that appears on the tree
16
private String JavaDoc id; // The id of the item, eg Friends, fred@jabber.org, muc.jabber.org
17

18     
19     /** Creates the contact list item.*/
20     public ContactListItem(){
21         this.type=-1;
22         this.label=Lang.gs("contacts");
23     }
24     
25     /** Creates a new group item.*/
26     public ContactListItem (String JavaDoc groupname){
27         this.label=groupname;
28         this.id=groupname;
29         this.type=GROUP;
30     }
31     
32     /** Constructor for services.*/
33     public ContactListItem(String JavaDoc name, String JavaDoc id, int type){
34         this.label=name;
35         this.id=id;
36         this.type=type;
37     }
38     
39     /** Creates a jabber user contact entry.*/
40     public ContactListItem(String JavaDoc nick,String JavaDoc id, Presence presence,RosterPacket.ItemType subscription){
41         this.type=ContactListItem.USER;
42         this.label=nick;
43         this.id=id;
44         this.presence=presence;
45         this.subscription=subscription;
46     }
47     
48     /** Creates a user contact entry.*/
49     public ContactListItem(String JavaDoc nick,String JavaDoc id, Presence presence,RosterPacket.ItemType subscription, String JavaDoc protocol){
50         this.type=ContactListItem.USER;
51         this.label=nick;
52         this.id=id;
53         this.presence=presence;
54         this.subscription=subscription;
55         this.protocol=protocol;
56     }
57     
58     /** Returns the label text.*/
59     public String JavaDoc toString(){
60         return label;
61     }
62     
63     public String JavaDoc getID(){
64         return id;
65     }
66     
67     /** Sets the displayed label text.*/
68     public void setLabel(String JavaDoc label){
69         this.label=label;
70     }
71     
72     /** Returns the IM protocol of this user.*/
73     public String JavaDoc getProtocol(){
74         return protocol;
75     }
76     
77     /** Sets the IM protocol of this user.*/
78     public void setProtocol(String JavaDoc protocol){
79         this.protocol=protocol;
80     }
81     
82     /** Returns the online status of the user.
83     *Returns null if the user is offline or subscription not subscribed -
84     * Use getSubscription to see which.*/

85     public Presence getPresence(){
86         return presence;
87     }
88     
89     public void setPresence(Presence presence){
90         this.presence=presence;
91     }
92     
93     /** Returns the users subscription status.*/
94     public RosterPacket.ItemType getSubscription(){
95         return subscription;
96     }
97     
98     public void setSubscription(RosterPacket.ItemType subscription){
99         this.subscription=subscription;
100     }
101     
102     /** Retruns the type of this ContactListItem.
103     * Eg, ContactListItem.USER */

104     public int getType(){
105         return type;
106     }
107 }
Popular Tags