1:
37:
38:
39: package ;
40:
41: import ;
42:
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:
80:
83: public class BasicInternalFrameUI extends InternalFrameUI
84: {
85:
89: protected class BasicInternalFrameListener implements InternalFrameListener
90: {
91:
96: public void internalFrameActivated(InternalFrameEvent e)
97: {
98: frame.getGlassPane().setVisible(false);
99: }
100:
101:
106: public void internalFrameClosed(InternalFrameEvent e)
107: {
108:
109: }
110:
111:
116: public void internalFrameClosing(InternalFrameEvent e)
117: {
118:
119: }
120:
121:
126: public void internalFrameDeactivated(InternalFrameEvent e)
127: {
128: frame.getGlassPane().setVisible(true);
129: }
130:
131:
136: public void internalFrameDeiconified(InternalFrameEvent e)
137: {
138:
139: }
140:
141:
146: public void internalFrameIconified(InternalFrameEvent e)
147: {
148:
149: }
150:
151:
156: public void internalFrameOpened(InternalFrameEvent e)
157: {
158:
159: }
160: }
161:
162:
167: protected class BorderListener extends MouseInputAdapter
168: implements SwingConstants
169: {
170:
174: transient boolean showingResizeCursor;
175:
176:
177: protected final int RESIZE_NONE = 0;
178:
179:
180: private transient int xOffset = 0;
181:
182:
183: private transient int yOffset = 0;
184:
185:
186: private transient int direction = -1;
187:
188:
189: private transient Rectangle cacheRect = new Rectangle();
190:
191:
196: public void mouseClicked(MouseEvent e)
197: {
198:
199:
200: }
201:
202:
208: public void mouseDragged(MouseEvent e)
209: {
210:
211:
212: if (frame.isMaximum())
213: return;
214: DesktopManager dm = getDesktopManager();
215: Rectangle b = frame.getBounds();
216: Dimension min = frame.getMinimumSize();
217: if (min == null)
218: min = new Dimension(0, 0);
219: Insets insets = frame.getInsets();
220: int x = e.getX();
221: int y = e.getY();
222: if (e.getSource() == frame && frame.isResizable())
223: {
224: switch (direction)
225: {
226: case NORTH:
227: cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
228: - min.height),
229: b.width, b.height - y);
230: break;
231: case NORTH_EAST:
232: cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
233: - min.height), x,
234: b.height - y);
235: break;
236: case EAST:
237: cacheRect.setBounds(b.x, b.y, x, b.height);
238: break;
239: case SOUTH_EAST:
240: cacheRect.setBounds(b.x, b.y, x, y);
241: break;
242: case SOUTH:
243: cacheRect.setBounds(b.x, b.y, b.width, y);
244: break;
245: case SOUTH_WEST:
246: cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
247: b.y, b.width - x, y);
248: break;
249: case WEST:
250: cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
251: b.y, b.width - x, b.height);
252: break;
253: case NORTH_WEST:
254: cacheRect.setBounds(
255: Math.min(b.x + x, b.x + b.width - min.width),
256: Math.min(b.y + y, b.y + b.height - min.height),
257: b.width - x, b.height - y);
258: break;
259: }
260: dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
261: Math.max(min.width, cacheRect.width),
262: Math.max(min.height, cacheRect.height));
263: }
264: else if (e.getSource() == titlePane)
265: {
266: Rectangle fBounds = frame.getBounds();
267: frame.putClientProperty("bufferedDragging", Boolean.TRUE);
268: dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset
269: + b.y);
270: }
271: }
272:
273:
278: public void mouseExited(MouseEvent e)
279: {
280:
281: if (showingResizeCursor)
282: {
283: frame.setCursor(Cursor.getDefaultCursor());
284: showingResizeCursor = false;
285: }
286: }
287:
288:
293: public void mouseMoved(MouseEvent e)
294: {
295:
296: if (showingResizeCursor && e.getSource() != frame)
297: {
298: frame.setCursor(Cursor.getDefaultCursor());
299: showingResizeCursor = false;
300: }
301: else if (e.getSource()==frame && frame.isResizable())
302: {
303: int cursor;
304: switch (sectionOfClick(e.getX(), e.getY()))
305: {
306: case NORTH:
307: cursor = Cursor.N_RESIZE_CURSOR;
308: break;
309: case NORTH_EAST:
310: cursor = Cursor.NE_RESIZE_CURSOR;
311: break;
312: case EAST:
313: cursor = Cursor.E_RESIZE_CURSOR;
314: break;
315: case SOUTH_EAST:
316: cursor = Cursor.SE_RESIZE_CURSOR;
317: break;
318: case SOUTH:
319: cursor = Cursor.S_RESIZE_CURSOR;
320: break;
321: case SOUTH_WEST:
322: cursor = Cursor.SW_RESIZE_CURSOR;
323: break;
324: case WEST:
325: cursor = Cursor.W_RESIZE_CURSOR;
326: break;
327: case NORTH_WEST:
328: cursor = Cursor.NW_RESIZE_CURSOR;
329: break;
330: default:
331: cursor = Cursor.DEFAULT_CURSOR;
332: }
333:
334: Cursor resize = Cursor.getPredefinedCursor(cursor);
335: frame.setCursor(resize);
336: showingResizeCursor = true;
337: }
338: }
339:
340:
345: public void mousePressed(MouseEvent e)
346: {
347: activateFrame(frame);
348: DesktopManager dm = getDesktopManager();
349: int x = e.getX();
350: int y = e.getY();
351: Insets insets = frame.getInsets();
352:
353: if (e.getSource() == frame && frame.isResizable())
354: {
355: direction = sectionOfClick(x, y);
356: dm.beginResizingFrame(frame, direction);
357: }
358: else if (e.getSource() == titlePane)
359: {
360: Rectangle tBounds = titlePane.getBounds();
361:
362: xOffset = e.getX() - tBounds.x + insets.left;
363: yOffset = e.getY() - tBounds.y + insets.top;
364:
365: dm.beginDraggingFrame(frame);
366: }
367: }
368:
369:
374: public void mouseReleased(MouseEvent e)
375: {
376: DesktopManager dm = getDesktopManager();
377: xOffset = 0;
378: yOffset = 0;
379: if (e.getSource() == frame && frame.isResizable())
380: dm.endResizingFrame(frame);
381: else if (e.getSource() == titlePane)
382: {
383: dm.endDraggingFrame(frame);
384: frame.putClientProperty("bufferedDragging", null);
385: }
386: }
387:
388:
397: private int sectionOfClick(int x, int y)
398: {
399: Insets insets = frame.getInsets();
400: Rectangle b = frame.getBounds();
401: if (x < insets.left && y < insets.top)
402: return NORTH_WEST;
403: else if (x > b.width - insets.right && y < insets.top)
404: return NORTH_EAST;
405: else if (x > b.width - insets.right && y > b.height - insets.bottom)
406: return SOUTH_EAST;
407: else if (x < insets.left && y > b.height - insets.bottom)
408: return SOUTH_WEST;
409: else if (y < insets.top)
410: return NORTH;
411: else if (x < insets.left)
412: return WEST;
413: else if (y > b.height - insets.bottom)
414: return SOUTH;
415: else if (x > b.width - insets.right)
416: return EAST;
417:
418: return -1;
419: }
420: }
421:
422:
427: protected class ComponentHandler implements ComponentListener
428: {
429:
435: public void componentHidden(ComponentEvent e)
436: {
437:
438: }
439:
440:
446: public void componentMoved(ComponentEvent e)
447: {
448:
449: }
450:
451:
457: public void componentResized(ComponentEvent e)
458: {
459: if (frame.isMaximum())
460: {
461: JDesktopPane pane = (JDesktopPane) e.getSource();
462: Insets insets = pane.getInsets();
463: Rectangle bounds = pane.getBounds();
464:
465: frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,
466: bounds.width - insets.left - insets.right,
467: bounds.height - insets.top - insets.bottom);
468: frame.revalidate();
469: frame.repaint();
470: }
471:
472:
473: }
474:
475:
481: public void componentShown(ComponentEvent e)
482: {
483:
484: }
485: }
486:
487:
490: public class InternalFrameLayout implements LayoutManager
491: {
492:
501: public void addLayoutComponent(String name, Component c)
502: {
503:
504: }
505:
506:
513: public void layoutContainer(Container c)
514: {
515: Dimension dims = frame.getSize();
516: Insets insets = frame.getInsets();
517:
518: dims.width -= insets.left + insets.right;
519: dims.height -= insets.top + insets.bottom;
520:
521: int nh = 0;
522: int sh = 0;
523: int ew = 0;
524: int ww = 0;
525:
526: if (northPane != null)
527: {
528: Dimension nDims = northPane.getPreferredSize();
529: nh = Math.min(nDims.height, dims.height);
530:
531: northPane.setBounds(insets.left, insets.top, dims.width, nh);
532: }
533:
534: if (southPane != null)
535: {
536: Dimension sDims = southPane.getPreferredSize();
537: sh = Math.min(sDims.height, dims.height - nh);
538:
539: southPane.setBounds(insets.left, insets.top + dims.height - sh,
540: dims.width, sh);
541: }
542:
543: int remHeight = dims.height - sh - nh;
544:
545: if (westPane != null)
546: {
547: Dimension wDims = westPane.getPreferredSize();
548: ww = Math.min(dims.width, wDims.width);
549:
550: westPane.setBounds(insets.left, insets.top + nh, ww, remHeight);
551: }
552:
553: if (eastPane != null)
554: {
555: Dimension eDims = eastPane.getPreferredSize();
556: ew = Math.min(eDims.width, dims.width - ww);
557:
558: eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh,
559: ew, remHeight);
560: }
561:
562: int remWidth = dims.width - ww - ew;
563:
564: frame.getRootPane().setBounds(insets.left + ww, insets.top + nh,
565: remWidth, remHeight);
566: }
567:
568:
575: public Dimension minimumLayoutSize(Container c)
576: {
577: return getSize(c, true);
578: }
579:
580:
587: public Dimension preferredLayoutSize(Container c)
588: {
589: return getSize(c, false);
590: }
591:
592:
601: private Dimension getSize(Container c, boolean min)
602: {
603: Insets insets = frame.getInsets();
604:
605: Dimension contentDims = frame.getContentPane().getPreferredSize();
606: if (min)
607: contentDims.width = contentDims.height = 0;
608: int nWidth = 0;
609: int nHeight = 0;
610: int sWidth = 0;
611: int sHeight = 0;
612: int eWidth = 0;
613: int eHeight = 0;
614: int wWidth = 0;
615: int wHeight = 0;
616: Dimension dims;
617:
618: if (northPane != null)
619: {
620: dims = northPane.getPreferredSize();
621: if (dims != null)
622: {
623: nWidth = dims.width;
624: nHeight = dims.height;
625: }
626: }
627:
628: if (southPane != null)
629: {
630: dims = southPane.getPreferredSize();
631: if (dims != null)
632: {
633: sWidth = dims.width;
634: sHeight = dims.height;
635: }
636: }
637:
638: if (eastPane != null)
639: {
640: dims = eastPane.getPreferredSize();
641: if (dims != null)
642: {
643: sWidth = dims.width;
644: sHeight = dims.height;
645: }
646: }
647:
648: if (westPane != null)
649: {
650: dims = westPane.getPreferredSize();
651: if (dims != null)
652: {
653: wWidth = dims.width;
654: wHeight = dims.height;
655: }
656: }
657:
658: int width = Math.max(sWidth, nWidth);
659: width = Math.max(width, contentDims.width + eWidth + wWidth);
660:
661: int height = Math.max(eHeight, wHeight);
662: height = Math.max(height, contentDims.height);
663: height += nHeight + sHeight;
664:
665: width += insets.left + insets.right;
666: height += insets.top + insets.bottom;
667:
668: return new Dimension(width, height);
669: }
670:
671:
677: public void removeLayoutComponent(Component c)
678: {
679:
680: }
681: }
682:
683:
688: protected class GlassPaneDispatcher implements MouseInputListener
689: {
690:
691: private transient Component mouseEventTarget;
692:
693:
694: private transient Component pressedComponent;
695:
696:
697: private transient Component lastComponentEntered;
698:
699:
700: private transient Component tempComponent;
701:
702:
703: private transient int pressCount;
704:
705:
711: public void mouseEntered(MouseEvent e)
712: {
713: handleEvent(e);
714: }
715:
716:
722: public void mouseClicked(MouseEvent e)
723: {
724: handleEvent(e);
725: }
726:
727:
733: public void mouseDragged(MouseEvent e)
734: {
735: handleEvent(e);
736: }
737:
738:
744: public void mouseExited(MouseEvent e)
745: {
746: handleEvent(e);
747: }
748:
749:
755: public void mouseMoved(MouseEvent e)
756: {
757: handleEvent(e);
758: }
759:
760:
766: public void mousePressed(MouseEvent e)
767: {
768: activateFrame(frame);
769: handleEvent(e);
770: }
771:
772:
778: public void mouseReleased(MouseEvent e)
779: {
780: handleEvent(e);
781: }
782:
783:
789: private void acquireComponentForMouseEvent(MouseEvent me)
790: {
791: int x = me.getX();
792: int y = me.getY();
793:
794:
795: Component parent = frame.getLayeredPane();
796: if (parent == null)
797: return;
798: Component candidate = null;
799: Point p = me.getPoint();
800: while (candidate == null && parent != null)
801: {
802: candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
803: if (candidate == null)
804: {
805: p = SwingUtilities.convertPoint(parent, p.x, p.y,
806: parent.getParent());
807: parent = parent.getParent();
808: }
809: }
810:
811:
812:
813:
814: if (candidate == frame.getContentPane())
815: candidate = null;
816:
817:
818: if (lastComponentEntered != null && lastComponentEntered.isShowing()
819: && lastComponentEntered != candidate)
820: {
821: Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
822: lastComponentEntered);
823: MouseEvent exited = new MouseEvent(lastComponentEntered,
824: MouseEvent.MOUSE_EXITED,
825: me.getWhen(), me.getModifiersEx(),
826: tp.x, tp.y, me.getClickCount(),
827: me.isPopupTrigger(),
828: me.getButton());
829: tempComponent = lastComponentEntered;
830: lastComponentEntered = null;
831: tempComponent.dispatchEvent(exited);
832: }
833:
834:
835: if (candidate != null)
836: {
837: mouseEventTarget = candidate;
838: if (candidate.isLightweight() && candidate.isShowing()
839: && candidate != frame.getContentPane()
840: && candidate != lastComponentEntered)
841: {
842: lastComponentEntered = mouseEventTarget;
843: Point cp = SwingUtilities.convertPoint(frame.getContentPane(), x,
844: y, lastComponentEntered);
845: MouseEvent entered = new MouseEvent(lastComponentEntered,
846: MouseEvent.MOUSE_ENTERED,
847: me.getWhen(),
848: me.getModifiersEx(), cp.x,
849: cp.y, me.getClickCount(),
850: me.isPopupTrigger(),
851: me.getButton());
852: lastComponentEntered.dispatchEvent(entered);
853: }
854: }
855:
856: if (me.getID() == MouseEvent.MOUSE_RELEASED
857: || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
858: || me.getID() == MouseEvent.MOUSE_DRAGGED)
859:
860:
861:
862:
863:
864:
865: mouseEventTarget = pressedComponent;
866: else if (me.getID() == MouseEvent.MOUSE_CLICKED)
867: {
868:
869:
870: if (candidate != pressedComponent)
871: mouseEventTarget = null;
872: else if (pressCount == 0)
873: pressedComponent = null;
874: }
875: }
876:
877:
885: private void handleEvent(AWTEvent e)
886: {
887: if (e instanceof MouseEvent)
888: {
889: MouseEvent me = (MouseEvent) e;
890: acquireComponentForMouseEvent(me);
891:
892:
893: if (mouseEventTarget == null)
894: return;
895:
896:
897: if (mouseEventTarget.equals(frame.getGlassPane()))
898: return;
899:
900:
901: if (mouseEventTarget.isShowing()
902: && e.getID() != MouseEvent.MOUSE_ENTERED
903: && e.getID() != MouseEvent.MOUSE_EXITED)
904: {
905: MouseEvent newEvt = SwingUtilities.convertMouseEvent(
906: frame.getGlassPane(),
907: me,
908: mouseEventTarget);
909: mouseEventTarget.dispatchEvent(newEvt);
910:
911: switch (e.getID())
912: {
913: case MouseEvent.MOUSE_PRESSED:
914: if (pressCount++ == 0)
915: pressedComponent = mouseEventTarget;
916: break;
917: case MouseEvent.MOUSE_RELEASED:
918:
919:
920:
921: if (--pressCount == 0 && mouseEventTarget != pressedComponent)
922: pressedComponent = null;
923: break;
924: }
925: }
926: }
927: }
928: }
929:
930:
934: public class InternalFramePropertyChangeListener
935: implements PropertyChangeListener
936: {
937:
938:
944: public void propertyChange(PropertyChangeEvent evt)
945: {
946: if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
947: {
948: if (frame.isMaximum())
949: maximizeFrame(frame);
950: else
951: minimizeFrame(frame);
952: }
953: else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))
954: {
955: if (frame.isIcon())
956: iconifyFrame(frame);
957: else
958: deiconifyFrame(frame);
959: }
960: else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))
961: {
962: if (frame.isSelected())
963: activateFrame(frame);
964: else
965: deactivateFrame(frame);
966: }
967: else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)
968: || evt.getPropertyName().equals(
969: JInternalFrame.GLASS_PANE_PROPERTY))
970: {
971: Component old = (Component) evt.getOldValue();
972: old.removeMouseListener(glassPaneDispatcher);
973: old.removeMouseMotionListener(glassPaneDispatcher);
974:
975: Component newPane = (Component) evt.getNewValue();
976: newPane.addMouseListener(glassPaneDispatcher);
977: newPane.addMouseMotionListener(glassPaneDispatcher);
978:
979: frame.revalidate();
980: }
981:
989: }
990: }
991:
992:
995: private class InternalFrameBorder extends AbstractBorder implements
996: UIResource
997: {
998:
999: private static final int bSize = 5;
1000:
1001:
1002: private static final int offset = 10;
1003:
1004:
1009: public boolean isBorderOpaque()
1010: {
1011: return true;
1012: }
1013:
1014:
1021: public Insets getBorderInsets(Component c)
1022: {
1023: return new Insets(bSize, bSize, bSize, bSize);
1024: }
1025:
1026:
1042: public void paintBorder(Component c, Graphics g, int x, int y, int width,
1043: int height)
1044: {
1045: g.translate(x, y);
1046: Color saved = g.getColor();
1047: Rectangle b = frame.getBounds();
1048:
1049: Color d = c.getBackground();
1050: g.setColor(d);
1051: g.fillRect(0, 0, bSize, b.height);
1052: g.fillRect(0, 0, b.width, bSize);
1053: g.fillRect(0, b.height - bSize, b.width, bSize);
1054: g.fillRect(b.width - bSize, 0, bSize, b.height);
1055:
1056: int x1 = 0;
1057: int x2 = bSize;
1058: int x3 = b.width - bSize;
1059: int x4 = b.width;
1060:
1061: int y1 = 0;
1062: int y2 = bSize;
1063: int y3 = b.height - bSize;
1064: int y4 = b.height;
1065:
1066: g.setColor(Color.GRAY);
1067: g.fillRect(0, 0, bSize, y4);
1068: g.fillRect(0, 0, x4, bSize);
1069: g.fillRect(0, y3, b.width, bSize);
1070: g.fillRect(x3, 0, bSize, b.height);
1071:
1072: g.fill3DRect(0, offset, bSize, b.height - 2 * offset, false);
1073: g.fill3DRect(offset, 0, b.width - 2 * offset, bSize, false);
1074: g.fill3DRect(offset, b.height - bSize, b.width - 2 * offset, bSize, false);
1075: g.fill3DRect(b.width - bSize, offset, bSize, b.height - 2 * offset, false);
1076:
1077: g.translate(-x, -y);
1078: g.setColor(saved);
1079: }
1080: }
1081:
1082:
1086: protected MouseInputAdapter borderListener;
1087:
1088:
1092: protected ComponentListener componentListener;
1093:
1094:
1098: protected MouseInputListener glassPaneDispatcher;
1099:
1100:
1104: protected PropertyChangeListener propertyChangeListener;
1105:
1106:
1107: private transient BasicInternalFrameListener internalFrameListener;
1108:
1109:
1110: protected JComponent eastPane;
1111:
1112:
1113: protected JComponent northPane;
1114:
1115:
1116: protected JComponent southPane;
1117:
1118:
1119: protected JComponent westPane;
1120:
1121:
1125: protected KeyStroke openMenuKey;
1126:
1127:
1128: protected BasicInternalFrameTitlePane titlePane;
1129:
1130:
1131: protected JInternalFrame frame;
1132:
1133:
1134: protected LayoutManager internalFrameLayout;
1135:
1136:
1137: private transient JDesktopPane desktopPane;
1138:
1139:
1144: public BasicInternalFrameUI(JInternalFrame b)
1145: {
1146:
1147: }
1148:
1149:
1157: public static ComponentUI createUI(JComponent b)
1158: {
1159: return new BasicInternalFrameUI((JInternalFrame) b);
1160: }
1161:
1162:
1167: public void installUI(JComponent c)
1168: {
1169: if (c instanceof JInternalFrame)
1170: {
1171: frame = (JInternalFrame) c;
1172:
1173: installDefaults();
1174: installListeners();
1175: installComponents();
1176: installKeyboardActions();
1177:
1178: if (! frame.isSelected())
1179: frame.getGlassPane().setVisible(true);
1180: }
1181: }
1182:
1183:
1188: public void uninstallUI(JComponent c)
1189: {
1190: uninstallKeyboardActions();
1191: uninstallComponents();
1192: uninstallListeners();
1193: uninstallDefaults();
1194:
1195: frame.getRootPane().getGlassPane().setVisible(false);
1196: frame = null;
1197: }
1198:
1199:
1202: protected void installDefaults()
1203: {
1204: internalFrameLayout = createLayoutManager();
1205: frame.setLayout(internalFrameLayout);
1206: LookAndFeel.installBorder(frame, "InternalFrame.border");
1207: frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
1208:
1209:
1210:
1211: Component contentPane = frame.getContentPane();
1212: if (contentPane != null
1213: && contentPane.getBackground() instanceof UIResource)
1214: {
1215: contentPane.setBackground(null);
1216: }
1217: }
1218:
1219:
1222: protected void installKeyboardActions()
1223: throws NotImplementedException
1224: {
1225:
1226: }
1227:
1228:
1231: protected void installComponents()
1232: {
1233: setNorthPane(createNorthPane(frame));
1234: setSouthPane(createSouthPane(frame));
1235: setEastPane(createEastPane(frame));
1236: setWestPane(createWestPane(frame));
1237: }
1238:
1239:
1242: protected void installListeners()
1243: {
1244: glassPaneDispatcher = createGlassPaneDispatcher();
1245: createInternalFrameListener();
1246: borderListener = createBorderListener(frame);
1247: componentListener = createComponentListener();
1248: propertyChangeListener = createPropertyChangeListener();
1249:
1250: frame.addMouseListener(borderListener);
1251: frame.addMouseMotionListener(borderListener);
1252: frame.addInternalFrameListener(internalFrameListener);
1253: frame.addPropertyChangeListener(propertyChangeListener);
1254: frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher);
1255: frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher);
1256: }
1257:
1258:
1261: protected void uninstallDefaults()
1262: {
1263: frame.setBorder(null);
1264: frame.setLayout(null);
1265: internalFrameLayout = null;
1266: }
1267:
1268:
1271: protected void uninstallComponents()
1272: {
1273: setNorthPane(null);
1274: setSouthPane(null);
1275: setEastPane(null);
1276: setWestPane(null);
1277: }
1278:
1279:
1282: protected void uninstallListeners()
1283: {
1284: if (desktopPane != null)
1285: desktopPane.removeComponentListener(componentListener);
1286:
1287: frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
1288: frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher);
1289:
1290: frame.removePropertyChangeListener(propertyChangeListener);
1291: frame.removeInternalFrameListener(internalFrameListener);
1292: frame.removeMouseMotionListener(borderListener);
1293: frame.removeMouseListener(borderListener);
1294:
1295: propertyChangeListener = null;
1296: componentListener = null;
1297: borderListener = null;
1298: internalFrameListener = null;
1299: glassPaneDispatcher = null;
1300: }
1301:
1302:
1305: protected void uninstallKeyboardActions()
1306: throws NotImplementedException
1307: {
1308:
1309: }
1310:
1311:
1316: protected LayoutManager createLayoutManager()
1317: {
1318: return new InternalFrameLayout();
1319: }
1320:
1321:
1326: protected PropertyChangeListener createPropertyChangeListener()
1327: {
1328: return new InternalFramePropertyChangeListener();
1329: }
1330:
1331:
1338: public Dimension getPreferredSize(JComponent x)
1339: {
1340: Dimension pref = null;
1341: LayoutManager layout = frame.getLayout();
1342: if (frame == x && layout != null)
1343: pref = layout.preferredLayoutSize(frame);
1344: else
1345: pref = new Dimension(100, 100);
1346: return pref;
1347: }
1348:
1349:
1356: public Dimension getMinimumSize(JComponent x)
1357: {
1358: Dimension min = null;
1359: LayoutManager layout = frame.getLayout();
1360: if (frame == x && layout != null)
1361: min = layout.minimumLayoutSize(frame);
1362: else
1363: min = new Dimension(0, 0);
1364: return min;
1365: }
1366:
1367:
1374: public Dimension getMaximumSize(JComponent x)
1375: {
1376: Dimension max = null;
1377: LayoutManager layout = frame.getLayout();
1378: if (frame == x && layout != null && layout instanceof LayoutManager2)
1379: max = ((LayoutManager2) layout).maximumLayoutSize(frame);
1380: else
1381: max = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
1382: return max;
1383: }
1384:
1385:
1393: protected void replacePane(JComponent currentPane, JComponent newPane)
1394: {
1395: if (currentPane != null)
1396: {
1397: deinstallMouseHandlers(currentPane);
1398: frame.remove(currentPane);
1399: }
1400:
1401: if (newPane != null)
1402: {
1403: installMouseHandlers(newPane);
1404: frame.add(newPane);
1405: }
1406: }
1407:
1408:
1414: protected void deinstallMouseHandlers(JComponent c)
1415: {
1416: c.removeMouseListener(borderListener);
1417: c.removeMouseMotionListener(borderListener);
1418: }
1419:
1420:
1426: protected void installMouseHandlers(JComponent c)
1427: {
1428: c.addMouseListener(borderListener);
1429: c.addMouseMotionListener(borderListener);
1430: }
1431:
1432:
1439: protected JComponent createNorthPane(JInternalFrame w)
1440: {
1441: titlePane = new BasicInternalFrameTitlePane(w);
1442: return titlePane;
1443: }
1444:
1445:
1452: protected JComponent createWestPane(JInternalFrame w)
1453: {
1454: return null;
1455: }
1456:
1457:
1464: protected JComponent createSouthPane(JInternalFrame w)
1465: {
1466: return null;
1467: }
1468:
1469:
1476: protected JComponent createEastPane(JInternalFrame w)
1477: {
1478: return null;
1479: }
1480:
1481:
1488: protected MouseInputAdapter createBorderListener(JInternalFrame w)
1489: {
1490: return new BorderListener();
1491: }
1492:
1493:
1496: protected void createInternalFrameListener()
1497: {
1498: internalFrameListener = new BasicInternalFrameListener();
1499: }
1500:
1501:
1506: protected final boolean isKeyBindingRegistered()
1507: {
1508:
1509: return false;
1510: }
1511:
1512:
1517: protected final void setKeyBindingRegistered(boolean b)
1518: {
1519:
1520: }
1521:
1522:
1527: public final boolean isKeyBindingActive()
1528: {
1529:
1530: return false;
1531: }
1532:
1533:
1538: protected final void setKeyBindingActive(boolean b)
1539: {
1540:
1541: }
1542:
1543:
1546: protected void setupMenuOpenKey()
1547: {
1548:
1549: }
1550:
1551:
1554: protected void setupMenuCloseKey()
1555: {
1556:
1557: }
1558:
1559:
1564: public JComponent getNorthPane()
1565: {
1566: return northPane;
1567: }
1568:
1569:
1574: public void setNorthPane(JComponent c)
1575: {
1576: replacePane(northPane, c);
1577: northPane = c;
1578: }
1579:
1580:
1585: public JComponent getSouthPane()
1586: {
1587: return southPane;
1588: }
1589:
1590:
1595: public void setSouthPane(JComponent c)
1596: {
1597: replacePane(southPane, c);
1598: southPane = c;
1599: }
1600:
1601:
1606: public void setEastPane(JComponent c)
1607: {
1608: replacePane(eastPane, c);
1609: eastPane = c;
1610: }
1611:
1612:
1617: public JComponent getEastPane()
1618: {
1619: return eastPane;
1620: }
1621:
1622:
1627: public void setWestPane(JComponent c)
1628: {
1629: replacePane(westPane, c);
1630: westPane = c;
1631: }
1632:
1633:
1638: public JComponent getWestPane()
1639: {
1640: return westPane;
1641: }
1642:
1643:
1648: protected DesktopManager getDesktopManager()
1649: {
1650: DesktopManager value = null;
1651: JDesktopPane pane = frame.getDesktopPane();
1652: if (pane != null)
1653: value = frame.getDesktopPane().getDesktopManager();
1654: if (value == null)
1655: value = createDesktopManager();
1656: return value;
1657: }
1658:
1659:
1666: protected DesktopManager createDesktopManager()
1667: {
1668: return new DefaultDesktopManager();
1669: }
1670:
1671:
1676: protected void closeFrame(JInternalFrame f)
1677: {
1678: getDesktopManager().closeFrame(f);
1679: }
1680:
1681:
1686: protected void maximizeFrame(JInternalFrame f)
1687: {
1688: getDesktopManager().maximizeFrame(f);
1689: }
1690:
1691:
1696: protected void minimizeFrame(JInternalFrame f)
1697: {
1698: getDesktopManager().minimizeFrame(f);
1699: }
1700:
1701:
1706: protected void iconifyFrame(JInternalFrame f)
1707: {
1708: getDesktopManager().iconifyFrame(f);
1709: }
1710:
1711:
1716: protected void deiconifyFrame(JInternalFrame f)
1717: {
1718: getDesktopManager().deiconifyFrame(f);
1719: }
1720:
1721:
1726: protected void activateFrame(JInternalFrame f)
1727: {
1728: getDesktopManager().activateFrame(f);
1729: }
1730:
1731:
1736: protected void deactivateFrame(JInternalFrame f)
1737: {
1738: getDesktopManager().deactivateFrame(f);
1739: }
1740:
1741:
1746: protected ComponentListener createComponentListener()
1747: {
1748: return new ComponentHandler();
1749: }
1750:
1751:
1756: protected MouseInputListener createGlassPaneDispatcher()
1757: {
1758: return new GlassPaneDispatcher();
1759: }
1760: }