View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
37  
38      //--- Data field(s) ---
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      //--- Constructor(s) ---
49  
50      private ChatManager()
51      {
52      }
53  
54      //--- Method(s) ---
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