com.alee.laf.checkbox
Class WebCheckBoxUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.ButtonUI
          extended by javax.swing.plaf.basic.BasicButtonUI
              extended by javax.swing.plaf.basic.BasicToggleButtonUI
                  extended by javax.swing.plaf.basic.BasicRadioButtonUI
                      extended by javax.swing.plaf.basic.BasicCheckBoxUI
                          extended by com.alee.laf.checkbox.WebCheckBoxUI
All Implemented Interfaces:
ShapeProvider
Direct Known Subclasses:
WebTristateCheckBoxUI

public class WebCheckBoxUI
extends javax.swing.plaf.basic.BasicCheckBoxUI
implements ShapeProvider

Custom UI for JCheckBox component.

Author:
Mikle Garin

Nested Class Summary
protected  class WebCheckBoxUI.CheckBoxIcon
          Custom icon for tristate checkbox.
 
Field Summary
protected  boolean animated
           
protected  int bgDarkness
          Icon background painting variables.
protected  WebTimer bgTimer
           
protected  java.awt.Color borderColor
          Style settings.
protected  java.awt.Stroke borderStroke
           
protected  java.awt.Color bottomBgColor
           
protected  java.awt.Color bottomSelectedBgColor
           
protected  javax.swing.JCheckBox checkBox
          Checkbox to which this UI is applied.
protected  CheckIcon checkIcon
          Check icon painting variables.
protected  boolean checking
           
protected  WebTimer checkTimer
           
protected  java.awt.Color darkBorderColor
           
protected  java.awt.Color disabledBorderColor
           
protected  java.beans.PropertyChangeListener enabledStateListener
          Checkbox listeners.
protected static float[] fractions
          Background gradient fractions.
protected  int iconHeight
           
protected  java.awt.Rectangle iconRect
          Last displayed icon rect.
protected  int iconWidth
           
protected  java.awt.event.ItemListener itemListener
           
protected  java.awt.Insets margin
           
static int MAX_DARKNESS
          Maximum border/background darkness.
protected  java.beans.PropertyChangeListener modelChangeListener
           
protected  java.awt.event.MouseAdapter mouseAdapter
           
protected  boolean rollover
           
protected  boolean rolloverDarkBorderOnly
           
protected  int round
           
protected  int shadeWidth
           
protected  java.awt.Color topBgColor
           
protected  java.awt.Color topSelectedBgColor
           
static long UPDATE_DELAY
          Animation updates delay in milliseconds.
 
Fields inherited from class javax.swing.plaf.basic.BasicRadioButtonUI
icon
 
Fields inherited from class javax.swing.plaf.basic.BasicButtonUI
defaultTextIconGap, defaultTextShiftOffset
 
Constructor Summary
WebCheckBoxUI()
           
 
Method Summary
protected  CheckIcon createCheckStateIcon()
          Creates check state icon.
protected  javax.swing.Icon createIcon()
          Creates and returns checkbox icon.
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
          Returns an instance of the WebCheckBoxUI for the specified component.
protected  java.awt.Color[] getBgColors()
          Returns background colors.
protected  float getBgDarkness()
          Returns background darkness.
 java.awt.Color getBorderColor()
          Returns border color.
 java.awt.Color getBottomBgColor()
          Returns bottom background color.
 java.awt.Color getBottomSelectedBgColor()
          Returns bottom selected background color.
 java.awt.Color getDarkBorderColor()
          Returns dark border color.
 java.awt.Color getDisabledBorderColor()
          Returns disabled border color.
 int getIconHeight()
          Returns icon height.
 java.awt.Rectangle getIconRect()
          Returns icon bounds.
 int getIconWidth()
          Returns icon width.
 java.awt.Insets getMargin()
          Returns component margin.
 int getRound()
          Returns border rounding.
 int getShadeWidth()
          Returns border shade width.
 java.awt.Color getTopBgColor()
          Returns top background color.
 java.awt.Color getTopSelectedBgColor()
          Returns top selected background color.
protected  void installEnabledStateListeners()
          Installs enabled state listeners.
protected  void installRolloverListeners()
          Installs rollover listeners.
