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 | 0 | private Document document = null; |
101 | 0 | private Board board = null; |
102 | |
|
103 | 0 | private JLabel player0Name = null; |
104 | 0 | private JLabel player1Name = null; |
105 | |
|
106 | 0 | private JLabel player0MatchScore = null; |
107 | 0 | private JLabel player1MatchScore = null; |
108 | |
|
109 | 0 | private JLabel player0PipCount = null; |
110 | 0 | private JLabel player1PipCount = null; |
111 | |
|
112 | 0 | private JLabel pipDifference = null; |
113 | |
|
114 | 0 | private JLabel matchLength = null; |
115 | |
|
116 | 0 | private JLabel jLabelBuckoFIBS = null; |
117 | |
|
118 | |
private MainDialog mainDialog; |
119 | |
|
120 | 0 | private JLabel player1Rating = null; |
121 | |
|
122 | 0 | private JLabel player0Rating = null; |
123 | |
|
124 | |
|
125 | |
public MatchStatusPanel() { |
126 | 0 | super(); |
127 | 0 | initialize(); |
128 | 0 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public void setDocument(Document document) { |
134 | 0 | this.document = document; |
135 | 0 | } |
136 | |
|
137 | |
|
138 | |
|
139 | |
public void setBoard(Board board) { |
140 | 0 | this.board = board; |
141 | 0 | updateStatus(); |
142 | 0 | } |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public void setMainDialog(MainDialog mainDialog) { |
148 | 0 | this.mainDialog = mainDialog; |
149 | 0 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
public void updateStatus() { |
154 | 0 | if (board != null) { |
155 | |
|
156 | 0 | String pn0 = board.getPlayerName()[0]; |
157 | 0 | String pn1 = board.getPlayerName()[1]; |
158 | |
try { |
159 | 0 | Player p = mainDialog.getPlayerTableModel().getPlayer(pn1); |
160 | 0 | if (p != null) |
161 | 0 | player1Rating.setText("" + p.getRating()); |
162 | 0 | if (board.isYouPlaying()) |
163 | 0 | p = mainDialog.getPlayerTableModel().getPlayer(document.getName()); |
164 | |
else |
165 | 0 | p = mainDialog.getPlayerTableModel().getPlayer(pn0); |
166 | 0 | if (p != null) |
167 | 0 | player0Rating.setText("" + p.getRating()); |
168 | |
|
169 | 0 | } catch (Exception e) { |
170 | 0 | e.printStackTrace(); |
171 | 0 | } |
172 | 0 | player0Name.setText(pn0); |
173 | 0 | player1Name.setText(pn1); |
174 | 0 | this.matchLength.setText("ML: " + board.getMatchLength()); |
175 | 0 | this.player0MatchScore.setText("" + board.getMatchScore()[0]); |
176 | 0 | this.player1MatchScore.setText("" + board.getMatchScore()[1]); |
177 | 0 | Color player0Color = Color.white; |
178 | 0 | Color player1Color = Color.white; |
179 | 0 | if (board.getWhosTurn()*board.getXO() == 1) |
180 | 0 | player0Color = Color.yellow; |
181 | 0 | else if (board.getWhosTurn()*board.getXO() == -1) |
182 | 0 | player1Color = Color.yellow; |
183 | 0 | player0Name.setForeground(player0Color); |
184 | 0 | player0Rating.setForeground(player0Color); |
185 | 0 | player1Name.setForeground(player1Color); |
186 | 0 | player1Rating.setForeground(player1Color); |
187 | |
|
188 | 0 | int pp[] = board.getPipCount(); |
189 | 0 | this.player0PipCount.setText("" + pp[0]); |
190 | 0 | this.player1PipCount.setText("" + pp[1]); |
191 | 0 | int diff = pp[1] - pp[0]; |
192 | 0 | Color c = Color.yellow; |
193 | 0 | if (diff > 0) |
194 | 0 | c = Color.green; |
195 | 0 | if (diff < 0) |
196 | 0 | c = Color.red; |
197 | 0 | this.pipDifference.setText("" + diff); |
198 | 0 | this.pipDifference.setForeground(c); |
199 | |
} |
200 | 0 | } |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
private void initialize() { |
207 | 0 | GridBagConstraints gridBagConstraints41 = new GridBagConstraints(); |
208 | 0 | gridBagConstraints41.gridx = 1; |
209 | 0 | gridBagConstraints41.anchor = GridBagConstraints.WEST; |
210 | 0 | gridBagConstraints41.weightx = 0.3; |
211 | 0 | gridBagConstraints41.gridy = 1; |
212 | 0 | player0Rating = new JLabel(); |
213 | 0 | player0Rating.setText("????.??"); |
214 | 0 | player0Rating.setFont(new Font("Dialog", Font.BOLD, 10)); |
215 | 0 | player0Rating.setHorizontalTextPosition(SwingConstants.LEFT); |
216 | 0 | player0Rating.setForeground(Color.white); |
217 | 0 | GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); |
218 | 0 | gridBagConstraints31.gridx = 1; |
219 | 0 | gridBagConstraints31.anchor = GridBagConstraints.WEST; |
220 | 0 | gridBagConstraints31.weightx = 0.3; |
221 | 0 | gridBagConstraints31.gridy = 0; |
222 | 0 | player1Rating = new JLabel(); |
223 | 0 | player1Rating.setText("????.??"); |
224 | 0 | player1Rating.setFont(new Font("Dialog", Font.BOLD, 10)); |
225 | 0 | player1Rating.setForeground(Color.white); |
226 | 0 | player1Rating.setHorizontalTextPosition(SwingConstants.LEFT); |
227 | 0 | GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
228 | 0 | gridBagConstraints8.gridx = 6; |
229 | 0 | gridBagConstraints8.gridy = 1; |
230 | 0 | jLabelBuckoFIBS = new JLabel(); |
231 | 0 | jLabelBuckoFIBS.setText("BuckoFIBS"); |
232 | 0 | jLabelBuckoFIBS.setFont(new Font("Dialog", Font.ITALIC, 10)); |
233 | 0 | jLabelBuckoFIBS.setForeground(Color.green); |
234 | 0 | GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
235 | 0 | gridBagConstraints7.gridx = 6; |
236 | 0 | gridBagConstraints7.anchor = GridBagConstraints.EAST; |
237 | 0 | gridBagConstraints7.gridy = 0; |
238 | 0 | matchLength = new JLabel(); |
239 | 0 | matchLength.setText("ML: 0"); |
240 | 0 | matchLength.setForeground(Color.white); |
241 | 0 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
242 | 0 | gridBagConstraints6.gridx = 5; |
243 | 0 | gridBagConstraints6.gridheight = 2; |
244 | 0 | gridBagConstraints6.weightx = 4.0; |
245 | 0 | gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL; |
246 | 0 | gridBagConstraints6.anchor = GridBagConstraints.WEST; |
247 | 0 | gridBagConstraints6.insets = new Insets(0, 10, 0, 0); |
248 | 0 | gridBagConstraints6.gridy = 0; |
249 | 0 | pipDifference = new JLabel(); |
250 | 0 | pipDifference.setText("0"); |
251 | 0 | pipDifference.setForeground(Color.yellow); |
252 | 0 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
253 | 0 | gridBagConstraints5.gridx = 4; |
254 | 0 | gridBagConstraints5.anchor = GridBagConstraints.EAST; |
255 | 0 | gridBagConstraints5.weightx = 1.0; |
256 | 0 | gridBagConstraints5.gridy = 0; |
257 | 0 | player1PipCount = new JLabel(); |
258 | 0 | player1PipCount.setText("0"); |
259 | 0 | player1PipCount.setForeground(Color.white); |
260 | 0 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
261 | 0 | gridBagConstraints4.gridx = 4; |
262 | 0 | gridBagConstraints4.weightx = 1.0; |
263 | 0 | gridBagConstraints4.anchor = GridBagConstraints.EAST; |
264 | 0 | gridBagConstraints4.gridy = 1; |
265 | 0 | player0PipCount = new JLabel(); |
266 | 0 | player0PipCount.setText("0"); |
267 | 0 | player0PipCount.setForeground(Color.white); |
268 | 0 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
269 | 0 | gridBagConstraints3.gridx = 2; |
270 | 0 | gridBagConstraints3.weightx = 1.0; |
271 | 0 | gridBagConstraints3.anchor = GridBagConstraints.WEST; |
272 | 0 | gridBagConstraints3.gridy = 0; |
273 | 0 | player1MatchScore = new JLabel(); |
274 | 0 | player1MatchScore.setText("0"); |
275 | 0 | player1MatchScore.setForeground(Color.white); |
276 | 0 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
277 | 0 | gridBagConstraints2.gridx = 2; |
278 | 0 | gridBagConstraints2.weightx = 1.0; |
279 | 0 | gridBagConstraints2.anchor = GridBagConstraints.WEST; |
280 | 0 | gridBagConstraints2.insets = new Insets(0, 0, 0, 0); |
281 | 0 | gridBagConstraints2.gridy = 1; |
282 | 0 | player0MatchScore = new JLabel(); |
283 | 0 | player0MatchScore.setText("0"); |
284 | 0 | player0MatchScore.setForeground(Color.white); |
285 | 0 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
286 | 0 | gridBagConstraints1.insets = new Insets(1, 1, 1, 1); |
287 | 0 | gridBagConstraints1.gridy = 1; |
288 | 0 | gridBagConstraints1.anchor = GridBagConstraints.WEST; |
289 | 0 | gridBagConstraints1.weightx = 0.2; |
290 | 0 | gridBagConstraints1.gridx = 0; |
291 | 0 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
292 | 0 | gridBagConstraints.insets = new Insets(1, 1, 1, 1); |
293 | 0 | gridBagConstraints.gridy = 0; |
294 | 0 | gridBagConstraints.anchor = GridBagConstraints.WEST; |
295 | 0 | gridBagConstraints.fill = GridBagConstraints.NONE; |
296 | 0 | gridBagConstraints.weightx = 0.2; |
297 | 0 | gridBagConstraints.weighty = 0.9; |
298 | 0 | gridBagConstraints.gridx = 0; |
299 | 0 | this.setLayout(new GridBagLayout()); |
300 | 0 | this.setBackground(Color.darkGray); |
301 | 0 | this.setSize(new Dimension(450, 32)); |
302 | 0 | this.setPreferredSize(new Dimension(450, 36)); |
303 | 0 | this.setForeground(Color.white); |
304 | 0 | player1Name = new JLabel(); |
305 | 0 | player1Name.setText("Player1"); |
306 | 0 | player1Name.setForeground(Color.white); |
307 | 0 | player0Name = new JLabel(); |
308 | 0 | player0Name.setText("Player0"); |
309 | 0 | player0Name.setForeground(Color.white); |
310 | 0 | this.add(player0Name, gridBagConstraints1); |
311 | 0 | this.add(player1Name, gridBagConstraints); |
312 | 0 | this.add(player0MatchScore, gridBagConstraints2); |
313 | 0 | this.add(player1MatchScore, gridBagConstraints3); |
314 | 0 | this.add(player0PipCount, gridBagConstraints4); |
315 | 0 | this.add(player1PipCount, gridBagConstraints5); |
316 | 0 | this.add(pipDifference, gridBagConstraints6); |
317 | 0 | this.add(matchLength, gridBagConstraints7); |
318 | 0 | this.add(jLabelBuckoFIBS, gridBagConstraints8); |
319 | 0 | this.add(player1Rating, gridBagConstraints31); |
320 | 0 | this.add(player0Rating, gridBagConstraints41); |
321 | 0 | } |
322 | |
} |