Package com.jgoodies.looks.common
Class MenuItemRenderer
- java.lang.Object
-
- com.jgoodies.looks.common.MenuItemRenderer
-
public class MenuItemRenderer extends java.lang.ObjectRenders and lays out menu items.- Version:
- $Revision: 1.14 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMenuItemRenderer.NullIconUsed as a placeholder if icons are disabled.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringacceleratorDelimiterprivate java.awt.FontacceleratorFontprivate java.awt.ColoracceleratorForeground(package private) static java.awt.RectangleacceleratorRectprivate java.awt.ColoracceleratorSelectionForeground(package private) static java.awt.RectanglearrowIconRect(package private) static java.awt.RectanglecheckIconRectprivate java.awt.ColordisabledForegroundprivate javax.swing.IconfillerIconprotected static java.lang.StringHTML_KEYprivate booleaniconBorderEnabled(package private) static java.awt.RectangleiconRect(package private) static java.lang.StringMAX_ACC_WIDTH(package private) static java.lang.StringMAX_TEXT_WIDTHprivate javax.swing.JMenuItemmenuItemprivate static javax.swing.IconNO_ICON(package private) static java.awt.Rectanglerprivate java.awt.ColorselectionForeground(package private) static java.awt.RectangletextRect(package private) static java.awt.RectangleviewRect(package private) static java.awt.RectanglezeroRect
-
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 booleandisabledTextHasShadow()private static javax.swing.IcongetIcon(javax.swing.JMenuItem aMenuItem, javax.swing.Icon defaultIcon)Looks up and answers the appropriate menu item icon.java.awt.DimensiongetPreferredMenuItemSize(javax.swing.JComponent c, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon, int defaultTextIconGap)private javax.swing.IcongetWrappedIcon(javax.swing.Icon icon)Answers the wrapped icon.private booleanhasCustomIcon()Checks and answers if the menu item has a custom icon.private booleanhideIcons()Checks and answers if the parent menu indicates that we should use no icons.private static booleanisLeftToRight(java.awt.Component c)protected booleanisMnemonicHidden()private java.lang.StringlayoutMenuItem(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 voidpaintBackground(java.awt.Graphics g, javax.swing.JMenuItem aMenuItem, java.awt.Color bgColor)Draws the background of the menu item.voidpaintMenuItem(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 voidpaintText(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 voidresetRects()private booleanuseCheckAndArrow()
-
-
-
Field Detail
-
HTML_KEY
protected static final java.lang.String HTML_KEY
- See Also:
- Constant Field Values
-
MAX_TEXT_WIDTH
static final java.lang.String MAX_TEXT_WIDTH
- See Also:
- Constant Field Values
-
MAX_ACC_WIDTH
static final java.lang.String MAX_ACC_WIDTH
- See Also:
- Constant Field Values
-
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 graphicsaMenuItem- menu item to be paintedbgColor- 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 contextaMenuItem- menu item to rendertextRectangle- bounding rectangle for rendering the texttext- 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.
-
-