1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package ch.elca.el4j.services.gui.swing.mdi;
23
24 import java.awt.Point;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.ContainerEvent;
28 import java.awt.event.ContainerListener;
29 import java.util.Arrays;
30 import java.util.Hashtable;
31
32 import javax.swing.JDesktopPane;
33 import javax.swing.JInternalFrame;
34 import javax.swing.JMenu;
35 import javax.swing.JRadioButtonMenuItem;
36 import javax.swing.UIManager;
37 import javax.swing.WindowConstants;
38 import javax.swing.event.InternalFrameEvent;
39 import javax.swing.event.InternalFrameListener;
40
41 import ch.elca.el4j.services.gui.swing.mdi.JInternalFrameComparator;
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 public final class WindowManager {
77
78
79
80
81 private int m_lastMenuItemsCount = 0;
82
83
84
85
86 private final Hashtable<JRadioButtonMenuItem, JInternalFrame> m_radioMenuItemsAndFrames = new Hashtable<JRadioButtonMenuItem, JInternalFrame>();
87
88
89
90
91 private final Hashtable<JInternalFrame, JRadioButtonMenuItem> m_framesAndRadioMenuItems = new Hashtable<JInternalFrame, JRadioButtonMenuItem>();
92
93
94
95
96 private final JInternalFrameComparator m_frameComparator = new JInternalFrameComparator();
97
98
99
100
101 private final FrameListener m_frameListener = new FrameListener();
102
103
104
105
106 private final SelectFrameListener m_selectFrameListener = new SelectFrameListener();
107
108
109
110
111 private final MenuItemActionListener m_radioMenuItemListener = new MenuItemActionListener();
112
113
114
115
116 private JDesktopPane m_desktop = null;
117
118
119
120
121 private JMenu m_windowsMenu = null;
122
123
124
125
126 private boolean m_outlineDragMode = false;
127
128
129
130
131 private boolean m_deiconifiablePolicy = false;
132
133
134
135
136 private boolean m_closePolicy = false;
137
138
139
140
141 private boolean m_autoPositionPolicy = true;
142
143
144
145
146
147 private Point m_nextFramePos = new Point(0, 0);
148
149
150
151
152
153
154 private void close_frame(JInternalFrame f) {
155 if (f != null && !f.isClosed() && f.isClosable()) {
156 try {
157 if (m_closePolicy) {
158 f.setClosed(true);
159 } else {
160 f.doDefaultCloseAction();
161 }
162 } catch (Exception e) {
163 e.printStackTrace();
164 }
165 }
166 }
167
168
169
170
171
172
173 private void iconify_frame(JInternalFrame f) {
174 if (f != null && !f.isIcon() && f.isIconifiable()) {
175 try {
176 f.setIcon(true);
177 } catch (Exception e) {
178 e.printStackTrace();
179 }
180 }
181 }
182
183
184
185
186
187
188 private void deiconify_frame(JInternalFrame f) {
189 if (f != null && f.isIcon() && f.isIconifiable()) {
190 try {
191 f.setIcon(false);
192 } catch (Exception e) {
193 e.printStackTrace();
194 }
195 }
196 }
197
198
199
200
201
202
203 private void restore_frame(JInternalFrame f) {
204 if (f != null) {
205 try {
206 f.setMaximum(false);
207 } catch (Exception e) {
208 e.printStackTrace();
209 }
210 }
211 }
212
213
214
215
216
217
218 private void maximize_frame(JInternalFrame f) {
219 if (f != null && !f.isMaximum() && f.isMaximizable()) {
220 try {
221 f.setMaximum(true);
222 } catch (Exception e) {
223 e.printStackTrace();
224 }
225 }
226 }
227
228
229
230
231
232
233 private void reset_frame(JInternalFrame f) {
234 if (f != null) {
235 f.pack();
236 }
237 }
238
239
240
241
242
243
244 private void select_frame(JInternalFrame f) {
245 if (f != null && !f.isSelected()) {
246 try {
247 f.setSelected(true);
248 f.toFront();
249 } catch (Exception e) {
250 e.printStackTrace();
251 }
252 }
253 }
254
255
256
257
258
259
260 private void hide_frame(JInternalFrame f) {
261 if (f != null && f.isVisible()) {
262 f.setVisible(false);
263
264 if (f.isSelected()) {
265 try {
266 f.setSelected(false);
267 } catch (Exception e) {
268 e.printStackTrace();
269 }
270 }
271
272
273 m_frameListener.manualFireEvent();
274 }
275 }
276
277
278
279
280
281
282
283
284
285
286
287
288 private boolean is_internal_frame_listener_attached(JInternalFrame jif) {
289 boolean found = false;
290
291 InternalFrameListener[] all = jif.getInternalFrameListeners();
292 for (int i = 0; i < all.length; i++) {
293 if (all[i] == m_selectFrameListener) {
294 found = true;
295 break;
296 }
297 }
298
299 return (found);
300 }
301
302
303
304
305
306
307
308
309 public WindowManager(JDesktopPane d, JMenu windowsMenu) {
310 m_desktop = d;
311 m_windowsMenu = windowsMenu;
312
313 if (m_desktop == null) {
314 throw new NullPointerException(
315 "JDesktopPane instance provided to WindowManager is NULL!");
316 }
317
318 if (m_windowsMenu == null) {
319 throw new NullPointerException(
320 "JMenu instance provided to WindowManager is NULL!");
321 }
322
323
324
325 m_lastMenuItemsCount = m_windowsMenu.getMenuComponentCount();
326
327
328 m_desktop.addContainerListener(m_frameListener);
329
330
331 JInternalFrame[] frames = m_desktop.getAllFrames();
332 for (int i = 0; frames != null && i < frames.length; i++) {
333 frames[i].addInternalFrameListener(m_selectFrameListener);
334 }
335
336
337
338 m_frameListener.manualFireEvent();
339 }
340
341
342
343
344
345
346
347
348
349 public void setOutlineDragMode(boolean outline) {
350 m_outlineDragMode = outline;
351
352 if (m_desktop != null) {
353 if (m_outlineDragMode) {
354 m_desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
355 } else {
356 m_desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
357 }
358 }
359 }
360
361
362
363
364
365
366
367
368
369 public boolean getOutlineDragMode() {
370 return (m_outlineDragMode);
371 }
372
373
374
375
376
377
378
379 public void setDeiconifiablePolicy(boolean p) {
380 m_deiconifiablePolicy = p;
381 }
382
383
384
385
386
387
388 public boolean getDeiconifiablePolicy() {
389 return (m_deiconifiablePolicy);
390 }
391
392
393
394
395
396
397
398
399 public void setClosePolicy(boolean p) {
400 m_closePolicy = p;
401 }
402
403
404
405
406
407
408
409 public boolean getClosePolicy() {
410 return (m_closePolicy);
411 }
412
413
414
415
416
417
418
419
420 public void setAutoPositionPolicy(boolean p) {
421 m_autoPositionPolicy = p;
422 }
423
424
425
426
427
428
429 public boolean getAutoPositionPolicy() {
430 return (m_autoPositionPolicy);
431 }
432
433
434
435
436
437
438
439
440
441
442 public int countFrames() {
443 if (m_desktop == null || m_desktop.getAllFrames() == null
444 || m_desktop.getAllFrames().length < 1) {
445 return (0);
446 }
447
448 JInternalFrame[] frames = m_desktop.getAllFrames();
449
450 return (frames.length );
451 }
452
453
454
455
456
457
458 public int countVisibleFrames() {
459 if (m_desktop == null || m_desktop.getAllFrames() == null
460 || m_desktop.getAllFrames().length < 1) {
461 return (0);
462 }
463
464 JInternalFrame[] frames = m_desktop.getAllFrames();
465
466 int count = 0;
467 for (int i = 0; i < frames.length; i++) {
468 if (frames[i].isVisible()) {
469 count++;
470 }
471 }
472
473 return (count);
474 }
475
476
477
478
479 public void close() {
480 if (m_desktop == null || m_desktop.getAllFrames() == null
481 || m_desktop.getAllFrames().length < 1) {
482 return;
483 }
484
485 JInternalFrame activeframe = m_desktop.getSelectedFrame();
486
487 close_frame(activeframe);
488 }
489
490
491
492
493 public void closeAll() {
494 if (m_desktop == null || m_desktop.getAllFrames() == null
495 || m_desktop.getAllFrames().length < 1) {
496 return;
497 }
498
499 JInternalFrame[] frames = m_desktop.getAllFrames();
500
501 for (int i = 0; i < frames.length; i++) {
502 close_frame(frames[i]);
503 }
504 }
505
506
507
508
509 public void minimize() {
510 if (m_desktop == null || m_desktop.getAllFrames() == null
511 || m_desktop.getAllFrames().length < 1) {
512 return;
513 }
514
515 JInternalFrame activeframe = m_desktop.getSelectedFrame();
516
517 iconify_frame(activeframe);
518 }
519
520
521
522
523 public void minimizeAll() {
524 if (m_desktop == null || m_desktop.getAllFrames() == null
525 || m_desktop.getAllFrames().length < 1) {
526 return;
527 }
528
529 JInternalFrame[] frames = m_desktop.getAllFrames();
530
531 for (int i = 0; i < frames.length; i++) {
532
533
534 if (!frames[i].isVisible())
535 continue;
536
537 iconify_frame(frames[i]);
538 }
539 }
540
541
542
543
544 public void restore() {
545 if (m_desktop == null || m_desktop.getAllFrames() == null
546 || m_desktop.getAllFrames().length < 1) {
547 return;
548 }
549
550 JInternalFrame activeframe = m_desktop.getSelectedFrame();
551
552 if (activeframe != null) {
553 if (activeframe.isMaximum() || activeframe.isIcon()) {
554
555 deiconify_frame(activeframe);
556
557 restore_frame(activeframe);
558 }
559 }
560 }
561
562
563
564
565 public void restoreAll() {
566 if (m_desktop == null || m_desktop.getAllFrames() == null
567 || m_desktop.getAllFrames().length < 1) {
568 return;
569 }
570
571 JInternalFrame[] frames = m_desktop.getAllFrames();
572
573 for (int i = 0; i < frames.length; i++) {
574
575
576 if (!frames[i].isVisible())
577 continue;
578
579 if (frames[i].isMaximum() || frames[i].isIcon()) {
580
581 deiconify_frame(frames[i]);
582
583 restore_frame(frames[i]);
584 }
585 }
586 }
587
588
589
590
591 public void maximize() {
592 if (m_desktop == null || m_desktop.getAllFrames() == null
593 || m_desktop.getAllFrames().length < 1) {
594 return;
595 }
596
597 JInternalFrame activeframe = m_desktop.getSelectedFrame();
598
599 maximize_frame(activeframe);
600 }
601
602
603
604
605 public void maximizeAll() {
606 if (m_desktop == null || m_desktop.getAllFrames() == null
607 || m_desktop.getAllFrames().length < 1) {
608 return;
609 }
610
611 JInternalFrame[] frames = m_desktop.getAllFrames();
612
613 for (int i = 0; i < frames.length; i++) {
614
615
616 if (!frames[i].isVisible())
617 continue;
618
619 maximize_frame(frames[i]);
620 }
621 }
622
623
624
625
626 public void reset() {
627 if (m_desktop == null || m_desktop.getAllFrames() == null
628 || m_desktop.getAllFrames().length < 1) {
629 return;
630 }
631
632 JInternalFrame activeframe = m_desktop.getSelectedFrame();
633
634 reset_frame(activeframe);
635 }
636
637
638
639
640 public void resetAll() {
641 if (m_desktop == null || m_desktop.getAllFrames() == null
642 || m_desktop.getAllFrames().length < 1) {
643 return;
644 }
645
646 JInternalFrame[] frames = m_desktop.getAllFrames();
647
648 for (int i = 0; i < frames.length; i++) {
649
650
651 if (!frames[i].isVisible())
652 continue;
653
654 reset_frame(frames[i]);
655 }
656 }
657
658
659
660
661
662 public void hide() {
663 if (m_desktop == null || m_desktop.getAllFrames() == null
664 || m_desktop.getAllFrames().length < 1) {
665 return;
666 }
667
668 if (m_windowsMenu == null) {
669 return;
670 }
671
672 JInternalFrame activeframe = m_desktop.getSelectedFrame();
673
674 hide_frame(activeframe);
675 }
676
677
678
679
680
681 public void hideAll() {
682 if (m_desktop == null || m_desktop.getAllFrames() == null
683 || m_desktop.getAllFrames().length < 1) {
684 return;
685 }
686
687 if (m_windowsMenu == null) {
688 return;
689 }
690
691 JInternalFrame[] frames = m_desktop.getAllFrames();
692
693 for (int i = 0; i < frames.length; i++) {
694
695 if (!frames[i].isVisible())
696 continue;
697
698 hide_frame(frames[i]);
699 }
700 }
701
702
703
704
705 public void selectNext() {
706 if (m_desktop == null || m_desktop.getAllFrames() == null
707 || m_desktop.getAllFrames().length < 1) {
708 return;
709 }
710
711 JInternalFrame[] frames = m_desktop.getAllFrames();
712
713
714 if (frames.length < 2) {
715 return;
716 }
717
718 JInternalFrame activeframe = m_desktop.getSelectedFrame();
719
720 if (activeframe == null) {
721 return;
722 }
723
724
725
726
727 Arrays.sort(frames, m_frameComparator);
728
729 int next_frame = -1;
730 for (int i = 0; i < frames.length; i++) {
731
732
733 if (!frames[i].isVisible())
734 continue;
735
736
737 if (frames[i] != activeframe)
738 continue;
739
740
741 for (int j = i + 1; j < frames.length; j++) {
742 if (!frames[j].isIcon()) {
743 next_frame = j;
744 break;
745 }
746 }
747
748
749 if (next_frame == -1) {
750 for (int k = 0; k < i; k++) {
751 if (!frames[k].isIcon()) {
752 next_frame = k;
753 break;
754 }
755 }
756 }
757
758 if (next_frame != -1)
759 break;
760 }
761
762 if (next_frame != -1) {
763 select_frame(frames[next_frame]);
764 }
765 }
766
767
768
769
770 public void selectPrevious() {
771 if (m_desktop == null || m_desktop.getAllFrames() == null
772 || m_desktop.getAllFrames().length < 1) {
773 return;
774 }
775
776 JInternalFrame[] frames = m_desktop.getAllFrames();
777
778
779 if (frames.length < 2) {
780 return;
781 }
782
783 JInternalFrame activeframe = m_desktop.getSelectedFrame();
784
785 if (activeframe == null) {
786 return;
787 }
788
789
790
791
792 Arrays.sort(frames, m_frameComparator);
793
794 int previous_frame = -1;
795 for (int i = 0; i < frames.length; i++) {
796
797
798 if (!frames[i].isVisible())
799 continue;
800
801
802 if (frames[i] != activeframe)
803 continue;
804
805
806 for (int j = i - 1; j >= 0; j--) {
807 if (!frames[j].isIcon()) {
808 previous_frame = j;
809 break;
810 }
811 }
812
813
814 if (previous_frame == -1) {
815 for (int k = frames.length - 1; k > i; k--) {
816 if (!frames[k].isIcon()) {
817 previous_frame = k;
818 break;
819 }
820 }
821 }
822
823 if (previous_frame != -1)
824 break;
825 }
826
827 if (previous_frame != -1) {
828 select_frame(frames[previous_frame]);
829 }
830 }
831
832
833
834
835
836 public void cascade() {
837 if (m_desktop == null || m_desktop.getAllFrames() == null
838 || m_desktop.getAllFrames().length < 1) {
839 return;
840 }
841
842 JInternalFrame activeframe = m_desktop.getSelectedFrame();
843 JInternalFrame[] frames = m_desktop.getAllFrames();
844
845
846 Arrays.sort(frames, m_frameComparator);
847
848 int x = 0;
849 int y = 0;
850 int width = m_desktop.getWidth() / 2;
851 int height = m_desktop.getHeight() / 2;
852
853 for (int i = 0; i < frames.length; i++) {
854
855
856 if (!frames[i].isVisible())
857 continue;
858
859
860 if (m_deiconifiablePolicy == false && frames[i].isIcon())
861 continue;
862
863 deiconify_frame(frames[i]);
864
865 frames[i].reshape(x, y, width, height);
866
867 frames[i].moveToFront();
868
869 if (frames[i] != activeframe) {
870 int next_pos = frames[i].getHeight()
871 - frames[i].getContentPane().getHeight();
872
873 frames[i].setLocation(x, y);
874 x += next_pos;
875 y += next_pos;
876 }
877
878
879 if ((x + width) > m_desktop.getWidth()) {
880 x = 0;
881 }
882 if ((y + height) > m_desktop.getHeight()) {
883 y = 0;
884 }
885 }
886
887
888 if (activeframe != null) {
889 activeframe.moveToFront();
890 activeframe.setLocation(x, y);
891 }
892 }
893
894
895
896
897 public void tileVertically() {
898 if (m_desktop == null || m_desktop.getAllFrames() == null
899 || m_desktop.getAllFrames().length < 1) {
900 return;
901 }
902
903 JInternalFrame[] frames = m_desktop.getAllFrames();
904
905 int visibleFrames = 0;
906 for (int i = 0; i < frames.length; i++) {
907 if (!frames[i].isVisible())
908 continue;
909
910 visibleFrames++;
911 }
912
913 if (visibleFrames == 0)
914 return;
915
916
917 Arrays.sort(frames, m_frameComparator);
918
919 int width = m_desktop.getWidth() / visibleFrames;
920 int height = m_desktop.getHeight();
921 int x = 0;
922
923 for (int i = 0; i < frames.length; i++) {
924
925
926 if (!frames[i].isVisible())
927 continue;
928
929 try {
930 frames[i].setMaximum(false);
931 frames[i].setIcon(false);
932 frames[i].moveToFront();
933 } catch (Exception ex) {
934 ex.printStackTrace();
935 }
936
937 frames[i].reshape(x, 0, width, height);
938
939 x += width;
940 }
941 }
942
943
944
945
946 public void tileHorizontally() {
947 if (m_desktop == null || m_desktop.getAllFrames() == null
948 || m_desktop.getAllFrames().length < 1) {
949 return;
950 }
951
952 JInternalFrame[] frames = m_desktop.getAllFrames();
953
954 int visibleFrames = 0;
955 for (int i = 0; i < frames.length; i++) {
956 if (!frames[i].isVisible())
957 continue;
958
959 visibleFrames++;
960 }
961
962 if (visibleFrames == 0)
963 return;
964
965
966 Arrays.sort(frames, m_frameComparator);
967
968 int width = m_desktop.getWidth();
969 int height = m_desktop.getHeight() / visibleFrames;
970 int y = 0;
971
972 for (int i = 0; i < frames.length; i++) {
973
974
975 if (!frames[i].isVisible())
976 continue;
977
978 try {
979 frames[i].setMaximum(false);
980 frames[i].setIcon(false);
981 frames[i].moveToFront();
982 } catch (Exception ex) {
983 ex.printStackTrace();
984 }
985
986 frames[i].reshape(0, y, width, height);
987
988 y += height;
989 }
990 }
991
992
993
994
995 public void tile() {
996 if (m_desktop == null || m_desktop.getAllFrames() == null
997 || m_desktop.getAllFrames().length < 1) {
998 return;
999 }
1000
1001 JInternalFrame[] frames = m_desktop.getAllFrames();
1002
1003 int visibleFrames = 0;
1004 for (int i = 0; i < frames.length; i++) {
1005 if (!frames[i].isVisible())
1006 continue;
1007
1008 visibleFrames++;
1009 }
1010
1011 if (visibleFrames == 0)
1012 return;
1013
1014
1015 Arrays.sort(frames, m_frameComparator);
1016
1017
1018 int sqrt = (int) Math.sqrt(frames.length);
1019 int numRows = sqrt;
1020 int numCols = sqrt;
1021
1022
1023 if (numRows * numCols < frames.length) {
1024 numCols++;
1025 if (numRows * numCols < frames.length) {
1026 numRows++;
1027 }
1028 }
1029
1030 int width = m_desktop.getWidth() / numCols;
1031 int height = m_desktop.getHeight() / numRows;
1032 int x = 0;
1033 int y = 0;
1034
1035 for (int i = 0; i < numRows; i++) {
1036 for (int j = 0; j < numCols; j++) {
1037 int index = (i * numCols) + j;
1038
1039 if (index >= frames.length)
1040 break;
1041
1042
1043
1044
1045 if (!frames[index].isVisible())
1046 continue;
1047
1048 try {
1049 frames[index].setMaximum(false);
1050 frames[index].setIcon(false);
1051 frames[index].moveToFront();
1052 } catch (Exception ex) {
1053 ex.printStackTrace();
1054 }
1055
1056 frames[index].reshape(x, y, width, height);
1057
1058 x += width;
1059 }
1060
1061 y += height;
1062 x = 0;
1063 }
1064 }
1065
1066
1067
1068
1069
1070
1071
1072 private final class FrameListener implements ContainerListener {
1073
1074
1075
1076
1077 private void rebuild_menu() {
1078 if (m_desktop != null && m_windowsMenu != null) {
1079
1080 while (m_windowsMenu.getMenuComponentCount() > m_lastMenuItemsCount) {
1081 m_windowsMenu
1082 .remove(m_windowsMenu.getMenuComponentCount() - 1);
1083 }
1084
1085 m_radioMenuItemsAndFrames.clear();
1086 m_framesAndRadioMenuItems.clear();
1087
1088
1089 JInternalFrame[] frames = m_desktop.getAllFrames();
1090
1091
1092 Arrays.sort(frames, m_frameComparator);
1093
1094
1095 if (frames.length > 0) {
1096 m_windowsMenu.addSeparator();
1097 }
1098
1099 for (int i = 0; i < frames.length; i++) {
1100 JRadioButtonMenuItem item = new JRadioButtonMenuItem(""
1101 + (i + 1) + ": " + frames[i].getTitle(), frames[i]
1102 .isSelected());
1103
1104
1105 item.setMnemonic(Integer.toString(i + 1).toCharArray()[0]);
1106
1107
1108 if (!frames[i].isVisible()) {
1109 item
1110 .setForeground(UIManager
1111 .getColor("RadioButtonMenuItem.disabledForeground"));
1112 }
1113
1114
1115
1116
1117
1118
1119 item.addActionListener(m_radioMenuItemListener);
1120 m_windowsMenu.add(item);
1121
1122 m_radioMenuItemsAndFrames.put(item, frames[i]);
1123 m_framesAndRadioMenuItems.put(frames[i], item);
1124 }
1125 }
1126 }
1127
1128
1129
1130
1131 public void manualFireEvent() {
1132 rebuild_menu();
1133 }
1134
1135
1136
1137
1138
1139
1140 public void componentAdded(ContainerEvent ce) {
1141
1142 if (m_desktop != null && m_autoPositionPolicy == true
1143 && ce.getChild() != null
1144 && ce.getChild() instanceof JInternalFrame) {
1145 JInternalFrame jif = (JInternalFrame) ce.getChild();
1146 int w = jif.getWidth();
1147 int h = jif.getHeight();
1148
1149
1150
1151
1152
1153 if (countFrames() == 1) {
1154 m_nextFramePos.setLocation(0, 0);
1155 }
1156
1157
1158 jif.setLocation(m_nextFramePos);
1159
1160 int next_pos = h - jif.getContentPane().getHeight();
1161 m_nextFramePos.x += next_pos;
1162 m_nextFramePos.y += next_pos;
1163
1164
1165 if ((m_nextFramePos.x + w) > m_desktop.getWidth()) {
1166 m_nextFramePos.x = 0;
1167 }
1168 if ((m_nextFramePos.y + h) > m_desktop.getHeight()) {
1169 m_nextFramePos.y = 0;
1170 }
1171 }
1172
1173
1174 if (m_desktop != null) {
1175 JInternalFrame[] frames = m_desktop.getAllFrames();
1176 for (int i = 0; frames != null && i < frames.length; i++) {
1177
1178 if (is_internal_frame_listener_attached(frames[i]))
1179 continue;
1180
1181 frames[i].addInternalFrameListener(m_selectFrameListener);
1182 }
1183 }
1184
1185 rebuild_menu();
1186 }
1187
1188
1189
1190
1191
1192
1193 public void componentRemoved(ContainerEvent ce) {
1194 rebuild_menu();
1195 }
1196
1197 }
1198
1199
1200
1201
1202
1203 private final class MenuItemActionListener implements ActionListener {
1204
1205
1206
1207
1208
1209
1210 public void actionPerformed(ActionEvent ae) {
1211 Object o = ae.getSource();
1212
1213 if (o instanceof JRadioButtonMenuItem) {
1214 JRadioButtonMenuItem item = (JRadioButtonMenuItem) o;
1215
1216 JInternalFrame frame = (JInternalFrame) m_radioMenuItemsAndFrames
1217 .get(item);
1218
1219 if (item.isSelected()) {
1220 try {
1221 if (!frame.isVisible()) {
1222 frame.setVisible(true);
1223 frame.toFront();
1224 }
1225
1226 if (!frame.isSelected()) {
1227 frame.setSelected(true);
1228 }
1229
1230 if (frame.isIcon()) {
1231 frame.setIcon(false);
1232 }
1233 } catch (Exception e) {
1234 e.printStackTrace();
1235 }
1236 } else {
1237
1238 item.setSelected(true);
1239 }
1240
1241
1242 m_frameListener.manualFireEvent();
1243 }
1244 }
1245
1246 }
1247
1248
1249
1250
1251 private final class SelectFrameListener implements InternalFrameListener {
1252
1253
1254
1255
1256
1257
1258 public void internalFrameActivated(InternalFrameEvent ife) {
1259 JInternalFrame jif = ife.getInternalFrame();
1260
1261 JRadioButtonMenuItem item = (JRadioButtonMenuItem) m_framesAndRadioMenuItems
1262 .get(jif);
1263
1264 item.setSelected(true);
1265 }
1266
1267
1268
1269
1270
1271
1272 public void internalFrameClosed(InternalFrameEvent ife) {
1273 }
1274
1275
1276
1277
1278
1279
1280 public void internalFrameClosing(InternalFrameEvent ife) {
1281 }
1282
1283
1284
1285
1286
1287
1288 public void internalFrameDeactivated(InternalFrameEvent ife) {
1289 JInternalFrame jif = ife.getInternalFrame();
1290
1291 JRadioButtonMenuItem item = (JRadioButtonMenuItem) m_framesAndRadioMenuItems
1292 .get(jif);
1293
1294 item.setSelected(false);
1295
1296
1297
1298
1299
1300
1301
1302 if (jif.getDefaultCloseOperation() == WindowConstants.HIDE_ON_CLOSE) {
1303
1304 m_frameListener.manualFireEvent();
1305 }
1306 }
1307
1308
1309
1310
1311
1312
1313 public void internalFrameDeiconified(InternalFrameEvent ife) {
1314 }
1315
1316
1317
1318
1319
1320
1321 public void internalFrameIconified(InternalFrameEvent ife) {
1322 }
1323
1324
1325
1326
1327
1328
1329 public void internalFrameOpened(InternalFrameEvent ife) {
1330 }
1331
1332 }
1333
1334 }