1. /*
  2. * @(#)WindowsMenuItemUI.java 1.19 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.event.*;
  11. import javax.swing.plaf.*;
  12. import javax.swing.plaf.basic.*;
  13. /**
  14. * Windows rendition of the component.
  15. * <p>
  16. * <strong>Warning:</strong>
  17. * Serialized objects of this class will not be compatible with
  18. * future Swing releases. The current serialization support is appropriate
  19. * for short term storage or RMI between applications running the same
  20. * version of Swing. A future release of Swing will provide support for
  21. * long term persistence.
  22. */
  23. public class WindowsMenuItemUI extends BasicMenuItemUI {
  24. public static ComponentUI createUI(JComponent c) {
  25. return new WindowsMenuItemUI();
  26. }
  27. /**
  28. * Method which renders the text of the current menu item.
  29. * <p>
  30. * @param g Graphics context
  31. * @param menuItem Current menu item to render
  32. * @param textRect Bounding rectangle to render the text.
  33. * @param text String to render
  34. */
  35. protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
  36. // Note: This method is almost identical to the same method in WindowsMenuUI
  37. ButtonModel model = menuItem.getModel();
  38. if(!model.isEnabled()) {
  39. // *** paint the text disabled
  40. WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
  41. } else {
  42. FontMetrics fm = g.getFontMetrics();
  43. int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
  44. // W2K Feature: Check to see if the Underscore should be rendered.
  45. if (WindowsLookAndFeel.isMnemonicHidden() == true) {
  46. mnemonicIndex = -1;
  47. }
  48. Color oldColor = g.getColor();
  49. // *** paint the text normally
  50. if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
  51. g.setColor(selectionForeground); // Uses protected field.
  52. }
  53. BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,
  54. mnemonicIndex,
  55. textRect.x,
  56. textRect.y + fm.getAscent());
  57. g.setColor(oldColor);
  58. }
  59. }
  60. }