protected  void installStateChangeListeners()
          Installs state change listeners.
 void installUI(javax.swing.JComponent c)
          Installs UI in the specified component.
 boolean isAnimated()
          Returns whether checkbox is animated or not.
protected  boolean isAnimatedByDefault()
          Returns whether checkbox should be animated by default or not.
protected  boolean isAnimationAllowed()
          Returns whether checkbox can be animated or not.
 boolean isRolloverDarkBorderOnly()
          Returns whether should draw dark border only on rollover or not.
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
          Paints checkbox.
protected  void paintCheckIcon(java.awt.Graphics2D g2d, int x, int y)
          Paints checkbox check icon.
protected  void paintIcon(java.awt.Graphics2D g2d, int x, int y)
          Paints checkbox icon.
protected  void paintIconBackground(java.awt.Graphics2D g2d, int x, int y)
          Paints checkbox icon background.
protected  void paintText(java.awt.Graphics g, javax.swing.AbstractButton b, java.awt.Rectangle textRect, java.lang.String text)
          Paints checkbox text.
protected  void performStateChanged()
          Performs visual state change.
 java.awt.Shape provideShape()
          Returns component shape.
 void setAnimated(boolean animated)
          Sets whether checkbox is animated or not.
 void setBorderColor(java.awt.Color borderColor)
          Sets border color.
 void setBottomBgColor(java.awt.Color bottomBgColor)
          Sets bottom background color.
 void setBottomSelectedBgColor(java.awt.Color bottomSelectedBgColor)
          Sets bottom selected background color.
 void setDarkBorderColor(java.awt.Color darkBorderColor)
          Sets dark border color.
 void setDisabledBorderColor(java.awt.Color disabledBorderColor)
          Sets disabled border color.
 void setIconHeight(int iconHeight)
          Sets icon height.
 void setIconWidth(int iconWidth)
          Sets icon width.
 void setMargin(java.awt.Insets margin)
          Sets component margin.
 void setRolloverDarkBorderOnly(boolean rolloverDarkBorderOnly)
          Sets whether should draw dark border only on rollover or not.
 void setRound(int round)
          Sets border rounding.
 void setShadeWidth(int shadeWidth)
          Sets border shade width.
 void setTopBgColor(java.awt.Color topBgColor)
          Sets top background color.
 void setTopSelectedBgColor(java.awt.Color topSelectedBgColor)
          Sets top selected background color.
protected  void uninstallEnabledStateListeners()
          Uninstalls enabled state listeners.
protected  void uninstallRolloverListeners()
          Uninstalls rollover listeners.
protected  void uninstallStateChangeListeners()
          Uninstalls state change listeners.
 void uninstallUI(javax.swing.JComponent c)
          Uninstalls UI from the specified component.
protected  void updateBorder()
          Updates custom UI border.
 
Methods inherited from class javax.swing.plaf.basic.BasicCheckBoxUI
getPropertyPrefix
 
Methods inherited from class javax.swing.plaf.basic.BasicRadioButtonUI
getDefaultIcon, getPreferredSize, installDefaults, paintFocus, uninstallDefaults
 
Methods inherited from class javax.swing.plaf.basic.BasicToggleButtonUI
getTextShiftOffset, paintIcon
 
Methods inherited from class javax.swing.plaf.basic.BasicButtonUI
clearTextShiftOffset, createButtonListener, getBaseline, getBaselineResizeBehavior, getDefaultTextIconGap, getMaximumSize, getMinimumSize, installKeyboardActions, installListeners, paintButtonPressed, paintFocus, paintIcon, paintText, setTextShiftOffset, uninstallKeyboardActions, uninstallListeners
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DARKNESS

public static final int MAX_DARKNESS
Maximum border/background darkness.

See Also:
Constant Field Values

UPDATE_DELAY

public static final long UPDATE_DELAY
Animation updates delay in milliseconds.

See Also:
Constant Field Values

fractions

protected static final float[] fractions
Background gradient fractions.


borderColor

protected java.awt.Color borderColor
Style settings.


darkBorderColor

protected java.awt.Color darkBorderColor

disabledBorderColor

protected java.awt.Color disabledBorderColor

topBgColor

protected java.awt.Color topBgColor

bottomBgColor

protected java.awt.Color bottomBgColor

