View Javadoc
1   /******************************************************************************
2    * GroupOfPlayers.java - A group of Players
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.8  2011/05/09 17:10:29  dick
10   * Use color as a long, strictly because java doesn't have unsigned int.
11   *
12   * Revision 1.7  2011/05/07 05:49:31  dick
13   * colorStore is a long, not an int.
14   *
15   * Revision 1.6  2011/01/01 20:32:05  dick
16   * Add some debug.
17   *
18   * Revision 1.5  2011/01/01 06:24:59  dick
19   * Javadoc.
20   *
21   * Revision 1.4  2011/01/01 02:30:19  dick
22   * We need to keep the whole list of PlayerGroups.  Hibernate goes bonkers recreating the rows.
23   * So, the master is the playerGroups list and we duplicate that to the players<Integer> list.
24   *
25   * Revision 1.3  2011/01/01 00:17:12  dick
26   * PlayerGroup had to move to a top level domain object so that the hibernate mapping would work.
27   * It doesn't like mapping to subclasses.
28   *
29   * Revision 1.2  2010/12/31 05:35:31  dick
30   * A group of Players.
31   *
32   * Revision 1.1  2010/12/30 17:41:08  dick
33   * Define a Group of Players.
34   *
35   */
36  
37  /* 
38   * This program is free software: you can redistribute it and/or modify
39   * it under the terms of the GNU General Public License as published by
40   * the Free Software Foundation, either version 3 of the License, or
41   * (at your option) any later version.
42   *
43   * This program is distributed in the hope that it will be useful,
44   * but WITHOUT ANY WARRANTY; without even the implied warranty of
45   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46   * GNU General Public License for more details.
47   *
48   * You should have received a copy of the GNU General Public License
49   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
50   *
51   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
52   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
53   * 
54   */
55  package com.buckosoft.fibs.domain;
56  
57  import java.awt.Color;
58  import java.util.LinkedList;
59  import java.util.List;
60  
61  /** A group of Players.
62   * @author Dick Balaska
63   * @since 2010/12/30
64   * @version $Revision$ <br> $Date$
65   * @see PlayerGroup
66   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/GroupOfPlayers.java">cvs GroupOfPlayers.java</a>
67   */
68  public class GroupOfPlayers {
69  	private	final static boolean DEBUG = false;
70  
71  	private	int		id;
72  	private String groupName = "";
73  	private	Color	color = Color.black;
74  	private	List<PlayerGroup> playerGroups = new LinkedList<PlayerGroup>();
75  	private	LinkedList<Integer>	players = new LinkedList<Integer>();
76  	private boolean ignore = false;
77  	private boolean active = false;
78  	private	boolean	dirty = true;
79  
80  	/** Default empty constructor
81  	 */
82  	public GroupOfPlayers() {}
83  
84  	/** Convienence constructor to set some fields
85  	 * @param groupName The name of this new GroupOfPlayers
86  	 * @param color The color to display this group in.
87  	 */
88  	public GroupOfPlayers(String groupName, Color color) {
89  		this.groupName = groupName;
90  		this.color = color;
91  	}
92  
93  	
94  	/** Return the unique id for this GroupOfPlayers
95  	 * @return the id
96  	 */
97  	public int getId() {
98  		return id;
99  	}
100 
101 	/** Set the unique id for this GroupOfPlayers
102 	 * @param id the id to set
103 	 */
104 	public void setId(int id) {
105 		this.id = id;
106 	}
107 
108 	/** Get the name of this group.
109 	 * @return the name
110 	 */
111 	public String getGroupName() {
112 		return groupName;
113 	}
114 	/** Set the name of this group.
115 	 * @param groupName the name to set
116 	 */
117 	public void setGroupName(String groupName) {
118 		this.groupName = groupName;
119 	}
120 	/** Get the color to display group members in.
121 	 * @return the color
122 	 */
123 	public Color getColor() {
124 		return color;
125 	}
126 	/** Set the color to display group members in.
127 	 * @param color the color to set
128 	 */
129 	public void setColor(Color color) {
130 		this.color = color;
131 	}
132 	
133 	/** Get the color in a database friendly format.
134 	 * @return the RGB triple in a long format
135 	 */
136 	public long getColorStore() {
137 		return(this.color.getRGB());
138 	}
139 	
140 	/** Set the color from a database friendly format.
141 	 * @param rgb
142 	 */
143 	public void setColorStore(long rgb) {
144 		this.color = new Color((int)rgb);
145 	}
146 	
147 	/** Get the list of Players in this group.
148 	 * @return the players
149 	 */
150 	public LinkedList<Integer> getPlayers() {
151 		return players;
152 	}
153 
154 	/** Get the PlayserGroup list, the database likes to do this for saving
155 	 * @return A reference to the PlayerGroup list.
156 	 */
157 	public List<PlayerGroup>	getPlayerGroups() {
158 		return(this.playerGroups);
159 	}
160 
161 	/** Set the PlayerGroup list, usually after loading it from the database.
162 	 * Upon setting this, update the handy players list. 
163 	 * @param playerGroups The PlayerGroups for this group
164 	 */
165 	public void setPlayerGroups(List<PlayerGroup> playerGroups) {
166 		this.playerGroups = playerGroups;
167 		this.players.clear();
168 		for (PlayerGroup pg : playerGroups)
169 			this.players.add(pg.getPlayerId());
170 	}
171 
172 	/** Add this player to this group.
173 	 * @param playerId The id of the player to add to this group.
174 	 */
175 	public void addPlayer(int playerId) {
176 		if (DEBUG)
177 			System.out.println("GroupOfPlayers: addPlayer " + playerId);
178 		this.playerGroups.add(new PlayerGroup(id, playerId));
179 		this.players.add(playerId);
180 		this.dirty = true;
181 	}
182 
183 	/** Is this a list of players to ignore?
184 	 * @return the ignore
185 	 */
186 	public boolean isIgnore() {
187 		return ignore;
188 	}
189 
190 	/** Are ignoring this list of players
191 	 * @param ignore the ignore to set
192 	 */
193 	public void setIgnore(boolean ignore) {
194 		this.ignore = ignore;
195 	}
196 
197 	/** Did the user select this Group to be active?
198 	 * @return the active
199 	 */
200 	public boolean isActive() {
201 		return active;
202 	}
203 
204 	/** The user changed this Group's active state.
205 	 * @param active the active to set
206 	 */
207 	public void setActive(boolean active) {
208 		this.active = active;
209 	}
210 
211 	/** Does this Group need to be saved to disk?
212 	 * @return the dirty
213 	 */
214 	public boolean isDirty() {
215 		return dirty;
216 	}
217 
218 	/** Set whether this Group needs to be saved or not.
219 	 * @param dirty the dirty to set
220 	 */
221 	public void setDirty(boolean dirty) {
222 		this.dirty = dirty;
223 	}
224 }