1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.chat;
21
22 import java.util.List;
23 import java.util.Vector;
24
25 import org.xnap.event.ListListener;
26 import org.xnap.event.ListSupport;
27
28 /***
29 * Manages chat providers and joined channels. ChatManager uses the singleton
30 * pattern. Use <code>getInstance()</code> to get a reference to the chat
31 * manager.
32 */
33 public class ChatManager
34 {
35
36
37
38
39
40 private static ChatManager instance = new ChatManager();
41
42 protected List channels = new Vector();
43 protected List providers = new Vector();
44
45 protected ListSupport channelSupport = new ListSupport(this);
46 protected ListSupport providerSupport = new ListSupport(this);
47
48
49
50 private ChatManager()
51 {
52 }
53
54
55
56 /***
57 * Returns a reference to the <code>ChatManager</code> singleton.
58 */
59 public static ChatManager getInstance()
60 {
61 return instance;
62 }
63
64 /***
65 *
66 */
67 public void add(Channel channel)
68 {
69 channels.add(channel);
70 channelSupport.fireItemAdded(channel);
71 }
72
73 public void add(ChatProvider provider)
74 {
75 providers.add(provider);
76 providerSupport.fireItemAdded(provider);
77 }
78
79 public void addChannelListListener(ListListener listener)
80 {
81 channelSupport.addListListener(listener);
82 }
83
84 public void addProviderListListener(ListListener listener)
85 {
86 providerSupport.addListListener(listener);
87 }
88
89 public boolean contains(Channel channel)
90 {
91 return channels.contains(channel);
92 }
93
94 public Channel[] getChannels()
95 {
96 return (Channel[])channels.toArray(new Channel[0]);
97 }
98
99 public ChatProvider[] getProviders()
100 {
101 return (ChatProvider[])providers.toArray(new ChatProvider[0]);
102 }
103
104 public void remove(Channel channel)
105 {
106 channels.remove(channel);
107 channelSupport.fireItemRemoved(channel);
108 }
109
110 public void remove(ChatProvider provider)
111 {
112 providers.remove(provider);
113 providerSupport.fireItemRemoved(provider);
114 }
115
116 public void removeChannelListListener(ListListener listener)
117 {
118 channelSupport.removeListListener(listener);
119 }
120
121 public void removeProviderListListener(ListListener listener)
122 {
123 providerSupport.removeListListener(listener);
124 }
125
126 }
127
128