KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > client > notify > NotifyUser


1 package rero.client.notify;
2
3 import java.util.*;
4 import java.util.regex.*;
5
6 import rero.util.*;
7
8 import rero.ircfw.*;
9 import rero.ircfw.interfaces.*;
10
11 import rero.net.*;
12 import rero.client.*;
13
14
15 public class NotifyUser extends Feature implements ChatListener, FrameworkConstants
16 {
17    protected String JavaDoc nickname;
18    protected String JavaDoc address;
19  
20    protected long time;
21    protected boolean signedon;
22
23    /** a method to tell this object the user has signed off and to take appropriate action */
24    public void signOff()
25    {
26       signedon = false;
27       time = System.currentTimeMillis();
28
29       getCapabilities().injectEvent(":" + nickname + "!" + address + " SIGNOFF :signed off");
30    }
31
32    public void signOn()
33    {
34       getCapabilities().addTemporaryListener(this);
35       getCapabilities().sendln("USERHOST " + nickname);
36    }
37
38    /** returns the users nickname */
39    public String JavaDoc getNickname()
40    {
41       return nickname;
42    }
43
44    /** returns the users address */
45    public String JavaDoc getAddress()
46    {
47       return address;
48    }
49
50    /** is the user signed on or not */
51    public boolean isSignedOn()
52    {
53       return signedon;
54    }
55  
56    /** returns total amount of time user has been online (in seconds) */
57    public long getTimeOnline()
58    {
59       return (System.currentTimeMillis() - time) / 1000;
60    }
61
62    public NotifyUser(String JavaDoc nick)
63    {
64       nickname = nick;
65       signedon = false;
66    }
67
68    public void init()
69    {
70       // no sweat..
71
}
72
73    public int fireChatEvent (HashMap eventDescription)
74    {
75       address = (String JavaDoc)eventDescription.get("$address");
76
77       signedon = true;
78       time = System.currentTimeMillis();
79          
80       getCapabilities().injectEvent(":" + nickname + "!" + address + " SIGNON :signed on");
81
82       return EVENT_HALT | REMOVE_LISTENER;
83    }
84
85    public boolean isChatEvent(String JavaDoc eventId, HashMap eventDescription)
86    {
87       if (eventId.equals("302"))
88       {
89          String JavaDoc parms = (String JavaDoc)eventDescription.get("$nick");
90          return parms.equals(nickname);
91       }
92
93       return false;
94    }
95
96    public String JavaDoc toString()
97    {
98       return nickname;
99    }
100 }
101
Popular Tags