com.alee.laf.menu
Class WebMenuItemUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.ButtonUI
          extended by javax.swing.plaf.MenuItemUI
              extended by javax.swing.plaf.basic.BasicMenuItemUI
                  extended by com.alee.laf.menu.WebMenuItemUI
All Implemented Interfaces:
BorderMethods, SwingMethods
Direct Known Subclasses:
WebCheckBoxMenuItemUI, WebRadioButtonMenuItemUI

public class WebMenuItemUI
extends javax.swing.plaf.basic.BasicMenuItemUI
implements BorderMethods

Custom UI for JMenuItem component.

Author:
Mikle Garin

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicMenuItemUI
javax.swing.plaf.basic.BasicMenuItemUI.MouseInputHandler
 
Field Summary
protected  java.awt.Color acceleratorBg
           
protected  java.awt.Color acceleratorDisabledFg
           
protected  java.awt.Color acceleratorFg
           
protected  int acceleratorGap
           
protected  boolean alignTextToMenuIcons
           
protected  MenuItemChangeListener buttonModelChangeListener
           
protected  java.awt.Color disabledFg
           
protected  int iconAlignment
           
protected  java.awt.Insets margin
          Style settings.
protected  Painter painter
           
protected  java.beans.PropertyChangeListener propertyChangeListener
          Menu item listeners.
protected  java.awt.Color selectedBottomBg
           
protected  java.awt.Color selectedTopBg
           
protected  int sideSpacing
           
 
Fields inherited from class javax.swing.plaf.basic.BasicMenuItemUI
acceleratorFont, acceleratorForeground, acceleratorSelectionForeground, arrowIcon, checkIcon, defaultTextIconGap, disabledForeground, menuDragMouseListener, menuItem, menuKeyListener, mouseInputListener, oldBorderPainted, selectionBackground, selectionForeground
 
Constructor Summary
WebMenuItemUI()
           
 
Method Summary
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
          Returns an instance of the WebMenuItemUI for the specified component.
 java.awt.Color getAcceleratorBg()
          Returns accelerator text background.
 java.awt.Color getAcceleratorDisabledFg()
          Returns disabled accelerator foreground.
 java.awt.Color getAcceleratorFg()
          Returns accelerator foreground.
 int getAcceleratorGap()
          Returns gap between menu item icon/text and accelerator.
 java.awt.Color getDisabledFg()
          Returns disabled menu item foreground.
 int getIconAlignment()
          Returns icon alignment.
 java.awt.Insets getMargin()
          Returns menu item margin.
 java.awt.Paint getNorthCornerFill()
          Returns paint used to fill north popup menu corner when this component is first in the menu.
 Painter getPainter()
          Returns menu item painter.
 java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
          Returns menu item preferred size.
 java.awt.Color getSelectedBottomBg()
          Returns bottom background color for selected item.
 java.awt.Color getSelectedTopBg()
          Returns top background color for selected item.
 int getSideSpacing()
          Returns spacing between menu item content and its left/right borders.
 java.awt.Paint getSouthCornerFill()
          Returns paint used to fill south popup menu corner when this component is last in the menu.
 void installUI(javax.swing.JComponent c)
          Installs UI in the specified component.
 boolean isAlignTextToMenuIcons()
          Returns whether should align all item texts to a single vertical line within single popup menu or not.
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
          Paints menu item decoration.
protected  void paintAcceleratorText(java.awt.Graphics2D g2d, javax.swing.JMenuItem menuItem, java.lang.String accText, java.awt.FontMetrics fm, int x, int y, int w, int h, boolean selected, boolean ltr)
          Paints menu item accelerator text.
protected  void paintBackground(java.awt.Graphics2D g2d, javax.swing.JMenuItem menuItem, int x, int y, int w, int h, boolean selected, boolean ltr)
          Paints menu item background.
protected  void paintIcon(java.awt.Graphics2D g2d, javax.swing.JMenuItem menuItem, int x, int y, int w, int h, boolean selected, boolean ltr)
          Paints menu item icon.
protected  void paintText(java.awt.Graphics2D g2d, javax.swing.JMenuItem menuItem, java.awt.FontMetrics fm, int x, int y, int w, int h, boolean selected, boolean ltr)
          Paints menu item text.
 void setAcceleratorBg(java.awt.Color background)
          Sets accelerator text background.
 void setAcceleratorDisabledFg(java.awt.Color foreground)
          Sets disabled accelerator foreground.
 void setAcceleratorFg(java.awt.Color foreground)
          Sets accelerator foreground.
 void setAcceleratorGap(int gap)
          Sets gap between menu icon/text and accelerator.
 void setAlignTextToMenuIcons(boolean align)
          Sets whether should align all item texts to a single vertical line within single popup menu or not.
 void setDisabledFg(java.awt.Color foreground)
          Sets disabled menu item foreground.
 void setIconAlignment(int alignment)
          Sets icon alignment
 void setMargin(java.awt.Insets margin)
          Sets menu item margin.
 void setPainter(Painter painter)
          Sets menu item painter.
 void setSelectedBottomBg(java.awt.Color background)
          Sets bottom background color for selected item.
 void setSelectedTopBg(java.awt.Color background)
          Sets top background color for selected item.
 void setSideSpacing(int sideSpacing)
          Sets spacing between menu item content and its left/right borders
 void uninstallUI(javax.swing.JComponent c)
          Uninstalls UI from the specified component.
 void updateBorder()
          Updates custom WebLaF border.
 
