com.alee.laf.menu
Class WebMenuUI

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 javax.swing.plaf.basic.BasicMenuUI
                      extended by com.alee.laf.menu.WebMenuUI
All Implemented Interfaces:
BorderMethods, SwingMethods

public class WebMenuUI
extends javax.swing.plaf.basic.BasicMenuUI
implements BorderMethods

Custom UI for JMenu component.

Author:
Mikle Garin

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicMenuUI
javax.swing.plaf.basic.BasicMenuUI.ChangeHandler, javax.swing.plaf.basic.BasicMenuUI.MouseInputHandler
 
Field Summary
protected  boolean alignTextToMenuIcons
           
protected  int arrowGap
           
static javax.swing.ImageIcon arrowLeftIcon
           
static javax.swing.ImageIcon arrowRightIcon
          Used icons.
protected  MenuItemChangeListener buttonModelChangeListener
           
protected  java.awt.Color disabledFg
           
protected  int iconAlignment
           
protected  java.awt.Insets margin
           
protected  java.awt.event.MouseAdapter mouseAdapter
           
protected  boolean mouseover
          Runtime variables.
protected  Painter painter
           
protected  java.beans.PropertyChangeListener propertyChangeListener
          Menu listeners.
protected  int round
          Style settings.
protected  java.awt.Color selectedBottomBg
           
protected  java.awt.Color selectedTopBg
           
protected  int shadeWidth
           
protected  int sideSpacing
           
 
Fields inherited from class javax.swing.plaf.basic.BasicMenuUI
changeListener, menuListener
 
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
WebMenuUI()
           
 
Method Summary
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
          Returns an instance of the WebMenuUI for the specified component.
 int getArrowGap()
          Returns gap between menu icon/text and submenu arrow.
protected  javax.swing.Icon getArrowIcon(javax.swing.JMenu menu)
          Returns arrow icon displayed when sub-menu is available.
 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.
 int getRound()
          Returns top-level menu border rounding.
 java.awt.Color getSelectedBottomBg()
          Returns bottom background color for selected item.
 java.awt.Color getSelectedTopBg()
          Returns top background color for selected item.
 int getShadeWidth()
          Returns top-level menu shade width.
 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 decoration.
protected  void paintBackground(java.awt.Graphics2D g2d, javax.swing.JMenu menu, boolean selected, boolean ltr)
          Paints menu item background.
protected  void paintIcon(java.awt.Graphics2D g2d, javax.swing.JMenu menu, 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.JMenu menu, java.awt.FontMetrics fm, int x, int y, int w, int h, boolean selected, boolean ltr)
          Paints menu item text.
 void setAlignTextToMenuIcons(boolean align)
          Sets whether should align all item texts to a single vertical line within single popup menu or not.
 void setArrowGap(int gap)
          Sets gap between menu icon/text and submenu arrow.
 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 setRound(int round)
          Sets top-level menu border rounding.
 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 setShadeWidth(int shadeWidth)
          Sets top-level menu shade width.
 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.BasicMenuUI
createChangeListener, createMenuDragMouseListener, createMenuKeyListener, createMenuListener, createMouseInputListener, createPropertyChangeListener, getMaximumSize, getPropertyPrefix, installDefaults, installKeyboardActions, installListeners, setupPostTimer, uninstallDefaults, uninstallKeyboardActions, uninstallListeners
 
Methods inherited from class javax.swing.plaf.basic.BasicMenuItemUI
doClick, getMinimumSize, getPath, getPreferredMenuItemSize, installComponents, paintBackground, paintMenuItem, paintText, uninstallComponents, 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

arrowRightIcon

public static final javax.swing.ImageIcon arrowRightIcon
Used icons.


arrowLeftIcon

public static final javax.swing.ImageIcon arrowLeftIcon

round

protected int round
Style settings.


shadeWidth

protected int shadeWidth

margin

protected java.awt.Insets margin

sideSpacing

protected int sideSpacing

disabledFg

protected java.awt.Color disabledFg

selectedTopBg

protected java.awt.Color selectedTopBg

selectedBottomBg

protected java.awt.Color selectedBottomBg

arrowGap

protected int arrowGap

alignTextToMenuIcons

protected boolean alignTextToMenuIcons

iconAlignment

protected int iconAlignment

painter

protected Painter painter

propertyChangeListener

protected java.beans.PropertyChangeListener propertyChangeListener
Menu listeners.


mouseAdapter

protected java.awt.event.MouseAdapter mouseAdapter

buttonModelChangeListener

protected MenuItemChangeListener buttonModelChangeListener

mouseover

protected boolean mouseover
Runtime variables.

Constructor Detail

WebMenuUI

public WebMenuUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
Returns an instance of the WebMenuUI 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 WebMenuUI

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

getRound

public int getRound()
Returns top-level menu border rounding.

Returns:
top-level menu border rounding

setRound

public void setRound(int round)
Sets top-level menu border rounding.

Parameters:
round - new top-level menu border rounding

getShadeWidth

public int getShadeWidth()
Returns top-level menu shade width.

Returns:
top-level menu shade width

setShadeWidth

public void setShadeWidth(int shadeWidth)
Sets top-level menu shade width.

Parameters:
shadeWidth - new top-level menu shade width

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

getArrowGap

public int getArrowGap()
Returns gap between menu icon/text and submenu arrow.

Returns:
gap between menu icon/text and submenu arrow

setArrowGap

public void setArrowGap(int gap)
Sets gap between menu icon/text and submenu arrow.

Parameters:
gap - new gap between menu icon/text and submenu arrow

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 decoration.

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

paintBackground

protected void paintBackground(java.awt.Graphics2D g2d,
                               javax.swing.JMenu menu,
                               boolean selected,
                               boolean ltr)
Paints menu item background.

Parameters:
g2d - graphics context
menu - menu
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.JMenu menu,
                         int x,
                         int y,
                         int w,
                         int h,
                         boolean selected,
                         boolean ltr)
Paints menu item icon.

Parameters:
g2d - graphics context
menu - menu
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.JMenu menu,
                         java.awt.FontMetrics fm,
                         int x,
                         int y,
                         int w,
                         int h,
                         boolean selected,
                         boolean ltr)
Paints menu item text.

Parameters:
g2d - graphics context
menu - menu
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

getArrowIcon

protected javax.swing.Icon getArrowIcon(javax.swing.JMenu menu)
Returns arrow icon displayed when sub-menu is available.

Returns:
arrow icon displayed when sub-menu is available

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