1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82:
83:
86: public class BasicInternalFrameUI extends InternalFrameUI
87: {
88:
92: protected class BasicInternalFrameListener implements InternalFrameListener
93: {
94:
99: public void internalFrameActivated(InternalFrameEvent e)
100: {
101: frame.getGlassPane().setVisible(false);
102: }
103:
104:
109: public void internalFrameClosed(InternalFrameEvent e)
110: {
111:
112: }
113:
114:
119: public void internalFrameClosing(InternalFrameEvent e)
120: {
121:
122: }
123:
124:
129: public void internalFrameDeactivated(InternalFrameEvent e)
130: {
131: frame.getGlassPane().setVisible(true);
132: }
133:
134:
139: public void internalFrameDeiconified(InternalFrameEvent e)
140: {
141:
142: }
143:
144:
149: public void internalFrameIconified(InternalFrameEvent e)
150: {
151:
152: }
153:
154:
159: public void internalFrameOpened(InternalFrameEvent e)
160: {
161:
162: }
163: }
164:
165:
170: protected class BorderListener extends MouseInputAdapter
171: implements SwingConstants
172: {
173:
176: transient int showingCursor;
177:
178:
179: protected final int RESIZE_NONE = 0;
180:
181:
182: private transient int xOffset;
183:
184:
185: private transient int yOffset;
186:
187:
188: private transient int direction = -1;
189:
190:
191: private transient Rectangle cacheRect = new Rectangle();
192:
193:
198: public void mouseClicked(MouseEvent e)
199: {
200:
201: if (e.getSource() == titlePane && e.getClickCount() == 2)
202: try
203: {
204: if (frame.isMaximizable() && ! frame.isMaximum())
205: frame.setMaximum(true);
206: else if (frame.isMaximum())
207: frame.setMaximum(false);
208: }
209: catch (PropertyVetoException pve)
210: {
211:
212: }
213:
214:
215:
216: }
217:
218:
224: public void mouseDragged(MouseEvent e)
225: {
226:
227:
228: if (frame.isMaximum())
229: return;
230: DesktopManager dm = getDesktopManager();
231: Rectangle b = frame.getBounds();
232: Dimension min = frame.getMinimumSize();
233: if (min == null)
234: min = new Dimension(0, 0);
235: Insets insets = frame.getInsets();
236: int x = e.getX();
237: int y = e.getY();
238: if (e.getSource() == frame && frame.isResizable())
239: {
240: switch (direction)
241: {
242: case Cursor.N_RESIZE_CURSOR:
243: cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
244: - min.height),
245: b.width, b.height - y);
246: break;
247: case Cursor.NE_RESIZE_CURSOR:
248: cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
249: - min.height), x + 1,
250: b.height - y);
251: break;
252: case Cursor.E_RESIZE_CURSOR:
253: cacheRect.setBounds(b.x, b.y, x + 1, b.height);
254: break;
255: case Cursor.SE_RESIZE_CURSOR:
256: cacheRect.setBounds(b.x, b.y, x + 1, y + 1);
257: break;
258: case Cursor.S_RESIZE_CURSOR:
259: cacheRect.setBounds(b.x, b.y, b.width, y + 1);
260: break;
261: case Cursor.SW_RESIZE_CURSOR:
262: cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
263: b.y, b.width - x, y + 1);
264: break;
265: case Cursor.W_RESIZE_CURSOR:
266: cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
267: b.y, b.width - x, b.height);
268: break;
269: case Cursor.NW_RESIZE_CURSOR:
270: cacheRect.setBounds(
271: Math.min(b.x + x, b.x + b.width - min.width),
272: Math.min(b.y + y, b.y + b.height - min.height),
273: b.width - x, b.height - y);
274: break;
275: }
276: dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
277: Math.max(min.width, cacheRect.width),
278: Math.max(min.height, cacheRect.height));
279: setCursor(e);
280: }
281: else if (e.getSource() == titlePane)
282: {
283: Rectangle fBounds = frame.getBounds();
284: frame.putClientProperty("bufferedDragging", Boolean.TRUE);
285: dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset
286: + b.y);
287: }
288: }
289:
290:
295: public void mouseExited(MouseEvent e)
296: {
297: if (showingCursor != Cursor.DEFAULT_CURSOR)
298: {
299: frame.setCursor(Cursor.getDefaultCursor());
300: showingCursor = Cursor.DEFAULT_CURSOR;
301: }
302: }
303:
304:
309: public void mouseMoved(MouseEvent e)
310: {
311:
312: if (showingCursor != Cursor.DEFAULT_CURSOR && e.getSource() != frame)
313: {
314: frame.setCursor(Cursor.getDefaultCursor());
315: showingCursor = Cursor.DEFAULT_CURSOR;
316: }
317: else if (e.getSource() == frame && frame.isResizable())
318: {
319: setCursor(e);
320: }
321: }
322:
323:
328: void setCursor(MouseEvent e)
329: {
330: int cursor = sectionOfClick(e.getX(), e.getY());
331: if (cursor != showingCursor)
332: {
333: Cursor resize = Cursor.getPredefinedCursor(cursor);
334: frame.setCursor(resize);
335: showingCursor = cursor;
336: }
337: }
338:
339:
344: public void mousePressed(MouseEvent e)
345: {
346: activateFrame(frame);
347: DesktopManager dm = getDesktopManager();
348: int x = e.getX();
349: int y = e.getY();
350: Insets insets = frame.getInsets();
351:
352: if (e.getSource() == frame && frame.isResizable())
353: {
354: direction = sectionOfClick(x, y);
355: dm.beginResizingFrame(frame, direction);
356: }
357: else if (e.getSource() == titlePane)
358: {
359: Rectangle tBounds = titlePane.getBounds();
360:
361: xOffset = e.getX() - tBounds.x + insets.left;
362: yOffset = e.getY() - tBounds.y + insets.top;
363:
364: dm.beginDraggingFrame(frame);
365: }
366: }
367:
368:
373: public void mouseReleased(MouseEvent e)
374: {
375: DesktopManager dm = getDesktopManager();
376: xOffset = 0;
377: yOffset = 0;
378: if (e.getSource() == frame && frame.isResizable())
379: dm.endResizingFrame(frame);
380: else if (e.getSource() == titlePane)
381: {
382: dm.endDraggingFrame(frame);
383: frame.putClientProperty("bufferedDragging", null);
384: }
385:
386: setCursor(e);
387: }
388:
389:
398: private int sectionOfClick(int x, int y)
399: {
400: Rectangle b = frame.getBounds();
401: int corner = InternalFrameBorder.cornerSize;
402:
403: if (x < corner && y < corner)
404: return Cursor.NW_RESIZE_CURSOR;
405: else if (x > b.width - corner && y < corner)
406: return Cursor.NE_RESIZE_CURSOR;
407: else if (x > b.width - corner && y > b.height - corner)
408: return Cursor.SE_RESIZE_CURSOR;
409: else if (x < corner && y > b.height - corner)
410: return Cursor.SW_RESIZE_CURSOR;
411: else if (y < corner)
412: return Cursor.N_RESIZE_CURSOR;
413: else if (x < corner)
414: return Cursor.W_RESIZE_CURSOR;
415: else if (y > b.height - corner)
416: return Cursor.S_RESIZE_CURSOR;
417: else if (x > b.width - corner)
418: return Cursor.E_RESIZE_CURSOR;
419:
420: return Cursor.DEFAULT_CURSOR;
421: }
422: }
423:
424:
429: protected class ComponentHandler implements ComponentListener
430: {
431:
437: public void componentHidden(ComponentEvent e)
438: {
439:
440: }
441:
442:
448: public void componentMoved(ComponentEvent e)
449: {
450:
451: }
452:
453:
459: public void componentResized(ComponentEvent e)
460: {
461: if (frame.isMaximum())
462: {
463: JDesktopPane pane = (JDesktopPane) e.getSource();
464: Insets insets = pane.getInsets();
465: Rectangle bounds = pane.getBounds();
466:
467: frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,
468: bounds.width - insets.left - insets.right,
469: bounds.height - insets.top - insets.bottom);
470: frame.revalidate();
471: frame.repaint();
472: }
473:
474:
475: }
476:
477:
483: public void componentShown(ComponentEvent e)
484: {
485:
486: }
487: }
488:
489:
492: public class InternalFrameLayout implements LayoutManager
493: {
494:
503: public void addLayoutComponent(String name, Component c)
504: {
505:
506: }
507:
508:
515: public void layoutContainer(Container c)
516: {
517: Dimension dims = frame.getSize();
518: Insets insets = frame.getInsets();
519:
520: dims.width -= insets.left + insets.right;
521: dims.height -= insets.top + insets.bottom;
522:
523: int nh = 0;
524: int sh = 0;
525: int ew = 0;
526: int ww = 0;
527:
528: if (northPane != null)
529: {
530: Dimension nDims = northPane.getPreferredSize();
531: nh = Math.min(nDims.height, dims.height);
532:
533: northPane.setBounds(insets.left, insets.top, dims.width, nh);
534: }
535:
536: if (southPane != null)
537: {
538: Dimension sDims = southPane.getPreferredSize();
539: sh = Math.min(sDims.height, dims.height - nh);
540:
541: southPane.setBounds(insets.left, insets.top + dims.height - sh,
542: dims.width, sh);
543: }
544:
545: int remHeight = dims.height - sh - nh;
546:
547: if (westPane != null)
548: {
549: Dimension wDims = westPane.getPreferredSize();
550: ww = Math.min(dims.width, wDims.width);
551:
552: westPane.setBounds(insets.left, insets.top + nh, ww, remHeight);
553: }
554:
555: if (eastPane != null)
556: {
557: Dimension eDims = eastPane.getPreferredSize();
558: ew = Math.min(eDims.width, dims.width - ww);
559:
560: eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh,
561: ew, remHeight);
562: }
563:
564: int remWidth = dims.width - ww - ew;
565:
566: frame.getRootPane().setBounds(insets.left + ww, insets.top + nh,
567: remWidth, remHeight);
568: }
569:
570:
577: public Dimension minimumLayoutSize(Container c)
578: {
579: return getSize(c, true);
580: }
581:
582:
589: public Dimension preferredLayoutSize(Container c)
590: {
591: return getSize(c, false);
592: }
593:
594:
603: private Dimension getSize(Container c, boolean min)
604: {
605: Insets insets = frame.getInsets();
606:
607: Dimension contentDims = frame.getContentPane().getPreferredSize();
608: if (min)
609: contentDims.width = contentDims.height = 0;
610: int nWidth = 0;
611: int nHeight = 0;
612: int sWidth = 0;
613: int sHeight = 0;
614: int eWidth = 0;
615: int eHeight = 0;
616: int wWidth = 0;
617: int wHeight = 0;
618: Dimension dims;
619:
620: if (northPane != null)
621: {
622: dims = northPane.getPreferredSize();
623: if (dims != null)
624: {
625: nWidth = dims.width;
626: nHeight = dims.height;
627: }
628: }
629:
630: if (southPane != null)
631: {
632: dims = southPane.getPreferredSize();
633: if (dims != null)
634: {
635: sWidth = dims.width;
636: sHeight = dims.height;
637: }
638: }
639:
640: if (eastPane != null)
641: {
642: dims = eastPane.getPreferredSize();
643: if (dims != null)
644: {
645: sWidth = dims.width;
646: sHeight = dims.height;
647: }
648: }
649:
650: if (westPane != null)
651: {
652: dims = westPane.getPreferredSize();
653: if (dims != null)
654: {
655: wWidth = dims.width;
656: wHeight = dims.height;
657: }
658: }
659:
660: int width = Math.max(sWidth, nWidth);
661: width = Math.max(width, contentDims.width + eWidth + wWidth);
662:
663: int height = Math.max(eHeight, wHeight);
664: height = Math.max(height, contentDims.height);
665: height += nHeight + sHeight;
666:
667: width += insets.left + insets.right;
668: height += insets.top + insets.bottom;
669:
670: return new Dimension(width, height);
671: }
672:
673:
679: public void removeLayoutComponent(Component c)
680: {
681:
682: }
683: }
684:
685:
690: protected class GlassPaneDispatcher implements MouseInputListener
691: {
692:
693: private transient Component mouseEventTarget;
694:
695:
696: private transient Component pressedComponent;
697:
698:
699: private transient Component lastComponentEntered;
700:
701:
702: private transient Component tempComponent;
703:
704:
705: private transient int pressCount;
706:
707:
713: public void mouseEntered(MouseEvent e)
714: {
715: handleEvent(e);
716: }
717:
718:
724: public void mouseClicked(MouseEvent e)
725: {
726: handleEvent(e);
727: }
728:
729:
735: public void mouseDragged(MouseEvent e)
736: {
737: handleEvent(e);
738: }
739:
740:
746: public void mouseExited(MouseEvent e)
747: {
748: handleEvent(e);
749: }
750:
751:
757: public void mouseMoved(MouseEvent e)
758: {
759: handleEvent(e);
760: }
761:
762:
768: public void mousePressed(MouseEvent e)
769: {
770: activateFrame(frame);
771: handleEvent(e);
772: }
773:
774:
780: public void mouseReleased(MouseEvent e)
781: {
782: handleEvent(e);
783: }
784:
785:
791: private void acquireComponentForMouseEvent(MouseEvent me)
792: {
793: int x = me.getX();
794: int y = me.getY();
795:
796:
797: Component parent = frame.getLayeredPane();
798: if (parent == null)
799: return;
800: Component candidate = null;
801: Point p = me.getPoint();
802: while (candidate == null && parent != null)
803: {
804: candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
805: if (candidate == null)
806: {
807: p = SwingUtilities.convertPoint(parent, p.x, p.y,
808: parent.getParent());
809: parent = parent.getParent();
810: }
811: }
812:
813:
814:
815:
816: if (candidate == frame.getContentPane())
817: candidate = null;
818:
819:
820: if (lastComponentEntered != null && lastComponentEntered.isShowing()
821: && lastComponentEntered != candidate)
822: {
823: Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
824: lastComponentEntered);
825: MouseEvent exited = new MouseEvent(lastComponentEntered,
826: MouseEvent.MOUSE_EXITED,
827: me.getWhen(), me.getModifiersEx(),
828: tp.x, tp.y, me.getClickCount(),
829: me.isPopupTrigger(),
830: me.getButton());
831: tempComponent = lastComponentEntered;
832: lastComponentEntered = null;
833: tempComponent.dispatchEvent(exited);
834: }
835:
836:
837: if (candidate != null)
838: {
839: mouseEventTarget = candidate;
840: if (candidate.isLightweight() && candidate.isShowing()
841: && candidate != frame.getContentPane()
842: && candidate != lastComponentEntered)
843: {
844: lastComponentEntered = mouseEventTarget;
845: Point cp = SwingUtilities.convertPoint(frame.getContentPane(), x,
846: y, lastComponentEntered);
847: MouseEvent entered = new MouseEvent(lastComponentEntered,
848: MouseEvent.MOUSE_ENTERED,
849: me.getWhen(),
850: me.getModifiersEx(), cp.x,
851: cp.y, me.getClickCount(),
852: me.isPopupTrigger(),
853: me.getButton());
854: lastComponentEntered.dispatchEvent(entered);
855: }
856: }
857:
858: if (me.getID() == MouseEvent.MOUSE_RELEASED
859: || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
860: || me.getID() == MouseEvent.MOUSE_DRAGGED)
861:
862:
863:
864:
865:
866:
867: mouseEventTarget = pressedComponent;
868: else if (me.getID() == MouseEvent.MOUSE_CLICKED)
869: {
870:
871:
872: if (candidate != pressedComponent)
873: mouseEventTarget = null;
874: else if (pressCount == 0)
875: pressedComponent = null;
876: }
877: }
878:
879:
887: private void handleEvent(AWTEvent e)
888: {
889: if (e instanceof MouseEvent)
890: {
891: MouseEvent me = (MouseEvent) e;
892: acquireComponentForMouseEvent(me);
893:
894:
895: if (mouseEventTarget == null)
896: return;
897:
898:
899: if (mouseEventTarget.equals(frame.getGlassPane()))
900: return;
901:
902:
903: if (mouseEventTarget.isShowing()
904: && e.getID() != MouseEvent.MOUSE_ENTERED
905: && e.getID() != MouseEvent.MOUSE_EXITED)
906: {
907: MouseEvent newEvt = SwingUtilities.convertMouseEvent(
908: frame.getGlassPane(),
909: me,
910: mouseEventTarget);
911: mouseEventTarget.dispatchEvent(newEvt);
912:
913: switch (e.getID())
914: {
915: case MouseEvent.MOUSE_PRESSED:
916: if (pressCount++ == 0)
917: pressedComponent = mouseEventTarget;
918: break;
919: case MouseEvent.MOUSE_RELEASED:
920:
921:
922:
923: if (--pressCount == 0 && mouseEventTarget != pressedComponent)
924: pressedComponent = null;
925: break;
926: }
927: }
928: }
929: }
930: }
931:
932:
936: public class InternalFramePropertyChangeListener
937: implements PropertyChangeListener
938: {
939:
940:
946: public void propertyChange(PropertyChangeEvent evt)
947: {
948: if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
949: {
950: if (frame.isMaximum())
951: maximizeFrame(frame);
952: else
953: minimizeFrame(frame);
954: }
955: else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))
956: {
957: if (frame.isIcon())
958: iconifyFrame(frame);
959: else
960: deiconifyFrame(frame);
961: }
962: else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))
963: {
964: if (frame.isSelected())
965: activateFrame(frame);
966: else
967: deactivateFrame(frame);
968: }
969: else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)
970: || evt.getPropertyName().equals(
971: JInternalFrame.GLASS_PANE_PROPERTY))
972: {
973: Component old = (Component) evt.getOldValue();
974: old.removeMouseListener(glassPaneDispatcher);
975: old.removeMouseMotionListener(glassPaneDispatcher);
976:
977: Component newPane = (Component) evt.getNewValue();
978: newPane.addMouseListener(glassPaneDispatcher);
979: newPane.addMouseMotionListener(glassPaneDispatcher);
980:
981: frame.revalidate();
982: }
983:
991: }
992: }
993:
994:
997: class InternalFrameBorder extends AbstractBorder implements
998: UIResource
999: {
1000:
1003: static final int bSize = 5;
1004:
1005:
1008: static final int cornerSize = 10;
1009:
1010:
1015: public boolean isBorderOpaque()
1016: {
1017: return true;
1018: }
1019:
1020:
1027: public Insets getBorderInsets(Component c)
1028: {
1029: return new Insets(bSize, bSize, bSize, bSize);
1030: }
1031:
1032:
1048: public void paintBorder(Component c, Graphics g, int x, int y, int width,
1049: int height)
1050: {
1051: g.translate(x, y);
1052: Color saved = g.getColor();
1053: Rectangle b = frame.getBounds();
1054:
1055: Color d = c.getBackground();
1056: g.setColor(d);
1057: g.fillRect(0, 0, bSize, b.height);
1058: g.fillRect(0, 0, b.width, bSize);
1059: g.fillRect(0, b.height - bSize, b.width, bSize);
1060: g.fillRect(b.width - bSize, 0, bSize, b.height);
1061:
1062: int x1 = 0;
1063: int x2 = bSize;
1064: int x3 = b.width - bSize;
1065: int x4 = b.width;
1066:
1067: int y1 = 0;
1068: int y2 = bSize;
1069: int y3 = b.height - bSize;
1070: int y4 = b.height;
1071:
1072: g.setColor(Color.GRAY);
1073: g.fillRect(0, 0, bSize, y4);
1074: g.fillRect(0, 0, x4, bSize);
1075: g.fillRect(0, y3, b.width, bSize);
1076: g.fillRect(x3, 0, bSize, b.height);
1077:
1078: g.fill3DRect(0, cornerSize, bSize, b.height - 2 * cornerSize, false);
1079: g.fill3DRect(cornerSize, 0, b.width - 2 * cornerSize, bSize, false);
1080: g.fill3DRect(cornerSize, b.height - bSize, b.width - 2 * cornerSize,
1081: bSize, false);
1082: g.fill3DRect(b.width - bSize, cornerSize, bSize,
1083: b.height - 2 * cornerSize, false);
1084:
1085: g.translate(-x, -y);
1086: g.setColor(saved);
1087: }
1088: }
1089:
1090:
1095: private class ShowSystemMenuAction
1096: extends AbstractAction
1097: {
1098: public void actionPerformed(ActionEvent e)
1099: {
1100: if (titlePane != null)
1101: {
1102: titlePane.showSystemMenu();
1103: }
1104: }
1105: }
1106:
1107:
1111: protected MouseInputAdapter borderListener;
1112:
1113:
1117: protected ComponentListener componentListener;
1118:
1119:
1123: protected MouseInputListener glassPaneDispatcher;
1124:
1125:
1129: protected PropertyChangeListener propertyChangeListener;
1130:
1131:
1132: private transient BasicInternalFrameListener internalFrameListener;
1133:
1134:
1135: protected JComponent eastPane;
1136:
1137:
1138: protected JComponent northPane;
1139:
1140:
1141: protected JComponent southPane;
1142:
1143:
1144: protected JComponent westPane;
1145:
1146:
1150: protected KeyStroke openMenuKey;
1151:
1152:
1153: protected BasicInternalFrameTitlePane titlePane;
1154:
1155:
1156: protected JInternalFrame frame;
1157:
1158:
1159: protected LayoutManager internalFrameLayout;
1160:
1161:
1162: private transient JDesktopPane desktopPane;
1163:
1164:
1169: public BasicInternalFrameUI(JInternalFrame b)
1170: {
1171:
1172: }
1173:
1174:
1182: public static ComponentUI createUI(JComponent b)
1183: {
1184: return new BasicInternalFrameUI((JInternalFrame) b);
1185: }
1186:
1187:
1192: public void installUI(JComponent c)
1193: {
1194: if (c instanceof JInternalFrame)
1195: {
1196: frame = (JInternalFrame) c;
1197:
1198: installDefaults();
1199: installListeners();
1200: installComponents();
1201: installKeyboardActions();
1202:
1203: if (! frame.isSelected())
1204: frame.getGlassPane().setVisible(true);
1205: }
1206: }
1207:
1208:
1213: public void uninstallUI(JComponent c)
1214: {
1215: uninstallKeyboardActions();
1216: uninstallComponents();
1217: uninstallListeners();
1218: uninstallDefaults();
1219:
1220: frame.getRootPane().getGlassPane().setVisible(false);
1221: frame = null;
1222: }
1223:
1224:
1227: protected void installDefaults()
1228: {
1229: internalFrameLayout = createLayoutManager();
1230: frame.setLayout(internalFrameLayout);
1231: LookAndFeel.installBorder(frame, "InternalFrame.border");
1232: frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
1233:
1234:
1235:
1236: Component contentPane = frame.getContentPane();
1237: if (contentPane != null
1238: && contentPane.getBackground() instanceof UIResource)
1239: {
1240: contentPane.setBackground(null);
1241: }
1242: }
1243:
1244:
1247: protected void installKeyboardActions()
1248: {
1249: ActionMapUIResource am = new ActionMapUIResource();
1250: am.put("showSystemMenu", new ShowSystemMenuAction());
1251:
1252:
1253:
1254: BasicLookAndFeel blaf = (BasicLookAndFeel) UIManager.getLookAndFeel();
1255: ActionMap audioActionMap = blaf.getAudioActionMap();
1256: am.setParent(audioActionMap);
1257:
1258: SwingUtilities.replaceUIActionMap(frame, am);
1259: }
1260:
1261:
1264: protected void installComponents()
1265: {
1266: setNorthPane(createNorthPane(frame));
1267: setSouthPane(createSouthPane(frame));
1268: setEastPane(createEastPane(frame));
1269: setWestPane(createWestPane(frame));
1270: }
1271:
1272:
1275: protected void installListeners()
1276: {
1277: glassPaneDispatcher = createGlassPaneDispatcher();
1278: createInternalFrameListener();
1279: borderListener = createBorderListener(frame);
1280: componentListener = createComponentListener();
1281: propertyChangeListener = createPropertyChangeListener();
1282:
1283: frame.addMouseListener(borderListener);
1284: frame.addMouseMotionListener(borderListener);
1285: frame.addInternalFrameListener(internalFrameListener);
1286: frame.addPropertyChangeListener(propertyChangeListener);
1287: frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher);
1288: frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher);
1289: }
1290:
1291:
1294: protected void uninstallDefaults()
1295: {
1296: frame.setBorder(null);
1297: frame.setLayout(null);
1298: internalFrameLayout = null;
1299: }
1300:
1301:
1304: protected void uninstallComponents()
1305: {
1306: setNorthPane(null);
1307: setSouthPane(null);
1308: setEastPane(null);
1309: setWestPane(null);
1310: }
1311:
1312:
1315: protected void uninstallListeners()
1316: {
1317: if (desktopPane != null)
1318: desktopPane.removeComponentListener(componentListener);
1319:
1320: frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
1321: frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher);
1322:
1323: frame.removePropertyChangeListener(propertyChangeListener);
1324: frame.removeInternalFrameListener(internalFrameListener);
1325: frame.removeMouseMotionListener(borderListener);
1326: frame.removeMouseListener(borderListener);
1327:
1328: propertyChangeListener = null;
1329: componentListener = null;
1330: borderListener = null;
1331: internalFrameListener = null;
1332: glassPaneDispatcher = null;
1333: }
1334:
1335:
1338: protected void uninstallKeyboardActions()
1339: {
1340: SwingUtilities.replaceUIActionMap(frame, null);
1341: SwingUtilities.replaceUIInputMap(frame, JComponent.WHEN_IN_FOCUSED_WINDOW,
1342: null);
1343: }
1344:
1345:
1350: protected LayoutManager createLayoutManager()
1351: {
1352: return new InternalFrameLayout();
1353: }
1354:
1355:
1360: protected PropertyChangeListener createPropertyChangeListener()
1361: {
1362: return new InternalFramePropertyChangeListener();
1363: }
1364:
1365:
1372: public Dimension getPreferredSize(JComponent x)
1373: {
1374: Dimension pref = null;
1375: LayoutManager layout = frame.getLayout();
1376: if (frame == x && layout != null)
1377: pref = layout.preferredLayoutSize(frame);
1378: else
1379: pref = new Dimension(100, 100);
1380: return pref;
1381: }
1382:
1383:
1390: public Dimension getMinimumSize(JComponent x)
1391: {
1392: Dimension min = null;
1393: LayoutManager layout = frame.getLayout();
1394: if (frame == x && layout != null)
1395: min = layout.minimumLayoutSize(frame);
1396: else
1397: min = new Dimension(0, 0);
1398: return min;
1399: }
1400:
1401:
1408: public Dimension getMaximumSize(JComponent x)
1409: {
1410: Dimension max = null;
1411: LayoutManager layout = frame.getLayout();
1412: if (frame == x && layout != null && layout instanceof LayoutManager2)
1413: max = ((LayoutManager2) layout).maximumLayoutSize(frame);
1414: else
1415: max = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
1416: return max;
1417: }
1418:
1419:
1427: protected void replacePane(JComponent currentPane, JComponent newPane)
1428: {
1429: if (currentPane != null)
1430: {
1431: deinstallMouseHandlers(currentPane);
1432: frame.remove(currentPane);
1433: }
1434:
1435: if (newPane != null)
1436: {
1437: installMouseHandlers(newPane);
1438: frame.add(newPane);
1439: }
1440: }
1441:
1442:
1448: protected void deinstallMouseHandlers(JComponent c)
1449: {
1450: c.removeMouseListener(borderListener);
1451: c.removeMouseMotionListener(borderListener);
1452: }
1453:
1454:
1460: protected void installMouseHandlers(JComponent c)
1461: {
1462: c.addMouseListener(borderListener);
1463: c.addMouseMotionListener(borderListener);
1464: }
1465:
1466:
1473: protected JComponent createNorthPane(JInternalFrame w)
1474: {
1475: titlePane = new BasicInternalFrameTitlePane(w);
1476: return titlePane;
1477: }
1478:
1479:
1486: protected JComponent createWestPane(JInternalFrame w)
1487: {
1488: return null;
1489: }
1490:
1491:
1498: protected JComponent createSouthPane(JInternalFrame w)
1499: {
1500: return null;
1501: }
1502:
1503:
1510: protected JComponent createEastPane(JInternalFrame w)
1511: {
1512: return null;
1513: }
1514:
1515:
1522: protected MouseInputAdapter createBorderListener(JInternalFrame w)
1523: {
1524: return new BorderListener();
1525: }
1526:
1527:
1530: protected void createInternalFrameListener()
1531: {
1532: internalFrameListener = new BasicInternalFrameListener();
1533: }
1534:
1535:
1540: protected final boolean isKeyBindingRegistered()
1541: {
1542:
1543: return false;
1544: }
1545:
1546:
1551: protected final void setKeyBindingRegistered(boolean b)
1552: {
1553:
1554: }
1555:
1556:
1561: public final boolean isKeyBindingActive()
1562: {
1563:
1564: return false;
1565: }
1566:
1567:
1572: protected final void setKeyBindingActive(boolean b)
1573: {
1574:
1575: }
1576:
1577:
1580: protected void setupMenuOpenKey()
1581: {
1582:
1583: }
1584:
1585:
1588: protected void setupMenuCloseKey()
1589: {
1590:
1591: }
1592:
1593:
1598: public JComponent getNorthPane()
1599: {
1600: return northPane;
1601: }
1602:
1603:
1608: public void setNorthPane(JComponent c)
1609: {
1610: replacePane(northPane, c);
1611: northPane = c;
1612: }
1613:
1614:
1619: public JComponent getSouthPane()
1620: {
1621: return southPane;
1622: }
1623:
1624:
1629: public void setSouthPane(JComponent c)
1630: {
1631: replacePane(southPane, c);
1632: southPane = c;
1633: }
1634:
1635:
1640: public void setEastPane(JComponent c)
1641: {
1642: replacePane(eastPane, c);
1643: eastPane = c;
1644: }
1645:
1646:
1651: public JComponent getEastPane()
1652: {
1653: return eastPane;
1654: }
1655:
1656:
1661: public void setWestPane(JComponent c)
1662: {
1663: replacePane(westPane, c);
1664: westPane = c;
1665: }
1666:
1667:
1672: public JComponent getWestPane()
1673: {
1674: return westPane;
1675: }
1676:
1677:
1682: protected DesktopManager getDesktopManager()
1683: {
1684: DesktopManager value = null;
1685: JDesktopPane pane = frame.getDesktopPane();
1686: if (pane != null)
1687: value = frame.getDesktopPane().getDesktopManager();
1688: if (value == null)
1689: value = createDesktopManager();
1690: return value;
1691: }
1692:
1693:
1700: protected DesktopManager createDesktopManager()
1701: {
1702: return new DefaultDesktopManager();
1703: }
1704:
1705:
1710: protected void closeFrame(JInternalFrame f)
1711: {
1712: getDesktopManager().closeFrame(f);
1713: }
1714:
1715:
1720: protected void maximizeFrame(JInternalFrame f)
1721: {
1722: getDesktopManager().maximizeFrame(f);
1723: }
1724:
1725:
1730: protected void minimizeFrame(JInternalFrame f)
1731: {
1732: getDesktopManager().minimizeFrame(f);
1733: }
1734:
1735:
1740: protected void iconifyFrame(JInternalFrame f)
1741: {
1742: getDesktopManager().iconifyFrame(f);
1743: }
1744:
1745:
1750: protected void deiconifyFrame(JInternalFrame f)
1751: {
1752: getDesktopManager().deiconifyFrame(f);
1753: }
1754:
1755:
1760: protected void activateFrame(JInternalFrame f)
1761: {
1762: getDesktopManager().activateFrame(f);
1763: }
1764:
1765:
1770: protected void deactivateFrame(JInternalFrame f)
1771: {
1772: getDesktopManager().deactivateFrame(f);
1773: }
1774:
1775:
1780: protected ComponentListener createComponentListener()
1781: {
1782: return new ComponentHandler();
1783: }
1784:
1785:
1790: protected MouseInputListener createGlassPaneDispatcher()
1791: {
1792: return new GlassPaneDispatcher();
1793: }
1794: }