Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MainDialog |
|
| 1.5918367346938775;1.592 | ||||
MainDialog$1 |
|
| 1.5918367346938775;1.592 |
1 | /****************************************************************************** | |
2 | * MainDialog.java - Load and manage all of the gui components in BuckoFIBS | |
3 | * $Id$ | |
4 | * | |
5 | * BuckoFIBS - Backgammon by BuckoSoft | |
6 | * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp. | |
7 | * | |
8 | * $Log$ | |
9 | * Revision 1.16 2011/06/13 04:41:00 dick | |
10 | * Use Version in a static manner. | |
11 | * Only write to gameMessagesTextPane if it exists. | |
12 | * | |
13 | * Revision 1.15 2011/06/10 20:36:48 dick | |
14 | * yourMove() is not public anymore as it only comes from the AnimateManager. | |
15 | * | |
16 | * Revision 1.14 2011/06/05 06:52:36 dick | |
17 | * playerListPane becomes playerListTab. | |
18 | * | |
19 | * Revision 1.13 2011/05/23 05:56:56 dick | |
20 | * playSound is an override. boardgui.moveEvent() became displayGameEvent(). | |
21 | * | |
22 | * Revision 1.12 2011/05/21 05:00:34 dick | |
23 | * gameManager.reset() takes a resume/new match parameter. (although that change is aborting...) | |
24 | * | |
25 | * Revision 1.11 2011/05/15 02:19:52 dick | |
26 | * Move the GameEvent objects to c.b.f.domain.gameEvent. | |
27 | * | |
28 | * Revision 1.10 2011/05/14 04:43:01 dick | |
29 | * I needed to deal with some lightweight Boards. | |
30 | * So finally make the primary document Document | |
31 | * and demote just the Board handling to a domain object. | |
32 | * | |
33 | * Revision 1.9 2011/05/13 18:24:35 dick | |
34 | * Set the properties to the GameManager. | |
35 | * | |
36 | * Revision 1.8 2011/05/13 14:29:35 dick | |
37 | * Extract some functions to a MainDialog API. | |
38 | * | |
39 | * Revision 1.7 2011/05/11 22:22:22 dick | |
40 | * Extract MainDialog's api to an Interface. | |
41 | * | |
42 | * Revision 1.6 2011/01/04 17:38:38 dick | |
43 | * Disable the game gui if we are just watching. | |
44 | * | |
45 | * Revision 1.5 2010/12/31 05:29:46 dick | |
46 | * Add the GroupManager. | |
47 | * | |
48 | * Revision 1.4 2010/09/05 04:08:09 dick | |
49 | * Version has to be a instantiated class. | |
50 | * | |
51 | * Revision 1.3 2010/03/03 13:12:21 inim | |
52 | * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8 | |
53 | * | |
54 | * Revision 1.2 2010/03/03 12:19:49 inim | |
55 | * 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. | |
56 | * | |
57 | * Revision 1.1 2010/02/04 05:57:53 inim | |
58 | * Mavenized project folder layout | |
59 | * | |
60 | * Revision 1.45 2010/01/29 23:12:44 dick | |
61 | * The default is the Systems tab. | |
62 | * Set the graph config. | |
63 | * getToolbar() is public. | |
64 | * | |
65 | * Revision 1.44 2010/01/27 02:10:12 dick | |
66 | * set the ratingGraphConfig to the graph. | |
67 | * | |
68 | * Revision 1.43 2010/01/25 21:06:15 dick | |
69 | * getChatPane is public so that the parser can manipulate it. | |
70 | * | |
71 | * Revision 1.42 2009/03/04 19:05:54 dick | |
72 | * Add the PlayerReportPane. | |
73 | * | |
74 | * Revision 1.41 2009/02/24 05:50:55 dick | |
75 | * Handle state changes to the ROP flags. | |
76 | * | |
77 | * Revision 1.40 2009/02/21 17:59:20 dick | |
78 | * Add the RatingGraphPanel. | |
79 | * | |
80 | * Revision 1.39 2009/02/20 10:25:36 dick | |
81 | * Create the database. | |
82 | * | |
83 | * Revision 1.38 2009/02/14 12:21:17 dick | |
84 | * Display the version in the startup message. | |
85 | * | |
86 | * Revision 1.37 2009/02/12 06:26:18 dick | |
87 | * Only make noise if playCues property is set. | |
88 | * | |
89 | * Revision 1.36 2009/02/11 09:02:35 dick | |
90 | * Gracefully continue if the AudioManager fails to initialize. | |
91 | * Write "move bar-24" in color to the game window. | |
92 | * | |
93 | * Revision 1.35 2009/02/09 22:45:40 dick | |
94 | * shutdown() cancels pending timers. | |
95 | * Handle resign (both ways). | |
96 | * | |
97 | * Revision 1.34 2009/02/06 07:56:48 dick | |
98 | * Working on doubles. | |
99 | * | |
100 | * Revision 1.33 2009/02/03 09:46:22 dick | |
101 | * MainDialog controls the ClientReceiveParser now. | |
102 | * | |
103 | * Revision 1.32 2009/02/01 21:25:08 dick | |
104 | * redrawOwnInfo() includes drawing our ready state. | |
105 | * | |
106 | * Revision 1.31 2009/01/31 08:48:48 dick | |
107 | * GameManager needs a reference to MainDialog. | |
108 | * | |
109 | * Revision 1.30 2009/01/28 22:32:35 dick | |
110 | * Setup the GameManager and the ReplayToolbar. | |
111 | * | |
112 | * Revision 1.29 2009/01/28 19:40:14 dick | |
113 | * package com.buckosoft.fibs.gui.* becomes com.buckosoft.fibs.BuckoFIBS.gui.*. | |
114 | * | |
115 | * Revision 1.28 2009/01/22 05:03:27 dick | |
116 | * yourMove() doesn't need an argument. | |
117 | * | |
118 | * Revision 1.27 2009/01/18 04:54:33 dick | |
119 | * The constructor now needs the CommandDispatcher sent to it. | |
120 | * Add yourMove(b) which turns on and off the player moving his checkers. | |
121 | * | |
122 | * Revision 1.26 2009/01/16 07:27:34 dick | |
123 | * ChatPane needs the CommandDispatcher now. | |
124 | * | |
125 | * Revision 1.25 2009/01/13 18:27:39 dick | |
126 | * Handle Ready To Play | |
127 | * | |
128 | * Revision 1.24 2009/01/10 05:05:14 dick | |
129 | * Handle onMatchOver. | |
130 | * Wrap scrolling with a try block. Sometimes scrolling throws a wacky exception. Why? | |
131 | * | |
132 | * Revision 1.23 2009/01/09 06:58:56 dick | |
133 | * GameMessages panel. | |
134 | * | |
135 | * Revision 1.22 2009/01/08 18:32:29 dick | |
136 | * Move all of the Board drawing/handling to BoardTab. | |
137 | * | |
138 | * Revision 1.21 2009/01/08 01:34:34 dick | |
139 | * BoardPane gets subsumed under BoardPanel so that we can also have a MatchStatusPanel. | |
140 | * | |
141 | * Revision 1.20 2008/12/20 23:03:27 dick | |
142 | * Add redrawOwnInfo. | |
143 | * | |
144 | * Revision 1.19 2008/12/15 01:50:11 dick | |
145 | * getPlayerListPane is public. | |
146 | * | |
147 | * Revision 1.18 2008/12/13 06:22:49 dick | |
148 | * Pass along the setConnected() event to the toolbar. | |
149 | * | |
150 | * Revision 1.17 2008/12/12 23:24:08 dick | |
151 | * If writeSystemMessage is an error message, then make the system tab visible. | |
152 | * | |
153 | * Revision 1.16 2008/12/11 20:28:53 dick | |
154 | * Make the board visible on StartNewGame. | |
155 | * | |
156 | * Revision 1.15 2008/12/11 08:48:48 dick | |
157 | * Handle autoConnect. | |
158 | * Add inbound chat handling. | |
159 | * | |
160 | * Revision 1.14 2008/12/10 18:05:53 dick | |
161 | * Add systemMessagesScrollToBottom() | |
162 | * | |
163 | * Revision 1.13 2008/12/09 19:38:13 dick | |
164 | * Add setInvitedTabVisible() which displays the invitations when a new one comes in. | |
165 | * | |
166 | * Revision 1.12 2008/12/09 01:52:02 dick | |
167 | * Add the InviterListPane. | |
168 | * | |
169 | * Revision 1.11 2008/12/08 10:16:48 dick | |
170 | * Initialize the board to the start positions. | |
171 | * | |
172 | * Revision 1.10 2008/12/08 06:45:02 dick | |
173 | * Create a Board and attach it to the BoardPane. | |
174 | * | |
175 | * Revision 1.9 2008/12/07 22:51:40 dick | |
176 | * Javadoc. | |
177 | * | |
178 | * Revision 1.8 2008/10/08 23:10:03 dick | |
179 | * Declare and use the chatPane. | |
180 | * | |
181 | * Revision 1.7 2008/04/09 20:57:38 dick | |
182 | * playerListPane needs the commandDispatcher. | |
183 | * | |
184 | * Revision 1.6 2008/04/05 01:43:06 dick | |
185 | * Add the game board to the top left panel. | |
186 | * | |
187 | * Revision 1.5 2008/04/02 23:24:43 dick | |
188 | * Move playerList to it's own package. | |
189 | * | |
190 | * Revision 1.4 2008/04/01 03:46:40 dick | |
191 | * Get rid of the builtin PlayerListPane and use the external one. | |
192 | * | |
193 | * Revision 1.3 2008/03/31 07:10:35 dick | |
194 | * Expose the playerTableModel. | |
195 | * | |
196 | * Revision 1.2 2008/03/30 05:42:58 dick | |
197 | * More skeleton work. MainDialog is fleshing out... | |
198 | * | |
199 | * Revision 1.1 2008/03/29 08:57:43 dick | |
200 | * BuckoFIBS skeleton checkin. | |
201 | */ | |
202 | ||
203 | /* | |
204 | * This program is free software: you can redistribute it and/or modify | |
205 | * it under the terms of the GNU General Public License as published by | |
206 | * the Free Software Foundation, either version 3 of the License, or | |
207 | * (at your option) any later version. | |
208 | * | |
209 | * This program is distributed in the hope that it will be useful, | |
210 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
211 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
212 | * GNU General Public License for more details. | |
213 | * | |
214 | * You should have received a copy of the GNU General Public License | |
215 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
216 | * | |
217 | * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>. | |
218 | * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp. | |
219 | * | |
220 | */ | |
221 | package com.buckosoft.fibs.BuckoFIBS.gui; | |
222 | ||
223 | import java.awt.BorderLayout; | |
224 | import java.awt.Dimension; | |
225 | import java.awt.Rectangle; | |
226 | ||
227 | import javax.swing.JFrame; | |
228 | import javax.swing.JPanel; | |
229 | import javax.swing.JScrollPane; | |
230 | import javax.swing.JSplitPane; | |
231 | import javax.swing.JTabbedPane; | |
232 | ||
233 | import com.buckosoft.fibs.BuckoFIBS.AudioManager; | |
234 | import com.buckosoft.fibs.BuckoFIBS.BFProperties; | |
235 | import com.buckosoft.fibs.BuckoFIBS.ClientReceiveParser; | |
236 | import com.buckosoft.fibs.BuckoFIBS.CommandDispatcher; | |
237 | import com.buckosoft.fibs.BuckoFIBS.GameManager; | |
238 | import com.buckosoft.fibs.BuckoFIBS.GroupManager; | |
239 | import com.buckosoft.fibs.BuckoFIBS.Version; | |
240 | import com.buckosoft.fibs.BuckoFIBS.db.Database; | |
241 | import com.buckosoft.fibs.BuckoFIBS.db.DatabaseImpl; | |
242 | import com.buckosoft.fibs.BuckoFIBS.gui.boardTab.BoardTab; | |
243 | import com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ReplayToolbar; | |
244 | import com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ResignOut; | |
245 | import com.buckosoft.fibs.BuckoFIBS.gui.chatWindow.ChatPane; | |
246 | import com.buckosoft.fibs.BuckoFIBS.gui.inviterList.InviterListPane; | |
247 | import com.buckosoft.fibs.BuckoFIBS.gui.inviterList.InviterTableModel; | |
248 | import com.buckosoft.fibs.BuckoFIBS.gui.playerList.PlayerListPane; | |
249 | import com.buckosoft.fibs.BuckoFIBS.gui.playerList.PlayerTableModel; | |
250 | import com.buckosoft.fibs.document.Document; | |
251 | import com.buckosoft.fibs.domain.Board; | |
252 | import com.buckosoft.fibs.domain.gameEvent.GameEvent; | |
253 | ||
254 | /** Manage all of the gui components in BuckoFIBS | |
255 | * @author Dick Balaska | |
256 | * @since 2008/03/29 | |
257 | * @version $Revision$ <br> $Date$ | |
258 | * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/MainDialog.java">cvs MainDialog.java</a> | |
259 | */ | |
260 | 0 | public class MainDialog extends JFrame implements MainDialogI { |
261 | private final static boolean DEBUG = false; | |
262 | private static final long serialVersionUID = 1L; | |
263 | 0 | private JPanel jContentPane = null; |
264 | 0 | private ToolBar toolbar = null; |
265 | ||
266 | 0 | private JSplitPane topBottomSplitPane = null; |
267 | 0 | private JSplitPane topLeftRightSplitPane = null; |
268 | 0 | private JSplitPane bottomLeftRightSplitPane = null; |
269 | 0 | private JTabbedPane topLeftTabbedPane = null; |
270 | 0 | private PlayerListPane playerListPane = null; |
271 | ||
272 | 0 | private JTabbedPane topRightTabbedPane = null; |
273 | 0 | private SystemMessagesTextPane systemMessagesTextPane = null; |
274 | 0 | private JScrollPane systemMessagesScrollPane = null; |
275 | 0 | private Dimension systemMessagesDimension = null; // @jve:decl-index=0: |
276 | 0 | private Rectangle systemMessagesRectangle = null; // @jve:decl-index=0: |
277 | ||
278 | 0 | private SystemMessagesTextPane gameMessagesTextPane = null; |
279 | 0 | private JScrollPane gameMessagesScrollPane = null; |
280 | 0 | private Dimension gameMessagesDimension = null; // @jve:decl-index=0: |
281 | 0 | private Rectangle gameMessagesRectangle = null; // @jve:decl-index=0: |
282 | ||
283 | 0 | private InviterListPane inviterListPane = null; |
284 | 0 | private JScrollPane inviterListScrollPane = null; |
285 | 0 | private PlayerReportPane playerReportPane = null; |
286 | ||
287 | 0 | private ChatPane bottomRightChatPane = null; // @jve:decl-index=0: |
288 | 0 | private BoardTab boardTab = null; // @jve:decl-index=0:visual-constraint="16,1526" |
289 | ||
290 | 0 | private BFProperties properties = null; |
291 | 0 | private CommandDispatcher commandDispatcher = null; |
292 | private ClientReceiveParser clientReceiveParser; | |
293 | private GameManager gameManager; | |
294 | private GroupManager groupManager; | |
295 | private AudioManager audioManager; | |
296 | ||
297 | 0 | private Document document = new Document(); |
298 | private Board board; | |
299 | 0 | private final String titleName = "BuckoFIBS"; |
300 | private final static String eol = "\r\n"; | |
301 | ||
302 | 0 | private Database database = new DatabaseImpl(); |
303 | ||
304 | ///////////////////////////////////////////////////////////////////// | |
305 | /** Create the main dialog | |
306 | * @param properties The Properties to use | |
307 | * @param commandDispatcher The commandDispatcher | |
308 | */ | |
309 | public MainDialog(BFProperties properties, CommandDispatcher commandDispatcher) { | |
310 | 0 | super(); |
311 | 0 | this.board = document.getBoard(); |
312 | 0 | this.properties = properties; |
313 | 0 | this.commandDispatcher = commandDispatcher; // @jve:decl-index=0: |
314 | 0 | this.commandDispatcher.setMainDialog(this); |
315 | 0 | this.commandDispatcher.setProperties(this.properties); |
316 | 0 | this.clientReceiveParser = new ClientReceiveParser(); |
317 | 0 | this.clientReceiveParser.setProperties(this.properties); |
318 | 0 | this.clientReceiveParser.setCommandDispatcher(this.commandDispatcher); |
319 | 0 | this.clientReceiveParser.setMainDialog(this); |
320 | 0 | this.groupManager = new GroupManager(); |
321 | 0 | this.groupManager.setDatabase(database); |
322 | 0 | this.database.setActiveProfile(this.properties.getSelectedProfile()); |
323 | 0 | initialize(); |
324 | 0 | this.gameManager = new GameManager(); |
325 | 0 | this.gameManager.setMainDialog(this); |
326 | 0 | this.gameManager.setProperties(this.properties); |
327 | 0 | this.audioManager = null; |
328 | try { | |
329 | 0 | this.audioManager = new AudioManager(); |
330 | 0 | this.audioManager.initialize(this); |
331 | 0 | } catch (Exception ex) { |
332 | 0 | System.out.println("Can't init audio manager"); |
333 | 0 | } |
334 | //this.gameManager.setCommandDispatcher(commandDispatcher); | |
335 | 0 | this.gameManager.setReplayToolbar(this.getReplayToolbar()); |
336 | 0 | this.gameManager.reset(false); |
337 | 0 | this.playerListPane.setROP(this.properties.getROP()); |
338 | 0 | if (this.properties.isAutoConnect()) |
339 | 0 | this.commandDispatcher.dispatch(CommandDispatcher.Command.CONNECT_TO_SERVER); |
340 | 0 | updateRatingPanel(); |
341 | 0 | } |
342 | ||
343 | @Override | |
344 | public Document getDocument() { | |
345 | 0 | return(document); |
346 | } | |
347 | ||
348 | /** Turn off You moving | |
349 | */ | |
350 | public void youCantMove() { | |
351 | 0 | this.getBoardTab().getBoardGui().youCantMove(); |
352 | 0 | this.getBoardTab().updateBoard(); |
353 | 0 | } |
354 | ||
355 | /** Call when you start watching another match. This turns off all of the game gui input. | |
356 | */ | |
357 | public void startWatching() { | |
358 | 0 | this.getBoardTab().getBoardGui().startWatching(); |
359 | 0 | } |
360 | ||
361 | @Override | |
362 | public void updateBoard() { | |
363 | 0 | this.getBoardTab().updateBoard(); |
364 | 0 | } |
365 | ||
366 | @Override | |
367 | public void moveEvent(GameEvent gameEvent) { | |
368 | 0 | this.getBoardTab().getBoardGui().displayGameEvent(gameEvent); |
369 | ||
370 | 0 | } |
371 | ||
372 | public void updateRatingPanel() { | |
373 | 0 | RatingGraphPanel rgp = this.getToolbar().getRatingGraphPanel(); |
374 | 0 | rgp.setConfig(this.properties.getRatingGraphConfig()); |
375 | 0 | rgp.setData(this.database.getAllRatingsByDate()); |
376 | 0 | } |
377 | ||
378 | @Override | |
379 | public void playSound(AudioManager.Cue cue) { | |
380 | 0 | if (this.properties.isAudioCues() && this.audioManager != null) |
381 | 0 | this.audioManager.play(cue); |
382 | 0 | } |
383 | ||
384 | /** This method initializes this | |
385 | */ | |
386 | private void initialize() { | |
387 | 0 | this.document.getBoard().setStartPositions(); |
388 | 0 | this.setSize(properties.getMainWidth(), properties.getMainHeight()); |
389 | 0 | this.setLocation(properties.getMainX(), properties.getMainY()); |
390 | 0 | this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); |
391 | 0 | this.setTitle(titleName); |
392 | 0 | this.setContentPane(getJContentPane()); |
393 | 0 | this.addWindowListener(new java.awt.event.WindowAdapter() { |
394 | public void windowClosing(java.awt.event.WindowEvent e) { | |
395 | 0 | mainDialogShuttingDown(); |
396 | 0 | } |
397 | }); | |
398 | 0 | systemMessagesTextPane.appendMessage("BuckoFIBS-" + Version.getVersion() + " Starting up\r\n"); |
399 | 0 | this.setSystemMessagesTabVisible(); |
400 | 0 | } |
401 | ||
402 | /** Get the PlayerTableModel from the playerListPane | |
403 | * @return The PlayerTableModel | |
404 | */ | |
405 | public PlayerTableModel getPlayerTableModel() { | |
406 | 0 | return(playerListPane.getPlayerTableModel()); |
407 | } | |
408 | ||
409 | /** Get the InviterTableModel from the inviterListPane | |
410 | * @return The InviterTableModel | |
411 | */ | |
412 | public InviterTableModel getInviterTableModel() { | |
413 | 0 | return(this.inviterListPane.getInviterTableModel()); |
414 | } | |
415 | ||
416 | private ReplayToolbar getReplayToolbar() { | |
417 | 0 | return(this.boardTab.getJToolBarReplay()); |
418 | } | |
419 | ||
420 | /** Return a reference to the game manager | |
421 | * @return The GameManager | |
422 | */ | |
423 | public GameManager getGameManager() { | |
424 | 0 | return(this.gameManager); |
425 | } | |
426 | ||
427 | /** Return a reference to our clientReceiveParser | |
428 | * @return the clientReceiveParser | |
429 | */ | |
430 | public ClientReceiveParser getClientReceiveParser() { | |
431 | 0 | return clientReceiveParser; |
432 | } | |
433 | ||
434 | /** Get a reference to the Database. | |
435 | * @return The database | |
436 | */ | |
437 | public Database getDB() { | |
438 | 0 | return(this.database); |
439 | } | |
440 | ||
441 | /** Make the invited tab visible | |
442 | */ | |
443 | public void setInvitedTabVisible() { | |
444 | 0 | this.topRightTabbedPane.setSelectedComponent(this.inviterListScrollPane); |
445 | 0 | } |
446 | ||
447 | /** After parsing the "Own info" message from FIBS, update the buttons etc. to match. | |
448 | */ | |
449 | public void redrawOwnInfo() { | |
450 | 0 | this.setTitle(titleName + " - " + this.document.getName()); |
451 | 0 | this.setReadyToPlay(this.document.isReady()); |
452 | 0 | this.getBoardTab().getGameToolBar().setAskDouble(this.document.isAskDouble()); |
453 | ||
454 | 0 | } |
455 | ||
456 | /** Set the display to show that we are connected to fibs. | |
457 | * @param b true if we're connected | |
458 | */ | |
459 | public void setConnected(boolean b) { | |
460 | 0 | this.getToolbar().setConnected(b); |
461 | 0 | } |
462 | ||
463 | public void setReadyToPlay(boolean b) { | |
464 | 0 | this.getToolbar().setReadyToPlay(b); |
465 | 0 | } |
466 | ||
467 | public void setAskDouble(boolean b) { | |
468 | 0 | this.getBoardTab().getGameToolBar().setAskDouble(b); |
469 | 0 | } |
470 | ||
471 | public void setSystemMessagesTabVisible() { | |
472 | 0 | this.topRightTabbedPane.setSelectedComponent(this.systemMessagesScrollPane); |
473 | 0 | } |
474 | ||
475 | public void setGameMessagesTabVisible() { | |
476 | 0 | if (this.gameMessagesScrollPane == null) { |
477 | 0 | topRightTabbedPane.addTab("Game", null, getGameMessagesScrollPane(), null); |
478 | 0 | if (this.topRightTabbedPane.getComponentCount() == 4 |
479 | 0 | && this.topRightTabbedPane.getComponentAt(2) == getPlayerReportPane()) { |
480 | 0 | this.topRightTabbedPane.remove(2); |
481 | 0 | topRightTabbedPane.addTab("Player", null, getPlayerReportPane(), null); |
482 | } | |
483 | 0 | this.topRightTabbedPane.setSelectedComponent(this.gameMessagesScrollPane); |
484 | } else { | |
485 | 0 | this.topRightTabbedPane.setSelectedComponent(this.gameMessagesScrollPane); |
486 | } | |
487 | 0 | } |
488 | ||
489 | public void setPlayerReportTabVisible() { | |
490 | 0 | if (this.playerReportPane == null) { |
491 | 0 | topRightTabbedPane.addTab("Player", null, getPlayerReportPane(), null); |
492 | 0 | this.topRightTabbedPane.setSelectedComponent(this.getPlayerReportPane()); |
493 | } | |
494 | 0 | } |
495 | ||
496 | public void setBoardTabVisible() { | |
497 | 0 | this.topLeftTabbedPane.setSelectedComponent(this.boardTab); |
498 | 0 | } |
499 | ||
500 | /** Make the list of Players visible | |
501 | */ | |
502 | public void setPlayerListTabVisible() { | |
503 | 0 | this.topLeftTabbedPane.setSelectedComponent(this.getPlayerListTab()); |
504 | ||
505 | 0 | } |
506 | ||
507 | public void showResignOutDialog() { | |
508 | 0 | ResignOut ro = new ResignOut(this, this.getBoardTab().getBoardGui(), this.commandDispatcher); |
509 | 0 | ro.setVisible(true); |
510 | 0 | } |
511 | ||
512 | /** Write a message to the game window. | |
513 | * @param s The message to write. | |
514 | */ | |
515 | public void writeGameMessageln(String s) { | |
516 | 0 | if (this.gameMessagesScrollPane == null) { |
517 | 0 | this.setGameMessagesTabVisible(); |
518 | } | |
519 | 0 | this.gameMessagesTextPane.appendMessage(s + eol); |
520 | 0 | gameMessagesScrollToBottom(); |
521 | 0 | } |
522 | ||
523 | /** Write a message to the Game message pane in the specified color. | |
524 | * Terminate the message with a crlf. | |
525 | * @param type The style of the text | |
526 | * @param s The message to write | |
527 | */ | |
528 | public void writeGameMessageln(int type, String s) { | |
529 | 0 | if (gameMessagesTextPane != null) { |
530 | 0 | this.gameMessagesTextPane.appendMessage(type, s + eol); |
531 | 0 | this.gameMessagesScrollToBottom(); |
532 | } | |
533 | 0 | } |
534 | ||
535 | ||
536 | /** Scroll the system messages pane so that the last line is visible. | |
537 | * Use this after adding text to the system messages. | |
538 | */ | |
539 | public void systemMessagesScrollToBottom() { | |
540 | try { | |
541 | 0 | systemMessagesDimension = systemMessagesTextPane.getSize(systemMessagesDimension); |
542 | 0 | systemMessagesRectangle.y = systemMessagesDimension.height; |
543 | 0 | systemMessagesScrollPane.getViewport().scrollRectToVisible(systemMessagesRectangle); |
544 | 0 | } catch (Exception e) { |
545 | if (DEBUG) { | |
546 | System.out.println("Exception ignored"); | |
547 | e.printStackTrace(); | |
548 | } | |
549 | 0 | } |
550 | 0 | } |
551 | ||
552 | /** Scroll the system messages pane so that the last line is visible. | |
553 | * Use this after adding text to the system messages. | |
554 | */ | |
555 | private void gameMessagesScrollToBottom() { | |
556 | try { | |
557 | 0 | gameMessagesDimension = gameMessagesTextPane.getSize(gameMessagesDimension); |
558 | 0 | gameMessagesRectangle.y = gameMessagesDimension.height; |
559 | 0 | gameMessagesScrollPane.getViewport().scrollRectToVisible(gameMessagesRectangle); |
560 | 0 | } catch (Exception e) { |
561 | if (DEBUG) { | |
562 | System.out.println("Exception ignored"); | |
563 | e.printStackTrace(); | |
564 | } | |
565 | 0 | } |
566 | 0 | } |
567 | ||
568 | private void mainDialogShuttingDown() { | |
569 | if (DEBUG) { | |
570 | System.out.println("x=" + this.getX() + " y=" + this.getY()); | |
571 | System.out.println("h/w = " + this.getHeight() + " / " + this.getWidth()); | |
572 | } | |
573 | 0 | this.commandDispatcher.dispatch(CommandDispatcher.Command.SHUTTING_DOWN); |
574 | 0 | this.clientReceiveParser.shutdown(); |
575 | 0 | properties.setMainX(getX()); |
576 | 0 | properties.setMainY(getY()); |
577 | 0 | properties.setMainWidth(getWidth()); |
578 | 0 | properties.setMainHeight(getHeight()); |
579 | 0 | properties.setMainTopBottomSplit(this.getTopBottomSplitPane().getDividerLocation()); |
580 | 0 | properties.setMainTopLRSplit(this.getTopLeftRightSplitPane().getDividerLocation()); |
581 | 0 | properties.setMainBotLRSplit(this.getBottomLeftRightSplitPane().getDividerLocation()); |
582 | 0 | } |
583 | ||
584 | ||
585 | public void onMatchOver(String winner, String score) { | |
586 | 0 | this.board.onMatchOver(winner, score); |
587 | 0 | updateBoard(); |
588 | 0 | } |
589 | ||
590 | /** This method initializes and returns a reference to jContentPane | |
591 | * @return javax.swing.JPanel | |
592 | */ | |
593 | private JPanel getJContentPane() { | |
594 | 0 | if (jContentPane == null) { |
595 | 0 | jContentPane = new JPanel(); |
596 | 0 | jContentPane.setLayout(new BorderLayout()); |
597 | ||
598 | 0 | jContentPane.add(getToolbar(), BorderLayout.NORTH); |
599 | 0 | jContentPane.add(getTopBottomSplitPane(), BorderLayout.CENTER); |
600 | } | |
601 | 0 | return jContentPane; |
602 | } | |
603 | ||
604 | /** | |
605 | * This method initializes and returns a reference to toolbar | |
606 | * | |
607 | * @return javax.swing.JToolBar | |
608 | */ | |
609 | public ToolBar getToolbar() { | |
610 | 0 | if (toolbar == null) { |
611 | 0 | toolbar = new ToolBar(); |
612 | 0 | toolbar.setCommandDispatcher(commandDispatcher); |
613 | } | |
614 | 0 | return toolbar; |
615 | } | |
616 | ||
617 | /** This method initializes and returns a reference to topBottomSplitPane | |
618 | * | |
619 | * @return javax.swing.JSplitPane | |
620 | */ | |
621 | private JSplitPane getTopBottomSplitPane() { | |
622 | 0 | if (topBottomSplitPane == null) { |
623 | 0 | topBottomSplitPane = new JSplitPane(); |
624 | 0 | topBottomSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); |
625 | 0 | topBottomSplitPane.setTopComponent(getTopLeftRightSplitPane()); |
626 | 0 | topBottomSplitPane.setBottomComponent(getBottomLeftRightSplitPane()); |
627 | 0 | topBottomSplitPane.setDividerLocation(properties.getMainTopBottomSplit()); |
628 | } | |
629 | 0 | return topBottomSplitPane; |
630 | } | |
631 | ||
632 | /** This method initializes and returns a reference to topLeftRightSplitPane | |
633 | * @return javax.swing.JSplitPane | |
634 | */ | |
635 | private JSplitPane getTopLeftRightSplitPane() { | |
636 | 0 | if (topLeftRightSplitPane == null) { |
637 | 0 | topLeftRightSplitPane = new JSplitPane(); |
638 | 0 | topLeftRightSplitPane.setDividerLocation(properties.getMainTopLRSplit()); |
639 | 0 | topLeftRightSplitPane.setLeftComponent(getTopLeftTabbedPane()); |
640 | 0 | topLeftRightSplitPane.setRightComponent(getTopRightTabbedPane()); |
641 | } | |
642 | 0 | return topLeftRightSplitPane; |
643 | } | |
644 | ||
645 | /** This method initializes and returns a reference to bottomLeftRightSplitPane | |
646 | * @return javax.swing.JSplitPane | |
647 | */ | |
648 | private JSplitPane getBottomLeftRightSplitPane() { | |
649 | 0 | if (bottomLeftRightSplitPane == null) { |
650 | 0 | bottomLeftRightSplitPane = new JSplitPane(); |
651 | 0 | bottomLeftRightSplitPane.setDividerLocation(properties.getMainBotLRSplit()); |
652 | 0 | bottomLeftRightSplitPane.setRightComponent(getChatPane()); |
653 | } | |
654 | 0 | return bottomLeftRightSplitPane; |
655 | } | |
656 | ||
657 | /** This method initializes and returns a reference to topLeftTabbedPane | |
658 | * @return javax.swing.JTabbedPane | |
659 | */ | |
660 | private JTabbedPane getTopLeftTabbedPane() { | |
661 | 0 | if (topLeftTabbedPane == null) { |
662 | 0 | topLeftTabbedPane = new JTabbedPane(); |
663 | 0 | topLeftTabbedPane.addTab("Players", null, getPlayerListTab(), null); |
664 | 0 | topLeftTabbedPane.addTab("Board", null, getBoardTab(), null); |
665 | } | |
666 | 0 | return topLeftTabbedPane; |
667 | } | |
668 | ||
669 | /** This method initializes and returns a reference to playerListlPane | |
670 | * @return javax.swing.JScrollPane | |
671 | */ | |
672 | public PlayerListPane getPlayerListTab() { | |
673 | 0 | if (playerListPane == null) { |
674 | 0 | playerListPane = new PlayerListPane(); |
675 | 0 | playerListPane.setCommandDispatcher(this.commandDispatcher); |
676 | 0 | playerListPane.setGroupManager(this.groupManager); |
677 | 0 | playerListPane.setMainDialog(this); |
678 | } | |
679 | 0 | return playerListPane; |
680 | } | |
681 | ||
682 | /** return a reference to the ChatPane. | |
683 | * (Also initialize it). | |
684 | * @return Our chat pane | |
685 | */ | |
686 | public ChatPane getChatPane() { | |
687 | 0 | if (bottomRightChatPane == null) { |
688 | 0 | bottomRightChatPane = new ChatPane(); |
689 | 0 | bottomRightChatPane.setCommandDispatcher(this.commandDispatcher); |
690 | } | |
691 | 0 | return(bottomRightChatPane); |
692 | } | |
693 | ||
694 | /** This method initializes and returns a reference to topRightTabbedPane | |
695 | * @return javax.swing.JTabbedPane | |
696 | */ | |
697 | private JTabbedPane getTopRightTabbedPane() { | |
698 | 0 | if (topRightTabbedPane == null) { |
699 | 0 | topRightTabbedPane = new JTabbedPane(); |
700 | 0 | topRightTabbedPane.addTab("System", null, getSystemMessagesScrollPane(), null); |
701 | 0 | topRightTabbedPane.addTab("Invites", null, getInviterListPane(), null); |
702 | } | |
703 | 0 | setPlayerReportTabVisible(); |
704 | 0 | return topRightTabbedPane; |
705 | } | |
706 | ||
707 | /** This method initializes and returns a reference to systemMessagesTextPane | |
708 | * @return javax.swing.JScrollPane | |
709 | */ | |
710 | public JScrollPane getSystemMessagesScrollPane() { | |
711 | 0 | if (systemMessagesScrollPane == null) { |
712 | 0 | systemMessagesTextPane = new SystemMessagesTextPane(); |
713 | 0 | systemMessagesScrollPane = new JScrollPane(systemMessagesTextPane); |
714 | 0 | systemMessagesScrollPane.setAutoscrolls(true); |
715 | 0 | systemMessagesDimension = new Dimension(10,10); |
716 | 0 | systemMessagesRectangle = new Rectangle(10,10); |
717 | } | |
718 | 0 | return systemMessagesScrollPane; |
719 | } | |
720 | ||
721 | public SystemMessagesTextPane getSystemMessagesTextPane() { | |
722 | 0 | return(this.systemMessagesTextPane); |
723 | } | |
724 | ||
725 | /** This method initializes and returns a reference to systemMessagesTextPane | |
726 | * @return javax.swing.JScrollPane | |
727 | */ | |
728 | public JScrollPane getGameMessagesScrollPane() { | |
729 | 0 | if (gameMessagesScrollPane == null) { |
730 | 0 | gameMessagesTextPane = new SystemMessagesTextPane(); |
731 | 0 | gameMessagesScrollPane = new JScrollPane(gameMessagesTextPane); |
732 | 0 | gameMessagesScrollPane.setAutoscrolls(true); |
733 | 0 | gameMessagesScrollPane.setVisible(false); |
734 | 0 | gameMessagesDimension = new Dimension(10,10); |
735 | 0 | gameMessagesRectangle = new Rectangle(10,10); |
736 | } | |
737 | 0 | return gameMessagesScrollPane; |
738 | } | |
739 | ||
740 | public PlayerReportPane getPlayerReportPane() { | |
741 | 0 | if (this.playerReportPane == null) { |
742 | 0 | this.playerReportPane = new PlayerReportPane(); |
743 | 0 | this.playerReportPane.setCommandDispatcher(this.commandDispatcher); |
744 | 0 | this.playerReportPane.setDatabase(database); |
745 | } | |
746 | 0 | return(this.playerReportPane); |
747 | } | |
748 | ||
749 | /** Add a chat message to the Chat Pane | |
750 | * @param name The Player this message is to | |
751 | * @param cookie The cookie that created this event | |
752 | * @param text The message to write | |
753 | */ | |
754 | public void addChatMessage(String name, int cookie, String text) { | |
755 | 0 | bottomRightChatPane.writeChatMessage(name, cookie, text); |
756 | 0 | } |
757 | ||
758 | /** | |
759 | * This method initializes systemMessagesTextPane | |
760 | * | |
761 | * @return javax.swing.JTextPane | |
762 | */ | |
763 | private JScrollPane getInviterListPane() { | |
764 | 0 | if (inviterListPane == null) { |
765 | 0 | inviterListPane = new InviterListPane(); |
766 | 0 | inviterListPane.setCommandDispatcher(this.commandDispatcher); |
767 | 0 | inviterListScrollPane = new JScrollPane(inviterListPane); |
768 | 0 | inviterListScrollPane.setAutoscrolls(true); |
769 | } | |
770 | 0 | return inviterListScrollPane; |
771 | } | |
772 | ||
773 | /** Get a reference to the BoardTab | |
774 | * @return The BoardTab | |
775 | */ | |
776 | public BoardTab getBoardTab() { | |
777 | 0 | if (boardTab == null) { |
778 | 0 | boardTab = new BoardTab(); |
779 | 0 | boardTab.setDocument(document); |
780 | 0 | boardTab.setCommandDispatcher(this.commandDispatcher); |
781 | } | |
782 | 0 | return(boardTab); |
783 | } | |
784 | ||
785 | } |