public class

MenuItemLayoutHelper

extends Object
java.lang.Object
   ↳ sun.swing.MenuItemLayoutHelper

Class Overview

Calculates preferred size and layouts menu items.

Summary

Nested Classes
class MenuItemLayoutHelper.ColumnAlignment  
class MenuItemLayoutHelper.LayoutResult  
class MenuItemLayoutHelper.RectSize  
Fields
public static final StringUIClientPropertyKey MAX_ACC_WIDTH
public static final StringUIClientPropertyKey MAX_ARROW_WIDTH
public static final StringUIClientPropertyKey MAX_CHECK_WIDTH
public static final StringUIClientPropertyKey MAX_ICON_WIDTH
public static final StringUIClientPropertyKey MAX_LABEL_WIDTH
public static final StringUIClientPropertyKey MAX_TEXT_WIDTH
Public Constructors
MenuItemLayoutHelper(JMenuItem mi, Icon checkIcon, Icon arrowIcon, Rectangle viewRect, int gap, String accDelimiter, boolean isLeftToRight, Font font, Font accFont, boolean useCheckAndArrow, String propertyPrefix)
Protected Constructors
MenuItemLayoutHelper()
The empty protected constructor is necessary for derived classes.
Public Methods
static void addMaxWidth(MenuItemLayoutHelper.RectSize size, int gap, Dimension result)
static void addWidth(int width, int gap, Dimension result)
static void clearUsedClientProperties(JComponent c)
static void clearUsedParentClientProperties(JMenuItem menuItem)
static Rectangle createMaxRect()
Font getAccFont()
FontMetrics getAccFontMetrics()
MenuItemLayoutHelper.RectSize getAccSize()
String getAccText()
int getAfterCheckIconGap()
Icon getArrowIcon()
MenuItemLayoutHelper.RectSize getArrowSize()
Icon getCheckIcon()
MenuItemLayoutHelper.RectSize getCheckSize()
Font getFont()
FontMetrics getFontMetrics()
int getGap()
int getHorizontalAlignment()
int getHorizontalTextPosition()
View getHtmlView()
Icon getIcon()
MenuItemLayoutHelper.RectSize getIconSize()
MenuItemLayoutHelper.ColumnAlignment getLTRColumnAlignment()
MenuItemLayoutHelper.RectSize getLabelSize()
int getLeadingGap()
JMenuItem getMenuItem()
static JComponent getMenuItemParent(JMenuItem menuItem)
Returns parent of this component if it is not a top-level menu Otherwise returns null.
JComponent getMenuItemParent()
int getMinTextOffset()
MenuItemLayoutHelper.ColumnAlignment getRTLColumnAlignment()
String getText()
MenuItemLayoutHelper.RectSize getTextSize()
int getVerticalAlignment()
int getVerticalTextPosition()
Rectangle getViewRect()
boolean isColumnLayout()
static boolean isColumnLayout(boolean isLeftToRight, int horizontalAlignment, int horizontalTextPosition, int verticalTextPosition)
Answers should we do column layout for a menu item or not.
static boolean isColumnLayout(boolean isLeftToRight, JMenuItem mi)
boolean isLeftToRight()
boolean isTopLevelMenu()
MenuItemLayoutHelper.LayoutResult layoutMenuItem()
Layout icon, text, check icon, accelerator text and arrow icon in the viewRect and return their positions.
static int max(int... values)
Finds and returns maximal integer value in the given array.
boolean useCheckAndArrow()
static boolean useCheckAndArrow(JMenuItem menuItem)
Returns false if the component is a JMenu and it is a top level menu (on the menubar).
Protected Methods
int calcMaxValue(Object propertyName, int value)
Calculates and returns maximal value through specified parent component client property.
void calcMaxWidth(MenuItemLayoutHelper.RectSize rs, Object key)
void calcMaxWidths()
void calcWidthsAndHeights()
int getParentIntProperty(Object propertyName)
Returns parent client property as int.
void layoutIconAndTextInLabelRect(MenuItemLayoutHelper.LayoutResult lr)
void prepareForLayout(MenuItemLayoutHelper.LayoutResult lr)
void reset(JMenuItem mi, Icon checkIcon, Icon arrowIcon, Rectangle viewRect, int gap, String accDelimiter, boolean isLeftToRight, Font font, Font accFont, boolean useCheckAndArrow, String propertyPrefix)
void setAccFont(Font accFont)
void setAccFontMetrics(FontMetrics accFm)
void setAccSize(MenuItemLayoutHelper.RectSize accSize)
void setAccText(String accText)
void setAfterCheckIconGap(int afterCheckIconGap)
void setArrowIcon(Icon arrowIcon)
void setArrowSize(MenuItemLayoutHelper.RectSize arrowSize)
void setCheckIcon(Icon checkIcon)
void setCheckSize(MenuItemLayoutHelper.RectSize checkSize)
void setColumnLayout(boolean columnLayout)
void setFont(Font font)
void setFontMetrics(FontMetrics fm)
void setGap(int gap)
void setHorizontalAlignment(int horizontalAlignment)
void setHorizontalTextPosition(int horizontalTextPosition)
void setHtmlView(View htmlView)
void setIcon(Icon icon)
void setIconSize(MenuItemLayoutHelper.RectSize iconSize)
void setLabelSize(MenuItemLayoutHelper.RectSize labelSize)
void setLeadingGap(int leadingGap)
void setLeftToRight(boolean leftToRight)
void setMenuItem(JMenuItem mi)
void setMenuItemParent(JComponent miParent)
void setMinTextOffset(int minTextOffset)
void setText(String text)
void setTextSize(MenuItemLayoutHelper.RectSize textSize)
void setTopLevelMenu(boolean topLevelMenu)
void setUseCheckAndArrow(boolean useCheckAndArrow)
void setVerticalAlignment(int verticalAlignment)
void setVerticalTextPosition(int verticalTextPosition)
void setViewRect(Rectangle viewRect)
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final StringUIClientPropertyKey MAX_ACC_WIDTH

