1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: 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: import ;
89: import ;
90: import ;
91: import ;
92: import ;
93:
94:
97: public class BasicMenuItemUI extends MenuItemUI
98: {
99:
102: protected Font acceleratorFont;
103:
104:
107: protected Color acceleratorForeground;
108:
109:
113: protected Color acceleratorSelectionForeground;
114:
115:
119: protected Icon arrowIcon;
120:
121:
125: protected Icon checkIcon;
126:
127:
130: protected int defaultTextIconGap = 4;
131:
132:
135: protected Color disabledForeground;
136:
137:
140: protected MenuDragMouseListener menuDragMouseListener;
141:
142:
145: protected JMenuItem menuItem;
146:
147:
150: protected MenuKeyListener menuKeyListener;
151:
152:
155: protected MouseInputListener mouseInputListener;
156:
157:
160: protected boolean oldBorderPainted;
161:
162:
165: protected Color selectionBackground;
166:
167:
170: protected Color selectionForeground;
171:
172:
175: private String acceleratorDelimiter;
176:
177:
180: private ItemListener itemListener;
181:
182:
185: private PropertyChangeHandler propertyChangeListener;
186:
187:
190: private Rectangle viewRect;
191:
192:
195: private Rectangle textRect;
196:
197:
200: private Rectangle accelRect;
201:
202:
205: private Rectangle iconRect;
206:
207:
210: private Rectangle arrowIconRect;
211:
212:
215: private Rectangle checkIconRect;
216:
217:
221: private Rectangle cachedRect;
222:
223:
227: class PropertyChangeHandler implements PropertyChangeListener
228: {
229:
236: public void propertyChange(PropertyChangeEvent e)
237: {
238: String property = e.getPropertyName();
239: if (property.equals("accelerator"))
240: {
241: InputMap map = SwingUtilities.getUIInputMap(menuItem,
242: 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: else if ((property.equals(AbstractButton.TEXT_CHANGED_PROPERTY)
254: || property.equals("font"))
255: && SystemProperties.getProperty("gnu.javax.swing.noGraphics2D")
256: == null)
257: {
258: AbstractButton b = (AbstractButton) e.getSource();
259: String text = b.getText();
260: if (text == null)
261: text = "";
262: FontRenderContext frc = new FontRenderContext(new AffineTransform(),
263: false, false);
264: TextLayout layout = new TextLayout(text, b.getFont(), frc);
265: b.putClientProperty(BasicGraphicsUtils.CACHED_TEXT_LAYOUT, layout);
266: }
267: }
268: }
269:
270:
276: class ClickAction extends AbstractAction
277: {
278:
282: public void actionPerformed(ActionEvent event)
283: {
284: doClick(MenuSelectionManager.defaultManager());
285: }
286: }
287:
288:
291: public BasicMenuItemUI()
292: {
293: mouseInputListener = createMouseInputListener(menuItem);
294: menuDragMouseListener = createMenuDragMouseListener(menuItem);
295: menuKeyListener = createMenuKeyListener(menuItem);
296: itemListener = new ItemHandler();
297: propertyChangeListener = new PropertyChangeHandler();
298:
299:
300: viewRect = new Rectangle();
301: textRect = new Rectangle();
302: iconRect = new Rectangle();
303: arrowIconRect = new Rectangle();
304: checkIconRect = new Rectangle();
305: accelRect = new Rectangle();
306: cachedRect = new Rectangle();
307: }
308:
309:
316: protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
317: {
318: return new MenuDragMouseHandler();
319: }
320:
321:
329: protected MenuKeyListener createMenuKeyListener(JComponent c)
330: {
331: return new MenuKeyHandler();
332: }
333:
334:
341: protected MouseInputListener createMouseInputListener(JComponent c)
342: {
343: return new MouseInputHandler();
344: }
345:
346:
354: public static ComponentUI createUI(JComponent c)
355: {
356: return new BasicMenuItemUI();
357: }
358:
359:
365: protected void doClick(MenuSelectionManager msm)
366: {
367: menuItem.doClick(0);
368: msm.clearSelectedPath();
369: }
370:
371:
378: public Dimension getMaximumSize(JComponent c)
379: {
380: return null;
381: }
382:
383:
390: public Dimension getMinimumSize(JComponent c)
391: {
392: return null;
393: }
394:
395:
401: public MenuElement[] getPath()
402: {
403: ArrayList path = new ArrayList();
404:
405: Component c = menuItem;
406: while (c instanceof MenuElement)
407: {
408: path.add(0, c);
409:
410: if (c instanceof JPopupMenu)
411: c = ((JPopupMenu) c).getInvoker();
412: else
413: c = c.getParent();
414: }
415:
416: MenuElement[] pathArray = new MenuElement[path.size()];
417: path.toArray(pathArray);
418: return pathArray;
419: }
420:
421:
434: protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,
435: Icon arrowIcon,
436: int defaultTextIconGap)
437: {
438: JMenuItem m = (JMenuItem) c;
439: String accelText = getAcceleratorString(m);
440:
441:
442:
443: resetRectangles(null);
444: layoutMenuItem(m, accelText);
445:
446:
447: cachedRect.setBounds(textRect);
448: Rectangle pref = SwingUtilities.computeUnion(iconRect.x, iconRect.y,
449: iconRect.width,
450: iconRect.height,
451: cachedRect);
452:
453:
454:
455:
456:
457: Container parent = m.getParent();
458: if (parent != null && parent instanceof JComponent
459: && !(m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
460: {
461: JComponent p = (JComponent) parent;
462:
463:
464: Integer maxTextWidth = (Integer) p.getClientProperty("maxTextWidth");
465: int maxTextValue = maxTextWidth == null ? 0 : maxTextWidth.intValue();
466: if (pref.width < maxTextValue)
467: pref.width = maxTextValue;
468: else
469: p.putClientProperty("maxTextWidth", new Integer(pref.width));
470:
471:
472: Integer maxAccelWidth = (Integer) p.getClientProperty("maxAccelWidth");
473: int maxAccelValue = maxAccelWidth == null ? 0
474: : maxAccelWidth.intValue();
475: if (accelRect.width > maxAccelValue)
476: {
477: maxAccelValue = accelRect.width;
478: p.putClientProperty("maxAccelWidth", new Integer(accelRect.width));
479: }
480: pref.width += maxAccelValue;
481: pref.width += defaultTextIconGap;
482: }
483:
484:
485: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
486: {
487: pref.width += checkIconRect.width;
488: pref.width += defaultTextIconGap;
489: pref.width += arrowIconRect.width;
490: pref.width += defaultTextIconGap;
491: }
492:
493:
494: pref.width += 2 * defaultTextIconGap;
495:
496:
497: Insets i = m.getInsets();
498: pref.width += i.left + i.right;
499: pref.height += i.top + i.bottom;
500:
501:
502: return pref.getSize();
503: }
504:
505:
512: public Dimension getPreferredSize(JComponent c)
513: {
514: return getPreferredMenuItemSize(c, checkIcon, arrowIcon,
515: defaultTextIconGap);
516: }
517:
518:
523: protected String getPropertyPrefix()
524: {
525: return "MenuItem";
526: }
527:
528:
534: protected void installComponents(JMenuItem menuItem)
535: {
536:
537: }
538:
539:
543: protected void installDefaults()
544: {
545: String prefix = getPropertyPrefix();
546: LookAndFeel.installBorder(menuItem, prefix + ".border");
547: LookAndFeel.installColorsAndFont(menuItem, prefix + ".background",
548: prefix + ".foreground", prefix + ".font");
549: menuItem.setMargin(UIManager.getInsets(prefix + ".margin"));
550: acceleratorFont = UIManager.getFont(prefix + ".acceleratorFont");
551: acceleratorForeground = UIManager.getColor(prefix
552: + ".acceleratorForeground");
553: acceleratorSelectionForeground = UIManager.getColor(prefix
554: + ".acceleratorSelectionForeground");
555: selectionBackground = UIManager.getColor(prefix + ".selectionBackground");
556: selectionForeground = UIManager.getColor(prefix + ".selectionForeground");
557: acceleratorDelimiter = UIManager.getString(prefix + ".acceleratorDelimiter");
558: checkIcon = UIManager.getIcon(prefix + ".checkIcon");
559:
560: menuItem.setHorizontalTextPosition(SwingConstants.TRAILING);
561: menuItem.setHorizontalAlignment(SwingConstants.LEADING);
562: }
563:
564:
567: protected void installKeyboardActions()
568: {
569: InputMap focusedWindowMap = SwingUtilities.getUIInputMap(menuItem,
570: JComponent.WHEN_IN_FOCUSED_WINDOW);
571: if (focusedWindowMap == null)
572: focusedWindowMap = new ComponentInputMapUIResource(menuItem);
573: KeyStroke accelerator = menuItem.getAccelerator();
574: if (accelerator != null)
575: focusedWindowMap.put(accelerator, "doClick");
576: SwingUtilities.replaceUIInputMap(menuItem,
577: JComponent.WHEN_IN_FOCUSED_WINDOW, focusedWindowMap);
578:
579: ActionMap UIActionMap = SwingUtilities.getUIActionMap(menuItem);
580: if (UIActionMap == null)
581: UIActionMap = new ActionMapUIResource();
582: UIActionMap.put("doClick", new ClickAction());
583: SwingUtilities.replaceUIActionMap(menuItem, UIActionMap);
584: }
585:
586:
589: protected void installListeners()
590: {
591: menuItem.addMouseListener(mouseInputListener);
592: menuItem.addMouseMotionListener(mouseInputListener);
593: menuItem.addMenuDragMouseListener(menuDragMouseListener);
594: menuItem.addMenuKeyListener(menuKeyListener);
595: menuItem.addItemListener(itemListener);
596: menuItem.addPropertyChangeListener(propertyChangeListener);
597:
598:
599: propertyChangeListener.propertyChange(new PropertyChangeEvent(menuItem,
600: "font", null,
601: menuItem.getFont()));
602: }
603:
604:
612: public void installUI(JComponent c)
613: {
614: super.installUI(c);
615: menuItem = (JMenuItem) c;
616: installDefaults();
617: installComponents(menuItem);
618: installListeners();
619: installKeyboardActions();
620: }
621:
622:
630: public void paint(Graphics g, JComponent c)
631: {
632: paintMenuItem(g, c, checkIcon, arrowIcon, selectionBackground,
633: c.getForeground(), defaultTextIconGap);
634: }
635:
636:
646: protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
647: {
648:
649:
650: ButtonModel mod = menuItem.getModel();
651: Color saved = g.getColor();
652: if (mod.isArmed() || ((menuItem instanceof JMenu) && mod.isSelected()))
653: {
654: g.setColor(bgColor);
655: g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
656: }
657: else if (menuItem.isOpaque())
658: {
659: g.setColor(menuItem.getBackground());
660: g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
661: }
662: g.setColor(saved);
663: }
664:
665:
683: protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,
684: Icon arrowIcon, Color background,
685: Color foreground, int defaultTextIconGap)
686: {
687: JMenuItem m = (JMenuItem) c;
688:
689:
690: Font oldFont = g.getFont();
691: Font font = c.getFont();
692: g.setFont(font);
693: FontMetrics accelFm = m.getFontMetrics(acceleratorFont);
694:
695:
696: String accelText = getAcceleratorString(m);
697:
698:
699:
700: resetRectangles(m);
701:
702: layoutMenuItem(m, accelText);
703:
704:
705: paintBackground(g, m, background);
706:
707: Color oldColor = g.getColor();
708:
709:
710: if (checkIcon != null)
711: {
712: checkIcon.paintIcon(m, g, checkIconRect.x, checkIconRect.y);
713: }
714:
715:
716: ButtonModel model = m.getModel();
717: if (m.getIcon() != null)
718: {
719:
720:
721: Icon icon;
722: if (! m.isEnabled())
723: {
724: icon = m.getDisabledIcon();
725: }
726: else if (model.isPressed() && model.isArmed())
727: {
728: icon = m.getPressedIcon();
729: if (icon == null)
730: {
731: icon = m.getIcon();
732: }
733: }
734: else
735: {
736: icon = m.getIcon();
737: }
738:
739: if (icon != null)
740: {
741: icon.paintIcon(m, g, iconRect.x, iconRect.y);
742: }
743: }
744:
745:
746: String text = m.getText();
747: if (text != null)
748: {
749:
750: View html = (View) m.getClientProperty(BasicHTML.propertyKey);
751: if (html != null)
752: {
753: html.paint(g, textRect);
754: }
755: else
756: {
757: paintText(g, m, textRect, text);
758: }
759: }
760:
761:
762: if (! accelText.equals(""))
763: {
764:
765:
766:
767:
768: int accelOffset = 0;
769: Container parent = m.getParent();
770: if (parent != null && parent instanceof JComponent)
771: {
772: JComponent p = (JComponent) parent;
773: Integer maxAccelWidth =
774: (Integer) p.getClientProperty("maxAccelWidth");
775: int maxAccelValue = maxAccelWidth == null ? 0
776: : maxAccelWidth.intValue();
777: accelOffset = maxAccelValue - accelRect.width;
778: }
779:
780: g.setFont(acceleratorFont);
781: if (! m.isEnabled())
782: {
783:
784: g.setColor(disabledForeground);
785: }
786: else
787: {
788: if (m.isArmed() || (m instanceof JMenu && m.isSelected()))
789: g.setColor(acceleratorSelectionForeground);
790: else
791: g.setColor(acceleratorForeground);
792: }
793: g.drawString(accelText, accelRect.x - accelOffset,
794: accelRect.y + accelFm.getAscent());
795: }
796:
797:
798: if (arrowIcon != null
799: && ! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
800: {
801: arrowIcon.paintIcon(m, g, arrowIconRect.x, arrowIconRect.y);
802: }
803:
804: g.setFont(oldFont);
805: g.setColor(oldColor);
806:
807: }
808:
809:
822: protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect,
823: String text)
824: {
825: Font f = menuItem.getFont();
826: g.setFont(f);
827: FontMetrics fm = g.getFontMetrics(f);
828:
829: if (text != null && !text.equals(""))
830: {
831: if (menuItem.isEnabled())
832: {
833:
834:
835: ButtonModel mod = menuItem.getModel();
836: if ((menuItem.isSelected() && checkIcon == null)
837: || (mod != null && mod.isArmed())
838: && (menuItem.getParent() instanceof MenuElement))
839: g.setColor(selectionForeground);
840: else
841: g.setColor(menuItem.getForeground());
842: }
843: else
844:
845:
846:
847:
848:
849: g.setColor(Color.gray);
850:
851: int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
852:
853: if (mnemonicIndex != -1)
854: BasicGraphicsUtils.drawStringUnderlineCharAt(menuItem, g, text,
855: mnemonicIndex,
856: textRect.x,
857: textRect.y
858: + fm.getAscent());
859: else
860: BasicGraphicsUtils.drawString(menuItem, g, text, 0, textRect.x,
861: textRect.y + fm.getAscent());
862: }
863: }
864:
865:
871: protected void uninstallComponents(JMenuItem menuItem)
872: {
873:
874: }
875:
876:
880: protected void uninstallDefaults()
881: {
882: menuItem.setForeground(null);
883: menuItem.setBackground(null);
884: menuItem.setBorder(null);
885: menuItem.setMargin(null);
886: menuItem.setBackground(null);
887: menuItem.setBorder(null);
888: menuItem.setFont(null);
889: menuItem.setForeground(null);
890: menuItem.setMargin(null);
891: acceleratorFont = null;
892: acceleratorForeground = null;
893: acceleratorSelectionForeground = null;
894: arrowIcon = null;
895: selectionBackground = null;
896: selectionForeground = null;
897: acceleratorDelimiter = null;
898: }
899:
900:
903: protected void uninstallKeyboardActions()
904: {
905: SwingUtilities.replaceUIInputMap(menuItem,
906: JComponent.WHEN_IN_FOCUSED_WINDOW, null);
907: }
908:
909:
912: protected void uninstallListeners()
913: {
914: menuItem.removeMouseListener(mouseInputListener);
915: menuItem.removeMenuDragMouseListener(menuDragMouseListener);
916: menuItem.removeMenuKeyListener(menuKeyListener);
917: menuItem.removeItemListener(itemListener);
918: menuItem.removePropertyChangeListener(propertyChangeListener);
919: }
920:
921:
929: public void uninstallUI(JComponent c)
930: {
931: uninstallListeners();
932: uninstallDefaults();
933: uninstallComponents(menuItem);
934: c.putClientProperty(BasicGraphicsUtils.CACHED_TEXT_LAYOUT, null);
935: menuItem = null;
936: }
937:
938:
946: public void update(Graphics g, JComponent c)
947: {
948: paint(g, c);
949: }
950:
951:
956: protected class MouseInputHandler implements MouseInputListener
957: {
958:
961: protected MouseInputHandler()
962: {
963:
964: }
965:
966:
973: public void mouseClicked(MouseEvent e)
974: {
975: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
976: manager.processMouseEvent(e);
977: }
978:
979:
986: public void mouseDragged(MouseEvent e)
987: {
988: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
989: manager.processMouseEvent(e);
990: }
991:
992:
1001: public void mouseEntered(MouseEvent e)
1002: {
1003: Component source = (Component) e.getSource();
1004: if (source.getParent() instanceof MenuElement)
1005: {
1006: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1007: manager.setSelectedPath(getPath());
1008: manager.processMouseEvent(e);
1009: }
1010: }
1011:
1012:
1019: public void mouseExited(MouseEvent e)
1020: {
1021: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1022: manager.processMouseEvent(e);
1023: }
1024:
1025:
1032: public void mouseMoved(MouseEvent e)
1033: {
1034: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1035: manager.processMouseEvent(e);
1036: }
1037:
1038:
1045: public void mousePressed(MouseEvent e)
1046: {
1047: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1048: manager.processMouseEvent(e);
1049: }
1050:
1051:
1059: public void mouseReleased(MouseEvent e)
1060: {
1061: MenuSelectionManager manager = MenuSelectionManager.defaultManager();
1062: int x = e.getX();
1063: int y = e.getY();
1064: if (x > 0 && x < menuItem.getWidth() && y > 0
1065: && y < menuItem.getHeight())
1066: {
1067: doClick(manager);
1068: }
1069: else
1070: manager.processMouseEvent(e);
1071: }
1072: }
1073:
1074:
1077: private class MenuDragMouseHandler implements MenuDragMouseListener
1078: {
1079:
1085: public void menuDragMouseDragged(MenuDragMouseEvent e)
1086: {
1087: MenuSelectionManager manager = e.getMenuSelectionManager();
1088: manager.setSelectedPath(e.getPath());
1089: }
1090:
1091:
1098: public void menuDragMouseEntered(MenuDragMouseEvent e)
1099: {
1100: MenuSelectionManager manager = e.getMenuSelectionManager();
1101: manager.setSelectedPath(e.getPath());
1102: }
1103:
1104:
1110: public void menuDragMouseExited(MenuDragMouseEvent e)
1111: {
1112:
1113: }
1114:
1115:
1122: public void menuDragMouseReleased(MenuDragMouseEvent e)
1123: {
1124: MenuSelectionManager manager = e.getMenuSelectionManager();
1125: int x = e.getX();
1126: int y = e.getY();
1127: if (x >= 0 && x < menuItem.getWidth() && y >= 0
1128: && y < menuItem.getHeight())
1129: doClick(manager);
1130: else
1131: manager.clearSelectedPath();
1132: }
1133: }
1134:
1135:
1139: private class MenuKeyHandler implements MenuKeyListener
1140: {
1141:
1147: public void menuKeyPressed(MenuKeyEvent e)
1148: {
1149:
1150: }
1151:
1152:
1158: public void menuKeyReleased(MenuKeyEvent e)
1159: {
1160:
1161: }
1162:
1163:
1170: public void menuKeyTyped(MenuKeyEvent e)
1171: {
1172:
1173: }
1174: }
1175:
1176:
1180: private class ItemHandler implements ItemListener
1181: {
1182:
1187: public void itemStateChanged(ItemEvent evt)
1188: {
1189: boolean state = false;
1190: if (menuItem instanceof JCheckBoxMenuItem)
1191: {
1192: if (evt.getStateChange() == ItemEvent.SELECTED)
1193: state = true;
1194: ((JCheckBoxMenuItem) menuItem).setState(state);
1195: }
1196: menuItem.revalidate();
1197: menuItem.repaint();
1198: }
1199: }
1200:
1201:
1210: private String getAcceleratorString(JMenuItem m)
1211: {
1212:
1213: KeyStroke accel = m.getAccelerator();
1214: String accelText = "";
1215: if (accel != null)
1216: {
1217: int mods = accel.getModifiers();
1218: if (mods > 0)
1219: {
1220: accelText = KeyEvent.getKeyModifiersText(mods);
1221: accelText += acceleratorDelimiter;
1222: }
1223: int keycode = accel.getKeyCode();
1224: if (keycode != 0)
1225: accelText += KeyEvent.getKeyText(keycode);
1226: else
1227: accelText += accel.getKeyChar();
1228: }
1229: return accelText;
1230: }
1231:
1232:
1240: private void resetRectangles(JMenuItem i)
1241: {
1242:
1243: iconRect.setBounds(0, 0, 0, 0);
1244: textRect.setBounds(0, 0, 0, 0);
1245: accelRect.setBounds(0, 0, 0, 0);
1246: checkIconRect.setBounds(0, 0, 0, 0);
1247: arrowIconRect.setBounds(0, 0, 0, 0);
1248: if (i == null)
1249: viewRect.setBounds(0, 0, Short.MAX_VALUE, Short.MAX_VALUE);
1250: else
1251: {
1252: Insets insets = i.getInsets();
1253: viewRect.setBounds(insets.left, insets.top,
1254: i.getWidth() - insets.left - insets.right,
1255: i.getHeight() - insets.top - insets.bottom);
1256: }
1257: }
1258:
1259:
1266: private void layoutMenuItem(JMenuItem m, String accelText)
1267: {
1268:
1269: Font font = m.getFont();
1270: FontMetrics fm = m.getFontMetrics(font);
1271: FontMetrics accelFm = m.getFontMetrics(acceleratorFont);
1272:
1273: String text = m.getText();
1274: SwingUtilities.layoutCompoundLabel(m, fm, text, m.getIcon(),
1275: m.getVerticalAlignment(),
1276: m.getHorizontalAlignment(),
1277: m.getVerticalTextPosition(),
1278: m.getHorizontalTextPosition(),
1279: viewRect, iconRect, textRect,
1280: defaultTextIconGap);
1281:
1282:
1283: if (! accelText.equals(""))
1284: {
1285: accelRect.width = accelFm.stringWidth(accelText);
1286: accelRect.height = accelFm.getHeight();
1287: }
1288:
1289:
1290: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1291: {
1292: if (checkIcon != null)
1293: {
1294: checkIconRect.width = checkIcon.getIconWidth();
1295: checkIconRect.height = checkIcon.getIconHeight();
1296: }
1297: if (arrowIcon != null)
1298: {
1299: arrowIconRect.width = arrowIcon.getIconWidth();
1300: arrowIconRect.height = arrowIcon.getIconHeight();
1301: }
1302: }
1303:
1304:
1305: cachedRect.setBounds(textRect);
1306: Rectangle labelRect = SwingUtilities.computeUnion(iconRect.x,
1307: iconRect.y,
1308: iconRect.width,
1309: iconRect.height,
1310: cachedRect);
1311: textRect.x += defaultTextIconGap;
1312: iconRect.x += defaultTextIconGap;
1313:
1314:
1315: accelRect.x = viewRect.x + viewRect.width - arrowIconRect.width
1316: - defaultTextIconGap - accelRect.width;
1317:
1318: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1319: {
1320: checkIconRect.x = viewRect.x + defaultTextIconGap;
1321: textRect.x += defaultTextIconGap + checkIconRect.width;
1322: iconRect.x += defaultTextIconGap + checkIconRect.width;
1323: arrowIconRect.x = viewRect.x + viewRect.width - defaultTextIconGap
1324: - arrowIconRect.width;
1325: }
1326:
1327:
1328:
1329: accelRect.y = labelRect.y + (labelRect.height / 2)
1330: - (accelRect.height / 2);
1331: if (! (m instanceof JMenu && ((JMenu) m).isTopLevelMenu()))
1332: {
1333: arrowIconRect.y = labelRect.y + (labelRect.height / 2)
1334: - (arrowIconRect.height / 2);
1335: checkIconRect.y = labelRect.y + (labelRect.height / 2)
1336: - (checkIconRect.height / 2);
1337: }
1338: }
1339: }