1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.table;
21
22 import java.util.ArrayList;
23 import java.util.Arrays;
24
25 import org.xnap.XNap;
26 import org.xnap.chat.ChannelInfo;
27 import org.xnap.chat.ChatProvider;
28
29 public class ChannelTableModel extends AbstractColumnTableModel
30 {
31
32
33
34
35 private ArrayList rows = new ArrayList();
36 private ChatProvider provider;
37
38
39
40 public ChannelTableModel()
41 {
42 Column columns[] = new Column[] {
43 new Column("channel", XNap.tr("Channel"), String.class),
44 new Column("userCount", XNap.tr("Users"), Integer.class,
45 new NumberCellRenderer()),
46 new Column("topic", XNap.tr("Topic"), String.class),
47 };
48 addColumns(columns);
49 }
50
51
52
53 public void clear()
54 {
55 rows.clear();
56 fireTableDataChanged();
57 }
58
59 public ChannelInfo get(int i)
60 {
61 return (ChannelInfo)rows.get(mapToIndex(i));
62 }
63
64 public int getRowCount()
65 {
66 return rows.size();
67 }
68
69 public Object get(int row, int column)
70 {
71 ChannelInfo i = (ChannelInfo)rows.get(row);
72
73 switch (column) {
74 case 0:
75 return i.getName();
76 case 1:
77 return new Integer(i.getPeerCount());
78 case 2:
79 return i.getTopic();
80 default:
81 return null;
82 }
83 }
84
85 public void set(ChatProvider provider)
86 {
87 this.provider = provider;
88
89 ChannelInfo[] channels = provider.getChannels();
90 if (channels != null) {
91 rows = new ArrayList(Arrays.asList(channels));
92 fireTableDataChanged();
93 resort();
94 }
95 else {
96 clear();
97 }
98 }
99
100 }