Methods inherited from class javax.swing.plaf.basic.BasicMenuItemUI
createMenuDragMouseListener, createMenuKeyListener, createMouseInputListener, createPropertyChangeListener, doClick, getMaximumSize, getMinimumSize, getPath, getPreferredMenuItemSize, getPropertyPrefix, installComponents, installDefaults, installKeyboardActions, installListeners, paintBackground, paintMenuItem, paintText, uninstallComponents, uninstallDefaults, uninstallKeyboardActions, uninstallListeners, update
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

margin

protected java.awt.Insets margin
Style settings.


sideSpacing

protected int sideSpacing

disabledFg

protected java.awt.Color disabledFg

selectedTopBg

protected java.awt.Color selectedTopBg

selectedBottomBg

protected java.awt.Color selectedBottomBg

acceleratorBg

protected java.awt.Color acceleratorBg

acceleratorFg

protected java.awt.Color acceleratorFg

acceleratorDisabledFg

protected java.awt.Color acceleratorDisabledFg

acceleratorGap

protected int acceleratorGap

alignTextToMenuIcons

protected boolean alignTextToMenuIcons

iconAlignment

protected int iconAlignment

painter

protected Painter painter

propertyChangeListener

protected java.beans.PropertyChangeListener propertyChangeListener
Menu item listeners.


buttonModelChangeListener

protected MenuItemChangeListener buttonModelChangeListener
Constructor Detail

WebMenuItemUI

public WebMenuItemUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
Returns an instance of the WebMenuItemUI for the specified component. This tricky method is used by UIManager to create component UIs when needed.

Parameters:
c - component that will use UI instance
Returns:
instance of the WebMenuItemUI

installUI

public void installUI(javax.swing.JComponent c)
Installs UI in the specified component.

Overrides:
installUI in class javax.swing.plaf.basic.BasicMenuItemUI
Parameters:
c - component for this UI

uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Uninstalls UI from the specified component.

Overrides:
uninstallUI in class javax.swing.plaf.basic.BasicMenuItemUI
Parameters:
c - component with this UI

updateBorder

public void updateBorder()
Updates custom WebLaF border.

Specified by:
updateBorder in interface BorderMethods

getMargin

public java.awt.Insets getMargin()
Returns menu item margin.

Returns:
menu item margin

setMargin

public void setMargin(java.awt.Insets margin)
Sets menu item margin.

Parameters:
margin - new menu item margin

getSideSpacing

public int getSideSpacing()
Returns spacing between menu item content and its left/right borders.

Returns:
spacing between menu item content and its left/right borders

setSideSpacing

public void setSideSpacing(int sideSpacing)
Sets spacing between menu item content and its left/right borders

Parameters:
sideSpacing - spacing between menu item content and its left/right borders

getDisabledFg

public java.awt.Color getDisabledFg()
Returns disabled menu item foreground.

Returns:
disabled menu item foreground

setDisabledFg

public void setDisabledFg(java.awt.Color foreground)
Sets disabled menu item foreground.

Parameters:
foreground - new disabled menu item foreground

getSelectedTopBg

public java.awt.Color getSelectedTopBg()
Returns top background color for selected item.

Returns:
top background color for selected item

setSelectedTopBg

public void setSelectedTopBg(java.awt.Color background)
Sets top background color for selected item.

Parameters:
background - new top background color for selected item

getSelectedBottomBg

public java.awt.Color getSelectedBottomBg()
Returns bottom background color for selected item.

Returns:
bottom background color for selected item

setSelectedBottomBg

public void setSelectedBottomBg(java.awt.Color background)
Sets bottom background color for selected item.

Parameters:
background - new bottom background color for selected item

getAcceleratorBg

public java.awt.Color getAcceleratorBg()
Returns accelerator text background.

Returns:
accelerator text background

setAcceleratorBg

public void setAcceleratorBg(java.awt.Color background)
Sets accelerator text background.

Parameters:
background - new accelerator text background

getAcceleratorFg

public java.awt.Color getAcceleratorFg()
Returns accelerator foreground.

Returns:
accelerator foreground

setAcceleratorFg

public void setAcceleratorFg(java.awt.Color foreground)
Sets accelerator foreground.

