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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
255
256
257
258
259
260 public class MainDialog extends JFrame implements MainDialogI {
261 private final static boolean DEBUG = false;
262 private static final long serialVersionUID = 1L;
263 private JPanel jContentPane = null;
264 private ToolBar toolbar = null;
265
266 private JSplitPane topBottomSplitPane = null;
267 private JSplitPane topLeftRightSplitPane = null;
268 private JSplitPane bottomLeftRightSplitPane = null;
269 private JTabbedPane topLeftTabbedPane = null;
270 private PlayerListPane playerListPane = null;
271
272 private JTabbedPane topRightTabbedPane = null;
273 private SystemMessagesTextPane systemMessagesTextPane = null;
274 private JScrollPane systemMessagesScrollPane = null;
275 private Dimension systemMessagesDimension = null;
276 private Rectangle systemMessagesRectangle = null;
277
278 private SystemMessagesTextPane gameMessagesTextPane = null;
279 private JScrollPane gameMessagesScrollPane = null;
280 private Dimension gameMessagesDimension = null;
281 private Rectangle gameMessagesRectangle = null;
282
283 private InviterListPane inviterListPane = null;
284 private JScrollPane inviterListScrollPane = null;
285 private PlayerReportPane playerReportPane = null;
286
287 private ChatPane bottomRightChatPane = null;
288 private BoardTab boardTab = null;
289
290 private BFProperties properties = null;
291 private CommandDispatcher commandDispatcher = null;
292 private ClientReceiveParser clientReceiveParser;
293 private GameManager gameManager;
294 private GroupManager groupManager;
295 private AudioManager audioManager;
296
297 private Document document = new Document();
298 private Board board;
299 private final String titleName = "BuckoFIBS";
300 private final static String eol = "\r\n";
301
302 private Database database = new DatabaseImpl();
303
304
305
306
307
308
309 public MainDialog(BFProperties properties, CommandDispatcher commandDispatcher) {
310 super();
311 this.board = document.getBoard();
312 this.properties = properties;
313 this.commandDispatcher = commandDispatcher;
314 this.commandDispatcher.setMainDialog(this);
315 this.commandDispatcher.setProperties(this.properties);
316 this.clientReceiveParser = new ClientReceiveParser();
317 this.clientReceiveParser.setProperties(this.properties);
318 this.clientReceiveParser.setCommandDispatcher(this.commandDispatcher);
319 this.clientReceiveParser.setMainDialog(this);
320 this.groupManager = new GroupManager();
321 this.groupManager.setDatabase(database);
322 this.database.setActiveProfile(this.properties.getSelectedProfile());
323 initialize();
324 this.gameManager = new GameManager();
325 this.gameManager.setMainDialog(this);
326 this.gameManager.setProperties(this.properties);
327 this.audioManager = null;
328 try {
329 this.audioManager = new AudioManager();
330 this.audioManager.initialize(this);
331 } catch (Exception ex) {
332 System.out.println("Can't init audio manager");
333 }
334
335 this.gameManager.setReplayToolbar(this.getReplayToolbar());
336 this.gameManager.reset(false);
337 this.playerListPane.setROP(this.properties.getROP());
338 if (this.properties.isAutoConnect())
339 this.commandDispatcher.dispatch(CommandDispatcher.Command.CONNECT_TO_SERVER);
340 updateRatingPanel();
341 }
342
343 @Override
344 public Document getDocument() {
345 return(document);
346 }
347
348
349
350 public void youCantMove() {
351 this.getBoardTab().getBoardGui().youCantMove();
352 this.getBoardTab().updateBoard();
353 }
354
355
356
357 public void startWatching() {
358 this.getBoardTab().getBoardGui().startWatching();
359 }
360
361 @Override
362 public void updateBoard() {
363 this.getBoardTab().updateBoard();
364 }
365
366 @Override
367 public void moveEvent(GameEvent gameEvent) {
368 this.getBoardTab().getBoardGui().displayGameEvent(gameEvent);
369
370 }
371
372 public void updateRatingPanel() {
373 RatingGraphPanel rgp = this.getToolbar().getRatingGraphPanel();
374 rgp.setConfig(this.properties.getRatingGraphConfig());
375 rgp.setData(this.database.getAllRatingsByDate());
376 }
377
378 @Override
379 public void playSound(AudioManager.Cue cue) {
380 if (this.properties.isAudioCues() && this.audioManager != null)
381 this.audioManager.play(cue);
382 }
383
384
385
386 private void initialize() {
387 this.document.getBoard().setStartPositions();
388 this.setSize(properties.getMainWidth(), properties.getMainHeight());
389 this.setLocation(properties.getMainX(), properties.getMainY());
390 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
391 this.setTitle(titleName);
392 this.setContentPane(getJContentPane());
393 this.addWindowListener(new java.awt.event.WindowAdapter() {
394 public void windowClosing(java.awt.event.WindowEvent e) {
395 mainDialogShuttingDown();
396 }
397 });
398 systemMessagesTextPane.appendMessage("BuckoFIBS-" + Version.getVersion() + " Starting up\r\n");
399 this.setSystemMessagesTabVisible();
400 }
401
402
403
404
405 public PlayerTableModel getPlayerTableModel() {
406 return(playerListPane.getPlayerTableModel());
407 }
408
409
410
411
412 public InviterTableModel getInviterTableModel() {
413 return(this.inviterListPane.getInviterTableModel());
414 }
415
416 private ReplayToolbar getReplayToolbar() {
417 return(this.boardTab.getJToolBarReplay());
418 }
419
420
421
422
423 public GameManager getGameManager() {
424 return(this.gameManager);
425 }
426
427
428
429
430 public ClientReceiveParser getClientReceiveParser() {
431 return clientReceiveParser;
432 }
433
434
435
436
437 public Database getDB() {
438 return(this.database);
439 }
440
441
442
443 public void setInvitedTabVisible() {
444 this.topRightTabbedPane.setSelectedComponent(this.inviterListScrollPane);
445 }
446
447
448
449 public void redrawOwnInfo() {
450 this.setTitle(titleName + " - " + this.document.getName());
451 this.setReadyToPlay(this.document.isReady());
452 this.getBoardTab().getGameToolBar().setAskDouble(this.document.isAskDouble());
453
454 }
455
456
457
458
459 public void setConnected(boolean b) {
460 this.getToolbar().setConnected(b);
461 }
462
463 public void setReadyToPlay(boolean b) {
464 this.getToolbar().setReadyToPlay(b);
465 }
466
467 public void setAskDouble(boolean b) {
468 this.getBoardTab().getGameToolBar().setAskDouble(b);
469 }
470
471 public void setSystemMessagesTabVisible() {
472 this.topRightTabbedPane.setSelectedComponent(this.systemMessagesScrollPane);
473 }
474
475 public void setGameMessagesTabVisible() {
476 if (this.gameMessagesScrollPane == null) {
477 topRightTabbedPane.addTab("Game", null, getGameMessagesScrollPane(), null);
478 if (this.topRightTabbedPane.getComponentCount() == 4
479 && this.topRightTabbedPane.getComponentAt(2) == getPlayerReportPane()) {
480 this.topRightTabbedPane.remove(2);
481 topRightTabbedPane.addTab("Player", null, getPlayerReportPane(), null);
482 }
483 this.topRightTabbedPane.setSelectedComponent(this.gameMessagesScrollPane);
484 } else {
485 this.topRightTabbedPane.setSelectedComponent(this.gameMessagesScrollPane);
486 }
487 }
488
489 public void setPlayerReportTabVisible() {
490 if (this.playerReportPane == null) {
491 topRightTabbedPane.addTab("Player", null, getPlayerReportPane(), null);
492 this.topRightTabbedPane.setSelectedComponent(this.getPlayerReportPane());
493 }
494 }
495
496 public void setBoardTabVisible() {
497 this.topLeftTabbedPane.setSelectedComponent(this.boardTab);
498 }
499
500
501
502 public void setPlayerListTabVisible() {
503 this.topLeftTabbedPane.setSelectedComponent(this.getPlayerListTab());
504
505 }
506
507 public void showResignOutDialog() {
508 ResignOut ro = new ResignOut(this, this.getBoardTab().getBoardGui(), this.commandDispatcher);
509 ro.setVisible(true);
510 }
511
512
513
514
515 public void writeGameMessageln(String s) {
516 if (this.gameMessagesScrollPane == null) {
517 this.setGameMessagesTabVisible();
518 }
519 this.gameMessagesTextPane.appendMessage(s + eol);
520 gameMessagesScrollToBottom();
521 }
522
523
524
525
526
527
528 public void writeGameMessageln(int type, String s) {
529 if (gameMessagesTextPane != null) {
530 this.gameMessagesTextPane.appendMessage(type, s + eol);
531 this.gameMessagesScrollToBottom();
532 }
533 }
534
535
536
537
538
539 public void systemMessagesScrollToBottom() {
540 try {
541 systemMessagesDimension = systemMessagesTextPane.getSize(systemMessagesDimension);
542 systemMessagesRectangle.y = systemMessagesDimension.height;
543 systemMessagesScrollPane.getViewport().scrollRectToVisible(systemMessagesRectangle);
544 } catch (Exception e) {
545 if (DEBUG) {
546 System.out.println("Exception ignored");
547 e.printStackTrace();
548 }
549 }
550 }
551
552
553
554
555 private void gameMessagesScrollToBottom() {
556 try {
557 gameMessagesDimension = gameMessagesTextPane.getSize(gameMessagesDimension);
558 gameMessagesRectangle.y = gameMessagesDimension.height;
559 gameMessagesScrollPane.getViewport().scrollRectToVisible(gameMessagesRectangle);
560 } catch (Exception e) {
561 if (DEBUG) {
562 System.out.println("Exception ignored");
563 e.printStackTrace();
564 }
565 }
566 }
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 this.commandDispatcher.dispatch(CommandDispatcher.Command.SHUTTING_DOWN);
574 this.clientReceiveParser.shutdown();
575 properties.setMainX(getX());
576 properties.setMainY(getY());
577 properties.setMainWidth(getWidth());
578 properties.setMainHeight(getHeight());
579 properties.setMainTopBottomSplit(this.getTopBottomSplitPane().getDividerLocation());
580 properties.setMainTopLRSplit(this.getTopLeftRightSplitPane().getDividerLocation());
581 properties.setMainBotLRSplit(this.getBottomLeftRightSplitPane().getDividerLocation());
582 }
583
584
585 public void onMatchOver(String winner, String score) {
586 this.board.onMatchOver(winner, score);
587 updateBoard();
588 }
589
590
591
592
593 private JPanel getJContentPane() {
594 if (jContentPane == null) {
595 jContentPane = new JPanel();
596 jContentPane.setLayout(new BorderLayout());
597
598 jContentPane.add(getToolbar(), BorderLayout.NORTH);
599 jContentPane.add(getTopBottomSplitPane(), BorderLayout.CENTER);
600 }
601 return jContentPane;
602 }
603
604
605
606
607
608
609 public ToolBar getToolbar() {
610 if (toolbar == null) {
611 toolbar = new ToolBar();
612 toolbar.setCommandDispatcher(commandDispatcher);
613 }
614 return toolbar;
615 }
616
617
618
619
620
621 private JSplitPane getTopBottomSplitPane() {
622 if (topBottomSplitPane == null) {
623 topBottomSplitPane = new JSplitPane();
624 topBottomSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
625 topBottomSplitPane.setTopComponent(getTopLeftRightSplitPane());
626 topBottomSplitPane.setBottomComponent(getBottomLeftRightSplitPane());
627 topBottomSplitPane.setDividerLocation(properties.getMainTopBottomSplit());
628 }
629 return topBottomSplitPane;
630 }
631
632
633
634
635 private JSplitPane getTopLeftRightSplitPane() {
636 if (topLeftRightSplitPane == null) {
637 topLeftRightSplitPane = new JSplitPane();
638 topLeftRightSplitPane.setDividerLocation(properties.getMainTopLRSplit());
639 topLeftRightSplitPane.setLeftComponent(getTopLeftTabbedPane());
640 topLeftRightSplitPane.setRightComponent(getTopRightTabbedPane());
641 }
642 return topLeftRightSplitPane;
643 }
644
645
646
647
648 private JSplitPane getBottomLeftRightSplitPane() {
649 if (bottomLeftRightSplitPane == null) {
650 bottomLeftRightSplitPane = new JSplitPane();
651 bottomLeftRightSplitPane.setDividerLocation(properties.getMainBotLRSplit());
652 bottomLeftRightSplitPane.setRightComponent(getChatPane());
653 }
654 return bottomLeftRightSplitPane;
655 }
656
657
658
659
660 private JTabbedPane getTopLeftTabbedPane() {
661 if (topLeftTabbedPane == null) {
662 topLeftTabbedPane = new JTabbedPane();
663 topLeftTabbedPane.addTab("Players", null, getPlayerListTab(), null);
664 topLeftTabbedPane.addTab("Board", null, getBoardTab(), null);
665 }
666 return topLeftTabbedPane;
667 }
668
669
670
671
672 public PlayerListPane getPlayerListTab() {
673 if (playerListPane == null) {
674 playerListPane = new PlayerListPane();
675 playerListPane.setCommandDispatcher(this.commandDispatcher);
676 playerListPane.setGroupManager(this.groupManager);
677 playerListPane.setMainDialog(this);
678 }
679 return playerListPane;
680 }
681
682
683
684
685
686 public ChatPane getChatPane() {
687 if (bottomRightChatPane == null) {
688 bottomRightChatPane = new ChatPane();
689 bottomRightChatPane.setCommandDispatcher(this.commandDispatcher);
690 }
691 return(bottomRightChatPane);
692 }
693
694
695
696
697 private JTabbedPane getTopRightTabbedPane() {
698 if (topRightTabbedPane == null) {
699 topRightTabbedPane = new JTabbedPane();
700 topRightTabbedPane.addTab("System", null, getSystemMessagesScrollPane(), null);
701 topRightTabbedPane.addTab("Invites", null, getInviterListPane(), null);
702 }
703 setPlayerReportTabVisible();
704 return topRightTabbedPane;
705 }
706
707
708
709
710 public JScrollPane getSystemMessagesScrollPane() {
711 if (systemMessagesScrollPane == null) {
712 systemMessagesTextPane = new SystemMessagesTextPane();
713 systemMessagesScrollPane = new JScrollPane(systemMessagesTextPane);
714 systemMessagesScrollPane.setAutoscrolls(true);
715 systemMessagesDimension = new Dimension(10,10);
716 systemMessagesRectangle = new Rectangle(10,10);
717 }
718 return systemMessagesScrollPane;
719 }
720
721 public SystemMessagesTextPane getSystemMessagesTextPane() {
722 return(this.systemMessagesTextPane);
723 }
724
725
726
727
728 public JScrollPane getGameMessagesScrollPane() {
729 if (gameMessagesScrollPane == null) {
730 gameMessagesTextPane = new SystemMessagesTextPane();
731 gameMessagesScrollPane = new JScrollPane(gameMessagesTextPane);
732 gameMessagesScrollPane.setAutoscrolls(true);
733 gameMessagesScrollPane.setVisible(false);
734 gameMessagesDimension = new Dimension(10,10);
735 gameMessagesRectangle = new Rectangle(10,10);
736 }
737 return gameMessagesScrollPane;
738 }
739
740 public PlayerReportPane getPlayerReportPane() {
741 if (this.playerReportPane == null) {
742 this.playerReportPane = new PlayerReportPane();
743 this.playerReportPane.setCommandDispatcher(this.commandDispatcher);
744 this.playerReportPane.setDatabase(database);
745 }
746 return(this.playerReportPane);
747 }
748
749
750
751
752
753
754 public void addChatMessage(String name, int cookie, String text) {
755 bottomRightChatPane.writeChatMessage(name, cookie, text);
756 }
757
758
759
760
761
762
763 private JScrollPane getInviterListPane() {
764 if (inviterListPane == null) {
765 inviterListPane = new InviterListPane();
766 inviterListPane.setCommandDispatcher(this.commandDispatcher);
767 inviterListScrollPane = new JScrollPane(inviterListPane);
768 inviterListScrollPane.setAutoscrolls(true);
769 }
770 return inviterListScrollPane;
771 }
772
773
774
775
776 public BoardTab getBoardTab() {
777 if (boardTab == null) {
778 boardTab = new BoardTab();
779 boardTab.setDocument(document);
780 boardTab.setCommandDispatcher(this.commandDispatcher);
781 }
782 return(boardTab);
783 }
784
785 }