Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InviterTableModel |
|
| 2.6875;2.688 | ||||
InviterTableModel$Inviter |
|
| 2.6875;2.688 | ||||
InviterTableModel$InviterColumns |
|
| 2.6875;2.688 |
1 | /****************************************************************************** | |
2 | * InviterTableModel.java - The Inviter's JList Table Model | |
3 | * $Id$ | |
4 | * | |
5 | * BuckoFIBS - Backgammon by BuckoSoft | |
6 | * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp. | |
7 | * | |
8 | * $Log$ | |
9 | * Revision 1.3 2010/03/03 13:12:21 inim | |
10 | * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8 | |
11 | * | |
12 | * Revision 1.2 2010/03/03 12:19:49 inim | |
13 | * Moved source to UTF8 encoding from CP1252 encoding. To this end all source files' (c) message was updated to "Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.". This replaces the (c) sign to UTF8, and adds the new year 2010. | |
14 | * | |
15 | * Revision 1.1 2010/02/04 05:57:53 inim | |
16 | * Mavenized project folder layout | |
17 | * | |
18 | * Revision 1.5 2009/02/24 08:06:48 dick | |
19 | * Add the hostName as a column. | |
20 | * | |
21 | * Revision 1.4 2009/02/14 15:46:36 dick | |
22 | * BuckoFIBS is released under the GNU license. | |
23 | * | |
24 | * Revision 1.3 2009/02/11 09:07:30 dick | |
25 | * playerChanged(Player) to update the changed player in the invter table. | |
26 | * This is in case we got invited by an unknown player, and then figured him out. | |
27 | * | |
28 | * Revision 1.2 2009/02/02 08:39:25 dick | |
29 | * Use a string for the match length, so we can say "" or "unlimited". | |
30 | * | |
31 | * Revision 1.1 2009/01/28 19:39:15 dick | |
32 | * package com.buckosoft.fibs.gui.inviterList becomes com.buckosoft.fibs.BuckoFIBS.gui.inviterList. | |
33 | * | |
34 | * Revision 1.6 2009/01/28 08:32:07 dick | |
35 | * Add removeAll to clean the list. | |
36 | * Javadoc. | |
37 | * | |
38 | * Revision 1.5 2009/01/27 19:16:43 dick | |
39 | * playerName gets a custom renderer so we can display warnings. | |
40 | * | |
41 | * Revision 1.4 2009/01/27 06:56:23 dick | |
42 | * playerchanged() and playerGone() become invited() and uninvited(). | |
43 | * | |
44 | * Revision 1.3 2009/01/09 07:19:28 dick | |
45 | * Turn off debug. | |
46 | * | |
47 | * Revision 1.2 2008/12/10 18:07:20 dick | |
48 | * Inviter contains a Player, not extends it. | |
49 | * | |
50 | * Revision 1.1 2008/12/09 19:40:15 dick | |
51 | * The Inviter's JList Table Model. | |
52 | */ | |
53 | ||
54 | /* | |
55 | * This program is free software: you can redistribute it and/or modify | |
56 | * it under the terms of the GNU General Public License as published by | |
57 | * the Free Software Foundation, either version 3 of the License, or | |
58 | * (at your option) any later version. | |
59 | * | |
60 | * This program is distributed in the hope that it will be useful, | |
61 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
62 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
63 | * GNU General Public License for more details. | |
64 | * | |
65 | * You should have received a copy of the GNU General Public License | |
66 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
67 | * | |
68 | * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>. | |
69 | * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp. | |
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 | /** The Inviter's JList Table Model | |
83 | * @author Dick Balaska | |
84 | * @since 2008/12/08 | |
85 | * @version $Revision$ <br> $Date$ | |
86 | * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/inviterList/InviterListPane.java">cvs InviterListPane.java</a> | |
87 | */ | |
88 | 0 | 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 | 0 | Inviter(Player p) { |
95 | 0 | super(); |
96 | 0 | this.p = p; |
97 | 0 | } |
98 | String matchLength; | |
99 | } | |
100 | ||
101 | private class InviterColumns { | |
102 | 0 | private LinkedList<Column> columns = new LinkedList<Column>(); |
103 | ||
104 | 0 | InviterColumns() { |
105 | 0 | columns.add(new Column("Name", 20)); |
106 | 0 | columns.add(new Column("Match", 10)); |
107 | 0 | columns.add(new Column("Rating", 10)); |
108 | 0 | columns.add(new Column("Exp", 9)); |
109 | 0 | columns.add(new Column("Host", 300)); |
110 | 0 | } |
111 | ||
112 | /** | |
113 | * @return the columns | |
114 | */ | |
115 | public LinkedList<Column> getColumns() { | |
116 | 0 | return columns; |
117 | } | |
118 | ||
119 | } | |
120 | ||
121 | 0 | private InviterColumns _inviterColumns = new InviterColumns(); |
122 | 0 | private LinkedList<Inviter> inviters = new LinkedList<Inviter>(); |
123 | ||
124 | /** Method to add a Player to the inviter table | |
125 | * @param player The Player that invited us | |
126 | * @param matchLength How many games in the match | |
127 | */ | |
128 | public void invited(Player player, String matchLength) { | |
129 | 0 | ListIterator<Inviter> liter = inviters.listIterator(); |
130 | 0 | int row = -1; |
131 | 0 | while (liter.hasNext()) { |
132 | 0 | row++; |
133 | 0 | Inviter p = liter.next(); |
134 | 0 | if (p.p.getName().equals(player.getName())) { |
135 | 0 | Inviter pi = new Inviter(player); |
136 | 0 | pi.matchLength = matchLength; |
137 | 0 | liter.set(pi); |
138 | 0 | this.fireTableRowsUpdated(row, row); |
139 | if (DEBUG) | |
140 | System.out.println("inviterChanged: " + player.getName()); | |
141 | 0 | return; |
142 | } | |
143 | 0 | } |
144 | 0 | Inviter pi = new Inviter(player); |
145 | 0 | pi.matchLength = matchLength; |
146 | 0 | inviters.add(pi); |
147 | if (DEBUG) | |
148 | System.out.println("inviterChanged: " + player.getName()); | |
149 | 0 | this.fireTableRowsInserted(inviters.size()-1, inviters.size()-1); |
150 | 0 | } |
151 | ||
152 | /** Method to remove a player from the inviter table. | |
153 | * This is called i.e. when a player starts a match with someone else, or logs out. | |
154 | * @param playerName The name of the player to remove | |
155 | */ | |
156 | public void uninvited(String playerName) { | |
157 | 0 | ListIterator<Inviter> liter = inviters.listIterator(); |
158 | 0 | int row = -1; |
159 | 0 | while (liter.hasNext()) { |
160 | 0 | row++; |
161 | 0 | Inviter p = liter.next(); |
162 | 0 | if (p.p.getName().equals(playerName)) { |
163 | 0 | liter.remove(); |
164 | 0 | this.fireTableRowsDeleted(row, row); |
165 | } | |
166 | 0 | } |
167 | 0 | } |
168 | ||
169 | /** Remove all of the inviters in the list | |
170 | */ | |
171 | public void removeAll() { | |
172 | 0 | inviters.clear(); |
173 | 0 | this.fireTableDataChanged(); |
174 | 0 | } |
175 | ||
176 | public void playerChanged(Player p) { | |
177 | 0 | Inviter i = getInviter(p.getName()); |
178 | 0 | if (i == null) |
179 | 0 | return; |
180 | 0 | i.p = p; |
181 | 0 | this.fireTableDataChanged(); |
182 | 0 | } |
183 | ||
184 | /** Return the Inviter that matches this playerName | |
185 | * @param playerName The name to match | |
186 | * @return the Inviter or null if not found | |
187 | */ | |
188 | public Inviter getInviter(String playerName) { | |
189 | 0 | for (Inviter p : inviters) { |
190 | 0 | if (p.p.getName().equals(playerName)) |
191 | 0 | return(p); |
192 | 0 | } |
193 | 0 | return(null); |
194 | } | |
195 | ||
196 | /** Add a warning to this inviter. <br> | |
197 | * Right now, we handle "Don't join if you want to resume a saved match with x".<br> | |
198 | * Eventually, we will add MissManners and RepBot warnings. | |
199 | * @param playerName The name of the questionable player | |
200 | * @param warning The warning message to display as a tooltip. | |
201 | */ | |
202 | public void setWarning(String playerName, String warning) { | |
203 | 0 | Inviter inv = getInviter(playerName); |
204 | 0 | if (inv != null) { |
205 | 0 | inv.p.setBfStatus(warning); |
206 | 0 | this.fireTableDataChanged(); |
207 | } | |
208 | 0 | } |
209 | ||
210 | /* (non-Javadoc) | |
211 | * @see javax.swing.table.TableModel#getColumnClass(int) | |
212 | */ | |
213 | public Class<?> getColumnClass(int arg0) { | |
214 | try { | |
215 | 0 | if (arg0 == 0) |
216 | 0 | return(Class.forName("com.buckosoft.fibs.domain.Player")); |
217 | 0 | return Class.forName("java.lang.String"); |
218 | 0 | } catch (ClassNotFoundException e) { |
219 | 0 | System.out.println("Exception ignored..."); |
220 | 0 | e.printStackTrace(); |
221 | } | |
222 | 0 | return(null); |
223 | } | |
224 | ||
225 | /* (non-Javadoc) | |
226 | * @see javax.swing.table.TableModel#getColumnCount() | |
227 | */ | |
228 | public int getColumnCount() { | |
229 | 0 | return _inviterColumns.getColumns().size(); |
230 | } | |
231 | ||
232 | /* (non-Javadoc) | |
233 | * @see javax.swing.table.TableModel#getColumnName(int) | |
234 | */ | |
235 | public String getColumnName(int arg0) { | |
236 | 0 | return _inviterColumns.getColumns().get(arg0).getName(); |
237 | } | |
238 | ||
239 | /* (non-Javadoc) | |
240 | * @see javax.swing.table.TableModel#getRowCount() | |
241 | */ | |
242 | public int getRowCount() { | |
243 | 0 | return this.inviters.size(); |
244 | } | |
245 | ||
246 | /* (non-Javadoc) | |
247 | * @see javax.swing.table.TableModel#getValueAt(int, int) | |
248 | */ | |
249 | public Object getValueAt(int arg0, int arg1) { | |
250 | 0 | Inviter p = inviters.get(arg0); |
251 | 0 | switch (arg1) { |
252 | case 0: | |
253 | 0 | return(p.p); |
254 | ||
255 | case 1: | |
256 | 0 | return(p.matchLength); |
257 | case 2: | |
258 | 0 | return(p.p.getRating()); |
259 | case 3: | |
260 | 0 | return(p.p.getExperience()); |
261 | case 4: | |
262 | 0 | return(p.p.getHostName()); |
263 | } | |
264 | 0 | return null; |
265 | } | |
266 | ||
267 | /** All cells are not editable | |
268 | * @see javax.swing.table.TableModel#isCellEditable(int, int) | |
269 | */ | |
270 | public boolean isCellEditable(int arg0, int arg1) { | |
271 | 0 | return false; |
272 | } | |
273 | ||
274 | ||
275 | /** We don't set no steenky values | |
276 | */ | |
277 | @Override | |
278 | public void setValueAt(Object arg0, int arg1, int arg2) { | |
279 | 0 | } |
280 | ||
281 | } |