Parameters:
foreground - new accelerator foreground

getAcceleratorDisabledFg

public java.awt.Color getAcceleratorDisabledFg()
Returns disabled accelerator foreground.

Returns:
disabled accelerator foreground

setAcceleratorDisabledFg

public void setAcceleratorDisabledFg(java.awt.Color foreground)
Sets disabled accelerator foreground.

Parameters:
foreground - new disabled accelerator foreground

getAcceleratorGap

public int getAcceleratorGap()
Returns gap between menu item icon/text and accelerator.

Returns:
gap between menu item icon/text and accelerator

setAcceleratorGap

public void setAcceleratorGap(int gap)
Sets gap between menu icon/text and accelerator.

Parameters:
gap - new gap between menu icon/text and accelerator

isAlignTextToMenuIcons

public boolean isAlignTextToMenuIcons()
Returns whether should align all item texts to a single vertical line within single popup menu or not.

Returns:
true if should align all item texts to a single vertical line within single popup menu, false otherwise

setAlignTextToMenuIcons

public void setAlignTextToMenuIcons(boolean align)
Sets whether should align all item texts to a single vertical line within single popup menu or not.

Parameters:
align - whether should align all item texts to a single vertical line within single popup menu or not

getIconAlignment

public int getIconAlignment()
Returns icon alignment.

Returns:
icon alignment

setIconAlignment

public void setIconAlignment(int alignment)
Sets icon alignment

Parameters:
alignment - new icon alignment

getPainter

public Painter getPainter()
Returns menu item painter.

Returns:
menu item painter

setPainter

public void setPainter(Painter painter)
Sets menu item painter.

Parameters:
painter - new menu item painter

getNorthCornerFill

public java.awt.Paint getNorthCornerFill()
Returns paint used to fill north popup menu corner when this component is first in the menu.

Returns:
paint used to fill north popup menu corner when this component is first in the menu

getSouthCornerFill

public java.awt.Paint getSouthCornerFill()
Returns paint used to fill south popup menu corner when this component is last in the menu.

Returns:
paint used to fill south popup menu corner when this component is last in the menu

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Paints menu item decoration.

Overrides:
paint in class javax.swing.plaf.basic.BasicMenuItemUI
Parameters:
g - graphics context
c - menu item component

paintBackground

protected void paintBackground(java.awt.Graphics2D g2d,
                               javax.swing.JMenuItem menuItem,
                               int x,
                               int y,
                               int w,
                               int h,
                               boolean selected,
                               boolean ltr)
Paints menu item background.

Parameters:
g2d - graphics context
menuItem - menu item
x - icon placeholder X coordinate
y - icon placeholder Y coordinate
w - icon placeholder width
h - icon placeholder height
selected - whether menu item is selected or not
ltr - whether menu item has left-to-right orientation or not

paintIcon

protected void paintIcon(java.awt.Graphics2D g2d,
                         javax.swing.JMenuItem menuItem,
                         int x,
                         int y,
                         int w,
                         int h,
                         boolean selected,
                         boolean ltr)
Paints menu item icon.

Parameters:
g2d - graphics context
menuItem - menu item
x - icon placeholder X coordinate
y - icon placeholder Y coordinate
w - icon placeholder width
h - icon placeholder height
selected - whether menu item is selected or not
ltr - whether menu item has left-to-right orientation or not

paintText

protected void paintText(java.awt.Graphics2D g2d,
                         javax.swing.JMenuItem menuItem,
                         java.awt.FontMetrics fm,
                         int x,
                         int y,
                         int w,
                         int h,
                         boolean selected,
                         boolean ltr)
Paints menu item text.

Parameters:
g2d - graphics context
menuItem - menu item
fm - text font metrics
x - text X coordinate
y - text rectangle Y coordinate
w - text width
h - text rectangle height
selected - whether menu item is selected or not
ltr - whether menu item has left-to-right orientation or not

paintAcceleratorText

protected void paintAcceleratorText(java.awt.Graphics2D g2d,
                                    javax.swing.JMenuItem menuItem,
                                    java.lang.String accText,
                                    java.awt.FontMetrics fm,
                                    int x,
                                    int y,
                                    int w,
                                    int h,
                                    boolean selected,
                                    boolean ltr)
Paints menu item accelerator text.

Parameters:
g2d - graphics context
menuItem - menu item
accText - accelerator text
fm - accelerator text font metrics
x - accelerator text X coordinate
y - accelerator text rectangle Y coordinate
w - accelerator text width
h - accelerator text rectangle height
selected - whether menu item is selected or not
ltr - whether menu item has left-to-right orientation or not

getPreferredSize

public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
Returns menu item preferred size.

Overrides:
getPreferredSize in class javax.swing.plaf.basic.BasicMenuItemUI
Parameters:
c - menu item component
Returns:
menu item preferred size