public static final StringUIClientPropertyKey MAX_ARROW_WIDTH

public static final StringUIClientPropertyKey MAX_CHECK_WIDTH

public static final StringUIClientPropertyKey MAX_ICON_WIDTH

public static final StringUIClientPropertyKey MAX_LABEL_WIDTH

public static final StringUIClientPropertyKey MAX_TEXT_WIDTH

Public Constructors

public MenuItemLayoutHelper (JMenuItem mi, Icon checkIcon, Icon arrowIcon, Rectangle viewRect, int gap, String accDelimiter, boolean isLeftToRight, Font font, Font accFont, boolean useCheckAndArrow, String propertyPrefix)

Protected Constructors

protected MenuItemLayoutHelper ()

The empty protected constructor is necessary for derived classes.

Public Methods

public static void addMaxWidth (MenuItemLayoutHelper.RectSize size, int gap, Dimension result)

public static void addWidth (int width, int gap, Dimension result)

public static void clearUsedClientProperties (JComponent c)

public static void clearUsedParentClientProperties (JMenuItem menuItem)

public static Rectangle createMaxRect ()

public Font getAccFont ()

public FontMetrics getAccFontMetrics ()

public MenuItemLayoutHelper.RectSize getAccSize ()

public String getAccText ()

public int getAfterCheckIconGap ()

public Icon getArrowIcon ()

public MenuItemLayoutHelper.RectSize getArrowSize ()

public Icon getCheckIcon ()

public MenuItemLayoutHelper.RectSize getCheckSize ()

public Font getFont ()

public FontMetrics getFontMetrics ()

public int getGap ()

public int getHorizontalAlignment ()

public int getHorizontalTextPosition ()

public View getHtmlView ()

public Icon getIcon ()

public MenuItemLayoutHelper.RectSize getIconSize ()

public MenuItemLayoutHelper.ColumnAlignment getLTRColumnAlignment ()

public MenuItemLayoutHelper.RectSize getLabelSize ()

public int getLeadingGap ()

public JMenuItem getMenuItem ()

public static JComponent getMenuItemParent (JMenuItem menuItem)

Returns parent of this component if it is not a top-level menu Otherwise returns null.

Parameters
menuItem the menu item whose parent will be returned.
Returns
  • parent of this component if it is not a top-level menu Otherwise returns null.

public JComponent getMenuItemParent ()

public int getMinTextOffset ()

public MenuItemLayoutHelper.ColumnAlignment getRTLColumnAlignment ()

public String getText ()