topSelectedBgColor

protected java.awt.Color topSelectedBgColor

bottomSelectedBgColor

protected java.awt.Color bottomSelectedBgColor

round

protected int round

shadeWidth

protected int shadeWidth

margin

protected java.awt.Insets margin

animated

protected boolean animated

rolloverDarkBorderOnly

protected boolean rolloverDarkBorderOnly

borderStroke

protected java.awt.Stroke borderStroke

iconWidth

protected int iconWidth

iconHeight

protected int iconHeight

bgDarkness

protected int bgDarkness
Icon background painting variables.


rollover

protected boolean rollover

bgTimer

protected WebTimer bgTimer

checkIcon

protected CheckIcon checkIcon
Check icon painting variables.


checking

protected boolean checking

checkTimer

protected WebTimer checkTimer

iconRect

protected java.awt.Rectangle iconRect
Last displayed icon rect.


checkBox

protected javax.swing.JCheckBox checkBox
Checkbox to which this UI is applied.


enabledStateListener

protected java.beans.PropertyChangeListener enabledStateListener
Checkbox listeners.


modelChangeListener

protected java.beans.PropertyChangeListener modelChangeListener

mouseAdapter

protected java.awt.event.MouseAdapter mouseAdapter

itemListener

protected java.awt.event.ItemListener itemListener
Constructor Detail

WebCheckBoxUI

public WebCheckBoxUI()
Method Detail

createUI

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

installUI

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

Overrides:
installUI in class javax.swing.plaf.basic.BasicButtonUI
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.BasicButtonUI
Parameters:
c - component with this UI

createCheckStateIcon

protected CheckIcon createCheckStateIcon()
Creates check state icon.

Returns:
check state icon

installEnabledStateListeners

protected void installEnabledStateListeners()
Installs enabled state listeners.


uninstallEnabledStateListeners

protected void uninstallEnabledStateListeners()
Uninstalls enabled state listeners.


installRolloverListeners

protected void installRolloverListeners()
Installs rollover listeners.


uninstallRolloverListeners

protected void uninstallRolloverListeners()
Uninstalls rollover listeners.


installStateChangeListeners

protected void installStateChangeListeners()
Installs state change listeners.


performStateChanged

protected void performStateChanged()
Performs visual state change. In case animation is possible and enabled state change will be animated.


uninstallStateChangeListeners

protected void uninstallStateChangeListeners()
Uninstalls state change listeners.


provideShape

public java.awt.Shape provideShape()
Returns component shape.

Specified by:
provideShape in interface ShapeProvider
Returns:
component shape

isAnimatedByDefault

protected boolean isAnimatedByDefault()
Returns whether checkbox should be animated by default or not.

Returns:
true if checkbox should be animated by default, false otherwise

isAnimationAllowed

protected boolean isAnimationAllowed()
Returns whether checkbox can be animated or not.

Returns:
true if checkbox can be animated, false otherwise

updateBorder

protected void updateBorder()
Updates custom UI border.


getMargin

public java.awt.Insets getMargin()
Returns component margin.

Returns:
component margin

setMargin

public void setMargin(java.awt.Insets margin)
Sets component margin.

Parameters:
margin - component margin

isAnimated

public boolean isAnimated()
Returns whether checkbox is animated or not.

Returns:
true if checkbox is animated, false otherwise

setAnimated

public void setAnimated(boolean animated)
Sets whether checkbox is animated or not.

Parameters:
animated - whether checkbox is animated or not

isRolloverDarkBorderOnly

public boolean isRolloverDarkBorderOnly()
Returns whether should draw dark border only on rollover or not.

Returns:
true if should draw dark border only on rollover, false otherwise

setRolloverDarkBorderOnly

public void setRolloverDarkBorderOnly(boolean rolloverDarkBorderOnly)
Sets whether should draw dark border only on rollover or not.

Parameters:
rolloverDarkBorderOnly - whether should draw dark border only on rollover or not

getBorderColor

public java.awt.Color getBorderColor()
Returns border color.

Returns:
border color

setBorderColor

public void setBorderColor(java.awt.Color borderColor)
Sets border color.

Parameters:
borderColor - border color

getDarkBorderColor

