com.alee.extended.painter
Class NinePatchStatePainter<E extends javax.swing.JComponent>

java.lang.Object
  extended by com.alee.extended.painter.AbstractPainter<E>
      extended by com.alee.extended.painter.NinePatchStatePainter<E>
Type Parameters:
E - component type
All Implemented Interfaces:
Painter<E>

public class NinePatchStatePainter<E extends javax.swing.JComponent>
extends AbstractPainter<E>

This painter class allows you to specify multiply 9-patch images for different component states. By default there is support for some standard Swing component states like buttons.

Author:
Mikle Garin
See Also:
ComponentState, NinePatchIcon, NinePatchIconPainter, AbstractPainter, Painter

Field Summary
protected  java.util.Map<java.lang.String,NinePatchIcon> stateIcons
          Map containing separate 9-patch icons for different component states.
 
Fields inherited from class com.alee.extended.painter.AbstractPainter
listeners, margin, opaque, preferredSize
 
Constructor Summary
NinePatchStatePainter()
          Constructs new 9-patch state painter with empty states.
NinePatchStatePainter(java.util.Map<java.lang.String,NinePatchIcon> stateIcons)
          Constructs new 9-patch state painter with specified states map.
 
Method Summary
 void addStateIcon(java.lang.String state, NinePatchIcon ninePatchIcon)
          Adds painter state.
protected  NinePatchIcon getButtonBackground(javax.swing.AbstractButton button)
          Returns current state icon for the specified button.
protected  NinePatchIcon getComponentBackground(E component)
          Returns current state icon for the specified component.
 NinePatchIcon getExactStateIcon(java.lang.String state)
          Returns exact state icon or null if it is not specified.
 java.awt.Insets getMargin(E c)
          Returns margin required for visual data provided by this painter.
 java.awt.Dimension getPreferredSize(E c)
          Returns preferred size required for proper painting of visual data provided by this painter.
 NinePatchIcon getStateIcon(java.lang.String state)
          Returns state icon or possible replacement for it.
 java.util.Map<java.lang.String,NinePatchIcon> getStateIcons()
          Returns states map.
protected  NinePatchIcon getToolBarBackground(javax.swing.JToolBar toolbar)
          Returns current state icon for the specified toolbar.
 boolean hasStateIcons()
          Returns whether atleast one state icon is available or not.
protected  boolean isFocused(E component)
          Returns whether component is in focused state or not.
 void paint(java.awt.Graphics2D g2d, java.awt.Rectangle bounds, E c)
          Paints visual data onto the component graphics.
 void removeStateIcon(java.lang.String state)
          Removes painter state.
 void setStateIcons(java.util.Map<java.lang.String,NinePatchIcon> stateIcons)
          Sets states map.
 
Methods inherited from class com.alee.extended.painter.AbstractPainter
addPainterListener, install, isOpaque, p, removePainterListener, repaint, repaint, repaint, revalidate, setMargin, setMargin, setMargin, setOpaque, setPreferredSize, uninstall, updateAll, updateOpacity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateIcons

protected java.util.Map<java.lang.String,NinePatchIcon> stateIcons
Map containing separate 9-patch icons for different component states.

Constructor Detail

NinePatchStatePainter

public NinePatchStatePainter()
Constructs new 9-patch state painter with empty states.


NinePatchStatePainter

public NinePatchStatePainter(java.util.Map<java.lang.String,NinePatchIcon> stateIcons)
Constructs new 9-patch state painter with specified states map.

Method Detail

getStateIcons

public java.util.Map<java.lang.String,NinePatchIcon> getStateIcons()
Returns states map.

Returns:
states map

setStateIcons

public void setStateIcons(java.util.Map<java.lang.String,NinePatchIcon> stateIcons)
Sets states map.

Parameters:
stateIcons - states map

addStateIcon

public void addStateIcon(java.lang.String state,
                         NinePatchIcon ninePatchIcon)
Adds painter state.

Parameters:
state - state to add
ninePatchIcon - 9-patch icon

removeStateIcon

public void removeStateIcon(java.lang.String state)
Removes painter state.

Parameters:
state - state to remove

hasStateIcons

public boolean hasStateIcons()
Returns whether atleast one state icon is available or not.

Returns:
true if atleast one state icon is available, false otherwise

paint

public void paint(java.awt.Graphics2D g2d,
                  java.awt.Rectangle bounds,
                  E c)
Paints visual data onto the component graphics. Provided graphics and component are taken directly from component UI paint method. Provided bounds are usually fake (zero location, component size) but in some cases it might be specified by componentUI.

Parameters:
g2d - component graphics
bounds - bounds for painter visual data
c - component to process

isFocused

protected boolean isFocused(E component)
Returns whether component is in focused state or not.

Parameters:
component - component to process
Returns:
true if component is in focused state, false otherwise

getComponentBackground

protected NinePatchIcon getComponentBackground(E component)
Returns current state icon for the specified component.

Parameters:
component - component to process
Returns:
current state icon

getButtonBackground

protected NinePatchIcon getButtonBackground(javax.swing.AbstractButton button)
Returns current state icon for the specified button.

Parameters:
button - button to process
Returns:
current state icon

getToolBarBackground

protected NinePatchIcon getToolBarBackground(javax.swing.JToolBar toolbar)
Returns current state icon for the specified toolbar.

Parameters:
toolbar - toolbar to process
Returns:
current state icon

getExactStateIcon

public NinePatchIcon getExactStateIcon(java.lang.String state)
Returns exact state icon or null if it is not specified.

Parameters:
state - component state
Returns:
exact state icon or null if it is not specified

getStateIcon

public NinePatchIcon getStateIcon(java.lang.String state)
Returns state icon or possible replacement for it.

Parameters:
state - component state
Returns:
state icon or possible replacement for it

getPreferredSize

public java.awt.Dimension getPreferredSize(E c)
Returns preferred size required for proper painting of visual data provided by this painter. This should not take into account any sizes not related to this painter settings (for example text size on button).

Specified by:
getPreferredSize in interface Painter<E extends javax.swing.JComponent>
Overrides:
getPreferredSize in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
preferred size required for proper painting of visual data provided by this painter

getMargin

public java.awt.Insets getMargin(E c)
Returns margin required for visual data provided by this painter. This margin is usually added to component's margin when the final component border is calculated. You may pass null instead of zero margin - it will simply be ignored in that case.

Specified by:
getMargin in interface Painter<E extends javax.swing.JComponent>
Overrides:
getMargin in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
c - component to process
Returns:
margin required for visual data provided by this painter or null for zero margin