1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
32 import java.util.Vector;
\r
35 * A channel list handler.
\r
37 public class ChanList extends IRCSource {
\r
38 private ListenerGroup _listeners;
\r
39 private Vector _channels;
\r
40 private String _name;
\r
41 private boolean _running;
\r
42 private int _ignored;
\r
45 * Create a new ChanList.
\r
48 * the global configuration.
\r
50 * the IRCServer from where to retreive channel list.
\r
52 * the chanlist name.
\r
54 public ChanList(IRCConfiguration config, IRCServer server, String name) {
\r
55 super(config, server);
\r
58 _listeners = new ListenerGroup();
\r
59 _channels = new Vector();
\r
64 public String getType() {
\r
69 * Get the chanlist name.
\r
71 * @return the chanlist name.
\r
74 public String getName() {
\r
81 * @return array of all channels.
\r
83 public ChannelInfo[] getChannels() {
\r
84 ChannelInfo[] ans = new ChannelInfo[_channels.size()];
\r
85 for (int i = 0; i < _channels.size(); i++)
\r
86 ans[i] = (ChannelInfo) _channels.elementAt(i);
\r
91 * Get the channel count.
\r
93 * @return the number of channels.
\r
95 public int getChannelCount() {
\r
96 return _channels.size();
\r
100 * Get the ignored channel count.
\r
102 * @return the number of channels that have been ignored.
\r
104 public int getIgnoredChannelCount() {
\r
109 * Add a channel in the channel list.
\r
112 * new channel to add.
\r
114 public void addChannel(ChannelInfo nfo) {
\r
115 if (_channels.size() > 1024 && nfo.userCount < 5) {
\r
119 _channels.insertElementAt(nfo, _channels.size());
\r
120 _listeners.sendEvent("channelAdded", nfo, this);
\r
124 * Begin a new channel listing. The channel list is cleared.
\r
126 public void begin() {
\r
129 _channels = new Vector();
\r
130 _listeners.sendEvent("channelBegin", this);
\r
134 * End the channel listing.
\r
136 public void end() {
\r
138 _listeners.sendEvent("channelEnd", this);
\r
142 * Add a ChanListListener.
\r
147 public void addChanListListener(ChanListListener lis) {
\r
148 _listeners.addListener(lis);
\r
152 * Remove a chanListListener.
\r
155 * listener to remove.
\r
157 public void removeChanListListeners(ChanListListener lis) {
\r
158 _listeners.removeListener(lis);
\r
162 * Request the destruction of this chanlist.
\r
165 public void leave() {
\r
168 getIRCServer().leaveChanList(_name);
\r
172 public boolean talkable() {
\r
177 public boolean mayDefault() {
\r