View Javadoc
1   /******************************************************************************
2    * MatchStatusPanel.java - Draw the Match statistics at the top of the board.
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.2  2011/05/31 19:45:15  dick
10   * Javadoc.
11   *
12   * Revision 1.1  2011/05/15 02:17:33  dick
13   * c.b.f.B.gui.board becomes c.b.f.B.gui.boardTab.
14   *
15   * Revision 1.6  2011/05/14 04:43:01  dick
16   * I needed to deal with some lightweight Boards.
17   * So finally make the primary document Document
18   * and demote just the Board handling to a domain object.
19   *
20   * Revision 1.5  2011/05/12 20:27:40  dick
21   * Scratch a to do block
22   *
23   * Revision 1.4  2010/12/22 04:36:08  dick
24   * Display the player's rating next to his name.
25   *
26   * Revision 1.3  2010/03/03 13:12:21  inim
27   * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
28   *
29   * Revision 1.2  2010/03/03 12:19:49  inim
30   * 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.
31   *
32   * Revision 1.1  2010/02/04 05:57:53  inim
33   * Mavenized project folder layout
34   *
35   * Revision 1.3  2009/02/14 15:27:42  dick
36   * BuckoFIBS is released under the GNU license.
37   *
38   * Revision 1.2  2009/01/29 08:27:22  dick
39   * Draw the correct player in yellow.
40   *
41   * Revision 1.1  2009/01/28 19:37:28  dick
42   * package com.buckosoft.fibs.gui.board becomes com.buckosoft.fibs.BuckoFIBS.gui.board.
43   *
44   * Revision 1.3  2009/01/10 05:07:29  dick
45   * Put the correct data in the correct place.
46   * Add pipCount handling.
47   *
48   * Revision 1.2  2009/01/08 18:33:29  dick
49   * Fleshing out functionality.
50   *
51   * Revision 1.1  2009/01/08 01:33:35  dick
52   * Draw the Match statistics at the top of the board.
53   */
54  
55  /* 
56   * This program is free software: you can redistribute it and/or modify
57   * it under the terms of the GNU General Public License as published by
58   * the Free Software Foundation, either version 3 of the License, or
59   * (at your option) any later version.
60   *
61   * This program is distributed in the hope that it will be useful,
62   * but WITHOUT ANY WARRANTY; without even the implied warranty of
63   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
64   * GNU General Public License for more details.
65   *
66   * You should have received a copy of the GNU General Public License
67   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
68   *
69   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
70   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
71   * 
72   */
73  package com.buckosoft.fibs.BuckoFIBS.gui.boardTab;
74  
75  import java.awt.Color;
76  import java.awt.Dimension;
77  import java.awt.Font;
78  import java.awt.GridBagConstraints;
79  import java.awt.GridBagLayout;
80  import java.awt.Insets;
81  
82  import javax.swing.JLabel;
83  import javax.swing.JPanel;
84  import javax.swing.SwingConstants;
85  
86  import com.buckosoft.fibs.BuckoFIBS.gui.MainDialog;
87  import com.buckosoft.fibs.document.Document;
88  import com.buckosoft.fibs.domain.Board;
89  import com.buckosoft.fibs.domain.Player;
90  
91  /** Draw the Match statistics at the top of the board.
92   * @author Dick Balaska
93   * @since 2009/01/06
94   * @version $Revision$ <br> $Date$
95   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/board/MatchStatusPanel.java">cvs MatchStatusPanel.java</a>
96   */
97  public class MatchStatusPanel extends JPanel {
98  	private static final long serialVersionUID = 1L;
99  
100 	private	Document	document = null;
101 	private	Board	board = null;  //  @jve:decl-index=0:
102 
103 	private JLabel player0Name = null;
104 	private JLabel player1Name = null;
105 
106 	private JLabel player0MatchScore = null;
107 	private JLabel player1MatchScore = null;
108 
109 	private JLabel player0PipCount = null;
110 	private JLabel player1PipCount = null;
111 
112 	private JLabel pipDifference = null;
113 
114 	private JLabel matchLength = null;
115 
116 	private JLabel jLabelBuckoFIBS = null;
117 
118 	private	MainDialog	mainDialog;
119 
120 	private JLabel player1Rating = null;
121 
122 	private JLabel player0Rating = null;
123 
124 	/** Crate and initialize a MatchStatusPanel	 */
125 	public MatchStatusPanel() {
126 		super();
127 		initialize();
128 	}
129 
130 	/** Set the reference to the document
131 	 * @param document The BuckoFIBS document
132 	 */
133 	public void setDocument(Document document) {
134 		this.document = document;
135 	}
136 	/** Set the reference to our Board
137 	 * @param board Reference to the board to display info about
138 	 */
139 	public void setBoard(Board board) {
140 		this.board = board;
141 		updateStatus();
142 	}
143 
144 	/** Set the reference to the MainDialog
145 	 * @param mainDialog The MainDialog
146 	 */
147 	public void setMainDialog(MainDialog mainDialog) {
148 		this.mainDialog = mainDialog;
149 	}
150 
151 	/** Update the widgets based on changes to the board
152 	 */
153 	public void updateStatus() {
154 		if (board != null) {
155 
156 			String pn0 = board.getPlayerName()[0];
157 			String pn1 = board.getPlayerName()[1];
158 			try {
159 				Player p = mainDialog.getPlayerTableModel().getPlayer(pn1);
160 				if (p != null)
161 					player1Rating.setText("" + p.getRating());
162 				if (board.isYouPlaying())
163 					p = mainDialog.getPlayerTableModel().getPlayer(document.getName());
164 				else
165 					p = mainDialog.getPlayerTableModel().getPlayer(pn0);
166 				if (p != null)
167 					player0Rating.setText("" + p.getRating());
168 				
169 			} catch (Exception e) {
170 				e.printStackTrace();
171 			}
172 			player0Name.setText(pn0);
173 			player1Name.setText(pn1);
174 			this.matchLength.setText("ML: " + board.getMatchLength());
175 			this.player0MatchScore.setText("" + board.getMatchScore()[0]);
176 			this.player1MatchScore.setText("" + board.getMatchScore()[1]);
177 			Color player0Color = Color.white;
178 			Color player1Color = Color.white;
179 			if (board.getWhosTurn()*board.getXO() == 1)
180 				player0Color = Color.yellow;
181 			else if (board.getWhosTurn()*board.getXO() == -1)
182 				player1Color = Color.yellow;
183 			player0Name.setForeground(player0Color);
184 			player0Rating.setForeground(player0Color);
185 			player1Name.setForeground(player1Color);
186 			player1Rating.setForeground(player1Color);
187 			
188 			int pp[] = board.getPipCount();
189 			this.player0PipCount.setText("" + pp[0]);
190 			this.player1PipCount.setText("" + pp[1]);
191 			int diff = pp[1] - pp[0];
192 			Color c = Color.yellow;
193 			if (diff > 0)
194 				c = Color.green;
195 			if (diff < 0)
196 				c = Color.red;
197 			this.pipDifference.setText("" + diff);
198 			this.pipDifference.setForeground(c);
199 		}
200 	}
201 
202 	/**
203 	 * This method initializes this
204 	 * 
205 	 */
206 	private void initialize() {
207         GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
208         gridBagConstraints41.gridx = 1;
209         gridBagConstraints41.anchor = GridBagConstraints.WEST;
210         gridBagConstraints41.weightx = 0.3;
211         gridBagConstraints41.gridy = 1;
212         player0Rating = new JLabel();
213         player0Rating.setText("????.??");
214         player0Rating.setFont(new Font("Dialog", Font.BOLD, 10));
215         player0Rating.setHorizontalTextPosition(SwingConstants.LEFT);
216         player0Rating.setForeground(Color.white);
217         GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
218         gridBagConstraints31.gridx = 1;
219         gridBagConstraints31.anchor = GridBagConstraints.WEST;
220         gridBagConstraints31.weightx = 0.3;
221         gridBagConstraints31.gridy = 0;
222         player1Rating = new JLabel();
223         player1Rating.setText("????.??");
224         player1Rating.setFont(new Font("Dialog", Font.BOLD, 10));
225         player1Rating.setForeground(Color.white);
226         player1Rating.setHorizontalTextPosition(SwingConstants.LEFT);
227         GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
228         gridBagConstraints8.gridx = 6;
229         gridBagConstraints8.gridy = 1;
230         jLabelBuckoFIBS = new JLabel();
231         jLabelBuckoFIBS.setText("BuckoFIBS");
232         jLabelBuckoFIBS.setFont(new Font("Dialog", Font.ITALIC, 10));
233         jLabelBuckoFIBS.setForeground(Color.green);
234         GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
235         gridBagConstraints7.gridx = 6;
236         gridBagConstraints7.anchor = GridBagConstraints.EAST;
237         gridBagConstraints7.gridy = 0;
238         matchLength = new JLabel();
239         matchLength.setText("ML: 0");
240         matchLength.setForeground(Color.white);
241         GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
242         gridBagConstraints6.gridx = 5;
243         gridBagConstraints6.gridheight = 2;
244         gridBagConstraints6.weightx = 4.0;
245         gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL;
246         gridBagConstraints6.anchor = GridBagConstraints.WEST;
247         gridBagConstraints6.insets = new Insets(0, 10, 0, 0);
248         gridBagConstraints6.gridy = 0;
249         pipDifference = new JLabel();
250         pipDifference.setText("0");
251         pipDifference.setForeground(Color.yellow);
252         GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
253         gridBagConstraints5.gridx = 4;
254         gridBagConstraints5.anchor = GridBagConstraints.EAST;
255         gridBagConstraints5.weightx = 1.0;
256         gridBagConstraints5.gridy = 0;
257         player1PipCount = new JLabel();
258         player1PipCount.setText("0");
259         player1PipCount.setForeground(Color.white);
260         GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
261         gridBagConstraints4.gridx = 4;
262         gridBagConstraints4.weightx = 1.0;
263         gridBagConstraints4.anchor = GridBagConstraints.EAST;
264         gridBagConstraints4.gridy = 1;
265         player0PipCount = new JLabel();
266         player0PipCount.setText("0");
267         player0PipCount.setForeground(Color.white);
268         GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
269         gridBagConstraints3.gridx = 2;
270         gridBagConstraints3.weightx = 1.0;
271         gridBagConstraints3.anchor = GridBagConstraints.WEST;
272         gridBagConstraints3.gridy = 0;
273         player1MatchScore = new JLabel();
274         player1MatchScore.setText("0");
275         player1MatchScore.setForeground(Color.white);
276         GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
277         gridBagConstraints2.gridx = 2;
278         gridBagConstraints2.weightx = 1.0;
279         gridBagConstraints2.anchor = GridBagConstraints.WEST;
280         gridBagConstraints2.insets = new Insets(0, 0, 0, 0);
281         gridBagConstraints2.gridy = 1;
282         player0MatchScore = new JLabel();
283         player0MatchScore.setText("0");
284         player0MatchScore.setForeground(Color.white);
285         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
286         gridBagConstraints1.insets = new Insets(1, 1, 1, 1);
287         gridBagConstraints1.gridy = 1;
288         gridBagConstraints1.anchor = GridBagConstraints.WEST;
289         gridBagConstraints1.weightx = 0.2;
290         gridBagConstraints1.gridx = 0;
291         GridBagConstraints gridBagConstraints = new GridBagConstraints();
292         gridBagConstraints.insets = new Insets(1, 1, 1, 1);
293         gridBagConstraints.gridy = 0;
294         gridBagConstraints.anchor = GridBagConstraints.WEST;
295         gridBagConstraints.fill = GridBagConstraints.NONE;
296         gridBagConstraints.weightx = 0.2;
297         gridBagConstraints.weighty = 0.9;
298         gridBagConstraints.gridx = 0;
299         this.setLayout(new GridBagLayout());
300         this.setBackground(Color.darkGray);
301         this.setSize(new Dimension(450, 32));
302         this.setPreferredSize(new Dimension(450, 36));
303         this.setForeground(Color.white);
304         player1Name = new JLabel();
305         player1Name.setText("Player1");
306         player1Name.setForeground(Color.white);
307         player0Name = new JLabel();
308         player0Name.setText("Player0");
309         player0Name.setForeground(Color.white);
310         this.add(player0Name, gridBagConstraints1);
311         this.add(player1Name, gridBagConstraints);
312         this.add(player0MatchScore, gridBagConstraints2);
313         this.add(player1MatchScore, gridBagConstraints3);
314         this.add(player0PipCount, gridBagConstraints4);
315         this.add(player1PipCount, gridBagConstraints5);
316         this.add(pipDifference, gridBagConstraints6);
317         this.add(matchLength, gridBagConstraints7);
318         this.add(jLabelBuckoFIBS, gridBagConstraints8);
319         this.add(player1Rating, gridBagConstraints31);
320         this.add(player0Rating, gridBagConstraints41);
321 	}
322 }  //  @jve:decl-index=0:visual-constraint="10,10"