public MenuItemLayoutHelper.RectSize getTextSize ()

public int getVerticalAlignment ()

public int getVerticalTextPosition ()

public Rectangle getViewRect ()

public boolean isColumnLayout ()

public static boolean isColumnLayout (boolean isLeftToRight, int horizontalAlignment, int horizontalTextPosition, int verticalTextPosition)

Answers should we do column layout for a menu item or not. We do it when a user doesn't set any alignments and text positions manually, except the vertical alignment.

public static boolean isColumnLayout (boolean isLeftToRight, JMenuItem mi)

public boolean isLeftToRight ()

public boolean isTopLevelMenu ()

public MenuItemLayoutHelper.LayoutResult layoutMenuItem ()

Layout icon, text, check icon, accelerator text and arrow icon in the viewRect and return their positions. If horizontalAlignment, verticalTextPosition and horizontalTextPosition are default (user doesn't set any manually) the layouting algorithm is: Elements are layouted in the five columns: check icon + icon + text + accelerator text + arrow icon In the other case elements are layouted in the four columns: check icon + label + accelerator text + arrow icon Label is union of icon and text. The order of columns can be reversed. It depends on the menu item orientation.

public static int max (int... values)

Finds and returns maximal integer value in the given array.

Parameters
values array where the search will be performed.
Returns
  • maximal vaule.

public boolean useCheckAndArrow ()

public static boolean useCheckAndArrow (JMenuItem menuItem)

Returns false if the component is a JMenu and it is a top level menu (on the menubar).

Protected Methods

protected int calcMaxValue (Object propertyName, int value)

Calculates and returns maximal value through specified parent component client property.

Parameters
propertyName name of the property, which stores the maximal value.
value a value which pretends to be maximal
Returns
  • maximal value among the parent property and the value.

protected void calcMaxWidth (MenuItemLayoutHelper.RectSize rs, Object key)

protected void calcMaxWidths ()

protected void calcWidthsAndHeights ()

protected int getParentIntProperty (Object propertyName)

Returns parent client property as int.

Parameters
propertyName name of the parent property.
Returns
  • value of the property as int.

protected void layoutIconAndTextInLabelRect (MenuItemLayoutHelper.LayoutResult lr)

protected void prepareForLayout (MenuItemLayoutHelper.LayoutResult lr)

protected void reset (JMenuItem mi, Icon checkIcon, Icon arrowIcon, Rectangle viewRect, int gap, String accDelimiter, boolean isLeftToRight, Font font, Font accFont, boolean useCheckAndArrow, String propertyPrefix)

protected void setAccFont (Font accFont)

protected void setAccFontMetrics (FontMetrics accFm)

protected void setAccSize (MenuItemLayoutHelper.RectSize accSize)

protected void setAccText (String accText)

protected void setAfterCheckIconGap (int afterCheckIconGap)

protected void setArrowIcon (Icon arrowIcon)

protected void setArrowSize (MenuItemLayoutHelper.RectSize arrowSize)

protected void setCheckIcon (Icon checkIcon)

protected void setCheckSize (MenuItemLayoutHelper.RectSize checkSize)

protected void setColumnLayout (boolean columnLayout)

protected void setFont (Font font)

protected void setFontMetrics (FontMetrics fm)

protected void setGap (int gap)

protected void setHorizontalAlignment (int horizontalAlignment)

protected void setHorizontalTextPosition (int horizontalTextPosition)

protected void setHtmlView (View htmlView)

protected void setIcon (Icon icon)

protected void setIconSize (MenuItemLayoutHelper.RectSize iconSize)

protected void setLabelSize (MenuItemLayoutHelper.RectSize labelSize)

protected void setLeadingGap (int leadingGap)

protected void setLeftToRight (boolean leftToRight)

protected void setMenuItem (JMenuItem mi)

protected void setMenuItemParent (JComponent miParent)

protected void setMinTextOffset (int minTextOffset)

protected void setText (String text)

protected void setTextSize (MenuItemLayoutHelper.RectSize textSize)

protected void setTopLevelMenu (boolean topLevelMenu)

protected void setUseCheckAndArrow (boolean useCheckAndArrow)

protected void setVerticalAlignment (int verticalAlignment)

protected void setVerticalTextPosition (int verticalTextPosition)

protected void setViewRect (Rectangle viewRect)