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: import ;
61: import ;
62: import ;
63:
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: import ;
83: import ;
84: import ;
85: import ;
86: import ;
87: import ;
88:
89:
92: public class BasicToolBarUI extends ToolBarUI implements SwingConstants
93: {
94:
95:
98: static class ToolBarAction
99: extends AbstractAction
100: {
101:
104: public void actionPerformed(ActionEvent event)
105: {
106: Object cmd = getValue("__command__");
107: JToolBar toolBar = (JToolBar) event.getSource();
108: BasicToolBarUI ui = (BasicToolBarUI) toolBar.getUI();
109:
110: if (cmd.equals("navigateRight"))
111: ui.navigateFocusedComp(EAST);
112: else if (cmd.equals("navigateLeft"))
113: ui.navigateFocusedComp(WEST);
114: else if (cmd.equals("navigateUp"))
115: ui.navigateFocusedComp(NORTH);
116: else if (cmd.equals("navigateDown"))
117: ui.navigateFocusedComp(SOUTH);
118: else
119: assert false : "Shouldn't reach here";
120: }
121: }
122:
123:
125: static JFrame owner = new JFrame();
126:
127:
128: private static Border nonRolloverBorder;
129:
130:
131: private static Border rolloverBorder;
132:
133:
134: protected String constraintBeforeFloating;
135:
136:
138: int lastGoodOrientation;
139:
140:
141: protected Color dockingBorderColor;
142:
143:
144: protected Color dockingColor;
145:
146:
147: protected MouseInputListener dockingListener;
148:
149:
150: protected BasicToolBarUI.DragWindow dragWindow;
151:
152:
153: protected Color floatingBorderColor;
154:
155:
156: protected Color floatingColor;
157:
158:
159: protected int focusedCompIndex;
160:
161:
162: protected PropertyChangeListener propertyListener;
163:
164:
165: protected JToolBar toolBar;
166:
167:
168: protected ContainerListener toolBarContListener;
169:
170:
171: protected FocusListener toolBarFocusListener;
172:
173:
176: protected KeyStroke leftKey;
177:
178:
181: protected KeyStroke rightKey;
182:
183:
186: protected KeyStroke upKey;
187:
188:
191: protected KeyStroke downKey;
192:
193:
197: private transient Window floatFrame;
198:
199:
201: transient Container origParent;
202:
203:
205: transient Hashtable borders;
206:
207:
208: private transient WindowListener windowListener;
209:
210:
212: transient Dimension cachedBounds;
213:
214:
216: transient int cachedOrientation;
217:
218:
221: public BasicToolBarUI()
222: {
223:
224: }
225:
226:
235: public boolean canDock(Component c, Point p)
236: {
237: return areaOfClick(c, p) != -1;
238: }
239:
240:
250: private int areaOfClick(Component c, Point p)
251: {
252:
253: Rectangle pBounds = c.getBounds();
254:
255:
256: Dimension d = toolBar.getSize();
257: int limit = Math.min(d.width, d.height);
258:
259:
260: if (! pBounds.contains(p))
261: return -1;
262:
263: if (p.y < limit)
264: return SwingConstants.NORTH;
265:
266: if (p.y > (pBounds.height - limit))
267: return SwingConstants.SOUTH;
268:
269: if (p.x < limit)
270: return SwingConstants.WEST;
271:
272: if (p.x > (pBounds.width - limit))
273: return SwingConstants.EAST;
274:
275: return -1;
276: }
277:
278:
283: protected MouseInputListener createDockingListener()
284: {
285: return new DockingListener(toolBar);
286: }
287:
288:
295: protected BasicToolBarUI.DragWindow createDragWindow(JToolBar toolbar)
296: {
297: return new DragWindow();
298: }
299:
300:
309: protected JFrame createFloatingFrame(JToolBar toolbar)
310: {
311:
312: return null;
313: }
314:
315:
323: protected RootPaneContainer createFloatingWindow(JToolBar toolbar)
324: {
325:
326: return new ToolBarDialog();
327: }
328:
329:
334: protected WindowListener createFrameListener()
335: {
336: return new FrameListener();
337: }
338:
339:
345: protected Border createNonRolloverBorder()
346: {
347: Border b = UIManager.getBorder("ToolBar.nonrolloverBorder");
348:
349: if (b == null)
350: {
351: b = new CompoundBorder(
352: new ButtonBorder(UIManager.getColor("Button.shadow"),
353: UIManager.getColor("Button.darkShadow"),
354: UIManager.getColor("Button.light"),
355: UIManager.getColor("Button.highlight")),
356: BasicBorders.getMarginBorder());
357: }
358:
359: return b; }
360:
361:
366: protected PropertyChangeListener createPropertyListener()
367: {
368: return new PropertyListener();
369: }
370:
371:
377: protected Border createRolloverBorder()
378: {
379: Border b = UIManager.getBorder("ToolBar.rolloverBorder");
380:
381: if (b == null)
382: {
383: b = new CompoundBorder(
384: new ButtonBorder(UIManager.getColor("Button.shadow"),
385: UIManager.getColor("Button.darkShadow"),
386: UIManager.getColor("Button.light"),
387: UIManager.getColor("Button.highlight")),
388: BasicBorders.getMarginBorder());
389: }
390:
391: return b;
392: }
393:
394:
399: protected ContainerListener createToolBarContListener()
400: {
401: return new ToolBarContListener();
402: }
403:
404:
409: protected FocusListener createToolBarFocusListener()
410: {
411: return new ToolBarFocusListener();
412: }
413:
414:
421: public static ComponentUI createUI(JComponent c)
422: {
423: return new BasicToolBarUI();
424: }
425:
426:
433: protected void dragTo(Point position, Point origin)
434: {
435: int loc = areaOfClick(origParent,
436: SwingUtilities.convertPoint(toolBar, position,
437: origParent));
438:
439: if (loc != -1)
440: {
441: dragWindow.setBorderColor(dockingBorderColor);
442: dragWindow.setBackground(dockingColor);
443: }
444: else
445: {
446: dragWindow.setBorderColor(floatingBorderColor);
447: dragWindow.setBackground(floatingColor);
448: }
449:
450: int w = 0;
451: int h = 0;
452:
453: boolean tmp = (loc == SwingConstants.NORTH)
454: || (loc == SwingConstants.SOUTH) || (loc == -1);
455:
456: cachedOrientation = toolBar.getOrientation();
457: cachedBounds = toolBar.getSize();
458: if (((cachedOrientation == SwingConstants.HORIZONTAL) && tmp)
459: || ((cachedOrientation == VERTICAL) && ! tmp))
460: {
461: w = cachedBounds.width;
462: h = cachedBounds.height;
463: }
464: else
465: {
466: w = cachedBounds.height;
467: h = cachedBounds.width;
468: }
469:
470: Point p = dragWindow.getOffset();
471: Insets insets = toolBar.getInsets();
472:
473: dragWindow.setBounds((origin.x + position.x) - p.x
474: - ((insets.left + insets.right) / 2),
475: (origin.y + position.y) - p.y
476: - ((insets.top + insets.bottom) / 2), w, h);
477:
478: if (! dragWindow.isVisible())
479: dragWindow.show();
480: }
481:
482:
492: protected void floatAt(Point position, Point origin)
493: {
494: Point p = new Point(position);
495: int aoc = areaOfClick(origParent,
496: SwingUtilities.convertPoint(toolBar, p, origParent));
497:
498: Container oldParent = toolBar.getParent();
499:
500: oldParent.remove(toolBar);
501: oldParent.doLayout();
502: oldParent.repaint();
503:
504: Container newParent;
505:
506: if (aoc == -1)
507: newParent = ((RootPaneContainer) floatFrame).getContentPane();
508: else
509: {
510: floatFrame.hide();
511: newParent = origParent;
512: }
513:
514: String constraint;
515: switch (aoc)
516: {
517: case SwingConstants.EAST:
518: constraint = BorderLayout.EAST;
519: break;
520: case SwingConstants.NORTH:
521: constraint = BorderLayout.NORTH;
522: break;
523: case SwingConstants.SOUTH:
524: constraint = BorderLayout.SOUTH;
525: break;
526: case SwingConstants.WEST:
527: constraint = BorderLayout.WEST;
528: break;
529: default:
530: constraint = BorderLayout.CENTER;
531: break;
532: }
533:
534: int newOrientation = SwingConstants.HORIZONTAL;
535: if ((aoc != -1)
536: && ((aoc == SwingConstants.EAST) || (aoc == SwingConstants.WEST)))
537: newOrientation = SwingConstants.VERTICAL;
538:
539: if (aoc != -1)
540: {
541: constraintBeforeFloating = constraint;
542: lastGoodOrientation = newOrientation;
543: }
544:
545: newParent.add(toolBar, constraint);
546:
547: setFloating(aoc == -1, null);
548: toolBar.setOrientation(newOrientation);
549:
550: Insets insets = floatFrame.getInsets();
551: Dimension dims = toolBar.getPreferredSize();
552: p = dragWindow.getOffset();
553: setFloatingLocation((position.x + origin.x) - p.x
554: - ((insets.left + insets.right) / 2),
555: (position.y + origin.y) - p.y
556: - ((insets.top + insets.bottom) / 2));
557:
558: if (aoc == -1)
559: {
560: floatFrame.pack();
561: floatFrame.setSize(dims.width + insets.left + insets.right,
562: dims.height + insets.top + insets.bottom);
563: floatFrame.show();
564: }
565:
566: newParent.invalidate();
567: newParent.validate();
568: newParent.repaint();
569: }
570:
571:
576: public Color getDockingColor()
577: {
578: return dockingColor;
579: }
580:
581:
587: public Color getFloatingColor()
588: {
589: return floatingColor;
590: }
591:
592:
599: public Dimension getMaximumSize(JComponent c)
600: {
601: return getPreferredSize(c);
602: }
603:
604:
611: public Dimension getMinimumSize(JComponent c)
612: {
613: return getPreferredSize(c);
614: }
615:
616:
619: protected void installComponents()
620: {
621: floatFrame = (Window) createFloatingWindow(toolBar);
622:
623: dragWindow = createDragWindow(toolBar);
624:
625: nonRolloverBorder = createNonRolloverBorder();
626: rolloverBorder = createRolloverBorder();
627:
628: borders = new Hashtable();
629: setRolloverBorders(toolBar.isRollover());
630:
631: fillHashtable();
632: }
633:
634:
637: protected void installDefaults()
638: {
639: LookAndFeel.installBorder(toolBar, "ToolBar.border");
640: LookAndFeel.installColorsAndFont(toolBar, "ToolBar.background",
641: "ToolBar.foreground", "ToolBar.font");
642:
643: dockingBorderColor = UIManager.getColor("ToolBar.dockingForeground");
644: dockingColor = UIManager.getColor("ToolBar.dockingBackground");
645:
646: floatingBorderColor = UIManager.getColor("ToolBar.floatingForeground");
647: floatingColor = UIManager.getColor("ToolBar.floatingBackground");
648: }
649:
650:
654: protected void installKeyboardActions()
655: {
656:
657: InputMap inputMap =
658: (InputMap) SharedUIDefaults.get("ToolBar.ancestorInputMap");
659: SwingUtilities.replaceUIInputMap(toolBar,
660: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
661: inputMap);
662:
663:
664: SwingUtilities.replaceUIActionMap(toolBar, getActionMap());
665: }
666:
667:
673: private ActionMap getActionMap()
674: {
675: ActionMap am = (ActionMap) UIManager.get("ToolBar.actionMap");
676: if (am == null)
677: {
678: am = createDefaultActions();
679: UIManager.getLookAndFeelDefaults().put("ToolBar.actionMap", am);
680: }
681: return am;
682: }
683:
684: private ActionMap createDefaultActions()
685: {
686: ActionMapUIResource am = new ActionMapUIResource();
687: Action action = new ToolBarAction();
688:
689: am.put("navigateLeft", action);
690: am.put("navigateRight", action);
691: am.put("navigateUp", action);
692: am.put("navigateDown", action);
693:
694: return am;
695: }
696:
697:
700: protected void installListeners()
701: {
702: dockingListener = createDockingListener();
703: toolBar.addMouseListener(dockingListener);
704: toolBar.addMouseMotionListener(dockingListener);
705:
706: propertyListener = createPropertyListener();
707: toolBar.addPropertyChangeListener(propertyListener);
708:
709: toolBarContListener = createToolBarContListener();
710: toolBar.addContainerListener(toolBarContListener);
711:
712: windowListener = createFrameListener();
713: floatFrame.addWindowListener(windowListener);
714:
715: toolBarFocusListener = createToolBarFocusListener();
716: if (toolBarFocusListener != null)
717: {
718: int count = toolBar.getComponentCount();
719: for (int i = 0; i < count; i++)
720: toolBar.getComponent(i).addFocusListener(toolBarFocusListener);
721: }
722: }
723:
724:
731: protected void installNonRolloverBorders(JComponent c)
732: {
733: Component[] components = toolBar.getComponents();
734:
735: for (int i = 0; i < components.length; i++)
736: setBorderToNonRollover(components[i]);
737: }
738:
739:
746: protected void installNormalBorders(JComponent c)
747: {
748: Component[] components = toolBar.getComponents();
749:
750: for (int i = 0; i < components.length; i++)
751: setBorderToNormal(components[i]);
752: }
753:
754:
761: protected void installRolloverBorders(JComponent c)
762: {
763: Component[] components = toolBar.getComponents();
764:
765: for (int i = 0; i < components.length; i++)
766: setBorderToRollover(components[i]);
767: }
768:
769:
773: private void fillHashtable()
774: {
775: Component[] c = toolBar.getComponents();
776:
777: for (int i = 0; i < c.length; i++)
778: {
779: if (c[i] instanceof JButton)
780: {
781:
782: JButton b = (JButton) c[i];
783:
784: if (b.getBorder() != null)
785: borders.put(b, b.getBorder());
786: }
787: }
788: }
789:
790:
795: public void installUI(JComponent c)
796: {
797: super.installUI(c);
798:
799: if (c instanceof JToolBar)
800: {
801: toolBar = (JToolBar) c;
802: installDefaults();
803: installComponents();
804: installListeners();
805: installKeyboardActions();
806: }
807: }
808:
809:
814: public boolean isFloating()
815: {
816: return floatFrame.isVisible();
817: }
818:
819:
824: public boolean isRolloverBorders()
825: {
826: return toolBar.isRollover();
827: }
828:
829:
835: protected void navigateFocusedComp(int direction)
836: {
837: int count = toolBar.getComponentCount();
838: switch (direction)
839: {
840: case EAST:
841: case SOUTH:
842: if (focusedCompIndex >= 0 && focusedCompIndex < count)
843: {
844: int i = focusedCompIndex + 1;
845: boolean focusRequested = false;
846:
847: while (i != focusedCompIndex && ! focusRequested)
848: {
849: if (i >= count)
850: i = 0;
851: Component comp = toolBar.getComponentAtIndex(i++);
852: if (comp != null && comp.isFocusable()
853: && comp.isEnabled())
854: {
855: comp.requestFocus();
856: focusRequested = true;
857: }
858: }
859: }
860: break;
861: case WEST:
862: case NORTH:
863: if (focusedCompIndex >= 0 && focusedCompIndex < count)
864: {
865: int i = focusedCompIndex - 1;
866: boolean focusRequested = false;
867:
868: while (i != focusedCompIndex && ! focusRequested)
869: {
870: if (i < 0)
871: i = count - 1;
872: Component comp = toolBar.getComponentAtIndex(i--);
873: if (comp != null && comp.isFocusable()
874: && comp.isEnabled())
875: {
876: comp.requestFocus();
877: focusRequested = true;
878: }
879: }
880: }
881: break;
882: default:
883: break;
884: }
885: }
886:
887:
893: protected void setBorderToNonRollover(Component c)
894: {
895: if (c instanceof AbstractButton)
896: {
897: AbstractButton b = (AbstractButton) c;
898: b.setRolloverEnabled(false);
899:
900:
901: if (b.getBorder() != null)
902: borders.put(b, b.getBorder());
903:
904: b.setBorder(nonRolloverBorder);
905: }
906: }
907:
908:
913: protected void setBorderToNormal(Component c)
914: {
915: if (c instanceof AbstractButton)
916: {
917: AbstractButton b = (AbstractButton) c;
918: b.setRolloverEnabled(true);
919: b.setBorder((Border) borders.remove(b));
920: }
921: }
922:
923:
928: protected void setBorderToRollover(Component c)
929: {
930: if (c instanceof AbstractButton)
931: {
932: AbstractButton b = (AbstractButton) c;
933: b.setRolloverEnabled(false);
934:
935:
936: if (b.getBorder() != null)
937: borders.put(b, b.getBorder());
938:
939: b.setBorder(rolloverBorder);
940: }
941: }
942:
943:
948: public void setDockingColor(Color c)
949: {
950: dockingColor = c;
951: }
952:
953:
959: public void setFloating(boolean b, Point p)
960: {
961:
962:
963: floatFrame.setVisible(b);
964: }
965:
966:
972: public void setFloatingColor(Color c)
973: {
974: floatingColor = c;
975: }
976:
977:
983: public void setFloatingLocation(int x, int y)
984: {
985:
986:
987: floatFrame.setLocation(x, y);
988: floatFrame.invalidate();
989: floatFrame.validate();
990: floatFrame.repaint();
991: }
992:
993:
999: public void setOrientation(int orientation)
1000: {
1001: toolBar.setOrientation(orientation);
1002: }
1003:
1004:
1011: public void setRolloverBorders(boolean rollover)
1012: {
1013: if (rollover)
1014: installRolloverBorders(toolBar);
1015: else
1016: installNonRolloverBorders(toolBar);
1017: }
1018:
1019:
1022: protected void uninstallComponents()
1023: {
1024: installNormalBorders(toolBar);
1025: borders = null;
1026: cachedBounds = null;
1027:
1028: floatFrame = null;
1029: dragWindow = null;
1030: }
1031:
1032:
1035: protected void uninstallDefaults()
1036: {
1037: toolBar.setBackground(null);
1038: toolBar.setForeground(null);
1039: toolBar.setFont(null);
1040:
1041: dockingBorderColor = null;
1042: dockingColor = null;
1043: floatingBorderColor = null;
1044: floatingColor = null;
1045: }
1046:
1047:
1050: protected void uninstallKeyboardActions()
1051: {
1052: SwingUtilities.replaceUIInputMap(toolBar, JComponent.
1053: WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
1054: SwingUtilities.replaceUIActionMap(toolBar, null);
1055: }
1056:
1057:
1060: protected void uninstallListeners()
1061: {
1062: if (toolBarFocusListener != null)
1063: {
1064: int count = toolBar.getComponentCount();
1065: for (int i = 0; i < count; i++)
1066: toolBar.getComponent(i).removeFocusListener(toolBarFocusListener);
1067: toolBarFocusListener = null;
1068: }
1069:
1070: floatFrame.removeWindowListener(windowListener);
1071: windowListener = null;
1072:
1073: toolBar.removeContainerListener(toolBarContListener);
1074: toolBarContListener = null;
1075:
1076: toolBar.removeMouseMotionListener(dockingListener);
1077: toolBar.removeMouseListener(dockingListener);
1078: dockingListener = null;
1079: }
1080:
1081:
1086: public void uninstallUI(JComponent c)
1087: {
1088: uninstallKeyboardActions();
1089: uninstallListeners();
1090: uninstallComponents();
1091: uninstallDefaults();
1092: toolBar = null;
1093: }
1094:
1095:
1099: public class DockingListener implements MouseInputListener
1100: {
1101:
1102: protected boolean isDragging;
1103:
1104:
1108: protected Point origin;
1109:
1110:
1111: protected JToolBar toolBar;
1112:
1113:
1118: public DockingListener(JToolBar t)
1119: {
1120: toolBar = t;
1121: }
1122:
1123:
1128: public void mouseClicked(MouseEvent e)
1129: {
1130:
1131: }
1132:
1133:
1139: public void mouseDragged(MouseEvent e)
1140: {
1141: if (isDragging)
1142: dragTo(e.getPoint(), origin);
1143: }
1144:
1145:
1150: public void mouseEntered(MouseEvent e)
1151: {
1152:
1153: }
1154:
1155:
1160: public void mouseExited(MouseEvent e)
1161: {
1162:
1163: }
1164:
1165:
1170: public void mouseMoved(MouseEvent e)
1171: {
1172:
1173: }
1174:
1175:
1182: public void mousePressed(MouseEvent e)
1183: {
1184: if (! toolBar.isFloatable())
1185: return;
1186:
1187: Point ssd = e.getPoint();
1188: Insets insets = toolBar.getInsets();
1189:
1190:
1191: if (toolBar.getOrientation() == SwingConstants.HORIZONTAL)
1192: {
1193: if (e.getX() > insets.left)
1194: return;
1195: }
1196: else
1197: {
1198: if (e.getY() > insets.top)
1199: return;
1200: }
1201:
1202: origin = new Point(0, 0);
1203: if (toolBar.isShowing())
1204: SwingUtilities.convertPointToScreen(ssd, toolBar);
1205:
1206: if (! (SwingUtilities.getAncestorOfClass(Window.class, toolBar) instanceof UIResource))
1207:
1208: origParent = toolBar.getParent();
1209:
1210: if (toolBar.isShowing())
1211: SwingUtilities.convertPointToScreen(origin, toolBar);
1212:
1213: isDragging = true;
1214:
1215: if (dragWindow != null)
1216: dragWindow.setOffset(new Point(cachedBounds.width / 2,
1217: cachedBounds.height / 2));
1218:
1219: dragTo(e.getPoint(), origin);
1220: }
1221:
1222:
1227: public void mouseReleased(MouseEvent e)
1228: {
1229: if (! isDragging || ! toolBar.isFloatable())
1230: return;
1231:
1232: isDragging = false;
1233: floatAt(e.getPoint(), origin);
1234: dragWindow.hide();
1235: }
1236: }
1237:
1238:
1242: protected class DragWindow extends Window
1243: {
1244:
1248: private Color borderColor;
1249:
1250:
1251: private Point offset;
1252:
1253:
1257: DragWindow()
1258: {
1259: super(owner);
1260: }
1261:
1262:
1267: public Color getBorderColor()
1268: {
1269: if (borderColor == null)
1270: return Color.BLACK;
1271:
1272: return borderColor;
1273: }
1274:
1275:
1280: public Insets getInsets()
1281: {
1282:
1283: return new Insets(0, 0, 0, 0);
1284: }
1285:
1286:
1292: public Point getOffset()
1293: {
1294: return offset;
1295: }
1296:
1297:
1302: public void paint(Graphics g)
1303: {
1304:
1305: Color saved = g.getColor();
1306: Rectangle b = getBounds();
1307:
1308: g.setColor(getBorderColor());
1309: g.drawRect(0, 0, b.width - 1, b.height - 1);
1310:
1311: g.setColor(saved);
1312: }
1313:
1314:
1319: public void setBorderColor(Color c)
1320: {
1321: borderColor = c;
1322: }
1323:
1324:
1329: public void setOffset(Point p)
1330: {
1331: offset = p;
1332: }
1333:
1334:
1341: public void setOrientation(int o)
1342: {
1343: toolBar.setOrientation(o);
1344: if (dragWindow != null)
1345: dragWindow.setOrientation(o);
1346: }
1347: }
1348:
1349:
1353: protected class FrameListener extends WindowAdapter
1354: {
1355:
1360: public void windowClosing(WindowEvent e)
1361: {
1362: Container parent = toolBar.getParent();
1363: parent.remove(toolBar);
1364:
1365: if (origParent != null)
1366: {
1367: origParent.add(toolBar,
1368: (constraintBeforeFloating != null)
1369: ? constraintBeforeFloating : BorderLayout.NORTH);
1370: toolBar.setOrientation(lastGoodOrientation);
1371: }
1372:
1373: origParent.invalidate();
1374: origParent.validate();
1375: origParent.repaint();
1376: }
1377: }
1378:
1379:
1382: protected class PropertyListener implements PropertyChangeListener
1383: {
1384:
1389: public void propertyChange(PropertyChangeEvent e)
1390: {
1391:
1392: if (e.getPropertyName().equals("rollover") && toolBar != null)
1393: setRolloverBorders(toolBar.isRollover());
1394: }
1395: }
1396:
1397:
1401: protected class ToolBarContListener implements ContainerListener
1402: {
1403:
1409: public void componentAdded(ContainerEvent e)
1410: {
1411: if (e.getChild() instanceof JButton)
1412: {
1413: JButton b = (JButton) e.getChild();
1414:
1415: if (b.getBorder() != null)
1416: borders.put(b, b.getBorder());
1417: }
1418:
1419: if (isRolloverBorders())
1420: setBorderToRollover(e.getChild());
1421: else
1422: setBorderToNonRollover(e.getChild());
1423:
1424: cachedBounds = toolBar.getPreferredSize();
1425: cachedOrientation = toolBar.getOrientation();
1426:
1427: Component c = e.getChild();
1428: if (toolBarFocusListener != null)
1429: c.addFocusListener(toolBarFocusListener);
1430: }
1431:
1432:
1438: public void componentRemoved(ContainerEvent e)
1439: {
1440: setBorderToNormal(e.getChild());
1441: cachedBounds = toolBar.getPreferredSize();
1442: cachedOrientation = toolBar.getOrientation();
1443:
1444: Component c = e.getChild();
1445: if (toolBarFocusListener != null)
1446: c.removeFocusListener(toolBarFocusListener);
1447: }
1448: }
1449:
1450:
1454: private class ToolBarDialog extends JDialog implements UIResource
1455: {
1456:
1459: public ToolBarDialog()
1460: {
1461: super();
1462: setName((toolBar.getName() != null) ? toolBar.getName() : "");
1463: }
1464: }
1465:
1466:
1469: protected class ToolBarFocusListener implements FocusListener
1470: {
1471:
1474: protected ToolBarFocusListener()
1475: {
1476:
1477: }
1478:
1479:
1485: public void focusGained(FocusEvent e)
1486: {
1487: Component c = e.getComponent();
1488: focusedCompIndex = toolBar.getComponentIndex(c);
1489: }
1490:
1491:
1497: public void focusLost(FocusEvent e)
1498: {
1499:
1500: }
1501: }
1502:
1503:
1506: private static class ToolBarBorder implements Border
1507: {
1508:
1509: private static final int offset = 10;
1510:
1511:
1512: private static final int regular = 2;
1513:
1514:
1521: public Insets getBorderInsets(Component c)
1522: {
1523: if (c instanceof JToolBar)
1524: {
1525: JToolBar tb = (JToolBar) c;
1526: int orientation = tb.getOrientation();
1527:
1528: if (! tb.isFloatable())
1529: return new Insets(regular, regular, regular, regular);
1530: else if (orientation == SwingConstants.HORIZONTAL)
1531: return new Insets(regular, offset, regular, regular);
1532: else
1533: return new Insets(offset, regular, regular, regular);
1534: }
1535:
1536: return new Insets(0, 0, 0, 0);
1537: }
1538:
1539:
1544: public boolean isBorderOpaque()
1545: {
1546: return false;
1547: }
1548:
1549:
1560: private void paintBumps(Graphics g, int x, int y, int w, int h, int size,
1561: Color c)
1562: {
1563: Color saved = g.getColor();
1564: g.setColor(c);
1565:
1566: int hgap = 2 * size;
1567: int vgap = 4 * size;
1568: int count = 0;
1569:
1570: for (int i = x; i < (w + x); i += hgap)
1571: for (int j = ((count++ % 2) == 0) ? y : (y + (2 * size)); j < (h + y);
1572: j += vgap)
1573: g.fillRect(i, j, size, size);
1574:
1575: g.setColor(saved);
1576: }
1577:
1578:
1588: public void paintBorder(Component c, Graphics g, int x, int y, int width,
1589: int height)
1590: {
1591: if (c instanceof JToolBar)
1592: {
1593: JToolBar tb = (JToolBar) c;
1594:
1595: int orientation = tb.getOrientation();
1596:
1597: if (orientation == SwingConstants.HORIZONTAL)
1598: {
1599: paintBumps(g, x, y, offset, height, 1, Color.WHITE);
1600: paintBumps(g, x + 1, y + 1, offset - 1, height - 1, 1, Color.GRAY);
1601: }
1602: else
1603: {
1604: paintBumps(g, x, y, width, offset, 1, Color.WHITE);
1605: paintBumps(g, x + 1, y + 1, width - 1, offset - 1, 1, Color.GRAY);
1606: }
1607: }
1608: }
1609: }
1610: }