1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package cs.pancava.caltha;
21
22 import cs.pancava.caltha.desktop.EditorDesktop;
23 import cs.pancava.caltha.menu.World2DPopupMenuListener;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ItemEvent;
27 import java.awt.event.ItemListener;
28 import java.util.Locale;
29 import java.util.MissingResourceException;
30 import java.util.ResourceBundle;
31 import javax.swing.JCheckBoxMenuItem;
32 import javax.swing.JMenu;
33 import javax.swing.JMenuBar;
34 import javax.swing.JMenuItem;
35 import javax.swing.JOptionPane;
36 import javax.swing.SwingUtilities;
37 import javax.swing.UIManager;
38 import javax.swing.UnsupportedLookAndFeelException;
39 import javax.swing.plaf.metal.DefaultMetalTheme;
40 import javax.swing.plaf.metal.MetalLookAndFeel;
41 import javax.swing.plaf.metal.OceanTheme;
42
43
44
45
46
47
48
49
50 public class MainMenu
51 {
52
53
54
55 private JMenuBar menuBar;
56
57
58
59
60 private JMenu fileMenu;
61
62
63
64 private JMenu newMenu;
65
66
67
68 private JMenuItem textBasedGamesIM;
69
70
71
72 private JMenuItem exitIM;
73
74
75
76
77 private JMenu helpMenu;
78
79
80
81 private JMenuItem aboutIM;
82
83
84
85
86 private JMenu optionsMenu;
87
88
89
90 private JMenu languageMenu;
91
92
93
94 private JCheckBoxMenuItem czechIM;
95
96
97
98 private JCheckBoxMenuItem englishIM;
99
100
101
102 private JMenu lookAndFeelMenu;
103
104
105
106 private JCheckBoxMenuItem defaultLaFIM;
107
108
109
110 private JCheckBoxMenuItem gtkLaFIM;
111
112
113
114 private JCheckBoxMenuItem macLaFIM;
115
116
117
118 private JCheckBoxMenuItem metalLaFIM;
119
120
121
122 private JCheckBoxMenuItem motifLaFIM;
123
124
125
126 private JCheckBoxMenuItem windowsLaFIM;
127
128
129
130 private JMenu metalThemeMenu;
131
132
133
134 private JCheckBoxMenuItem defaultMetalThemeIM;
135
136
137
138 private JCheckBoxMenuItem oceanMetalThemeIM;
139
140
141
142 private JCheckBoxMenuItem myMetalThemeIM;
143
144
145
146
147 MainMenu()
148 {
149
150 this.menuBar = new JMenuBar();
151
152
153 this.createMenuFile();
154
155
156 this.createMenuOptions();
157
158
159 this.createMenuHelp();
160 }
161
162
163
164
165
166 public final JMenuBar getMenuBar()
167 {
168 return this.menuBar;
169 }
170
171
172
173
174
175
176
177
178
179 private JCheckBoxMenuItem addCheckBoxMenuItem(final String name, final boolean stav, final String tip, final boolean enable)
180 {
181 try
182 {
183 JCheckBoxMenuItem cbmi;
184
185 cbmi = new JCheckBoxMenuItem(Editor.getResourcesBundleString(name), stav);
186 if (tip != null)
187 {
188 if (!MainMenu.isEmpty(Editor.getResourcesBundleString(tip)))
189 {
190 cbmi.setToolTipText(Editor.getResourcesBundleString(tip));
191 }
192 }
193 cbmi.setEnabled(enable);
194 return cbmi;
195 }
196 catch (MissingResourceException e)
197 {
198 Editor.showDialogMissingResources(e.getMessage());
199 }
200
201
202
203
204 return null;
205 }
206
207
208
209
210
211
212
213
214 private JMenu addMenu(final String name, final String help, final String tip)
215 {
216 try
217 {
218 JMenu m;
219
220 m = new JMenu(Editor.getResourcesBundleString(name));
221
222 if (help != null)
223 {
224
225
226
227 }
228
229 if (tip != null)
230 {
231 try
232 {
233 if (!MainMenu.isEmpty(Editor.getResourcesBundleString(tip)))
234 {
235 m.setToolTipText(Editor.getResourcesBundleString(tip));
236 }
237 }
238 catch (MissingResourceException e)
239 {
240 Editor.showDialogMissingResources(e.getMessage());
241 }
242 }
243
244 return m;
245 }
246 catch (MissingResourceException e)
247 {
248 Editor.showDialogMissingResources(e.getMessage());
249 }
250
251
252
253
254 return null;
255 }
256
257
258
259
260
261
262
263
264 public static JMenuItem addMenuItem(final String name, final String tip, final boolean enable)
265 {
266 try
267 {
268 JMenuItem mi;
269
270 mi = new JMenuItem(Editor.getResourcesBundleString(name));
271
272 if (tip != null)
273 {
274 try
275 {
276 if (!MainMenu.isEmpty(Editor.getResourcesBundleString(tip)))
277 {
278 mi.setToolTipText(Editor.getResourcesBundleString(tip));
279 }
280 }
281 catch (MissingResourceException e)
282 {
283 Editor.showDialogMissingResources(e.getMessage());
284 }
285 }
286
287 mi.setEnabled(enable);
288 return mi;
289 }
290 catch (MissingResourceException e)
291 {
292 Editor.showDialogMissingResources(e.getMessage());
293 }
294
295
296
297
298 return null;
299 }
300
301
302
303
304 private void createEditorTextBasedGames()
305 {
306 Editor.setEditorDesktop(EditorDesktop.EDITOR_TEXT_BASED_GAMES);
307 }
308
309
310
311
312 private void createItemMenuFileExit()
313 {
314 this.exitIM = MainMenu.addMenuItem("cs.pancava.caltha.MainMenu-createItemMenuFileExit_exitIM",
315 "cs.pancava.caltha.MainMenu-createItemMenuFileExit_exitIM_tip",
316 true);
317
318 this.exitIM.addActionListener(new ActionListener()
319 {
320 @Override
321 public void actionPerformed(final ActionEvent e)
322 {
323 final Object[] options = {"OK", "CANCEL", "HELP"};
324 int index = 0;
325 try
326 {
327 index = JOptionPane.showOptionDialog(null,
328 Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuFileExit_Dialog_msg"),
329 Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuFileExit_Dialog_tit"),
330 JOptionPane.DEFAULT_OPTION,
331 JOptionPane.QUESTION_MESSAGE,
332 null,
333 options,
334 options[0]
335 );
336
337 }
338 catch (MissingResourceException mre)
339 {
340 Editor.showDialogMissingResources(mre.getMessage());
341 }
342
343 switch (index)
344 {
345 case 0:
346
347 System.exit(0);
348 break;
349 case 1:
350 break;
351 case 2:
352 default:
353 this.helpMenuFileExit();
354 break;
355 }
356 }
357
358
359
360
361 private void helpMenuFileExit()
362 {
363
364 }
365 });
366
367 this.fileMenu.addSeparator();
368 this.fileMenu.add(this.exitIM);
369 }
370
371
372
373
374 private void createItemMenuFileNewTextBasedGames()
375 {
376 this.textBasedGamesIM = MainMenu.addMenuItem("cs.pancava.caltha.MainMenu-createItemMenuFileNewTextBasedGames_textBasedGamesIM",
377 "cs.pancava.caltha.MainMenu-createItemMenuFileNewTextBasedGames_textBasedGamesIM_tip",
378 true);
379
380 this.textBasedGamesIM.addActionListener(new ActionListener()
381 {
382 @Override
383 public void actionPerformed(final ActionEvent e)
384 {
385 createEditorTextBasedGames();
386 }
387 });
388
389 this.newMenu.add(this.textBasedGamesIM);
390 }
391
392
393
394
395 private void createItemMenuHelpAbout()
396 {
397 this.helpMenu.addSeparator();
398
399 this.aboutIM = MainMenu.addMenuItem("cs.pancava.caltha.MainMenu-createItemMenuHelpAbout_aboutIM",
400 "cs.pancava.caltha.MainMenu-createItemMenuHelpAbout_aboutIM_tip",
401 true);
402
403 this.aboutIM.addActionListener(new ActionListener()
404 {
405 @Override
406 public void actionPerformed(final ActionEvent e)
407 {
408 showAboutDialog();
409 }
410 });
411
412 this.helpMenu.add(this.aboutIM);
413 }
414
415
416
417
418 private void createItemMenuOptionsLanguageCzech()
419 {
420 this.czechIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageCzech_czechIM",
421 true,
422 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageCzech_czechIM",
423 true);
424
425 this.czechIM.addItemListener(new ItemListener()
426 {
427 @Override
428 public void itemStateChanged(final ItemEvent e)
429 {
430 czechIM_itemStateChanged(e);
431 }
432 });
433
434 this.languageMenu.add(this.czechIM);
435 }
436
437
438
439
440 private void createItemMenuOptionsLanguageEnglish()
441 {
442 this.englishIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageEnglish_englishIM",
443 false,
444 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageEnglish_englishIM_tip",
445 true);
446
447 this.englishIM.addItemListener(new ItemListener()
448 {
449 @Override
450 public void itemStateChanged(final ItemEvent e)
451 {
452 englishIM_itemStateChanged(e);
453 }
454 });
455
456 this.languageMenu.add(this.englishIM);
457 }
458
459
460
461
462 private void createItemMenuOptionsLookAndFeelDefaultLaF()
463 {
464 this.defaultLaFIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelDefaultLaF_defaultLaFIM",
465 true,
466 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelDefaultLaF_defaultLaFIM_tip",
467 true);
468
469 this.defaultLaFIM.addItemListener(new ItemListener()
470 {
471 @Override
472 public void itemStateChanged(final ItemEvent e)
473 {
474 defaultLaFIM_itemStateChanged(e);
475 }
476 });
477
478 this.lookAndFeelMenu.add(this.defaultLaFIM);
479 }
480
481
482
483
484 private void createItemMenuOptionsLookAndFeelGtkLaF()
485 {
486 this.gtkLaFIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelGtkLaF_gtkLaFIM",
487 false,
488 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelGtkLaF_gtkLaFIM_tip",
489 true);
490
491 this.gtkLaFIM.addItemListener(new ItemListener()
492 {
493 @Override
494 public void itemStateChanged(final ItemEvent e)
495 {
496 gtkLaFIM_itemStateChanged(e);
497 }
498 });
499
500 this.lookAndFeelMenu.add(this.gtkLaFIM);
501 }
502
503
504
505
506 private void createItemMenuOptionsLookAndFeelMacLaF()
507 {
508 this.macLaFIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMacLaF_macLaFIM",
509 false,
510 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMacLaF_macLaFIM_tip",
511 true);
512
513 this.macLaFIM.addItemListener(new ItemListener()
514 {
515 @Override
516 public void itemStateChanged(final ItemEvent e)
517 {
518 macLaFIM_itemStateChanged(e);
519 }
520 });
521
522 this.lookAndFeelMenu.add(this.macLaFIM);
523 }
524
525
526
527
528 private void createItemMenuOptionsLookAndFeelMetalLaF()
529 {
530 this.metalLaFIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalLaF_metalLaFIM",
531 false,
532 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalLaF_metalLaFIM_tip",
533 true);
534
535 this.metalLaFIM.addItemListener(new ItemListener()
536 {
537 @Override
538 public void itemStateChanged(final ItemEvent e)
539 {
540 metalLaFIM_itemStateChanged(e);
541 }
542 });
543
544 this.lookAndFeelMenu.add(this.metalLaFIM);
545 }
546
547
548
549
550 private void createItemMenuOptionsLookAndFeelMetalThemeDefault()
551 {
552 this.defaultMetalThemeIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeDefault_defaultMetalThemeIM",
553 true,
554 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeDefault_defaultMetalThemeIM_tip",
555 true);
556
557 this.defaultMetalThemeIM.addItemListener(new ItemListener()
558 {
559 @Override
560 public void itemStateChanged(final ItemEvent e)
561 {
562 defaultMetalThemeIM_itemStateChanged(e);
563 }
564 });
565
566 this.metalThemeMenu.add(this.defaultMetalThemeIM);
567 }
568
569
570
571
572 private void createItemMenuOptionsLookAndFeelMetalThemeMyMetal()
573 {
574 this.myMetalThemeIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeMyMetal_myMetalThemeIM",
575 false,
576 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeMyMetal_myMetalThemeIM_tip",
577 true);
578
579 this.myMetalThemeIM.addItemListener(new ItemListener()
580 {
581 @Override
582 public void itemStateChanged(final ItemEvent e)
583 {
584 myMetalThemeIM_itemStateChanged(e);
585 }
586 });
587
588 this.metalThemeMenu.add(this.myMetalThemeIM);
589 }
590
591
592
593
594 private void createItemMenuOptionsLookAndFeelMetalThemeOcean()
595 {
596 this.oceanMetalThemeIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeOcean_oceanMetalThemeIM",
597 false,
598 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeOcean_oceanMetalThemeIM_tip",
599 true);
600
601 this.oceanMetalThemeIM.addItemListener(new ItemListener()
602 {
603 @Override
604 public void itemStateChanged(final ItemEvent e)
605 {
606 oceanMetalThemeIM_itemStateChanged(e);
607 }
608 });
609
610 this.metalThemeMenu.add(this.oceanMetalThemeIM);
611 }
612
613
614
615
616 private void createItemMenuOptionsLookAndFeelMotifLaF()
617 {
618 this.motifLaFIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMotifLaF_motifLaFIM",
619 false,
620 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMotifLaF_motifLaFIM_tip",
621 true);
622
623 this.motifLaFIM.addItemListener(new ItemListener()
624 {
625 @Override
626 public void itemStateChanged(final ItemEvent e)
627 {
628 motifLaFIM_itemStateChanged(e);
629 }
630 });
631
632 this.lookAndFeelMenu.add(this.motifLaFIM);
633 }
634
635
636
637
638 private void createItemMenuOptionsLookAndFeelWindowsLaF()
639 {
640 this.windowsLaFIM = this.addCheckBoxMenuItem("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelWindowsLaF_windowsLaFIM",
641 false,
642 "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelWindowsLaF_windowsLaFIM_tip",
643 true);
644
645 this.windowsLaFIM.addItemListener(new ItemListener()
646 {
647 @Override
648 public void itemStateChanged(final ItemEvent e)
649 {
650 windowsLaFIM_itemStateChanged(e);
651 }
652 });
653
654 this.lookAndFeelMenu.add(this.windowsLaFIM);
655 }
656
657
658
659
660 private void createMenuFile()
661 {
662 this.fileMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuFile_fileMenu",
663 "cs.pancava.caltha.MainMenu-createMenuFile_fileMenu",
664 "cs.pancava.caltha.MainMenu-createMenuFile_fileMenu_tip");
665
666 this.createMenuFileNew();
667 this.createItemMenuFileExit();
668
669 this.menuBar.add(this.fileMenu);
670 }
671
672
673
674
675 private void createMenuFileNew()
676 {
677 this.newMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuFileNew_newMenu",
678 "cs.pancava.caltha.MainMenu-createMenuFileNew_newMenu",
679 "cs.pancava.caltha.MainMenu-createMenuFileNew_newMenu_tip");
680
681 this.createItemMenuFileNewTextBasedGames();
682
683 this.fileMenu.add(this.newMenu);
684 }
685
686
687
688
689 private void createMenuHelp()
690 {
691 this.helpMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuHelp_helpMenu",
692 "cs.pancava.caltha.MainMenu-createMenuHelp_helpMenu",
693 "cs.pancava.caltha.MainMenu-createMenuHelp_helpMenu_tip");
694
695
696
697 this.createItemMenuHelpAbout();
698
699 this.menuBar.add(this.helpMenu);
700 }
701
702
703
704
705 private void createMenuOptions()
706 {
707 this.optionsMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuOptions_optionsMenu",
708 "cs.pancava.caltha.MainMenu-createMenuOptions_optionsMenu",
709 "cs.pancava.caltha.MainMenu-createMenuOptions_optionsMenu_tip");
710
711 this.createMenuOptionsLanguage();
712
713 this.optionsMenu.addSeparator();
714
715 this.createMenuOptionsLookAndFeel();
716
717 this.menuBar.add(this.optionsMenu);
718 }
719
720
721
722
723 private void createMenuOptionsLanguage()
724 {
725 this.languageMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuOptionsLanguage_languageMenu",
726 "cs.pancava.caltha.MainMenu-createMenuOptionsLanguage_languageMenu",
727 "cs.pancava.caltha.MainMenu-createMenuOptionsLanguage_languageMenu_tip");
728
729 this.createItemMenuOptionsLanguageCzech();
730 this.createItemMenuOptionsLanguageEnglish();
731
732 this.optionsMenu.add(this.languageMenu);
733 }
734
735
736
737
738 private void createMenuOptionsLookAndFeel()
739 {
740 this.lookAndFeelMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeel_lookAndFeelMenu",
741 "cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeel_lookAndFeelMenu",
742 "cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeel_lookAndFeelMenu_tip");
743
744 this.createItemMenuOptionsLookAndFeelDefaultLaF();
745 this.createItemMenuOptionsLookAndFeelGtkLaF();
746 this.createItemMenuOptionsLookAndFeelMacLaF();
747 this.createItemMenuOptionsLookAndFeelMetalLaF();
748 this.createItemMenuOptionsLookAndFeelMotifLaF();
749 this.createItemMenuOptionsLookAndFeelWindowsLaF();
750 this.createMenuOptionsLookAndFeelMetalTheme();
751
752 this.optionsMenu.add(this.lookAndFeelMenu);
753 }
754
755
756
757
758 private void createMenuOptionsLookAndFeelMetalTheme()
759 {
760 this.metalThemeMenu = this.addMenu("cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeelMetalTheme_metalThemeMenu",
761 null,
762 "cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeelMetalTheme_metalThemeMenu_tip");
763
764 this.createItemMenuOptionsLookAndFeelMetalThemeDefault();
765 this.createItemMenuOptionsLookAndFeelMetalThemeOcean();
766 this.createItemMenuOptionsLookAndFeelMetalThemeMyMetal();
767
768 this.metalThemeMenu.setEnabled(false);
769
770 this.lookAndFeelMenu.add(this.metalThemeMenu);
771 }
772
773
774
775
776
777 private void czechIM_itemStateChanged(final ItemEvent e)
778 {
779 if (e.getStateChange() == ItemEvent.SELECTED)
780 {
781 this.englishIM.setSelected(false);
782
783 try
784 {
785 Editor.setResourcesBundle(ResourceBundle.getBundle("Caltha", Editor.getCzLocale()));
786 }
787 catch (MissingResourceException mre)
788 {
789 Editor.errorMissingResource(mre.getMessage());
790 }
791
792 this.updateText();
793 }
794 else
795 {
796 if (!this.englishIM.isSelected())
797 {
798 this.czechIM.setSelected(true);
799 }
800 }
801 }
802
803
804
805
806
807 private void defaultLaFIM_itemStateChanged(final ItemEvent e)
808 {
809 if (e.getStateChange() == ItemEvent.SELECTED)
810 {
811 this.gtkLaFIM.setSelected(false);
812 this.macLaFIM.setSelected(false);
813 this.metalLaFIM.setSelected(false);
814 this.motifLaFIM.setSelected(false);
815 this.windowsLaFIM.setSelected(false);
816
817 this.metalThemeMenu.setEnabled(false);
818
819 this.setLookAndFeel(UIManager.getSystemLookAndFeelClassName(), null);
820 }
821 else
822 {
823 if ((!this.gtkLaFIM.isSelected())
824 && (!this.macLaFIM.isSelected())
825 && (!this.metalLaFIM.isSelected())
826 && (!this.motifLaFIM.isSelected())
827 && (!this.windowsLaFIM.isSelected()))
828 {
829 this.defaultLaFIM.setSelected(true);
830 }
831 }
832 }
833
834
835
836
837
838 private void defaultMetalThemeIM_itemStateChanged(final ItemEvent e)
839 {
840 if (e.getStateChange() == ItemEvent.SELECTED)
841 {
842 this.oceanMetalThemeIM.setSelected(false);
843 this.myMetalThemeIM.setSelected(false);
844
845 this.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel", "DefaultMetal");
846 }
847 else
848 {
849 if ((!this.oceanMetalThemeIM.isSelected())
850 && (!this.myMetalThemeIM.isSelected()))
851 {
852 this.defaultMetalThemeIM.setSelected(true);
853 }
854 }
855 }
856
857
858
859
860
861 private void englishIM_itemStateChanged(final ItemEvent e)
862 {
863 if (e.getStateChange() == ItemEvent.SELECTED)
864 {
865 this.czechIM.setSelected(false);
866
867 try
868 {
869 Editor.setResourcesBundle(ResourceBundle.getBundle("Caltha", Locale.ENGLISH));
870 }
871 catch (MissingResourceException mre)
872 {
873 Editor.errorMissingResource(mre.getMessage());
874 }
875
876 this.updateText();
877 }
878 else
879 {
880 if (!this.czechIM.isSelected())
881 {
882 this.englishIM.setSelected(true);
883 }
884 }
885 }
886
887
888
889
890
891 private void gtkLaFIM_itemStateChanged(final ItemEvent e)
892 {
893 if (e.getStateChange() == ItemEvent.SELECTED)
894 {
895 this.defaultLaFIM.setSelected(false);
896 this.macLaFIM.setSelected(false);
897 this.metalLaFIM.setSelected(false);
898 this.motifLaFIM.setSelected(false);
899 this.windowsLaFIM.setSelected(false);
900
901 this.metalThemeMenu.setEnabled(false);
902
903 this.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel", null);
904 }
905 else
906 {
907 if ((!this.defaultLaFIM.isSelected())
908 && (!this.macLaFIM.isSelected())
909 && (!this.metalLaFIM.isSelected())
910 && (!this.motifLaFIM.isSelected())
911 && (!this.windowsLaFIM.isSelected()))
912 {
913 gtkLaFIM.setSelected(true);
914 }
915 }
916 }
917
918
919
920
921
922
923 public static boolean isEmpty(final String s)
924 {
925
926 final String t = s.trim();
927
928 if (t.length() == 0)
929 {
930 return true;
931 }
932
933 return false;
934 }
935
936
937
938
939
940 private void macLaFIM_itemStateChanged(final ItemEvent e)
941 {
942 if (e.getStateChange() == ItemEvent.SELECTED)
943 {
944 this.defaultLaFIM.setSelected(false);
945 this.gtkLaFIM.setSelected(false);
946 this.metalLaFIM.setSelected(false);
947 this.motifLaFIM.setSelected(false);
948 this.windowsLaFIM.setSelected(false);
949
950 this.metalThemeMenu.setEnabled(false);
951
952 this.setLookAndFeel("com.sun.java.swing.plaf.mac.MacLookAndFeel", null);
953 }
954 else
955 {
956 if ((!this.defaultLaFIM.isSelected())
957 && (!this.gtkLaFIM.isSelected())
958 && (!this.metalLaFIM.isSelected())
959 && (!this.motifLaFIM.isSelected())
960 && (!this.windowsLaFIM.isSelected()))
961 {
962 this.macLaFIM.setSelected(true);
963 }
964 }
965 }
966
967
968
969
970
971 private void metalLaFIM_itemStateChanged(final ItemEvent e)
972 {
973 if (e.getStateChange() == ItemEvent.SELECTED)
974 {
975 this.defaultLaFIM.setSelected(false);
976 this.gtkLaFIM.setSelected(false);
977 this.macLaFIM.setSelected(false);
978 this.motifLaFIM.setSelected(false);
979 this.windowsLaFIM.setSelected(false);
980
981 this.metalThemeMenu.setEnabled(true);
982
983 this.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel", "DefaultMetal");
984 }
985 else
986 {
987 if ((!this.defaultLaFIM.isSelected())
988 && (!this.gtkLaFIM.isSelected())
989 && (!this.macLaFIM.isSelected())
990 && (!this.motifLaFIM.isSelected())
991 && (!this.windowsLaFIM.isSelected()))
992 {
993 this.metalLaFIM.setSelected(true);
994 }
995 }
996 }
997
998
999
1000
1001
1002 private void motifLaFIM_itemStateChanged(final ItemEvent e)
1003 {
1004 if (e.getStateChange() == ItemEvent.SELECTED)
1005 {
1006 this.defaultLaFIM.setSelected(false);
1007 this.gtkLaFIM.setSelected(false);
1008 this.macLaFIM.setSelected(false);
1009 this.metalLaFIM.setSelected(false);
1010 this.windowsLaFIM.setSelected(false);
1011
1012 this.metalThemeMenu.setEnabled(false);
1013
1014 this.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel", null);
1015 }
1016 else
1017 {
1018 if ((!this.defaultLaFIM.isSelected())
1019 && (!this.gtkLaFIM.isSelected())
1020 && (!this.macLaFIM.isSelected())
1021 && (!this.metalLaFIM.isSelected())
1022 && (!this.windowsLaFIM.isSelected()))
1023 {
1024 this.motifLaFIM.setSelected(true);
1025 }
1026 }
1027 }
1028
1029
1030
1031
1032
1033 private void myMetalThemeIM_itemStateChanged(final ItemEvent e)
1034 {
1035 if (e.getStateChange() == ItemEvent.SELECTED)
1036 {
1037 this.oceanMetalThemeIM.setSelected(false);
1038 this.defaultMetalThemeIM.setSelected(false);
1039
1040 this.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel", "MyMetal");
1041 }
1042 else
1043 {
1044 if ((!this.defaultMetalThemeIM.isSelected())
1045 && (!this.oceanMetalThemeIM.isSelected()))
1046 {
1047 this.myMetalThemeIM.setSelected(true);
1048 }
1049 }
1050 }
1051
1052
1053
1054
1055
1056 private void oceanMetalThemeIM_itemStateChanged(final ItemEvent e)
1057 {
1058 if (e.getStateChange() == ItemEvent.SELECTED)
1059 {
1060 this.defaultMetalThemeIM.setSelected(false);
1061 this.myMetalThemeIM.setSelected(false);
1062
1063 this.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel", "Ocean");
1064 }
1065 else
1066 {
1067 if ((!this.defaultMetalThemeIM.isSelected())
1068 && (this.myMetalThemeIM.isSelected()))
1069 {
1070 this.oceanMetalThemeIM.setSelected(true);
1071 }
1072 }
1073 }
1074
1075
1076
1077
1078
1079
1080 private void setLookAndFeel(final String vzhled, final String tema)
1081 {
1082 try
1083 {
1084 UIManager.setLookAndFeel(vzhled);
1085
1086 if (vzhled.equals("javax.swing.plaf.metal.MetalLookAndFeel"))
1087 {
1088 if (tema != null)
1089 {
1090 if (tema.equals("DefaultMetal"))
1091 {
1092 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
1093 }
1094 else if (tema.equals("Ocean"))
1095 {
1096 MetalLookAndFeel.setCurrentTheme(new OceanTheme());
1097 }
1098 else if (tema.equals("MyMetal"))
1099 {
1100 MetalLookAndFeel.setCurrentTheme(new MyTheme());
1101 }
1102 else
1103 {
1104 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
1105 }
1106 }
1107 UIManager.setLookAndFeel(new MetalLookAndFeel());
1108 }
1109
1110 SwingUtilities.updateComponentTreeUI(Editor.getCalthaEditor());
1111 }
1112 catch (ClassNotFoundException e)
1113 {
1114 try
1115 {
1116 final String msg1 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_ClassNotFoundException_msg1");
1117 final String msg2 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_ClassNotFoundException_msg2");
1118 final String msg3 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_ClassNotFoundException_msg3");
1119 final String tit = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_ClassNotFoundException_tit");
1120
1121 Editor.showDialog(msg1 + " " + vzhled + " " + msg2 + "\n" + e.getMessage() + "\n" + msg3,
1122 tit,
1123 JOptionPane.WARNING_MESSAGE);
1124
1125 this.defaultLaFIM.doClick();
1126 }
1127 catch (MissingResourceException mre)
1128 {
1129 Editor.showDialogMissingResources(mre.getMessage());
1130 }
1131 }
1132 catch (UnsupportedLookAndFeelException e)
1133 {
1134 try
1135 {
1136 final String msg1 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_UnsupportedLookAndFeelException_msg1");
1137 final String msg2 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_UnsupportedLookAndFeelException_msg2");
1138 final String tit = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_UnsupportedLookAndFeelException_tit");
1139
1140 Editor.showDialog(msg1 + " " + vzhled + "\n" + e.getMessage() + "\n" + msg2,
1141 tit,
1142 JOptionPane.WARNING_MESSAGE);
1143
1144 this.defaultLaFIM.doClick();
1145 }
1146 catch (MissingResourceException mre)
1147 {
1148 Editor.showDialogMissingResources(mre.getMessage());
1149 }
1150 }
1151 catch (Exception e)
1152 {
1153 try
1154 {
1155 final String msg1 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_Exception_msg1");
1156 final String msg2 = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_Exception_msg2");
1157 final String tit = Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-setLookAndFeel_Exception_tit");
1158
1159 Editor.showDialog(msg1 + " " + vzhled + "\n" + e.getMessage() + "\n" + msg2,
1160 tit,
1161 JOptionPane.WARNING_MESSAGE);
1162
1163 this.defaultLaFIM.doClick();
1164 }
1165 catch (MissingResourceException mre)
1166 {
1167 Editor.showDialogMissingResources(mre.getMessage());
1168 }
1169 }
1170 }
1171
1172
1173
1174
1175 private void showAboutDialog()
1176 {
1177 final AboutDialog ad = new AboutDialog();
1178 ad.setVisible(true);
1179 }
1180
1181
1182
1183
1184
1185 private void updateText()
1186 {
1187 Editor.getCalthaEditor().updateText();
1188
1189 World2DPopupMenuListener.updateText();
1190
1191 try
1192 {
1193 this.fileMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuFile_fileMenu"));
1194 this.updateTextTipMenu(this.fileMenu, "cs.pancava.caltha.MainMenu-createMenuFile_fileMenu_tip");
1195
1196 this.newMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuFileNew_newMenu"));
1197 this.updateTextTipMenu(this.newMenu, "cs.pancava.caltha.MainMenu-createMenuFileNew_newMenu_tip");
1198
1199 this.textBasedGamesIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuFileNewTextBasedGames_textBasedGamesIM"));
1200 MainMenu.updateTextTipMenuItem(this.textBasedGamesIM, "cs.pancava.caltha.MainMenu-createItemMenuFileNewTextBasedGames_textBasedGamesIM_tip");
1201
1202 this.exitIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuFileExit_exitIM"));
1203 MainMenu.updateTextTipMenuItem(this.exitIM, "cs.pancava.caltha.MainMenu-createItemMenuFileExit_exitIM_tip");
1204
1205 this.optionsMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuOptions_optionsMenu"));
1206 this.updateTextTipMenu(this.optionsMenu, "cs.pancava.caltha.MainMenu-createMenuOptions_optionsMenu_tip");
1207
1208 this.languageMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuOptionsLanguage_languageMenu"));
1209 this.updateTextTipMenu(this.languageMenu, "cs.pancava.caltha.MainMenu-createMenuOptionsLanguage_languageMenu_tip");
1210
1211 this.czechIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageCzech_czechIM"));
1212 this.updateTextTipCheckBoxMenuItem(this.czechIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageCzech_czechIM_tip");
1213
1214 this.englishIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageEnglish_englishIM"));
1215 this.updateTextTipCheckBoxMenuItem(this.englishIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLanguageEnglish_englishIM_tip");
1216
1217 this.lookAndFeelMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeel_lookAndFeelMenu"));
1218 this.updateTextTipMenu(this.lookAndFeelMenu, "cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeel_lookAndFeelMenu_tip");
1219
1220 this.defaultLaFIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelDefaultLaF_defaultLaFIM"));
1221 this.updateTextTipCheckBoxMenuItem(this.defaultLaFIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelDefaultLaF_defaultLaFIM_tip");
1222
1223 this.gtkLaFIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelGtkLaF_gtkLaFIM"));
1224 this.updateTextTipCheckBoxMenuItem(this.gtkLaFIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelGtkLaF_gtkLaFIM_tip");
1225
1226 this.macLaFIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMacLaF_macLaFIM"));
1227 this.updateTextTipCheckBoxMenuItem(this.macLaFIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMacLaF_macLaFIM_tip");
1228
1229 this.metalLaFIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalLaF_metalLaFIM"));
1230 this.updateTextTipCheckBoxMenuItem(this.metalLaFIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalLaF_metalLaFIM_tip");
1231
1232 this.motifLaFIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMotifLaF_motifLaFIM"));
1233 this.updateTextTipCheckBoxMenuItem(this.motifLaFIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMotifLaF_motifLaFIM_tip");
1234
1235 this.windowsLaFIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelWindowsLaF_windowsLaFIM"));
1236 this.updateTextTipCheckBoxMenuItem(this.windowsLaFIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelWindowsLaF_windowsLaFIM_tip");
1237
1238 this.metalThemeMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeelMetalTheme_metalThemeMenu"));
1239 this.updateTextTipCheckBoxMenuItem(this.metalThemeMenu, "cs.pancava.caltha.MainMenu-createMenuOptionsLookAndFeelMetalTheme_metalThemeMenu_tip");
1240
1241 this.defaultMetalThemeIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeDefault_defaultMetalThemeIM"));
1242 this.updateTextTipCheckBoxMenuItem(this.defaultMetalThemeIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeDefault_defaultMetalThemeIM_tip");
1243
1244 this.oceanMetalThemeIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeOcean_oceanMetalThemeIM"));
1245 this.updateTextTipCheckBoxMenuItem(this.oceanMetalThemeIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeOcean_oceanMetalThemeIM_tip");
1246
1247 this.myMetalThemeIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeMyMetal_myMetalThemeIM"));
1248 this.updateTextTipCheckBoxMenuItem(this.myMetalThemeIM, "cs.pancava.caltha.MainMenu-createItemMenuOptionsLookAndFeelMetalThemeMyMetal_myMetalThemeIM_tip");
1249
1250 this.helpMenu.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createMenuHelp_helpMenu"));
1251 this.updateTextTipMenu(this.helpMenu, "cs.pancava.caltha.MainMenu-createMenuHelp_helpMenu_tip");
1252
1253 this.aboutIM.setText(Editor.getResourcesBundleString("cs.pancava.caltha.MainMenu-createItemMenuHelpAbout_aboutIM"));
1254 MainMenu.updateTextTipMenuItem(this.aboutIM, "cs.pancava.caltha.MainMenu-createItemMenuHelpAbout_aboutIM");
1255 }
1256 catch (MissingResourceException e)
1257 {
1258 Editor.showDialogMissingResources(e.getMessage());
1259 }
1260 }
1261
1262
1263
1264
1265
1266
1267 private void updateTextTipCheckBoxMenuItem(final JCheckBoxMenuItem cbmi, final String tip)
1268 {
1269 if (Editor.getResourcesBundleString(tip).trim().length() != 0)
1270 {
1271 cbmi.setToolTipText(Editor.getResourcesBundleString(tip));
1272 }
1273 }
1274
1275
1276
1277
1278
1279
1280 private void updateTextTipCheckBoxMenuItem(final JMenu m, final String tip)
1281 {
1282 if (Editor.getResourcesBundleString(tip).trim().length() != 0)
1283 {
1284 m.setToolTipText(Editor.getResourcesBundleString(tip));
1285 }
1286 }
1287
1288
1289
1290
1291
1292
1293 private void updateTextTipMenu(final JMenu m, final String tip)
1294 {
1295 if (Editor.getResourcesBundleString(tip).trim().length() != 0)
1296 {
1297 m.setToolTipText(Editor.getResourcesBundleString(tip));
1298 }
1299 }
1300
1301
1302
1303
1304
1305
1306 public static void updateTextTipMenuItem(final JMenuItem mi, final String tip)
1307 {
1308 if (Editor.getResourcesBundleString(tip).trim().length() != 0)
1309 {
1310 mi.setToolTipText(Editor.getResourcesBundleString(tip));
1311 }
1312 }
1313
1314
1315
1316
1317
1318 private void windowsLaFIM_itemStateChanged(final ItemEvent e)
1319 {
1320 if (e.getStateChange() == ItemEvent.SELECTED)
1321 {
1322 this.defaultLaFIM.setSelected(false);
1323 this.gtkLaFIM.setSelected(false);
1324 this.macLaFIM.setSelected(false);
1325 this.metalLaFIM.setSelected(false);
1326 this.motifLaFIM.setSelected(false);
1327
1328 this.metalThemeMenu.setEnabled(false);
1329
1330 this.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel", null);
1331 }
1332 else
1333 {
1334 if ((!this.defaultLaFIM.isSelected())
1335 && (!this.gtkLaFIM.isSelected())
1336 && (!this.macLaFIM.isSelected())
1337 && (!this.metalLaFIM.isSelected())
1338 && (!this.motifLaFIM.isSelected()))
1339 {
1340 this.windowsLaFIM.setSelected(true);
1341 }
1342 }
1343 }
1344 }