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
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
92
93
94
95
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;
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
125 public MatchStatusPanel() {
126 super();
127 initialize();
128 }
129
130
131
132
133 public void setDocument(Document document) {
134 this.document = document;
135 }
136
137
138
139 public void setBoard(Board board) {
140 this.board = board;
141 updateStatus();
142 }
143
144
145
146
147 public void setMainDialog(MainDialog mainDialog) {
148 this.mainDialog = mainDialog;
149 }
150
151
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
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 }