Class MenuItemRenderer


  • public class MenuItemRenderer
    extends java.lang.Object
    Renders and lays out menu items.
    Version:
    $Revision: 1.14 $
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  MenuItemRenderer.NullIcon
      Used as a placeholder if icons are disabled.
    • Constructor Summary

      Constructors 
      Constructor Description
      MenuItemRenderer​(javax.swing.JMenuItem menuItem, boolean iconBorderEnabled, java.awt.Font acceleratorFont, java.awt.Color selectionForeground, java.awt.Color disabledForeground, java.awt.Color acceleratorForeground, java.awt.Color acceleratorSelectionForeground)
      Constructs a MenuItemRenderer for the specified menu item and settings.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean disabledTextHasShadow()  
      private static javax.swing.Icon getIcon​(javax.swing.JMenuItem aMenuItem, javax.swing.Icon defaultIcon)
      Looks up and answers the appropriate menu item icon.
      java.awt.Dimension getPreferredMenuItemSize​(javax.swing.JComponent c, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon, int defaultTextIconGap)  
      private javax.swing.Icon getWrappedIcon​(javax.swing.Icon icon)
      Answers the wrapped icon.
      private boolean hasCustomIcon()
      Checks and answers if the menu item has a custom icon.
      private boolean hideIcons()
      Checks and answers if the parent menu indicates that we should use no icons.
      private static boolean isLeftToRight​(java.awt.Component c)  
      protected boolean isMnemonicHidden()  
      private java.lang.String layoutMenuItem​(java.awt.FontMetrics fm, java.lang.String text, java.awt.FontMetrics fmAccel, java.lang.String acceleratorText, javax.swing.Icon icon, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewRectangle, java.awt.Rectangle iconRectangle, java.awt.Rectangle textRectangle, java.awt.Rectangle acceleratorRectangle, java.awt.Rectangle checkIconRectangle, java.awt.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.
      private static void paintBackground​(java.awt.Graphics g, javax.swing.JMenuItem aMenuItem, java.awt.Color bgColor)
      Draws the background of the menu item.
      void paintMenuItem​(java.awt.Graphics g, javax.swing.JComponent c, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon, java.awt.Color background, java.awt.Color foreground, int defaultTextIconGap)  
      private void paintText​(java.awt.Graphics g, javax.swing.JMenuItem aMenuItem, java.awt.Rectangle textRectangle, java.lang.String text)
      Renders the text of the current menu item.
      private static void resetRects()  
      private boolean useCheckAndArrow()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NO_ICON

        private static final javax.swing.Icon NO_ICON
      • zeroRect

        static java.awt.Rectangle zeroRect
      • iconRect

        static java.awt.Rectangle iconRect
      • textRect

        static java.awt.Rectangle textRect
      • acceleratorRect

        static java.awt.Rectangle acceleratorRect
      • checkIconRect

        static java.awt.Rectangle checkIconRect
      • arrowIconRect

        static java.awt.Rectangle arrowIconRect
      • viewRect

        static java.awt.Rectangle viewRect
      • r

        static java.awt.Rectangle r
      • menuItem

        private final javax.swing.JMenuItem menuItem
      • iconBorderEnabled

        private final boolean iconBorderEnabled
      • acceleratorFont

        private final java.awt.Font acceleratorFont
      • selectionForeground

        private final java.awt.Color selectionForeground
      • disabledForeground

        private final java.awt.Color disabledForeground
      • acceleratorForeground

        private final java.awt.Color acceleratorForeground
      • acceleratorSelectionForeground

        private final java.awt.Color acceleratorSelectionForeground
      • acceleratorDelimiter

        private final java.lang.String acceleratorDelimiter
      • fillerIcon

        private final javax.swing.Icon fillerIcon
    • Constructor Detail

      • MenuItemRenderer

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

      • getIcon

        private static javax.swing.Icon getIcon​(javax.swing.JMenuItem aMenuItem,
                                                javax.swing.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 javax.swing.Icon getWrappedIcon​(javax.swing.Icon icon)
        Answers the wrapped icon.
      • resetRects

        private static void resetRects()
      • getPreferredMenuItemSize

        public java.awt.Dimension getPreferredMenuItemSize​(javax.swing.JComponent c,
                                                           javax.swing.Icon checkIcon,
                                                           javax.swing.Icon arrowIcon,
                                                           int defaultTextIconGap)
      • paintMenuItem

        public void paintMenuItem​(java.awt.Graphics g,
                                  javax.swing.JComponent c,
                                  javax.swing.Icon checkIcon,
                                  javax.swing.Icon arrowIcon,
                                  java.awt.Color background,
                                  java.awt.Color foreground,
                                  int defaultTextIconGap)
      • layoutMenuItem

        private java.lang.String layoutMenuItem​(java.awt.FontMetrics fm,
                                                java.lang.String text,
                                                java.awt.FontMetrics fmAccel,
                                                java.lang.String acceleratorText,
                                                javax.swing.Icon icon,
                                                javax.swing.Icon checkIcon,
                                                javax.swing.Icon arrowIcon,
                                                int verticalAlignment,
                                                int horizontalAlignment,
                                                int verticalTextPosition,
                                                int horizontalTextPosition,
                                                java.awt.Rectangle viewRectangle,
                                                java.awt.Rectangle iconRectangle,
                                                java.awt.Rectangle textRectangle,
                                                java.awt.Rectangle acceleratorRectangle,
                                                java.awt.Rectangle checkIconRectangle,
                                                java.awt.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​(java.awt.Component c)
      • paintBackground

        private static void paintBackground​(java.awt.Graphics g,
                                            javax.swing.JMenuItem aMenuItem,
                                            java.awt.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​(java.awt.Graphics g,
                               javax.swing.JMenuItem aMenuItem,
                               java.awt.Rectangle textRectangle,
                               java.lang.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.