Class MenuItemRenderer

java.lang.Object
com.jgoodies.looks.common.MenuItemRenderer

public class MenuItemRenderer extends Object
Renders and lays out menu items.
Version:
$Revision: 1.14 $
  • Field Details

    • HTML_KEY

      protected static final String HTML_KEY
      See Also:
    • MAX_TEXT_WIDTH

      static final String MAX_TEXT_WIDTH
      See Also:
    • MAX_ACC_WIDTH

      static final String MAX_ACC_WIDTH
      See Also:
    • NO_ICON

      private static final Icon NO_ICON
    • zeroRect

      static Rectangle zeroRect
    • iconRect

      static Rectangle iconRect
    • textRect

      static Rectangle textRect
    • acceleratorRect

      static Rectangle acceleratorRect
    • checkIconRect

      static Rectangle checkIconRect
    • arrowIconRect

      static Rectangle arrowIconRect
    • viewRect

      static Rectangle viewRect
    • r

      static Rectangle r
    • iconBorderEnabled

      private final boolean iconBorderEnabled
    • acceleratorFont

      private final Font acceleratorFont
    • selectionForeground

      private final Color selectionForeground
    • disabledForeground

      private final Color disabledForeground
    • acceleratorForeground

      private final Color acceleratorForeground
    • acceleratorSelectionForeground

      private final Color acceleratorSelectionForeground
    • acceleratorDelimiter

      private final String acceleratorDelimiter
    • fillerIcon

      private final Icon fillerIcon
  • Constructor Details

    • MenuItemRenderer

      public MenuItemRenderer(JMenuItem menuItem, boolean iconBorderEnabled, Font acceleratorFont, Color selectionForeground, Color disabledForeground, Color acceleratorForeground, Color acceleratorSelectionForeground)
      Constructs a MenuItemRenderer for the specified menu item and settings.
  • Method Details

    • getIcon

      private static Icon getIcon(JMenuItem aMenuItem, Icon defaultIcon)
      Looks up and answers the appropriate menu item icon.
    • hasCustomIcon

      private boolean hasCustomIcon()
      Checks and answers if the menu item has a custom icon.
    • getWrappedIcon

      private Icon getWrappedIcon(Icon icon)
      Answers the wrapped icon.
    • resetRects

      private static void resetRects()
    • getPreferredMenuItemSize

      public Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap)
    • paintMenuItem

      public void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap)
    • layoutMenuItem

      private String layoutMenuItem(FontMetrics fm, String text, FontMetrics fmAccel, String acceleratorText, Icon icon, Icon checkIcon, Icon arrowIcon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewRectangle, Rectangle iconRectangle, Rectangle textRectangle, Rectangle acceleratorRectangle, Rectangle checkIconRectangle, Rectangle arrowIconRectangle, int textIconGap, int menuItemGap)
      Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewRect rectangle.
    • useCheckAndArrow

      private boolean useCheckAndArrow()
    • isLeftToRight

      private static boolean isLeftToRight(Component c)
    • paintBackground

      private static void paintBackground(Graphics g, JMenuItem aMenuItem, Color bgColor)
      Draws the background of the menu item. Copied from 1.4.1 BasicMenuItem to make it visible to the MenuItemLayouter
      Parameters:
      g - the paint graphics
      aMenuItem - menu item to be painted
      bgColor - selection background color
      Since:
      1.4
    • paintText

      private void paintText(Graphics g, JMenuItem aMenuItem, Rectangle textRectangle, String text)
      Renders the text of the current menu item.

      Parameters:
      g - graphics context
      aMenuItem - menu item to render
      textRectangle - bounding rectangle for rendering the text
      text - string to render
      Since:
      1.4
    • isMnemonicHidden

      protected boolean isMnemonicHidden()
    • disabledTextHasShadow

      protected boolean disabledTextHasShadow()
    • hideIcons

      private boolean hideIcons()
      Checks and answers if the parent menu indicates that we should use no icons.