Class MenuUtilities
java.lang.Object
org.pushingpixels.radiance.theming.internal.utils.menu.MenuUtilities
Menu-related utilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Layout information for a single menu item.static class
Layout metrics for a single popup menu.static class
Listener to track changes in the menu items. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
cleanPopupLayoutMetrics
(JMenuItem menuItem) Cleans the layout metrics of the popup menu of the specified menu item.static void
cleanPopupLayoutMetrics
(JPopupMenu popupMenu) Cleans the layout metrics of the specified popup menu.static MenuUtilities.MenuLayoutInfo
getMenuLayoutInfo
(boolean forPainting, JMenuItem menuItem, Font acceleratorFont, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) Returns the layout info for the specified menu item.getMetrics
(JPopupMenu popupMenu, boolean forPainting) Returns the layout metrics of the specified popup menu.getPopupLayoutMetrics
(JMenuItem menuItem, boolean forPainting) Returns the layout metrics of the popup menu of the specified menu item.getPopupLayoutMetrics
(JPopupMenu popupMenu, boolean forPainting) static int
getPreferredWidth
(JMenuItem menuItem) Returns the preferred width of the specified menu item.static int
getTextOffset
(JComponent menuItem, Component menuItemParent) Returns the text offset of the specified menu item.private static String
layoutMenuItem
(JMenuItem menuItem, FontMetrics fm, String text, FontMetrics fmAccel, String acceleratorText, Icon icon, Icon checkIcon, Icon arrowIcon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewRect, Rectangle iconRect, Rectangle textRect, Rectangle acceleratorRect, Rectangle checkIconRect, Rectangle arrowIconRect, 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
(Graphics g, JMenuItem menuItem) Paints the background of the specified menu item.static void
paintMenuItem
(Graphics g, JMenuItem menuItem, Icon checkIcon, Icon arrowIcon) Paints the specified menu item.private static boolean
useCheckAndArrow
(JMenuItem menuItem)
-
Field Details
-
LAYOUT_METRICS
Key to store the layout metrics. The value should be an instance ofMenuUtilities.MenuLayoutMetrics
.- See Also:
-
GUTTER_X
Key to store the gutter X location. The value should be an instance ofInteger
.- See Also:
-
-
Constructor Details
-
MenuUtilities
public MenuUtilities()
-
-
Method Details
-
getMenuLayoutInfo
public static MenuUtilities.MenuLayoutInfo getMenuLayoutInfo(boolean forPainting, JMenuItem menuItem, Font acceleratorFont, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) Returns the layout info for the specified menu item.- Parameters:
menuItem
- Menu item.acceleratorFont
- Font for the accelerator text.checkIcon
- Check icon.arrowIcon
- Arrow icon.defaultTextIconGap
- Gap between the icon and the text.- Returns:
- Layout info for the specified menu item.
-
layoutMenuItem
private static String layoutMenuItem(JMenuItem menuItem, FontMetrics fm, String text, FontMetrics fmAccel, String acceleratorText, Icon icon, Icon checkIcon, Icon arrowIcon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewRect, Rectangle iconRect, Rectangle textRect, Rectangle acceleratorRect, Rectangle checkIconRect, Rectangle arrowIconRect, 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
-
paintMenuItem
Paints the specified menu item.- Parameters:
g
- Graphics context.menuItem
- Menu item.checkIcon
- Check icon.arrowIcon
- Arrow icon.
-
paintBackground
Paints the background of the specified menu item.- Parameters:
g
- Graphics context.menuItem
- Menu item.
-
getMetrics
Returns the layout metrics of the specified popup menu.- Parameters:
popupMenu
- Popup menu.- Returns:
- Layout metrics of the specified popup menu.
-
getPopupLayoutMetrics
public static MenuUtilities.MenuLayoutMetrics getPopupLayoutMetrics(JMenuItem menuItem, boolean forPainting) Returns the layout metrics of the popup menu of the specified menu item.- Parameters:
menuItem
- Menu item.- Returns:
- Layout metrics of the popup menu of the specified menu item.
-
getPopupLayoutMetrics
public static MenuUtilities.MenuLayoutMetrics getPopupLayoutMetrics(JPopupMenu popupMenu, boolean forPainting) -
cleanPopupLayoutMetrics
Cleans the layout metrics of the popup menu of the specified menu item.- Parameters:
menuItem
- Menu item.
-
cleanPopupLayoutMetrics
Cleans the layout metrics of the specified popup menu.- Parameters:
popupMenu
- Popup menu.
-
getPreferredWidth
Returns the preferred width of the specified menu item. The preferred width depends on the layout metrics of the entire popup menu of this menu item.- Parameters:
menuItem
- Menu item.- Returns:
- Preferred width of the specified menu item
-
getTextOffset
Returns the text offset of the specified menu item.- Parameters:
menuItem
- Menu item.menuItemParent
- Menu item parent.- Returns:
- Text offset of the specified menu item.
-