1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 package com.buckosoft.fibs.BuckoFIBS.gui.inviterList;
73
74 import java.util.LinkedList;
75 import java.util.ListIterator;
76
77 import javax.swing.table.AbstractTableModel;
78
79 import com.buckosoft.fibs.BuckoFIBS.gui.playerList.Column;
80 import com.buckosoft.fibs.domain.Player;
81
82
83
84
85
86
87
88 public class InviterTableModel extends AbstractTableModel {
89 private final static boolean DEBUG = false;
90 private static final long serialVersionUID = 1L;
91
92 public class Inviter {
93 Player p;
94 Inviter(Player p) {
95 super();
96 this.p = p;
97 }
98 String matchLength;
99 }
100
101 private class InviterColumns {
102 private LinkedList<Column> columns = new LinkedList<Column>();
103
104 InviterColumns() {
105 columns.add(new Column("Name", 20));
106 columns.add(new Column("Match", 10));
107 columns.add(new Column("Rating", 10));
108 columns.add(new Column("Exp", 9));
109 columns.add(new Column("Host", 300));
110 }
111
112
113
114
115 public LinkedList<Column> getColumns() {
116 return columns;
117 }
118
119 }
120
121 private InviterColumns _inviterColumns = new InviterColumns();
122 private LinkedList<Inviter> inviters = new LinkedList<Inviter>();
123
124
125
126
127
128 public void invited(Player player, String matchLength) {
129 ListIterator<Inviter> liter = inviters.listIterator();
130 int row = -1;
131 while (liter.hasNext()) {
132 row++;
133 Inviter p = liter.next();
134 if (p.p.getName().equals(player.getName())) {
135 Inviter pi = new Inviter(player);
136 pi.matchLength = matchLength;
137 liter.set(pi);
138 this.fireTableRowsUpdated(row, row);
139 if (DEBUG)
140 System.out.println("inviterChanged: " + player.getName());
141 return;
142 }
143 }
144 Inviter pi = new Inviter(player);
145 pi.matchLength = matchLength;
146 inviters.add(pi);
147 if (DEBUG)
148 System.out.println("inviterChanged: " + player.getName());
149 this.fireTableRowsInserted(inviters.size()-1, inviters.size()-1);
150 }
151
152
153
154
155
156 public void uninvited(String playerName) {
157 ListIterator<Inviter> liter = inviters.listIterator();
158 int row = -1;
159 while (liter.hasNext()) {
160 row++;
161 Inviter p = liter.next();
162 if (p.p.getName().equals(playerName)) {
163 liter.remove();
164 this.fireTableRowsDeleted(row, row);
165 }
166 }
167 }
168
169
170
171 public void removeAll() {
172 inviters.clear();
173 this.fireTableDataChanged();
174 }
175
176 public void playerChanged(Player p) {
177 Inviter i = getInviter(p.getName());
178 if (i == null)
179 return;
180 i.p = p;
181 this.fireTableDataChanged();
182 }
183
184
185
186
187
188 public Inviter getInviter(String playerName) {
189 for (Inviter p : inviters) {
190 if (p.p.getName().equals(playerName))
191 return(p);
192 }
193 return(null);
194 }
195
196
197
198
199
200
201
202 public void setWarning(String playerName, String warning) {
203 Inviter inv = getInviter(playerName);
204 if (inv != null) {
205 inv.p.setBfStatus(warning);
206 this.fireTableDataChanged();
207 }
208 }
209
210
211
212
213 public Class<?> getColumnClass(int arg0) {
214 try {
215 if (arg0 == 0)
216 return(Class.forName("com.buckosoft.fibs.domain.Player"));
217 return Class.forName("java.lang.String");
218 } catch (ClassNotFoundException e) {
219 System.out.println("Exception ignored...");
220 e.printStackTrace();
221 }
222 return(null);
223 }
224
225
226
227
228 public int getColumnCount() {
229 return _inviterColumns.getColumns().size();
230 }
231
232
233
234
235 public String getColumnName(int arg0) {
236 return _inviterColumns.getColumns().get(arg0).getName();
237 }
238
239
240
241
242 public int getRowCount() {
243 return this.inviters.size();
244 }
245
246
247
248
249 public Object getValueAt(int arg0, int arg1) {
250 Inviter p = inviters.get(arg0);
251 switch (arg1) {
252 case 0:
253 return(p.p);
254
255 case 1:
256 return(p.matchLength);
257 case 2:
258 return(p.p.getRating());
259 case 3:
260 return(p.p.getExperience());
261 case 4:
262 return(p.p.getHostName());
263 }
264 return null;
265 }
266
267
268
269
270 public boolean isCellEditable(int arg0, int arg1) {
271 return false;
272 }
273
274
275
276
277 @Override
278 public void setValueAt(Object arg0, int arg1, int arg2) {
279 }
280
281 }