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, JComponent.WHEN_IN_FOCUSED_WINDOW);
243: if (map != null)
244: map.remove((KeyStroke)e.getOldValue());
245: else
246: map = new ComponentInputMapUIResource(menuItem);
247:
248: KeyStroke accelerator = (KeyStroke) e.getNewValue();
249: if (accelerator != null)
250: map.put(accelerator, "doClick");
251: }
252: }
253: }
254:
255:
261: class ClickAction extends AbstractAction
262: {
263:
267: public void actionPerformed(ActionEvent event)
268: {
269: doClick(MenuSelectionManager.defaultManager());
270: }
271: }
272:
273:
276: public BasicMenuItemUI()
277: {
278: mouseInputListener = createMouseInputListener(menuItem);
279: menuDragMouseListener = createMenuDragMouseListener(menuItem);
280: menuKeyListener = createMenuKeyListener(menuItem);
281: itemListener = new ItemHandler();
282: propertyChangeListener = new PropertyChangeHandler();
283:
284:
285: viewRect = new Rectangle();
286: textRect = new Rectangle();
287: iconRect = new Rectangle();
288: arrowIconRect = new Rectangle();
289: checkIconRect = new Rectangle();
290: accelRect = new Rectangle();
291: cachedRect = new Rectangle();
292: }
293:
294:
301: protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
302: {
303: return new MenuDragMouseHandler();
304: }
305:
306:
314: protected MenuKeyListener createMenuKeyListener(JComponent c)
315: {
316: return new MenuKeyHandler();
317: }
318:
319:
326: protected MouseInputListener createMouseInputListener(JComponent c)
327: {
328: return new MouseInputHandler();
329: }
330:
331:
339: public static ComponentUI createUI(JComponent c)
340: {
341: return new BasicMenuItemUI();
342: }
343:
344:
350: protected void doClick(MenuSelectionManager msm)
351: {
352: menuItem.doClick();
353: msm.clearSelectedPath();
354: }
355:
356:
363: public Dimension getMaximumSize(JComponent c)
364: {
365: return null;
366: }
367:
368:
375: public Dimension getMinimumSize(JComponent c)
376: {
377: return null;
378: }
379:
380:
386: public MenuElement[] getPath()
387: {
388: ArrayList path = new ArrayList();
389:
390:
391: if (menuItem instanceof JMenu)
392: path.add(((JMenu) menuItem).getPopupMenu());
393:
394: Component c = menuItem;
395: while (c instanceof MenuElement)
396: {
397: path.add(0, (MenuElement) c);
398:
399: if (c instanceof JPopupMenu)
400: c = ((JPopupMenu) c).getInvoker();
401: else
402: c = c.getParent();
403: }
404:
405: MenuElement[] pathArray = new MenuElement[path.size()];
406: path.toArray(pathArray);
407: return pathArray;
408: }
409:
410:
423: protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,
424: Icon arrowIcon,
425: int defaultTextIconGap)
426: {
427: JMenuItem m = (JMenuItem) c;
428: String accelText = getAcceleratorString(m);
429:
430:
431:
432: layoutMenuItem(m, accelText);
433:
434:
435: cachedRect.setBounds(textRect);
436: Rectangle pref = SwingUtilities.computeUnion(iconRect.x, iconRect.y,
437: iconRect.width,
438: iconRect.height,
439: cachedRect);
440:
441:
442:
443:
444:
445: Container parent = m.getParent();
446: if (parent != null && parent instanceof JComponent
447: && !(m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
448: {
449: JComponent p = (JComponent) parent;
450:
451:
452: Integer maxTextWidth = (Integer) p.getClientProperty("maxTextWidth");
453: int maxTextValue = maxTextWidth == null ? 0 : maxTextWidth.intValue();
454: if (pref.width < maxTextValue)
455: pref.width = maxTextValue;
456: else
457: p.putClientProperty("maxTextWidth", new Integer(pref.width));
458:
459:
460: Integer maxAccelWidth = (Integer) p.getClientProperty("maxAccelWidth");
461: int maxAccelValue = maxAccelWidth == null ? 0
462: : maxAccelWidth.intValue();
463: if (accelRect.width > maxAccelValue)
464: {
465: maxAccelValue = accelRect.width;
466: p.putClientProperty("maxAccelWidth", new Integer(accelRect.width));
467: }
468: pref.width += maxAccelValue;
469: pref.width += defaultTextIconGap;
470: }
471:
472:
473: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
474: {
475: pref.width += checkIconRect.width;
476: pref.width += defaultTextIconGap;
477: pref.width += arrowIconRect.width;
478: pref.width += defaultTextIconGap;
479: }
480:
481:
482: pref.width += 2 * defaultTextIconGap;
483:
484:
485: Insets i = m.getInsets();
486: pref.width += i.left + i.right;
487: pref.height += i.top + i.bottom;
488:
489:
490: return pref.getSize();
491: }
492:
493:
500: public Dimension getPreferredSize(JComponent c)
501: {
502: return getPreferredMenuItemSize(c, checkIcon, arrowIcon, defaultTextIconGap);
503: }
504:
505:
510: protected String getPropertyPrefix()
511: {
512: return "MenuItem";
513: }
514:
515:
521: protected void installComponents(JMenuItem menuItem)
522: {
523:
524: }
525:
526:
530: protected void installDefaults()
531: {
532: String prefix = getPropertyPrefix();
533: LookAndFeel.installBorder(menuItem, prefix + ".border");
534: LookAndFeel.installColorsAndFont(menuItem, prefix + ".background",
535: prefix + ".foreground", prefix + ".font");
536: menuItem.setMargin(UIManager.getInsets(prefix + ".margin"));
537: acceleratorFont = UIManager.getFont(prefix + ".acceleratorFont");
538: acceleratorForeground = UIManager.getColor(prefix + ".acceleratorForeground");
539: acceleratorSelectionForeground = UIManager.getColor(prefix + ".acceleratorSelectionForeground");
540: selectionBackground = UIManager.getColor(prefix + ".selectionBackground");
541: selectionForeground = UIManager.getColor(prefix + ".selectionForeground");
542: acceleratorDelimiter = UIManager.getString(prefix + ".acceleratorDelimiter");
543: checkIcon = UIManager.getIcon(prefix + ".checkIcon");
544:
545: menuItem.setHorizontalTextPosition(SwingConstants.TRAILING);
546: menuItem.setHorizontalAlignment(SwingConstants.LEADING);
547: }
548:
549:
552: protected void installKeyboardActions()
553: {
554: InputMap focusedWindowMap = SwingUtilities.getUIInputMap(menuItem, JComponent.WHEN_IN_FOCUSED_WINDOW);
555: if (focusedWindowMap == null)
556: focusedWindowMap = new ComponentInputMapUIResource(menuItem);
557: KeyStroke accelerator = menuItem.getAccelerator();
558: if (accelerator != null)
559: focusedWindowMap.put(accelerator, "doClick");
560: SwingUtilities.replaceUIInputMap(menuItem, JComponent.WHEN_IN_FOCUSED_WINDOW, focusedWindowMap);
561:
562: ActionMap UIActionMap = SwingUtilities.getUIActionMap(menuItem);
563: if (UIActionMap == null)
564: UIActionMap = new ActionMapUIResource();
565: UIActionMap.put("doClick", new ClickAction());
566: SwingUtilities.replaceUIActionMap(menuItem, UIActionMap);
567: }
568:
569:
572: protected void installListeners()
573: {
574: menuItem.addMouseListener(mouseInputListener);
575: menuItem.addMouseMotionListener(mouseInputListener);
576: menuItem.addMenuDragMouseListener(menuDragMouseListener);
577: menuItem.addMenuKeyListener(menuKeyListener);
578: menuItem.addItemListener(itemListener);
579: menuItem.addPropertyChangeListener(propertyChangeListener);
580: }
581:
582:
590: public void installUI(JComponent c)
591: {
592: super.installUI(c);
593: menuItem = (JMenuItem) c;
594: installDefaults();
595: installComponents(menuItem);
596: installListeners();
597: installKeyboardActions();
598: }
599:
600:
608: public void paint(Graphics g, JComponent c)
609: {
610: paintMenuItem(g, c, checkIcon, arrowIcon, selectionBackground,
611: c.getForeground(), defaultTextIconGap);
612: }
613:
614:
624: protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
625: {
626:
627:
628: ButtonModel mod = menuItem.getModel();
629: Color saved = g.getColor();
630: if (mod.isArmed() || ((menuItem instanceof JMenu) && mod.isSelected()))
631: {
632: g.setColor(bgColor);
633: g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
634: }
635: else if (menuItem.isOpaque())
636: {
637: g.setColor(menuItem.getBackground());
638: g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
639: }
640: g.setColor(saved);
641: }
642:
643:
661: protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,
662: Icon arrowIcon, Color background,
663: Color foreground, int defaultTextIconGap)
664: {
665: JMenuItem m = (JMenuItem) c;
666:
667:
668: Font oldFont = g.getFont();
669: Font font = c.getFont();
670: g.setFont(font);
671: FontMetrics accelFm = m.getFontMetrics(acceleratorFont);
672:
673:
674: String accelText = getAcceleratorString(m);
675:
676:
677:
678: layoutMenuItem(m, accelText);
679:
680:
681: paintBackground(g, m, background);
682:
683: Color oldColor = g.getColor();
684:
685:
686: if (checkIcon != null)
687: {
688: checkIcon.paintIcon(m, g, checkIconRect.x, checkIconRect.y);
689: }
690:
691:
692: ButtonModel model = m.getModel();
693: if (m.getIcon() != null)
694: {
695:
696:
697: Icon icon;
698: if (! m.isEnabled())
699: {
700: icon = m.getDisabledIcon();
701: }
702: else if (model.isPressed() && model.isArmed())
703: {
704: icon = m.getPressedIcon();
705: if (icon == null)
706: {
707: icon = m.getIcon();
708: }
709: }
710: else
711: {
712: icon = m.getIcon();
713: }
714:
715: if (icon != null)
716: {
717: icon.paintIcon(m, g, iconRect.x, iconRect.y);
718: }
719: }
720:
721:
722: String text = m.getText();
723: if (text != null)
724: {
725:
726: View html = (View) m.getClientProperty(BasicHTML.propertyKey);
727: if (html != null)
728: {
729: html.paint(g, textRect);
730: }
731: else
732: {
733: paintText(g, m, textRect, text);
734: }
735: }
736:
737:
738: if (! accelText.equals(""))
739: {
740:
741:
742:
743:
744: int accelOffset = 0;
745: Container parent = m.getParent();
746: if (parent != null && parent instanceof JComponent)
747: {
748: JComponent p = (JComponent) parent;
749: Integer maxAccelWidth =
750: (Integer) p.getClientProperty("maxAccelWidth");
751: int maxAccelValue = maxAccelWidth == null ? 0
752: : maxAccelWidth.intValue();
753: accelOffset = maxAccelValue - accelRect.width;
754: }
755:
756: g.setFont(acceleratorFont);
757: if (! m.isEnabled())
758: {
759:
760: g.setColor(disabledForeground);
761: }
762: else
763: {
764: if (m.isArmed() || (m instanceof JMenu && m.isSelected()))
765: g.setColor(acceleratorSelectionForeground);
766: else
767: g.setColor(acceleratorForeground);
768: }
769: g.drawString(accelText, accelRect.x - accelOffset,
770: accelRect.y + accelFm.getAscent());
771: }
772:
773:
774: if (arrowIcon != null
775: && ! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
776: {
777: arrowIcon.paintIcon(m, g, arrowIconRect.x, arrowIconRect.y);
778: }
779:
780: g.setFont(oldFont);
781: g.setColor(oldColor);
782:
783: }
784:
785:
798: protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect,
799: String text)
800: {
801: Font f = menuItem.getFont();
802: g.setFont(f);
803: FontMetrics fm = g.getFontMetrics(f);
804:
805: if (text != null && !text.equals(""))
806: {
807: if (menuItem.isEnabled())
808: {
809:
810:
811: ButtonModel mod = menuItem.getModel();
812: if ((menuItem.isSelected() && checkIcon == null)
813: || (mod != null && mod.isArmed())
814: && (menuItem.getParent() instanceof MenuElement))
815: g.setColor(selectionForeground);
816: else
817: g.setColor(menuItem.getForeground());
818: }
819: else
820:
821:
822:
823:
824:
825: g.setColor(Color.gray);
826:
827: int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
828:
829: if (mnemonicIndex != -1)
830: BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
831: textRect.x,
832: textRect.y
833: + fm.getAscent());
834: else
835: BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
836: textRect.y + fm.getAscent());
837: }
838: }
839:
840:
846: protected void uninstallComponents(JMenuItem menuItem)
847: {
848:
849: }
850:
851:
855: protected void uninstallDefaults()
856: {
857: menuItem.setForeground(null);
858: menuItem.setBackground(null);
859: menuItem.setBorder(null);
860: menuItem.setMargin(null);
861: menuItem.setBackground(null);
862: menuItem.setBorder(null);
863: menuItem.setFont(null);
864: menuItem.setForeground(null);
865: menuItem.setMargin(null);
866: acceleratorFont = null;
867: acceleratorForeground = null;
868: acceleratorSelectionForeground = null;
869: arrowIcon = null;
870: selectionBackground = null;
871: selectionForeground = null;
872: acceleratorDelimiter = null;
873: }
874:
875:
878: protected void uninstallKeyboardActions()
879: {
880: SwingUtilities.replaceUIInputMap(menuItem,
881: JComponent.WHEN_IN_FOCUSED_WINDOW, null);
882: }
883:
884:
887: protected void uninstallListeners()
888: {
889: menuItem.removeMouseListener(mouseInputListener);
890: menuItem.removeMenuDragMouseListener(menuDragMouseListener);
891: menuItem.removeMenuKeyListener(menuKeyListener);
892: menuItem.removeItemListener(itemListener);
893: menuItem.removePropertyChangeListener(propertyChangeListener);
894: }
895:
896:
904: public void uninstallUI(JComponent c)
905: {
906: uninstallListeners();
907: uninstallDefaults();
908: uninstallComponents(menuItem);
909: menuItem = null;
910: }
911:
912:
920: public void update(Graphics g, JComponent c)
921: {
922: paint(g, c);
923: }
924:
925:
932: private String getAcceleratorText(KeyStroke accelerator)
933: {
934:
935: String modifiersText = "";
936: int modifiers = accelerator.getModifiers();
937: char keyChar = accelerator.getKeyChar();
938: int keyCode = accelerator.getKeyCode();
939:
940: if (modifiers != 0)
941: modifiersText = KeyEvent.getKeyModifiersText(modifiers)
942: + acceleratorDelimiter;
943:
944: if (keyCode == KeyEvent.VK_UNDEFINED)
945: return modifiersText + keyChar;
946: else
947: return modifiersText + KeyEvent.getKeyText(keyCode);
948: }
949:
950:
959: private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm)
960: {
961: int width = fm.stringWidth(getAcceleratorText(accelerator));
962: int height = fm.getHeight();
963: return new Rectangle(0, 0, width, height);
964: }
965:
966:
971: protected class MouseInputHandler implements MouseInputListener
972: {
973:
976: protected MouseInputHandler()
977: {
978:
979: }
980:
981:
988: public void mouseClicked(MouseEvent e)
989: {
990: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
991: manager.processMouseEvent(e);
992: }
993:
994:
1001: public void mouseDragged(MouseEvent e)
1002: {
1003: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1004: manager.processMouseEvent(e);
1005: }
1006:
1007:
1016: public void mouseEntered(MouseEvent e)
1017: {
1018: Component source = (Component) e.getSource();
1019: if (source.getParent() instanceof MenuElement)
1020: {
1021: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1022: manager.setSelectedPath(getPath());
1023: manager.processMouseEvent(e);
1024: }
1025: }
1026:
1027:
1034: public void mouseExited(MouseEvent e)
1035: {
1036: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1037: manager.processMouseEvent(e);
1038: }
1039:
1040:
1047: public void mouseMoved(MouseEvent e)
1048: {
1049: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1050: manager.processMouseEvent(e);
1051: }
1052:
1053:
1060: public void mousePressed(MouseEvent e)
1061: {
1062: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1063: manager.processMouseEvent(e);
1064: }
1065:
1066:
1074: public void mouseReleased(MouseEvent e)
1075: {
1076: Rectangle size = menuItem.getBounds();
1077: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1078: if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0
1079: && e.getY() < size.height)
1080: {
1081: manager.clearSelectedPath();
1082: menuItem.doClick();
1083: }
1084:
1085: else
1086: manager.processMouseEvent(e);
1087: }
1088: }
1089:
1090:
1093: private class MenuDragMouseHandler implements MenuDragMouseListener
1094: {
1095:
1101: public void menuDragMouseDragged(MenuDragMouseEvent e)
1102: {
1103: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1104: manager.setSelectedPath(e.getPath());
1105: }
1106:
1107:
1114: public void menuDragMouseEntered(MenuDragMouseEvent e)
1115: {
1116: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1117: manager.setSelectedPath(e.getPath());
1118: }
1119:
1120:
1126: public void menuDragMouseExited(MenuDragMouseEvent e)
1127: {
1128:
1129: }
1130:
1131:
1138: public void menuDragMouseReleased(MenuDragMouseEvent e)
1139: {
1140: MenuElement[] path = e.getPath();
1141:
1142: if (path[path.length - 1] instanceof JMenuItem)
1143: ((JMenuItem) path[path.length - 1]).doClick();
1144:
1145: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1146: manager.clearSelectedPath();
1147: }
1148: }
1149:
1150:
1154: private class MenuKeyHandler implements MenuKeyListener
1155: {
1156:
1162: public void menuKeyPressed(MenuKeyEvent e)
1163: {
1164:
1165: }
1166:
1167:
1173: public void menuKeyReleased(MenuKeyEvent e)
1174: {
1175:
1176: }
1177:
1178:
1185: public void menuKeyTyped(MenuKeyEvent e)
1186: {
1187:
1188: }
1189: }
1190:
1191:
1195: private class ItemHandler implements ItemListener
1196: {
1197:
1202: public void itemStateChanged(ItemEvent evt)
1203: {
1204: boolean state = false;
1205: if (menuItem instanceof JCheckBoxMenuItem)
1206: {
1207: if (evt.getStateChange() == ItemEvent.SELECTED)
1208: state = true;
1209: ((JCheckBoxMenuItem) menuItem).setState(state);
1210: }
1211: menuItem.revalidate();
1212: menuItem.repaint();
1213: }
1214: }
1215:
1216:
1225: private String getAcceleratorString(JMenuItem m)
1226: {
1227:
1228: KeyStroke accel = m.getAccelerator();
1229: String accelText = "";
1230: if (accel != null)
1231: {
1232: int mods = accel.getModifiers();
1233: if (mods > 0)
1234: {
1235: accelText = KeyEvent.getKeyModifiersText(mods);
1236: accelText += acceleratorDelimiter;
1237: }
1238: int keycode = accel.getKeyCode();
1239: if (keycode != 0)
1240: accelText += KeyEvent.getKeyText(keycode);
1241: else
1242: accelText += accel.getKeyChar();
1243: }
1244: return accelText;
1245: }
1246:
1247:
1254: private void layoutMenuItem(JMenuItem m, String accelText)
1255: {
1256: int width = m.getWidth();
1257: int height = m.getHeight();
1258:
1259:
1260: iconRect.setBounds(0, 0, 0, 0);
1261: textRect.setBounds(0, 0, 0, 0);
1262: accelRect.setBounds(0, 0, 0, 0);
1263: checkIconRect.setBounds(0, 0, 0, 0);
1264: arrowIconRect.setBounds(0, 0, 0, 0);
1265: viewRect.setBounds(0, 0, width, height);
1266:
1267:
1268: Insets insets = m.getInsets();
1269: viewRect.x += insets.left;
1270: viewRect.y += insets.top;
1271: viewRect.width -= (insets.left + insets.right);
1272: viewRect.height -= (insets.top + insets.bottom);
1273:
1274:
1275: Font font = m.getFont();
1276: FontMetrics fm = m.getFontMetrics(font);
1277: FontMetrics accelFm = m.getFontMetrics(acceleratorFont);
1278:
1279: String text = m.getText();
1280: SwingUtilities.layoutCompoundLabel(m, fm, text, m.getIcon(),
1281: m.getVerticalAlignment(),
1282: m.getHorizontalAlignment(),
1283: m.getVerticalTextPosition(),
1284: m.getHorizontalTextPosition(),
1285: viewRect, iconRect, textRect,
1286: defaultTextIconGap);
1287:
1288:
1289: if (! accelText.equals(""))
1290: {
1291: accelRect.width = accelFm.stringWidth(accelText);
1292: accelRect.height = accelFm.getHeight();
1293: }
1294:
1295:
1296: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1297: {
1298: if (checkIcon != null)
1299: {
1300: checkIconRect.width = checkIcon.getIconWidth();
1301: checkIconRect.height = checkIcon.getIconHeight();
1302: }
1303: if (arrowIcon != null)
1304: {
1305: arrowIconRect.width = arrowIcon.getIconWidth();
1306: arrowIconRect.height = arrowIcon.getIconHeight();
1307: }
1308: }
1309:
1310:
1311: cachedRect.setBounds(textRect);
1312: Rectangle labelRect = SwingUtilities.computeUnion(iconRect.x,
1313: iconRect.y,
1314: iconRect.width,
1315: iconRect.height,
1316: cachedRect);
1317: textRect.x += defaultTextIconGap;
1318: iconRect.x += defaultTextIconGap;
1319:
1320:
1321: accelRect.x = viewRect.x + viewRect.width - arrowIconRect.width
1322: - defaultTextIconGap - accelRect.width;
1323:
1324: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1325: {
1326: checkIconRect.x = viewRect.x + defaultTextIconGap;
1327: textRect.x += defaultTextIconGap + checkIconRect.width;
1328: iconRect.x += defaultTextIconGap + checkIconRect.width;
1329: arrowIconRect.x = viewRect.x + viewRect.width - defaultTextIconGap
1330: - arrowIconRect.width;
1331: }
1332:
1333:
1334:
1335: accelRect.y = labelRect.y + (labelRect.height / 2)
1336: - (accelRect.height / 2);
1337: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1338: {
1339: arrowIconRect.y = labelRect.y + (labelRect.height / 2)
1340: - (arrowIconRect.height / 2);
1341: checkIconRect.y = labelRect.y + (labelRect.height / 2)
1342: - (checkIconRect.height / 2);
1343: }
1344: }
1345: }