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:
59: import ;
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: import ;
82: import ;
83: import ;
84: import ;
85: import ;
86: import ;
87:
88:
91: public class BasicMenuItemUI extends MenuItemUI
92: {
93:
96: protected Font acceleratorFont;
97:
98:
101: protected Color acceleratorForeground;
102:
103:
107: protected Color acceleratorSelectionForeground;
108:
109:
113: protected Icon arrowIcon;
114:
115:
119: protected Icon checkIcon;
120:
121:
124: protected int defaultTextIconGap = 4;
125:
126:
129: protected Color disabledForeground;
130:
131:
134: protected MenuDragMouseListener menuDragMouseListener;
135:
136:
139: protected JMenuItem menuItem;
140:
141:
144: protected MenuKeyListener menuKeyListener;
145:
146:
149: protected MouseInputListener mouseInputListener;
150:
151:
154: protected boolean oldBorderPainted;
155:
156:
159: protected Color selectionBackground;
160:
161:
164: protected Color selectionForeground;
165:
166:
169: private String acceleratorDelimiter;
170:
171:
174: private ItemListener itemListener;
175:
176:
179: private int defaultAcceleratorLabelGap = 10;
180:
181:
184: private int MenuGap = 10;
185:
186:
187: PropertyChangeHandler propertyChangeListener;
188:
189:
192: private Rectangle viewRect;
193:
194:
197: private Rectangle textRect;
198:
199:
202: private Rectangle accelRect;
203:
204:
207: private Rectangle iconRect;
208:
209:
212: private Rectangle arrowIconRect;
213:
214:
217: private Rectangle checkIconRect;
218:
219:
223: private Rectangle cachedRect;
224:
225:
229: class PropertyChangeHandler implements PropertyChangeListener
230: {
231:
238: public void propertyChange(PropertyChangeEvent e)
239: {
240: if (e.getPropertyName() == "accelerator")
241: {
242: InputMap map = SwingUtilities.getUIInputMap(menuItem,
243: JComponent.WHEN_IN_FOCUSED_WINDOW);
244: if (map != null)
245: map.remove((KeyStroke) e.getOldValue());
246: else
247: map = new ComponentInputMapUIResource(menuItem);
248:
249: KeyStroke accelerator = (KeyStroke) e.getNewValue();
250: if (accelerator != null)
251: map.put(accelerator, "doClick");
252: }
253: }
254: }
255:
256:
262: class ClickAction extends AbstractAction
263: {
264:
268: public void actionPerformed(ActionEvent event)
269: {
270: doClick(MenuSelectionManager.defaultManager());
271: }
272: }
273:
274:
277: public BasicMenuItemUI()
278: {
279: mouseInputListener = createMouseInputListener(menuItem);
280: menuDragMouseListener = createMenuDragMouseListener(menuItem);
281: menuKeyListener = createMenuKeyListener(menuItem);
282: itemListener = new ItemHandler();
283: propertyChangeListener = new PropertyChangeHandler();
284:
285:
286: viewRect = new Rectangle();
287: textRect = new Rectangle();
288: iconRect = new Rectangle();
289: arrowIconRect = new Rectangle();
290: checkIconRect = new Rectangle();
291: accelRect = new Rectangle();
292: cachedRect = new Rectangle();
293: }
294:
295:
302: protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
303: {
304: return new MenuDragMouseHandler();
305: }
306:
307:
315: protected MenuKeyListener createMenuKeyListener(JComponent c)
316: {
317: return new MenuKeyHandler();
318: }
319:
320:
327: protected MouseInputListener createMouseInputListener(JComponent c)
328: {
329: return new MouseInputHandler();
330: }
331:
332:
340: public static ComponentUI createUI(JComponent c)
341: {
342: return new BasicMenuItemUI();
343: }
344:
345:
351: protected void doClick(MenuSelectionManager msm)
352: {
353: menuItem.doClick();
354: msm.clearSelectedPath();
355: }
356:
357:
364: public Dimension getMaximumSize(JComponent c)
365: {
366: return null;
367: }
368:
369:
376: public Dimension getMinimumSize(JComponent c)
377: {
378: return null;
379: }
380:
381:
387: public MenuElement[] getPath()
388: {
389: ArrayList path = new ArrayList();
390:
391:
392: if (menuItem instanceof JMenu)
393: path.add(((JMenu) menuItem).getPopupMenu());
394:
395: Component c = menuItem;
396: while (c instanceof MenuElement)
397: {
398: path.add(0, (MenuElement) c);
399:
400: if (c instanceof JPopupMenu)
401: c = ((JPopupMenu) c).getInvoker();
402: else
403: c = c.getParent();
404: }
405:
406: MenuElement[] pathArray = new MenuElement[path.size()];
407: path.toArray(pathArray);
408: return pathArray;
409: }
410:
411:
424: protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,
425: Icon arrowIcon,
426: int defaultTextIconGap)
427: {
428: JMenuItem m = (JMenuItem) c;
429: String accelText = getAcceleratorString(m);
430:
431:
432:
433: layoutMenuItem(m, accelText);
434:
435:
436: cachedRect.setBounds(textRect);
437: Rectangle pref = SwingUtilities.computeUnion(iconRect.x, iconRect.y,
438: iconRect.width,
439: iconRect.height,
440: cachedRect);
441:
442:
443:
444:
445:
446: Container parent = m.getParent();
447: if (parent != null && parent instanceof JComponent
448: && !(m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
449: {
450: JComponent p = (JComponent) parent;
451:
452:
453: Integer maxTextWidth = (Integer) p.getClientProperty("maxTextWidth");
454: int maxTextValue = maxTextWidth == null ? 0 : maxTextWidth.intValue();
455: if (pref.width < maxTextValue)
456: pref.width = maxTextValue;
457: else
458: p.putClientProperty("maxTextWidth", new Integer(pref.width));
459:
460:
461: Integer maxAccelWidth = (Integer) p.getClientProperty("maxAccelWidth");
462: int maxAccelValue = maxAccelWidth == null ? 0
463: : maxAccelWidth.intValue();
464: if (accelRect.width > maxAccelValue)
465: {
466: maxAccelValue = accelRect.width;
467: p.putClientProperty("maxAccelWidth", new Integer(accelRect.width));
468: }
469: pref.width += maxAccelValue;
470: pref.width += defaultTextIconGap;
471: }
472:
473:
474: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
475: {
476: pref.width += checkIconRect.width;
477: pref.width += defaultTextIconGap;
478: pref.width += arrowIconRect.width;
479: pref.width += defaultTextIconGap;
480: }
481:
482:
483: pref.width += 2 * defaultTextIconGap;
484:
485:
486: Insets i = m.getInsets();
487: pref.width += i.left + i.right;
488: pref.height += i.top + i.bottom;
489:
490:
491: return pref.getSize();
492: }
493:
494:
501: public Dimension getPreferredSize(JComponent c)
502: {
503: return getPreferredMenuItemSize(c, checkIcon, arrowIcon,
504: defaultTextIconGap);
505: }
506:
507:
512: protected String getPropertyPrefix()
513: {
514: return "MenuItem";
515: }
516:
517:
523: protected void installComponents(JMenuItem menuItem)
524: {
525:
526: }
527:
528:
532: protected void installDefaults()
533: {
534: String prefix = getPropertyPrefix();
535: LookAndFeel.installBorder(menuItem, prefix + ".border");
536: LookAndFeel.installColorsAndFont(menuItem, prefix + ".background",
537: prefix + ".foreground", prefix + ".font");
538: menuItem.setMargin(UIManager.getInsets(prefix + ".margin"));
539: acceleratorFont = UIManager.getFont(prefix + ".acceleratorFont");
540: acceleratorForeground = UIManager.getColor(prefix
541: + ".acceleratorForeground");
542: acceleratorSelectionForeground = UIManager.getColor(prefix
543: + ".acceleratorSelectionForeground");
544: selectionBackground = UIManager.getColor(prefix + ".selectionBackground");
545: selectionForeground = UIManager.getColor(prefix + ".selectionForeground");
546: acceleratorDelimiter = UIManager.getString(prefix + ".acceleratorDelimiter");
547: checkIcon = UIManager.getIcon(prefix + ".checkIcon");
548:
549: menuItem.setHorizontalTextPosition(SwingConstants.TRAILING);
550: menuItem.setHorizontalAlignment(SwingConstants.LEADING);
551: }
552:
553:
556: protected void installKeyboardActions()
557: {
558: InputMap focusedWindowMap = SwingUtilities.getUIInputMap(menuItem,
559: JComponent.WHEN_IN_FOCUSED_WINDOW);
560: if (focusedWindowMap == null)
561: focusedWindowMap = new ComponentInputMapUIResource(menuItem);
562: KeyStroke accelerator = menuItem.getAccelerator();
563: if (accelerator != null)
564: focusedWindowMap.put(accelerator, "doClick");
565: SwingUtilities.replaceUIInputMap(menuItem,
566: JComponent.WHEN_IN_FOCUSED_WINDOW, focusedWindowMap);
567:
568: ActionMap UIActionMap = SwingUtilities.getUIActionMap(menuItem);
569: if (UIActionMap == null)
570: UIActionMap = new ActionMapUIResource();
571: UIActionMap.put("doClick", new ClickAction());
572: SwingUtilities.replaceUIActionMap(menuItem, UIActionMap);
573: }
574:
575:
578: protected void installListeners()
579: {
580: menuItem.addMouseListener(mouseInputListener);
581: menuItem.addMouseMotionListener(mouseInputListener);
582: menuItem.addMenuDragMouseListener(menuDragMouseListener);
583: menuItem.addMenuKeyListener(menuKeyListener);
584: menuItem.addItemListener(itemListener);
585: menuItem.addPropertyChangeListener(propertyChangeListener);
586: }
587:
588:
596: public void installUI(JComponent c)
597: {
598: super.installUI(c);
599: menuItem = (JMenuItem) c;
600: installDefaults();
601: installComponents(menuItem);
602: installListeners();
603: installKeyboardActions();
604: }
605:
606:
614: public void paint(Graphics g, JComponent c)
615: {
616: paintMenuItem(g, c, checkIcon, arrowIcon, selectionBackground,
617: c.getForeground(), defaultTextIconGap);
618: }
619:
620:
630: protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
631: {
632:
633:
634: ButtonModel mod = menuItem.getModel();
635: Color saved = g.getColor();
636: if (mod.isArmed() || ((menuItem instanceof JMenu) && mod.isSelected()))
637: {
638: g.setColor(bgColor);
639: g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
640: }
641: else if (menuItem.isOpaque())
642: {
643: g.setColor(menuItem.getBackground());
644: g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
645: }
646: g.setColor(saved);
647: }
648:
649:
667: protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,
668: Icon arrowIcon, Color background,
669: Color foreground, int defaultTextIconGap)
670: {
671: JMenuItem m = (JMenuItem) c;
672:
673:
674: Font oldFont = g.getFont();
675: Font font = c.getFont();
676: g.setFont(font);
677: FontMetrics accelFm = m.getFontMetrics(acceleratorFont);
678:
679:
680: String accelText = getAcceleratorString(m);
681:
682:
683:
684: layoutMenuItem(m, accelText);
685:
686:
687: paintBackground(g, m, background);
688:
689: Color oldColor = g.getColor();
690:
691:
692: if (checkIcon != null)
693: {
694: checkIcon.paintIcon(m, g, checkIconRect.x, checkIconRect.y);
695: }
696:
697:
698: ButtonModel model = m.getModel();
699: if (m.getIcon() != null)
700: {
701:
702:
703: Icon icon;
704: if (! m.isEnabled())
705: {
706: icon = m.getDisabledIcon();
707: }
708: else if (model.isPressed() && model.isArmed())
709: {
710: icon = m.getPressedIcon();
711: if (icon == null)
712: {
713: icon = m.getIcon();
714: }
715: }
716: else
717: {
718: icon = m.getIcon();
719: }
720:
721: if (icon != null)
722: {
723: icon.paintIcon(m, g, iconRect.x, iconRect.y);
724: }
725: }
726:
727:
728: String text = m.getText();
729: if (text != null)
730: {
731:
732: View html = (View) m.getClientProperty(BasicHTML.propertyKey);
733: if (html != null)
734: {
735: html.paint(g, textRect);
736: }
737: else
738: {
739: paintText(g, m, textRect, text);
740: }
741: }
742:
743:
744: if (! accelText.equals(""))
745: {
746:
747:
748:
749:
750: int accelOffset = 0;
751: Container parent = m.getParent();
752: if (parent != null && parent instanceof JComponent)
753: {
754: JComponent p = (JComponent) parent;
755: Integer maxAccelWidth =
756: (Integer) p.getClientProperty("maxAccelWidth");
757: int maxAccelValue = maxAccelWidth == null ? 0
758: : maxAccelWidth.intValue();
759: accelOffset = maxAccelValue - accelRect.width;
760: }
761:
762: g.setFont(acceleratorFont);
763: if (! m.isEnabled())
764: {
765:
766: g.setColor(disabledForeground);
767: }
768: else
769: {
770: if (m.isArmed() || (m instanceof JMenu && m.isSelected()))
771: g.setColor(acceleratorSelectionForeground);
772: else
773: g.setColor(acceleratorForeground);
774: }
775: g.drawString(accelText, accelRect.x - accelOffset,
776: accelRect.y + accelFm.getAscent());
777: }
778:
779:
780: if (arrowIcon != null
781: && ! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
782: {
783: arrowIcon.paintIcon(m, g, arrowIconRect.x, arrowIconRect.y);
784: }
785:
786: g.setFont(oldFont);
787: g.setColor(oldColor);
788:
789: }
790:
791:
804: protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect,
805: String text)
806: {
807: Font f = menuItem.getFont();
808: g.setFont(f);
809: FontMetrics fm = g.getFontMetrics(f);
810:
811: if (text != null && !text.equals(""))
812: {
813: if (menuItem.isEnabled())
814: {
815:
816:
817: ButtonModel mod = menuItem.getModel();
818: if ((menuItem.isSelected() && checkIcon == null)
819: || (mod != null && mod.isArmed())
820: && (menuItem.getParent() instanceof MenuElement))
821: g.setColor(selectionForeground);
822: else
823: g.setColor(menuItem.getForeground());
824: }
825: else
826:
827:
828:
829:
830:
831: g.setColor(Color.gray);
832:
833: int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
834:
835: if (mnemonicIndex != -1)
836: BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
837: textRect.x,
838: textRect.y
839: + fm.getAscent());
840: else
841: BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
842: textRect.y + fm.getAscent());
843: }
844: }
845:
846:
852: protected void uninstallComponents(JMenuItem menuItem)
853: {
854:
855: }
856:
857:
861: protected void uninstallDefaults()
862: {
863: menuItem.setForeground(null);
864: menuItem.setBackground(null);
865: menuItem.setBorder(null);
866: menuItem.setMargin(null);
867: menuItem.setBackground(null);
868: menuItem.setBorder(null);
869: menuItem.setFont(null);
870: menuItem.setForeground(null);
871: menuItem.setMargin(null);
872: acceleratorFont = null;
873: acceleratorForeground = null;
874: acceleratorSelectionForeground = null;
875: arrowIcon = null;
876: selectionBackground = null;
877: selectionForeground = null;
878: acceleratorDelimiter = null;
879: }
880:
881:
884: protected void uninstallKeyboardActions()
885: {
886: SwingUtilities.replaceUIInputMap(menuItem,
887: JComponent.WHEN_IN_FOCUSED_WINDOW, null);
888: }
889:
890:
893: protected void uninstallListeners()
894: {
895: menuItem.removeMouseListener(mouseInputListener);
896: menuItem.removeMenuDragMouseListener(menuDragMouseListener);
897: menuItem.removeMenuKeyListener(menuKeyListener);
898: menuItem.removeItemListener(itemListener);
899: menuItem.removePropertyChangeListener(propertyChangeListener);
900: }
901:
902:
910: public void uninstallUI(JComponent c)
911: {
912: uninstallListeners();
913: uninstallDefaults();
914: uninstallComponents(menuItem);
915: menuItem = null;
916: }
917:
918:
926: public void update(Graphics g, JComponent c)
927: {
928: paint(g, c);
929: }
930:
931:
938: private String getAcceleratorText(KeyStroke accelerator)
939: {
940:
941: String modifiersText = "";
942: int modifiers = accelerator.getModifiers();
943: char keyChar = accelerator.getKeyChar();
944: int keyCode = accelerator.getKeyCode();
945:
946: if (modifiers != 0)
947: modifiersText = KeyEvent.getKeyModifiersText(modifiers)
948: + acceleratorDelimiter;
949:
950: if (keyCode == KeyEvent.VK_UNDEFINED)
951: return modifiersText + keyChar;
952: else
953: return modifiersText + KeyEvent.getKeyText(keyCode);
954: }
955:
956:
965: private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm)
966: {
967: int width = fm.stringWidth(getAcceleratorText(accelerator));
968: int height = fm.getHeight();
969: return new Rectangle(0, 0, width, height);
970: }
971:
972:
977: protected class MouseInputHandler implements MouseInputListener
978: {
979:
982: protected MouseInputHandler()
983: {
984:
985: }
986:
987:
994: public void mouseClicked(MouseEvent e)
995: {
996: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
997: manager.processMouseEvent(e);
998: }
999:
1000:
1007: public void mouseDragged(MouseEvent e)
1008: {
1009: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1010: manager.processMouseEvent(e);
1011: }
1012:
1013:
1022: public void mouseEntered(MouseEvent e)
1023: {
1024: Component source = (Component) e.getSource();
1025: if (source.getParent() instanceof MenuElement)
1026: {
1027: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1028: manager.setSelectedPath(getPath());
1029: manager.processMouseEvent(e);
1030: }
1031: }
1032:
1033:
1040: public void mouseExited(MouseEvent e)
1041: {
1042: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1043: manager.processMouseEvent(e);
1044: }
1045:
1046:
1053: public void mouseMoved(MouseEvent e)
1054: {
1055: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1056: manager.processMouseEvent(e);
1057: }
1058:
1059:
1066: public void mousePressed(MouseEvent e)
1067: {
1068: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1069: manager.processMouseEvent(e);
1070: }
1071:
1072:
1080: public void mouseReleased(MouseEvent e)
1081: {
1082: Rectangle size = menuItem.getBounds();
1083: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1084: if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0
1085: && e.getY() < size.height)
1086: {
1087: manager.clearSelectedPath();
1088: menuItem.doClick();
1089: }
1090:
1091: else
1092: manager.processMouseEvent(e);
1093: }
1094: }
1095:
1096:
1099: private class MenuDragMouseHandler implements MenuDragMouseListener
1100: {
1101:
1107: public void menuDragMouseDragged(MenuDragMouseEvent e)
1108: {
1109: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1110: manager.setSelectedPath(e.getPath());
1111: }
1112:
1113:
1120: public void menuDragMouseEntered(MenuDragMouseEvent e)
1121: {
1122: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1123: manager.setSelectedPath(e.getPath());
1124: }
1125:
1126:
1132: public void menuDragMouseExited(MenuDragMouseEvent e)
1133: {
1134:
1135: }
1136:
1137:
1144: public void menuDragMouseReleased(MenuDragMouseEvent e)
1145: {
1146: MenuElement[] path = e.getPath();
1147:
1148: if (path[path.length - 1] instanceof JMenuItem)
1149: ((JMenuItem) path[path.length - 1]).doClick();
1150:
1151: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1152: manager.clearSelectedPath();
1153: }
1154: }
1155:
1156:
1160: private class MenuKeyHandler implements MenuKeyListener
1161: {
1162:
1168: public void menuKeyPressed(MenuKeyEvent e)
1169: {
1170:
1171: }
1172:
1173:
1179: public void menuKeyReleased(MenuKeyEvent e)
1180: {
1181:
1182: }
1183:
1184:
1191: public void menuKeyTyped(MenuKeyEvent e)
1192: {
1193:
1194: }
1195: }
1196:
1197:
1201: private class ItemHandler implements ItemListener
1202: {
1203:
1208: public void itemStateChanged(ItemEvent evt)
1209: {
1210: boolean state = false;
1211: if (menuItem instanceof JCheckBoxMenuItem)
1212: {
1213: if (evt.getStateChange() == ItemEvent.SELECTED)
1214: state = true;
1215: ((JCheckBoxMenuItem) menuItem).setState(state);
1216: }
1217: menuItem.revalidate();
1218: menuItem.repaint();
1219: }
1220: }
1221:
1222:
1231: private String getAcceleratorString(JMenuItem m)
1232: {
1233:
1234: KeyStroke accel = m.getAccelerator();
1235: String accelText = "";
1236: if (accel != null)
1237: {
1238: int mods = accel.getModifiers();
1239: if (mods > 0)
1240: {
1241: accelText = KeyEvent.getKeyModifiersText(mods);
1242: accelText += acceleratorDelimiter;
1243: }
1244: int keycode = accel.getKeyCode();
1245: if (keycode != 0)
1246: accelText += KeyEvent.getKeyText(keycode);
1247: else
1248: accelText += accel.getKeyChar();
1249: }
1250: return accelText;
1251: }
1252:
1253:
1260: private void layoutMenuItem(JMenuItem m, String accelText)
1261: {
1262: int width = m.getWidth();
1263: int height = m.getHeight();
1264:
1265:
1266: iconRect.setBounds(0, 0, 0, 0);
1267: textRect.setBounds(0, 0, 0, 0);
1268: accelRect.setBounds(0, 0, 0, 0);
1269: checkIconRect.setBounds(0, 0, 0, 0);
1270: arrowIconRect.setBounds(0, 0, 0, 0);
1271: viewRect.setBounds(0, 0, width, height);
1272:
1273:
1274: Insets insets = m.getInsets();
1275: viewRect.x += insets.left;
1276: viewRect.y += insets.top;
1277: viewRect.width -= insets.left + insets.right;
1278: viewRect.height -= insets.top + insets.bottom;
1279:
1280:
1281: Font font = m.getFont();
1282: FontMetrics fm = m.getFontMetrics(font);
1283: FontMetrics accelFm = m.getFontMetrics(acceleratorFont);
1284:
1285: String text = m.getText();
1286: SwingUtilities.layoutCompoundLabel(m, fm, text, m.getIcon(),
1287: m.getVerticalAlignment(),
1288: m.getHorizontalAlignment(),
1289: m.getVerticalTextPosition(),
1290: m.getHorizontalTextPosition(),
1291: viewRect, iconRect, textRect,
1292: defaultTextIconGap);
1293:
1294:
1295: if (! accelText.equals(""))
1296: {
1297: accelRect.width = accelFm.stringWidth(accelText);
1298: accelRect.height = accelFm.getHeight();
1299: }
1300:
1301:
1302: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1303: {
1304: if (checkIcon != null)
1305: {
1306: checkIconRect.width = checkIcon.getIconWidth();
1307: checkIconRect.height = checkIcon.getIconHeight();
1308: }
1309: if (arrowIcon != null)
1310: {
1311: arrowIconRect.width = arrowIcon.getIconWidth();
1312: arrowIconRect.height = arrowIcon.getIconHeight();
1313: }
1314: }
1315:
1316:
1317: cachedRect.setBounds(textRect);
1318: Rectangle labelRect = SwingUtilities.computeUnion(iconRect.x,
1319: iconRect.y,
1320: iconRect.width,
1321: iconRect.height,
1322: cachedRect);
1323: textRect.x += defaultTextIconGap;
1324: iconRect.x += defaultTextIconGap;
1325:
1326:
1327: accelRect.x = viewRect.x + viewRect.width - arrowIconRect.width
1328: - defaultTextIconGap - accelRect.width;
1329:
1330: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1331: {
1332: checkIconRect.x = viewRect.x + defaultTextIconGap;
1333: textRect.x += defaultTextIconGap + checkIconRect.width;
1334: iconRect.x += defaultTextIconGap + checkIconRect.width;
1335: arrowIconRect.x = viewRect.x + viewRect.width - defaultTextIconGap
1336: - arrowIconRect.width;
1337: }
1338:
1339:
1340:
1341: accelRect.y = labelRect.y + (labelRect.height / 2)
1342: - (accelRect.height / 2);
1343: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1344: {
1345: arrowIconRect.y = labelRect.y + (labelRect.height / 2)
1346: - (arrowIconRect.height / 2);
1347: checkIconRect.y = labelRect.y + (labelRect.height / 2)
1348: - (checkIconRect.height / 2);
1349: }
1350: }
1351: }