public java.awt.Color getDarkBorderColor()
Returns dark border color.

Returns:
dark border color

setDarkBorderColor

public void setDarkBorderColor(java.awt.Color darkBorderColor)
Sets dark border color.

Parameters:
darkBorderColor - dark border color

getDisabledBorderColor

public java.awt.Color getDisabledBorderColor()
Returns disabled border color.

Returns:
disabled border color

setDisabledBorderColor

public void setDisabledBorderColor(java.awt.Color disabledBorderColor)
Sets disabled border color.

Parameters:
disabledBorderColor - disabled border color

getTopBgColor

public java.awt.Color getTopBgColor()
Returns top background color.

Returns:
top background color

setTopBgColor

public void setTopBgColor(java.awt.Color topBgColor)
Sets top background color.

Parameters:
topBgColor - top background color

getBottomBgColor

public java.awt.Color getBottomBgColor()
Returns bottom background color.

Returns:
bottom background color

setBottomBgColor

public void setBottomBgColor(java.awt.Color bottomBgColor)
Sets bottom background color.

Parameters:
bottomBgColor - bottom background color

getTopSelectedBgColor

public java.awt.Color getTopSelectedBgColor()
Returns top selected background color.

Returns:
top selected background color

setTopSelectedBgColor

public void setTopSelectedBgColor(java.awt.Color topSelectedBgColor)
Sets top selected background color.

Parameters:
topSelectedBgColor - top selected background color

getBottomSelectedBgColor

public java.awt.Color getBottomSelectedBgColor()
Returns bottom selected background color.

Returns:
bottom selected background color

setBottomSelectedBgColor

public void setBottomSelectedBgColor(java.awt.Color bottomSelectedBgColor)
Sets bottom selected background color.

Parameters:
bottomSelectedBgColor - bottom selected background color

getRound

public int getRound()
Returns border rounding.

Returns:
border rounding

setRound

public void setRound(int round)
Sets border rounding.

Parameters:
round - border rounding

getShadeWidth

public int getShadeWidth()
Returns border shade width.

Returns:
border shade width

setShadeWidth

public void setShadeWidth(int shadeWidth)
Sets border shade width.

Parameters:
shadeWidth - border shade width

getIconWidth

public int getIconWidth()
Returns icon width.

Returns:
icon width

setIconWidth

public void setIconWidth(int iconWidth)
Sets icon width.

Parameters:
iconWidth - icon width

getIconHeight

public int getIconHeight()
Returns icon height.

Returns:
icon height

setIconHeight

public void setIconHeight(int iconHeight)
Sets icon height.

Parameters:
iconHeight - icon height

createIcon

protected javax.swing.Icon createIcon()
Creates and returns checkbox icon.

Returns:
checkbox icon

getBgColors

protected java.awt.Color[] getBgColors()
Returns background colors.

Returns:
background colors

getBgDarkness

protected float getBgDarkness()
Returns background darkness.

Returns:
background darkness

getIconRect

public java.awt.Rectangle getIconRect()
Returns icon bounds.

Returns:
icon bounds

paint

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

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

paintIcon

protected void paintIcon(java.awt.Graphics2D g2d,
                         int x,
                         int y)
Paints checkbox icon.

Parameters:
g2d - 2D graphics context
x - icon location X coordinate
y - icon location Y coordinate

paintIconBackground

protected void paintIconBackground(java.awt.Graphics2D g2d,
                                   int x,
                                   int y)
Paints checkbox icon background.

Parameters:
g2d - 2D graphics context
x - icon location X coordinate
y - icon location Y coordinate

paintCheckIcon

protected void paintCheckIcon(java.awt.Graphics2D g2d,
                              int x,
                              int y)
Paints checkbox check icon.

Parameters:
g2d - 2D graphics context
x - icon location X coordinate
y - icon location Y coordinate

paintText

protected void paintText(java.awt.Graphics g,
                         javax.swing.AbstractButton b,
                         java.awt.Rectangle textRect,
                         java.lang.String text)
Paints checkbox text.

Overrides:
paintText in class javax.swing.plaf.basic.BasicButtonUI
Parameters:
g - graphics context
b - abstract button
textRect - text bounds
text - text to be painted