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:
60: import ;
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:
82:
85: public class BasicInternalFrameUI extends InternalFrameUI
86: {
87:
91: protected class BasicInternalFrameListener implements InternalFrameListener
92: {
93:
98: public void internalFrameActivated(InternalFrameEvent e)
99: {
100: frame.getGlassPane().setVisible(false);
101: }
102:
103:
108: public void internalFrameClosed(InternalFrameEvent e)
109: {
110:
111: }
112:
113:
118: public void internalFrameClosing(InternalFrameEvent e)
119: {
120:
121: }
122:
123:
128: public void internalFrameDeactivated(InternalFrameEvent e)
129: {
130: frame.getGlassPane().setVisible(true);
131: }
132:
133:
138: public void internalFrameDeiconified(InternalFrameEvent e)
139: {
140:
141: }
142:
143:
148: public void internalFrameIconified(InternalFrameEvent e)
149: {
150:
151: }
152:
153:
158: public void internalFrameOpened(InternalFrameEvent e)
159: {
160:
161: }
162: }
163:
164:
169: protected class BorderListener extends MouseInputAdapter
170: implements SwingConstants
171: {
172:
175: transient int showingCursor;
176:
177:
178: protected final int RESIZE_NONE = 0;
179:
180:
181: private transient int xOffset;
182:
183:
184: private transient int yOffset;
185:
186:
187: private transient int direction = -1;
188:
189:
190: private transient Rectangle cacheRect = new Rectangle();
191:
192:
197: public void mouseClicked(MouseEvent e)
198: {
199:
200: if (e.getSource() == titlePane && e.getClickCount() == 2)
201: try
202: {
203: if (frame.isMaximizable() && ! frame.isMaximum())
204: frame.setMaximum(true);
205: else if (frame.isMaximum())
206: frame.setMaximum(false);
207: }
208: catch (PropertyVetoException pve)
209: {
210:
211: }
212:
213:
214:
215: }
216:
217:
223: public void mouseDragged(MouseEvent e)
224: {
225:
226:
227: if (frame.isMaximum())
228: return;
229: DesktopManager dm = getDesktopManager();
230: Rectangle b = frame.getBounds();
231: Dimension min = frame.getMinimumSize();
232: if (min == null)
233: min = new Dimension(0, 0);
234: Insets insets = frame.getInsets();
235: int x = e.getX();
236: int y = e.getY();
237: if (e.getSource() == frame && frame.isResizable())
238: {
239: switch (direction)
240: {
241: case Cursor.N_RESIZE_CURSOR:
242: cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
243: - min.height),
244: b.width, b.height - y);
245: break;
246: case Cursor.NE_RESIZE_CURSOR:
247: cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
248: - min.height), x + 1,
249: b.height - y);
250: break;
251: case Cursor.E_RESIZE_CURSOR:
252: cacheRect.setBounds(b.x, b.y, x + 1, b.height);
253: break;
254: case Cursor.SE_RESIZE_CURSOR:
255: cacheRect.setBounds(b.x, b.y, x + 1, y + 1);
256: break;
257: case Cursor.S_RESIZE_CURSOR:
258: cacheRect.setBounds(b.x, b.y, b.width, y + 1);
259: break;
260: case Cursor.SW_RESIZE_CURSOR:
261: cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
262: b.y, b.width - x, y + 1);
263: break;
264: case Cursor.W_RESIZE_CURSOR:
265: cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
266: b.y, b.width - x, b.height);
267: break;
268: case Cursor.NW_RESIZE_CURSOR:
269: cacheRect.setBounds(
270: Math.min(b.x + x, b.x + b.width - min.width),
271: Math.min(b.y + y, b.y + b.height - min.height),
272: b.width - x, b.height - y);
273: break;
274: }
275: dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
276: Math.max(min.width, cacheRect.width),
277: Math.max(min.height, cacheRect.height));
278: setCursor(e);
279: }
280: else if (e.getSource() == titlePane)
281: {
282: Rectangle fBounds = frame.getBounds();
283: frame.putClientProperty("bufferedDragging", Boolean.TRUE);
284: dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset
285: + b.y);
286: }
287: }
288:
289:
294: public void mouseExited(MouseEvent e)
295: {
296: if (showingCursor != Cursor.DEFAULT_CURSOR)
297: {
298: frame.setCursor(Cursor.getDefaultCursor());
299: showingCursor = Cursor.DEFAULT_CURSOR;
300: }
301: }
302:
303:
308: public void mouseMoved(MouseEvent e)
309: {
310:
311: if (showingCursor != Cursor.DEFAULT_CURSOR && e.getSource() != frame)
312: {
313: frame.setCursor(Cursor.getDefaultCursor());
314: showingCursor = Cursor.DEFAULT_CURSOR;
315: }
316: else if (e.getSource() == frame && frame.isResizable())
317: {
318: setCursor(e);
319: }
320: }
321:
322:
327: void setCursor(MouseEvent e)
328: {
329: int cursor = sectionOfClick(e.getX(), e.getY());
330: if (cursor != showingCursor)
331: {
332: Cursor resize = Cursor.getPredefinedCursor(cursor);
333: frame.setCursor(resize);
334: showingCursor = cursor;
335: }
336: }
337:
338:
343: public void mousePressed(MouseEvent e)
344: {
345: activateFrame(frame);
346: DesktopManager dm = getDesktopManager();
347: int x = e.getX();
348: int y = e.getY();
349: Insets insets = frame.getInsets();
350:
351: if (e.getSource() == frame && frame.isResizable())
352: {
353: direction = sectionOfClick(x, y);
354: dm.beginResizingFrame(frame, direction);
355: }
356: else if (e.getSource() == titlePane)
357: {
358: Rectangle tBounds = titlePane.getBounds();
359:
360: xOffset = e.getX() - tBounds.x + insets.left;
361: yOffset = e.getY() - tBounds.y + insets.top;
362:
363: dm.beginDraggingFrame(frame);
364: }
365: }
366:
367:
372: public void mouseReleased(MouseEvent e)
373: {
374: DesktopManager dm = getDesktopManager();
375: xOffset = 0;
376: yOffset = 0;
377: if (e.getSource() == frame && frame.isResizable())
378: dm.endResizingFrame(frame);
379: else if (e.getSource() == titlePane)
380: {
381: dm.endDraggingFrame(frame);
382: frame.putClientProperty("bufferedDragging", null);
383: }
384:
385: setCursor(e);
386: }
387:
388:
397: private int sectionOfClick(int x, int y)
398: {
399: Rectangle b = frame.getBounds();
400: int corner = InternalFrameBorder.cornerSize;
401:
402: if (x < corner && y < corner)
403: return Cursor.NW_RESIZE_CURSOR;
404: else if (x > b.width - corner && y < corner)
405: return Cursor.NE_RESIZE_CURSOR;
406: else if (x > b.width - corner && y > b.height - corner)
407: return Cursor.SE_RESIZE_CURSOR;
408: else if (x < corner && y > b.height - corner)
409: return Cursor.SW_RESIZE_CURSOR;
410: else if (y < corner)
411: return Cursor.N_RESIZE_CURSOR;
412: else if (x < corner)
413: return Cursor.W_RESIZE_CURSOR;
414: else if (y > b.height - corner)
415: return Cursor.S_RESIZE_CURSOR;
416: else if (x > b.width - corner)
417: return Cursor.E_RESIZE_CURSOR;
418:
419: return Cursor.DEFAULT_CURSOR;
420: }
421: }
422:
423:
428: protected class ComponentHandler implements ComponentListener
429: {
430:
436: public void componentHidden(ComponentEvent e)
437: {
438:
439: }
440:
441:
447: public void componentMoved(ComponentEvent e)
448: {
449:
450: }
451:
452:
458: public void componentResized(ComponentEvent e)
459: {
460: if (frame.isMaximum())
461: {
462: JDesktopPane pane = (JDesktopPane) e.getSource();
463: Insets insets = pane.getInsets();
464: Rectangle bounds = pane.getBounds();
465:
466: frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,
467: bounds.width - insets.left - insets.right,
468: bounds.height - insets.top - insets.bottom);
469: frame.revalidate();
470: frame.repaint();
471: }
472:
473:
474: }
475:
476:
482: public void componentShown(ComponentEvent e)
483: {
484:
485: }
486: }
487:
488:
491: public class InternalFrameLayout implements LayoutManager
492: {
493:
502: public void addLayoutComponent(String name, Component c)
503: {
504:
505: }
506:
507:
514: public void layoutContainer(Container c)
515: {
516: Dimension dims = frame.getSize();
517: Insets insets = frame.getInsets();
518:
519: dims.width -= insets.left + insets.right;
520: dims.height -= insets.top + insets.bottom;
521:
522: int nh = 0;
523: int sh = 0;
524: int ew = 0;
525: int ww = 0;
526:
527: if (northPane != null)
528: {
529: Dimension nDims = northPane.getPreferredSize();
530: nh = Math.min(nDims.height, dims.height);
531:
532: northPane.setBounds(insets.left, insets.top, dims.width, nh);
533: }
534:
535: if (southPane != null)
536: {
537: Dimension sDims = southPane.getPreferredSize();
538: sh = Math.min(sDims.height, dims.height - nh);
539:
540: southPane.setBounds(insets.left, insets.top + dims.height - sh,
541: dims.width, sh);
542: }
543:
544: int remHeight = dims.height - sh - nh;
545:
546: if (westPane != null)
547: {
548: Dimension wDims = westPane.getPreferredSize();
549: ww = Math.min(dims.width, wDims.width);
550:
551: westPane.setBounds(insets.left, insets.top + nh, ww, remHeight);
552: }
553:
554: if (eastPane != null)
555: {
556: Dimension eDims = eastPane.getPreferredSize();
557: ew = Math.min(eDims.width, dims.width - ww);
558:
559: eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh,
560: ew, remHeight);
561: }
562:
563: int remWidth = dims.width - ww - ew;
564:
565: frame.getRootPane().setBounds(insets.left + ww, insets.top + nh,
566: remWidth, remHeight);
567: }
568:
569:
576: public Dimension minimumLayoutSize(Container c)
577: {
578: return getSize(c, true);
579: }
580:
581:
588: public Dimension preferredLayoutSize(Container c)
589: {
590: return getSize(c, false);
591: }
592:
593:
602: private Dimension getSize(Container c, boolean min)
603: {
604: Insets insets = frame.getInsets();
605:
606: Dimension contentDims = frame.getContentPane().getPreferredSize();
607: if (min)
608: contentDims.width = contentDims.height = 0;
609: int nWidth = 0;
610: int nHeight = 0;
611: int sWidth = 0;
612: int sHeight = 0;
613: int eWidth = 0;
614: int eHeight = 0;
615: int wWidth = 0;
616: int wHeight = 0;
617: Dimension dims;
618:
619: if (northPane != null)
620: {
621: dims = northPane.getPreferredSize();
622: if (dims != null)
623: {
624: nWidth = dims.width;
625: nHeight = dims.height;
626: }
627: }
628:
629: if (southPane != null)
630: {
631: dims = southPane.getPreferredSize();
632: if (dims != null)
633: {
634: sWidth = dims.width;
635: sHeight = dims.height;
636: }
637: }
638:
639: if (eastPane != null)
640: {
641: dims = eastPane.getPreferredSize();
642: if (dims != null)
643: {
644: sWidth = dims.width;
645: sHeight = dims.height;
646: }
647: }
648:
649: if (westPane != null)
650: {
651: dims = westPane.getPreferredSize();
652: if (dims != null)
653: {
654: wWidth = dims.width;
655: wHeight = dims.height;
656: }
657: }
658:
659: int width = Math.max(sWidth, nWidth);
660: width = Math.max(width, contentDims.width + eWidth + wWidth);
661:
662: int height = Math.max(eHeight, wHeight);
663: height = Math.max(height, contentDims.height);
664: height += nHeight + sHeight;
665:
666: width += insets.left + insets.right;
667: height += insets.top + insets.bottom;
668:
669: return new Dimension(width, height);
670: }
671:
672:
678: public void removeLayoutComponent(Component c)
679: {
680:
681: }
682: }
683:
684:
689: protected class GlassPaneDispatcher implements MouseInputListener
690: {
691:
692: private transient Component mouseEventTarget;
693:
694: private Component dragTarget;
695:
696:
699: private boolean isDragging;
700:
701:
707: public void mouseEntered(MouseEvent e)
708: {
709: handleEvent(e);
710: }
711:
712:
718: public void mouseClicked(MouseEvent e)
719: {
720: handleEvent(e);
721: }
722:
723:
729: public void mouseDragged(MouseEvent e)
730: {
731: handleEvent(e);
732: }
733:
734:
740: public void mouseExited(MouseEvent e)
741: {
742: handleEvent(e);
743: }
744:
745:
751: public void mouseMoved(MouseEvent e)
752: {
753: handleEvent(e);
754: }
755:
756:
762: public void mousePressed(MouseEvent e)
763: {
764:
765:
766: if (borderListener != null)
767: borderListener.mousePressed(e);
768: handleEvent(e);
769: }
770:
771:
777: public void mouseReleased(MouseEvent e)
778: {
779: handleEvent(e);
780: }
781:
782:
788: private void handleEvent(MouseEvent e)
789: {
790:
791: Component target = frame.getLayeredPane().findComponentAt(e.getX(),
792: e.getY());
793:
794:
795:
796: while (target != null
797: && target.getMouseListeners().length == 0
798: && target.getMouseMotionListeners().length == 0
799: && target.getMouseWheelListeners().length == 0)
800: {
801: target = target.getParent();
802: }
803:
804: if (target != null)
805: {
806: int id = e.getID();
807: switch (id)
808: {
809: case MouseEvent.MOUSE_ENTERED:
810:
811: if (! isDragging || frame.isSelected())
812: {
813: mouseEventTarget = target;
814: redispatch(id, e, mouseEventTarget);
815: }
816: break;
817: case MouseEvent.MOUSE_EXITED:
818: if (! isDragging || frame.isSelected())
819: {
820: redispatch(id, e, mouseEventTarget);
821: }
822: break;
823: case MouseEvent.MOUSE_PRESSED:
824: mouseEventTarget = target;
825: redispatch(id, e, mouseEventTarget);
826:
827: dragTarget = target;
828: break;
829: case MouseEvent.MOUSE_RELEASED:
830: if (isDragging)
831: {
832: redispatch(id, e, dragTarget);
833: isDragging = false;
834: }
835: else
836: redispatch(id, e, mouseEventTarget);
837: break;
838: case MouseEvent.MOUSE_CLICKED:
839: redispatch(id, e, mouseEventTarget);
840: break;
841: case MouseEvent.MOUSE_MOVED:
842: if (target != mouseEventTarget)
843: {
844:
845: redispatch(MouseEvent.MOUSE_EXITED, e, mouseEventTarget);
846: mouseEventTarget = target;
847: redispatch(MouseEvent.MOUSE_ENTERED, e, mouseEventTarget);
848: }
849: redispatch(id, e, mouseEventTarget);
850: break;
851: case MouseEvent.MOUSE_DRAGGED:
852: if (! isDragging)
853: isDragging = true;
854: redispatch(id, e, mouseEventTarget);
855: break;
856: case MouseEvent.MOUSE_WHEEL:
857: redispatch(id, e, mouseEventTarget);
858: break;
859: default:
860: assert false : "Must not reach here";
861: }
862: }
863: }
864:
865:
872: private void redispatch(int id, MouseEvent e, Component target)
873: {
874: Point p = SwingUtilities.convertPoint(frame.getLayeredPane(), e.getX(),
875: e.getY(), target);
876: MouseEvent ev = new MouseEvent(target, id, e.getWhen(),
877: e.getModifiers() | e.getModifiersEx(),
878: p.x, p.y, e.getClickCount(),
879: e.isPopupTrigger());
880: target.dispatchEvent(ev);
881: }
882: }
883:
884:
888: public class InternalFramePropertyChangeListener
889: implements PropertyChangeListener
890: {
891:
892:
898: public void propertyChange(PropertyChangeEvent evt)
899: {
900: String property = evt.getPropertyName();
901: if (property.equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
902: {
903: if (frame.isMaximum())
904: maximizeFrame(frame);
905: else
906: minimizeFrame(frame);
907: }
908: else if (property.equals(JInternalFrame.IS_ICON_PROPERTY))
909: {
910: if (frame.isIcon())
911: iconifyFrame(frame);
912: else
913: deiconifyFrame(frame);
914: }
915: else if (property.equals(JInternalFrame.IS_SELECTED_PROPERTY))
916: {
917: Component glassPane = frame.getGlassPane();
918: if (frame.isSelected())
919: {
920: activateFrame(frame);
921: glassPane.setVisible(false);
922: }
923: else
924: {
925: deactivateFrame(frame);
926: glassPane.setVisible(true);
927: }
928: }
929: else if (property.equals(JInternalFrame.ROOT_PANE_PROPERTY)
930: || property.equals(JInternalFrame.GLASS_PANE_PROPERTY))
931: {
932: Component old = (Component) evt.getOldValue();
933: if (old != null)
934: {
935: old.removeMouseListener(glassPaneDispatcher);
936: old.removeMouseMotionListener(glassPaneDispatcher);
937: }
938:
939: Component newPane = (Component) evt.getNewValue();
940: if (newPane != null)
941: {
942: newPane.addMouseListener(glassPaneDispatcher);
943: newPane.addMouseMotionListener(glassPaneDispatcher);
944: }
945:
946: frame.revalidate();
947: }
948: else if (property.equals(JInternalFrame.IS_CLOSED_PROPERTY))
949: {
950: if (evt.getNewValue() == Boolean.TRUE)
951: {
952: closeFrame(frame);
953: }
954: }
955:
963: }
964: }
965:
966:
969: class InternalFrameBorder extends AbstractBorder implements
970: UIResource
971: {
972:
975: static final int bSize = 5;
976:
977:
980: static final int cornerSize = 10;
981:
982:
987: public boolean isBorderOpaque()
988: {
989: return true;
990: }
991:
992:
999: public Insets getBorderInsets(Component c)
1000: {
1001: return new Insets(bSize, bSize, bSize, bSize);
1002: }
1003:
1004:
1020: public void paintBorder(Component c, Graphics g, int x, int y, int width,
1021: int height)
1022: {
1023: g.translate(x, y);
1024: Color saved = g.getColor();
1025: Rectangle b = frame.getBounds();
1026:
1027: Color d = c.getBackground();
1028: g.setColor(d);
1029: g.fillRect(0, 0, bSize, b.height);
1030: g.fillRect(0, 0, b.width, bSize);
1031: g.fillRect(0, b.height - bSize, b.width, bSize);
1032: g.fillRect(b.width - bSize, 0, bSize, b.height);
1033:
1034: int x1 = 0;
1035: int x2 = bSize;
1036: int x3 = b.width - bSize;
1037: int x4 = b.width;
1038:
1039: int y1 = 0;
1040: int y2 = bSize;
1041: int y3 = b.height - bSize;
1042: int y4 = b.height;
1043:
1044: g.setColor(Color.GRAY);
1045: g.fillRect(0, 0, bSize, y4);
1046: g.fillRect(0, 0, x4, bSize);
1047: g.fillRect(0, y3, b.width, bSize);
1048: g.fillRect(x3, 0, bSize, b.height);
1049:
1050: g.fill3DRect(0, cornerSize, bSize, b.height - 2 * cornerSize, false);
1051: g.fill3DRect(cornerSize, 0, b.width - 2 * cornerSize, bSize, false);
1052: g.fill3DRect(cornerSize, b.height - bSize, b.width - 2 * cornerSize,
1053: bSize, false);
1054: g.fill3DRect(b.width - bSize, cornerSize, bSize,
1055: b.height - 2 * cornerSize, false);
1056:
1057: g.translate(-x, -y);
1058: g.setColor(saved);
1059: }
1060: }
1061:
1062:
1067: private class ShowSystemMenuAction
1068: extends AbstractAction
1069: {
1070: public void actionPerformed(ActionEvent e)
1071: {
1072: if (titlePane != null)
1073: {
1074: titlePane.showSystemMenu();
1075: }
1076: }
1077: }
1078:
1079:
1083: protected MouseInputAdapter borderListener;
1084:
1085:
1089: protected ComponentListener componentListener;
1090:
1091:
1095: protected MouseInputListener glassPaneDispatcher;
1096:
1097:
1101: protected PropertyChangeListener propertyChangeListener;
1102:
1103:
1104: private transient BasicInternalFrameListener internalFrameListener;
1105:
1106:
1107: protected JComponent eastPane;
1108:
1109:
1110: protected JComponent northPane;
1111:
1112:
1113: protected JComponent southPane;
1114:
1115:
1116: protected JComponent westPane;
1117:
1118:
1122: protected KeyStroke openMenuKey;
1123:
1124:
1125: protected BasicInternalFrameTitlePane titlePane;
1126:
1127:
1128: protected JInternalFrame frame;
1129:
1130:
1131: protected LayoutManager internalFrameLayout;
1132:
1133:
1134: private transient JDesktopPane desktopPane;
1135:
1136:
1141: public BasicInternalFrameUI(JInternalFrame b)
1142: {
1143:
1144: }
1145:
1146:
1154: public static ComponentUI createUI(JComponent b)
1155: {
1156: return new BasicInternalFrameUI((JInternalFrame) b);
1157: }
1158:
1159:
1164: public void installUI(JComponent c)
1165: {
1166: if (c instanceof JInternalFrame)
1167: {
1168: frame = (JInternalFrame) c;
1169:
1170: installDefaults();
1171: installListeners();
1172: installComponents();
1173: installKeyboardActions();
1174:
1175: if (! frame.isSelected())
1176: frame.getGlassPane().setVisible(true);
1177: }
1178: }
1179:
1180:
1185: public void uninstallUI(JComponent c)
1186: {
1187: uninstallKeyboardActions();
1188: uninstallComponents();
1189: uninstallListeners();
1190: uninstallDefaults();
1191:
1192: frame.getRootPane().getGlassPane().setVisible(false);
1193: frame = null;
1194: }
1195:
1196:
1199: protected void installDefaults()
1200: {
1201: internalFrameLayout = createLayoutManager();
1202: frame.setLayout(internalFrameLayout);
1203: LookAndFeel.installBorder(frame, "InternalFrame.border");
1204: frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
1205:
1206:
1207:
1208: Component contentPane = frame.getContentPane();
1209: if (contentPane != null
1210: && contentPane.getBackground() instanceof UIResource)
1211: {
1212: contentPane.setBackground(null);
1213: }
1214: }
1215:
1216:
1219: protected void installKeyboardActions()
1220: {
1221: ActionMapUIResource am = new ActionMapUIResource();
1222: am.put("showSystemMenu", new ShowSystemMenuAction());
1223:
1224:
1225:
1226: BasicLookAndFeel blaf = (BasicLookAndFeel) UIManager.getLookAndFeel();
1227: ActionMap audioActionMap = blaf.getAudioActionMap();
1228: am.setParent(audioActionMap);
1229:
1230: SwingUtilities.replaceUIActionMap(frame, am);
1231: }
1232:
1233:
1236: protected void installComponents()
1237: {
1238: setNorthPane(createNorthPane(frame));
1239: setSouthPane(createSouthPane(frame));
1240: setEastPane(createEastPane(frame));
1241: setWestPane(createWestPane(frame));
1242: }
1243:
1244:
1247: protected void installListeners()
1248: {
1249: glassPaneDispatcher = createGlassPaneDispatcher();
1250: createInternalFrameListener();
1251: borderListener = createBorderListener(frame);
1252: componentListener = createComponentListener();
1253: propertyChangeListener = createPropertyChangeListener();
1254:
1255: frame.addMouseListener(borderListener);
1256: frame.addMouseMotionListener(borderListener);
1257: frame.addInternalFrameListener(internalFrameListener);
1258: frame.addPropertyChangeListener(propertyChangeListener);
1259: frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher);
1260: frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher);
1261: }
1262:
1263:
1266: protected void uninstallDefaults()
1267: {
1268: frame.setBorder(null);
1269: frame.setLayout(null);
1270: internalFrameLayout = null;
1271: }
1272:
1273:
1276: protected void uninstallComponents()
1277: {
1278: setNorthPane(null);
1279: setSouthPane(null);
1280: setEastPane(null);
1281: setWestPane(null);
1282: }
1283:
1284:
1287: protected void uninstallListeners()
1288: {
1289: if (desktopPane != null)
1290: desktopPane.removeComponentListener(componentListener);
1291:
1292: frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
1293: frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher);
1294:
1295: frame.removePropertyChangeListener(propertyChangeListener);
1296: frame.removeInternalFrameListener(internalFrameListener);
1297: frame.removeMouseMotionListener(borderListener);
1298: frame.removeMouseListener(borderListener);
1299:
1300: propertyChangeListener = null;
1301: componentListener = null;
1302: borderListener = null;
1303: internalFrameListener = null;
1304: glassPaneDispatcher = null;
1305: }
1306:
1307:
1310: protected void uninstallKeyboardActions()
1311: {
1312: SwingUtilities.replaceUIActionMap(frame, null);
1313: SwingUtilities.replaceUIInputMap(frame, JComponent.WHEN_IN_FOCUSED_WINDOW,
1314: null);
1315: }
1316:
1317:
1322: protected LayoutManager createLayoutManager()
1323: {
1324: return new InternalFrameLayout();
1325: }
1326:
1327:
1332: protected PropertyChangeListener createPropertyChangeListener()
1333: {
1334: return new InternalFramePropertyChangeListener();
1335: }
1336:
1337:
1344: public Dimension getPreferredSize(JComponent x)
1345: {
1346: Dimension pref = null;
1347: LayoutManager layout = frame.getLayout();
1348: if (frame == x && layout != null)
1349: pref = layout.preferredLayoutSize(frame);
1350: else
1351: pref = new Dimension(100, 100);
1352: return pref;
1353: }
1354:
1355:
1362: public Dimension getMinimumSize(JComponent x)
1363: {
1364: Dimension min = null;
1365: LayoutManager layout = frame.getLayout();
1366: if (frame == x && layout != null)
1367: min = layout.minimumLayoutSize(frame);
1368: else
1369: min = new Dimension(0, 0);
1370: return min;
1371: }
1372:
1373:
1380: public Dimension getMaximumSize(JComponent x)
1381: {
1382: Dimension max = null;
1383: LayoutManager layout = frame.getLayout();
1384: if (frame == x && layout != null && layout instanceof LayoutManager2)
1385: max = ((LayoutManager2) layout).maximumLayoutSize(frame);
1386: else
1387: max = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
1388: return max;
1389: }
1390:
1391:
1399: protected void replacePane(JComponent currentPane, JComponent newPane)
1400: {
1401: if (currentPane != null)
1402: {
1403: deinstallMouseHandlers(currentPane);
1404: frame.remove(currentPane);
1405: }
1406:
1407: if (newPane != null)
1408: {
1409: installMouseHandlers(newPane);
1410: frame.add(newPane);
1411: }
1412: }
1413:
1414:
1420: protected void deinstallMouseHandlers(JComponent c)
1421: {
1422: c.removeMouseListener(borderListener);
1423: c.removeMouseMotionListener(borderListener);
1424: }
1425:
1426:
1432: protected void installMouseHandlers(JComponent c)
1433: {
1434: c.addMouseListener(borderListener);
1435: c.addMouseMotionListener(borderListener);
1436: }
1437:
1438:
1445: protected JComponent createNorthPane(JInternalFrame w)
1446: {
1447: titlePane = new BasicInternalFrameTitlePane(w);
1448: return titlePane;
1449: }
1450:
1451:
1458: protected JComponent createWestPane(JInternalFrame w)
1459: {
1460: return null;
1461: }
1462:
1463:
1470: protected JComponent createSouthPane(JInternalFrame w)
1471: {
1472: return null;
1473: }
1474:
1475:
1482: protected JComponent createEastPane(JInternalFrame w)
1483: {
1484: return null;
1485: }
1486:
1487:
1494: protected MouseInputAdapter createBorderListener(JInternalFrame w)
1495: {
1496: return new BorderListener();
1497: }
1498:
1499:
1502: protected void createInternalFrameListener()
1503: {
1504: internalFrameListener = new BasicInternalFrameListener();
1505: }
1506:
1507:
1512: protected final boolean isKeyBindingRegistered()
1513: {
1514:
1515: return false;
1516: }
1517:
1518:
1523: protected final void setKeyBindingRegistered(boolean b)
1524: {
1525:
1526: }
1527:
1528:
1533: public final boolean isKeyBindingActive()
1534: {
1535:
1536: return false;
1537: }
1538:
1539:
1544: protected final void setKeyBindingActive(boolean b)
1545: {
1546:
1547: }
1548:
1549:
1552: protected void setupMenuOpenKey()
1553: {
1554:
1555: }
1556:
1557:
1560: protected void setupMenuCloseKey()
1561: {
1562:
1563: }
1564:
1565:
1570: public JComponent getNorthPane()
1571: {
1572: return northPane;
1573: }
1574:
1575:
1580: public void setNorthPane(JComponent c)
1581: {
1582: replacePane(northPane, c);
1583: northPane = c;
1584: }
1585:
1586:
1591: public JComponent getSouthPane()
1592: {
1593: return southPane;
1594: }
1595:
1596:
1601: public void setSouthPane(JComponent c)
1602: {
1603: replacePane(southPane, c);
1604: southPane = c;
1605: }
1606:
1607:
1612: public void setEastPane(JComponent c)
1613: {
1614: replacePane(eastPane, c);
1615: eastPane = c;
1616: }
1617:
1618:
1623: public JComponent getEastPane()
1624: {
1625: return eastPane;
1626: }
1627:
1628:
1633: public void setWestPane(JComponent c)
1634: {
1635: replacePane(westPane, c);
1636: westPane = c;
1637: }
1638:
1639:
1644: public JComponent getWestPane()
1645: {
1646: return westPane;
1647: }
1648:
1649:
1654: protected DesktopManager getDesktopManager()
1655: {
1656: DesktopManager value = null;
1657: JDesktopPane pane = frame.getDesktopPane();
1658: if (pane != null)
1659: value = frame.getDesktopPane().getDesktopManager();
1660: if (value == null)
1661: value = createDesktopManager();
1662: return value;
1663: }
1664:
1665:
1672: protected DesktopManager createDesktopManager()
1673: {
1674: return new DefaultDesktopManager();
1675: }
1676:
1677:
1682: protected void closeFrame(JInternalFrame f)
1683: {
1684: getDesktopManager().closeFrame(f);
1685: }
1686:
1687:
1692: protected void maximizeFrame(JInternalFrame f)
1693: {
1694: getDesktopManager().maximizeFrame(f);
1695: }
1696:
1697:
1702: protected void minimizeFrame(JInternalFrame f)
1703: {
1704: getDesktopManager().minimizeFrame(f);
1705: }
1706:
1707:
1712: protected void iconifyFrame(JInternalFrame f)
1713: {
1714: getDesktopManager().iconifyFrame(f);
1715: }
1716:
1717:
1722: protected void deiconifyFrame(JInternalFrame f)
1723: {
1724: getDesktopManager().deiconifyFrame(f);
1725: }
1726:
1727:
1732: protected void activateFrame(JInternalFrame f)
1733: {
1734: getDesktopManager().activateFrame(f);
1735: }
1736:
1737:
1742: protected void deactivateFrame(JInternalFrame f)
1743: {
1744: getDesktopManager().deactivateFrame(f);
1745: }
1746:
1747:
1752: protected ComponentListener createComponentListener()
1753: {
1754: return new ComponentHandler();
1755: }
1756:
1757:
1762: protected MouseInputListener createGlassPaneDispatcher()
1763: {
1764: return new GlassPaneDispatcher();
1765: }
1766: }