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
30 package irc.gui.pixx;
\r
32 import irc.ChanList;
\r
33 import irc.ChanListListener;
\r
34 import irc.ChannelInfo;
\r
35 import irc.style.StyledList;
\r
37 import java.awt.BorderLayout;
\r
40 * The AWT channel list.
\r
42 public class AWTChanList extends BaseAWTSource implements ChanListListener {
\r
44 * Horizontal scrollbar.
\r
46 protected PixxHorizontalScrollBar _hscroll;
\r
49 * Create a new AWTChanList.
\r
52 * the global irc configuration.
\r
54 * the source channel list.
\r
56 public AWTChanList(PixxConfiguration config, ChanList list) {
\r
57 super(config, list, true);
\r
59 list.addChanListListener(this);
\r
61 _hscroll = new PixxHorizontalScrollBar(_pixxConfiguration, 0, 0, 0.1);
\r
62 _hscroll.addPixxScrollBarListener(this);
\r
64 _list.setWrap(false);
\r
67 add(_hscroll, BorderLayout.SOUTH);
\r
69 setTitle(getText(PixxTextProvider.SOURCE_CHANLIST, getChanList().getName()));
\r
74 public void release() {
\r
75 ((ChanList) _source).removeChanListListeners(this);
\r
76 _hscroll.removePixxScrollBarListener(this);
\r
83 public String getShortTitle() {
\r
84 return getText(PixxTextProvider.GUI_CHANNELS);
\r
88 public void setFieldText(String txt) {
\r
92 public String getFieldText() {
\r
97 public void validateText() {
\r
101 * Get the source chanlist.
\r
103 * @return source chanlist.
\r
105 public ChanList getChanList() {
\r
106 return (ChanList) getSource();
\r
110 public void channelBegin(ChanList list) {
\r
111 clear(getSource());
\r
112 print(_pixxConfiguration.getText(PixxTextProvider.SOURCE_CHANLIST_RETREIVING));
\r
116 private void sort(ChannelInfo[] info, int begin, int end, int deep) {
\r
121 int f = (begin + end) / 2;
\r
123 info[f] = info[begin];
\r
127 ChannelInfo pivot = info[p_pos];
\r
128 for (int i = begin; i <= end; i++) {
\r
129 if (info[i].userCount > pivot.userCount) {
\r
132 info[p_pos] = info[i];
\r
137 info[p_pos] = info[begin];
\r
140 sort(info, begin, p_pos - 1, deep + 1);
\r
141 sort(info, p_pos + 1, end, deep + 1);
\r
144 for (int i = begin; i <= end; i++) {
\r
145 ChannelInfo little = info[i];
\r
146 int littleindex = i;
\r
147 int littleuser = little.userCount;
\r
148 for (int j = i + 1; j <= end; j++) {
\r
149 if (info[j].userCount > littleuser) {
\r
152 littleuser = little.userCount;
\r
156 ChannelInfo tmp = info[i];
\r
157 info[i] = info[littleindex];
\r
158 info[littleindex] = tmp;
\r
163 private void sort(ChannelInfo[] info) {
\r
164 sort(info, 0, info.length - 1, 0);
\r
168 public void channelEnd(ChanList list) {
\r
169 ChannelInfo[] info = getChanList().getChannels();
\r
171 int count = info.length;
\r
174 String[] lines = new String[count];
\r
175 for (int i = 0; i < count; i++)
\r
176 lines[i] = format(info[i]);
\r
178 clear(getSource());
\r
179 _list.addLines(lines);
\r
181 _scroll.setMaximum(_list.getLineCount() - 1);
\r
182 _scroll.setValue(_list.getLast());
\r
183 _hscroll.setMaximum(_list.getLogicalWidth() / 10);
\r
186 private String format(ChannelInfo item) {
\r
187 String msg = item.name;
\r
188 String count = "" + item.userCount;
\r
189 for (int i = 0; i < 20 - item.name.length(); i++)
\r
191 msg += " " + item.userCount;
\r
192 for (int i = 0; i < 5 - count.length(); i++)
\r
194 msg += " " + item.topic;
\r
199 public void channelAdded(ChannelInfo item, ChanList list) {
\r
200 int count = getChanList().getChannelCount();
\r
201 int total = getChanList().getIgnoredChannelCount() + count;
\r
202 if (total % 100 == 0) {
\r
203 clear(getSource());
\r
204 print(_pixxConfiguration.getText(PixxTextProvider.SOURCE_CHANLIST_RETREIVING) + " (" + count + "/" + total + ")");
\r
210 public void valueChanged(PixxScrollBar pixScrollBar) {
\r
211 if (pixScrollBar == _hscroll)
\r
212 _list.setLeft(_hscroll.getValue() * 10);
\r
214 super.valueChanged(pixScrollBar);
\r
218 public void virtualSizeChanged(StyledList lis) {
\r
219 _hscroll.setMaximum(_list.getLogicalWidth() / 10);
\r
220 super.virtualSizeChanged(lis);
\r