Class MenuUtilities
- java.lang.Object
-
- org.pushingpixels.radiance.theming.internal.utils.menu.MenuUtilities
-
public class MenuUtilities extends java.lang.ObjectMenu-related utilities.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMenuUtilities.MenuLayoutInfoLayout information for a single menu item.static classMenuUtilities.MenuLayoutMetricsLayout metrics for a single popup menu.static classMenuUtilities.MenuPropertyListenerListener to track changes in the menu items.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringGUTTER_XKey to store the gutter X location.private static java.lang.StringLAYOUT_METRICSKey to store the layout metrics.
-
Constructor Summary
Constructors Constructor Description MenuUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidcleanPopupLayoutMetrics(javax.swing.JMenuItem menuItem)Cleans the layout metrics of the popup menu of the specified menu item.static voidcleanPopupLayoutMetrics(javax.swing.JPopupMenu popupMenu)Cleans the layout metrics of the specified popup menu.static MenuUtilities.MenuLayoutInfogetMenuLayoutInfo(boolean forPainting, javax.swing.JMenuItem menuItem, java.awt.Font acceleratorFont, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon, int defaultTextIconGap)Returns the layout info for the specified menu item.static MenuUtilities.MenuLayoutMetricsgetMetrics(javax.swing.JPopupMenu popupMenu, boolean forPainting)Returns the layout metrics of the specified popup menu.static MenuUtilities.MenuLayoutMetricsgetPopupLayoutMetrics(javax.swing.JMenuItem menuItem, boolean forPainting)Returns the layout metrics of the popup menu of the specified menu item.static MenuUtilities.MenuLayoutMetricsgetPopupLayoutMetrics(javax.swing.JPopupMenu popupMenu, boolean forPainting)static intgetPreferredWidth(javax.swing.JMenuItem menuItem)Returns the preferred width of the specified menu item.static intgetTextOffset(javax.swing.JComponent menuItem, java.awt.Component menuItemParent)Returns the text offset of the specified menu item.private static java.lang.StringlayoutMenuItem(javax.swing.JMenuItem menuItem, 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 viewRect, java.awt.Rectangle iconRect, java.awt.Rectangle textRect, java.awt.Rectangle acceleratorRect, java.awt.Rectangle checkIconRect, java.awt.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 voidpaintBackground(java.awt.Graphics g, javax.swing.JMenuItem menuItem)Paints the background of the specified menu item.static voidpaintMenuItem(java.awt.Graphics g, javax.swing.JMenuItem menuItem, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon)Paints the specified menu item.private static booleanuseCheckAndArrow(javax.swing.JMenuItem menuItem)
-
-
-
Field Detail
-
LAYOUT_METRICS
private static final java.lang.String LAYOUT_METRICS
Key to store the layout metrics. The value should be an instance ofMenuUtilities.MenuLayoutMetrics.- See Also:
- Constant Field Values
-
GUTTER_X
private static final java.lang.String GUTTER_X
Key to store the gutter X location. The value should be an instance ofInteger.- See Also:
- Constant Field Values
-
-
Method Detail
-
getMenuLayoutInfo
public static MenuUtilities.MenuLayoutInfo getMenuLayoutInfo(boolean forPainting, javax.swing.JMenuItem menuItem, java.awt.Font acceleratorFont, javax.swing.Icon checkIcon, javax.swing.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 java.lang.String layoutMenuItem(javax.swing.JMenuItem menuItem, 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 viewRect, java.awt.Rectangle iconRect, java.awt.Rectangle textRect, java.awt.Rectangle acceleratorRect, java.awt.Rectangle checkIconRect, java.awt.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
private static boolean useCheckAndArrow(javax.swing.JMenuItem menuItem)
-
paintMenuItem
public static void paintMenuItem(java.awt.Graphics g, javax.swing.JMenuItem menuItem, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon)Paints the specified menu item.- Parameters:
g- Graphics context.menuItem- Menu item.checkIcon- Check icon.arrowIcon- Arrow icon.
-
paintBackground
private static void paintBackground(java.awt.Graphics g, javax.swing.JMenuItem menuItem)Paints the background of the specified menu item.- Parameters:
g- Graphics context.menuItem- Menu item.
-
getMetrics
public static MenuUtilities.MenuLayoutMetrics getMetrics(javax.swing.JPopupMenu popupMenu, boolean forPainting)
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(javax.swing.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(javax.swing.JPopupMenu popupMenu, boolean forPainting)
-
cleanPopupLayoutMetrics
private static void cleanPopupLayoutMetrics(javax.swing.JMenuItem menuItem)
Cleans the layout metrics of the popup menu of the specified menu item.- Parameters:
menuItem- Menu item.
-
cleanPopupLayoutMetrics
public static void cleanPopupLayoutMetrics(javax.swing.JPopupMenu popupMenu)
Cleans the layout metrics of the specified popup menu.- Parameters:
popupMenu- Popup menu.
-
getPreferredWidth
public static int getPreferredWidth(javax.swing.JMenuItem menuItem)
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
public static int getTextOffset(javax.swing.JComponent menuItem, java.awt.Component menuItemParent)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.
-
-