com.alee.managers.style.skin.ninepatch
Class NPDecorationPainter<E extends javax.swing.JComponent>

java.lang.Object
  extended by com.alee.extended.painter.AbstractPainter<E>
      extended by com.alee.managers.style.skin.ninepatch.NPDecorationPainter<E>
All Implemented Interfaces:
Painter<E>, PartialDecoration
Direct Known Subclasses:
NPPanelPainter

public class NPDecorationPainter<E extends javax.swing.JComponent>
extends AbstractPainter<E>
implements PartialDecoration

9-patch partial decoration painter for any kind of components. This painter is similar to WebDecorationPainter but this one is based on 9-patch icons. It uses 9-patch icons for normal and focused component states and its side separators.

Author:
Mikle Garin
See Also:
WebDecorationPainter

Field Summary
protected  NinePatchIcon backgroundIcon
          Used 9-patch icons.
protected  NinePatchIcon bottomSeparatorIcon
           
protected  boolean detectSideByContentPatches
           
protected  boolean focused
           
protected  NinePatchIcon focusedBackgroundIcon
           
protected  FocusTracker focusTracker
          Runtime variables.
protected  int hiddenSideSpacing
           
protected  NinePatchIcon leftSeparatorIcon
           
protected  boolean paintBottom
           
protected  boolean paintBottomLine
           
protected  boolean paintFocus
           
protected  boolean paintLeft
           
protected  boolean paintLeftLine
           
protected  boolean paintRight
           
protected  boolean paintRightLine
           
protected  boolean paintTop
           
protected  boolean paintTopLine
           
protected  NinePatchIcon rightSeparatorIcon
           
protected  NinePatchIcon separatorIcon
           
protected  NinePatchIcon topSeparatorIcon
           
protected  boolean undecorated
          Style settings.
 
Fields inherited from class com.alee.extended.painter.AbstractPainter
listeners, margin, opaque, preferredSize
 
Constructor Summary
NPDecorationPainter()
           
 
Method Summary
protected  java.awt.Rectangle getBackgroundBounds(NinePatchIcon icon, java.awt.Rectangle b, E c)
          Returns bounds within which background 9-patch icon should be painted.
 NinePatchIcon getBackgroundIcon()
          Returns background 9-patch icon.
 NinePatchIcon getBottomSeparatorIcon()
          Returns bottom side separator 9-patch icon.
protected  NinePatchIcon getCurrentBackgroundIcon()
          Returns background 9-patch icon that should be painted right now.
protected  NinePatchIcon getCurrentBottomSeparatorIcon()
          Returns bottom separator 9-patch icon that should be painted according to provided icons.
protected  NinePatchIcon getCurrentLeftSeparatorIcon()
          Returns left separator 9-patch icon that should be painted according to provided icons.
protected  NinePatchIcon getCurrentRightSeparatorIcon()
          Returns right separator 9-patch icon that should be painted according to provided icons.
protected  NinePatchIcon getCurrentTopSeparatorIcon()
          Returns top separator 9-patch icon that should be painted according to provided icons.
 NinePatchIcon getFocusedBackgroundIcon()
          Returns focused background 9-patch icon.
 int getHiddenSideSpacing()
          Returns additional spacing provided for side with hidden decoration.
 NinePatchIcon getLeftSeparatorIcon()
          Returns left side separator 9-patch icon.
 java.awt.Insets getMargin(E c)
          Returns margin required for visual data provided by this painter.
 NinePatchIcon getRightSeparatorIcon()
          Returns right side separator 9-patch icon.
 NinePatchIcon getSeparatorIcon()
          Returns default side separator 9-patch icon.
 NinePatchIcon getTopSeparatorIcon()
          Sets top side separator 9-patch icon.
 void install(E c)
          Called when painter is intalled into some component.
protected  boolean isAnyLineShouldBePainted()
          Returns whether at least one side line should be painted or not.
protected  boolean isBottomLineShouldBePainted()
          Returns whether bottom side line should be painted or not.
 boolean isDetectSideByContentPatches()
          Returns whether single decoration side size should be detected by content patches on the image or not.
protected  boolean isLeftLineShouldBePainted()
          Returns whether left side line should be painted or not.
 boolean isPaintBottom()
          Returns whether should paint bottom side or not.
 boolean isPaintBottomLine()
          Returns whether should paint bottom side line or not.
 boolean isPaintFocus()
          Returns whether focus should be painted or not.
 boolean isPaintLeft()
          Returns whether should paint left side or not.
 boolean isPaintLeftLine()
          Returns whether should paint left side line or not.
 boolean isPaintRight()
          Returns whether should paint right side or not.
 boolean isPaintRightLine()
          Returns whether should paint right side line or not.
 boolean isPaintTop()
          Returns whether should paint top side or not.
 boolean isPaintTopLine()
          Returns whether should paint top side line or not.
protected  boolean isRightLineShouldBePainted()
          Returns whether right side line should be painted or not.
protected  boolean isTopLineShouldBePainted()
          Returns whether top side line should be painted or not.
 boolean isUndecorated()
          Returns whether decoration should be painted or not.
 void paint(java.awt.Graphics2D g2d, java.awt.Rectangle bounds, E c)
          Paints visual data onto the component graphics.
 void setBackgroundIcon(NinePatchIcon icon)
          Sets background 9-patch icon.
 void setBottomSeparatorIcon(NinePatchIcon icon)
          Sets bottom side separator 9-patch icon.
 void setDetectSideByContentPatches(boolean detectSideByContentPatches)
          Set whether single decoration side size should be detected by content patches on the image or not.
 void setFocusedBackgroundIcon(NinePatchIcon icon)
          Sets focused background 9-patch icon.
 void setHiddenSideSpacing(int spacing)
          Sets additional spacing provided for side with hidden decoration.
 void setLeftSeparatorIcon(NinePatchIcon icon)
          Sets left side separator 9-patch icon.
 void setPaintBottom(boolean bottom)
          Sets whether should paint bottom side or not.
 void setPaintBottomLine(boolean bottom)
          Sets whether should paint bottom side line or not.
 void setPaintFocus(boolean paint)
          Sets whether focus should be painted or not.
 void setPaintLeft(boolean left)
          Sets whether should paint left side or not.
 void setPaintLeftLine(boolean left)
          Sets whether should paint left side line or not.
 void setPaintRight(boolean right)
          Sets whether should paint right side or not.
 void setPaintRightLine(boolean right)
          Sets whether should paint right side line or not.
 void setPaintSideLines(boolean top, boolean left, boolean bottom, boolean right)
          Sets whether should paint specific side lines or not.
 void setPaintSides(boolean top, boolean left, boolean bottom, boolean right)
          Sets whether should paint specific sides or not.
 void setPaintTop(boolean top)
          Sets whether should paint top side or not.
 void setPaintTopLine(boolean top)
          Sets whether should paint top side line or not.
 void setRightSeparatorIcon(NinePatchIcon icon)
          Sets right side separator 9-patch icon.
 void setSeparatorIcon(NinePatchIcon icon)
          Sets default side separator 9-patch icon.
 void setTopSeparatorIcon(NinePatchIcon icon)
          Sets top side separator 9-patch icon.
 void setUndecorated(boolean undecorated)
          Sets whether decoration should be painted or not.
 void uninstall(E c)
          Called when painter is intalled into some component.
 
Methods inherited from class com.alee.extended.painter.AbstractPainter
addPainterListener, getPreferredSize, isOpaque, p, removePainterListener, repaint, repaint, repaint, revalidate, setMargin, setMargin, setMargin, setOpaque, setPreferredSize, updateAll, updateOpacity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

undecorated

protected boolean undecorated
Style settings.


paintFocus

protected boolean paintFocus

paintTop

protected boolean paintTop

paintLeft

protected boolean paintLeft

paintBottom

protected boolean paintBottom

paintRight

protected boolean paintRight

paintTopLine

protected boolean paintTopLine

paintLeftLine

protected boolean paintLeftLine

paintBottomLine

protected boolean paintBottomLine

paintRightLine

protected boolean paintRightLine

detectSideByContentPatches

protected boolean detectSideByContentPatches

hiddenSideSpacing

protected int hiddenSideSpacing

backgroundIcon

protected NinePatchIcon backgroundIcon
Used 9-patch icons.


focusedBackgroundIcon

protected NinePatchIcon focusedBackgroundIcon

separatorIcon

protected NinePatchIcon separatorIcon

topSeparatorIcon

protected NinePatchIcon topSeparatorIcon

leftSeparatorIcon

protected NinePatchIcon leftSeparatorIcon

bottomSeparatorIcon

protected NinePatchIcon bottomSeparatorIcon

rightSeparatorIcon

protected NinePatchIcon rightSeparatorIcon

focusTracker

protected FocusTracker focusTracker
Runtime variables.


focused

protected boolean focused
Constructor Detail

NPDecorationPainter

public NPDecorationPainter()
Method Detail

install

public void install(E c)
Called when painter is intalled into some component. You might want to use this method to add custom component listeners or modify component settings.

Specified by:
install in interface Painter<E extends javax.swing.JComponent>
Overrides:
install in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
c - component to process

uninstall

public void uninstall(E c)
Called when painter is intalled into some component. You might want to use this method to add custom component listeners or modify component settings.

Specified by:
uninstall in interface Painter<E extends javax.swing.JComponent>
Overrides:
uninstall in class AbstractPainter<E extends javax.swing.JComponent>
Parameters:
c - component to process

isUndecorated

public boolean isUndecorated()
Returns whether decoration should be painted or not.

Returns:
true if decoration should be painted, false otherwise

setUndecorated

public void setUndecorated(boolean undecorated)
Sets whether decoration should be painted or not.

Parameters:
undecorated - whether decoration should be painted or not

isPaintFocus

public boolean isPaintFocus()
Returns whether focus should be painted or not.

Returns:
true if focus should be painted, false otherwise

setPaintFocus

public void setPaintFocus(boolean paint)
Sets whether focus should be painted or not.

Parameters:
paint - whether focus should be painted or not

isPaintTop

public boolean isPaintTop()
Returns whether should paint top side or not.

Returns:
true if should paint top side, false otherwise

setPaintTop

public void setPaintTop(boolean top)
Sets whether should paint top side or not.

Specified by:
setPaintTop in interface PartialDecoration
Parameters:
top - whether should paint top side or not

isPaintLeft

public boolean isPaintLeft()
Returns whether should paint left side or not.

Returns:
true if should paint left side, false otherwise

setPaintLeft

public void setPaintLeft(boolean left)
Sets whether should paint left side or not.

Specified by:
setPaintLeft in interface PartialDecoration
Parameters:
left - whether should paint left side or not

isPaintBottom

public boolean isPaintBottom()
Returns whether should paint bottom side or not.

Returns:
true if should paint bottom side, false otherwise

setPaintBottom

public void setPaintBottom(boolean bottom)
Sets whether should paint bottom side or not.

Specified by:
setPaintBottom in interface PartialDecoration
Parameters:
bottom - whether should paint bottom side or not

isPaintRight

public boolean isPaintRight()
Returns whether should paint right side or not.

Returns:
true if should paint right side, false otherwise

setPaintRight

public void setPaintRight(boolean right)
Sets whether should paint right side or not.

Specified by:
setPaintRight in interface PartialDecoration
Parameters:
right - whether should paint right side or not

setPaintSides

public void setPaintSides(boolean top,
                          boolean left,
                          boolean bottom,
                          boolean right)
Sets whether should paint specific sides or not.

Specified by:
setPaintSides in interface PartialDecoration
Parameters:
top - whether should paint top side or not
left - whether should paint left side or not
bottom - whether should paint bottom side or not
right - whether should paint right side or not

isPaintTopLine

public boolean isPaintTopLine()
Returns whether should paint top side line or not.

Returns:
true if should paint top side line, false otherwise

setPaintTopLine

public void setPaintTopLine(boolean top)
Sets whether should paint top side line or not.

Specified by:
setPaintTopLine in interface PartialDecoration
Parameters:
top - whether should paint top side line or not

isPaintLeftLine

public boolean isPaintLeftLine()
Returns whether should paint left side line or not.

Returns:
true if should paint left side line, false otherwise

setPaintLeftLine

public void setPaintLeftLine(boolean left)
Sets whether should paint left side line or not.

Specified by:
setPaintLeftLine in interface PartialDecoration
Parameters:
left - whether should paint left side line or not

isPaintBottomLine

public boolean isPaintBottomLine()
Returns whether should paint bottom side line or not.

Returns:
true if should paint bottom side line, false otherwise

setPaintBottomLine

public void setPaintBottomLine(boolean bottom)
Sets whether should paint bottom side line or not.

Specified by:
setPaintBottomLine in interface PartialDecoration
Parameters:
bottom - whether should paint bottom side line or not

isPaintRightLine

public boolean isPaintRightLine()
Returns whether should paint right side line or not.

Returns:
true if should paint right side line, false otherwise

setPaintRightLine

public void setPaintRightLine(boolean right)
Sets whether should paint right side line or not.

Specified by:
setPaintRightLine in interface PartialDecoration
Parameters:
right - whether should paint right side line or not

setPaintSideLines

public void setPaintSideLines(boolean top,
                              boolean left,
                              boolean bottom,
                              boolean right)
Sets whether should paint specific side lines or not.

Specified by:
setPaintSideLines in interface PartialDecoration
Parameters:
top - whether should paint top side line or not
left - whether should paint left side line or not
bottom - whether should paint bottom side line or not
right - whether should paint right side line or not

isDetectSideByContentPatches

public boolean isDetectSideByContentPatches()
Returns whether single decoration side size should be detected by content patches on the image or not. When true - hidden panel sides will cut appropriate 9-patch image sides using its content patches. When false - hidden panel sides will cut appropriate 9-patch image sides using its stretch patches.

Returns:
true if single decoration side size should be detected by content patches on the image, false otherwise

setDetectSideByContentPatches

public void setDetectSideByContentPatches(boolean detectSideByContentPatches)
Set whether single decoration side size should be detected by content patches on the image or not. If set to true - hidden panel sides will cut appropriate 9-patch image sides using its content patches. If set to - hidden panel sides will cut appropriate 9-patch image sides using its stretch patches.

Parameters:
detectSideByContentPatches - whether single decoration side size should be detected by content patches on the image or not

getHiddenSideSpacing

public int getHiddenSideSpacing()
Returns additional spacing provided for side with hidden decoration.

Returns:
additional spacing provided for side with hidden decoration

setHiddenSideSpacing

public void setHiddenSideSpacing(int spacing)
Sets additional spacing provided for side with hidden decoration. This might be useful if you want to keep default component size the same even if some sides are hidden.

Parameters:
spacing - additional spacing provided for side with hidden decoration

getBackgroundIcon

public NinePatchIcon getBackgroundIcon()
Returns background 9-patch icon.

Returns:
background 9-patch icon

setBackgroundIcon

public void setBackgroundIcon(NinePatchIcon icon)
Sets background 9-patch icon.

Parameters:
icon - background 9-patch icon

getFocusedBackgroundIcon

public NinePatchIcon getFocusedBackgroundIcon()
Returns focused background 9-patch icon.

Returns:
focused background 9-patch icon

setFocusedBackgroundIcon

public void setFocusedBackgroundIcon(NinePatchIcon icon)
Sets focused background 9-patch icon.

Parameters:
icon - focused background 9-patch icon

getSeparatorIcon

public NinePatchIcon getSeparatorIcon()
Returns default side separator 9-patch icon. This icon is used instead of specific side separator icon if one not specified.

Returns:
default side separator 9-patch icon

setSeparatorIcon

public void setSeparatorIcon(NinePatchIcon icon)
Sets default side separator 9-patch icon. This icon is used instead of specific side separator icon if one not specified.

Parameters:
icon - default side separator 9-patch icon

getTopSeparatorIcon

public NinePatchIcon getTopSeparatorIcon()
Sets top side separator 9-patch icon.

Returns:
top side separator 9-patch icon

setTopSeparatorIcon

public void setTopSeparatorIcon(NinePatchIcon icon)
Sets top side separator 9-patch icon.

Parameters:
icon - top side separator 9-patch icon

getLeftSeparatorIcon

public NinePatchIcon getLeftSeparatorIcon()
Returns left side separator 9-patch icon.

Returns:
left side separator 9-patch icon

setLeftSeparatorIcon

public void setLeftSeparatorIcon(NinePatchIcon icon)
Sets left side separator 9-patch icon.

Parameters:
icon - left side separator 9-patch icon

getBottomSeparatorIcon

public NinePatchIcon getBottomSeparatorIcon()
Returns bottom side separator 9-patch icon.

Returns:
bottom side separator 9-patch icon

setBottomSeparatorIcon

public void setBottomSeparatorIcon(NinePatchIcon icon)
Sets bottom side separator 9-patch icon.

Parameters:
icon - bottom side separator 9-patch icon

getRightSeparatorIcon

public NinePatchIcon getRightSeparatorIcon()
Returns right side separator 9-patch icon.

Returns:
right side separator 9-patch icon

setRightSeparatorIcon

public void setRightSeparatorIcon(NinePatchIcon icon)
Sets right side separator 9-patch icon.

Parameters:
icon - right side separator 9-patch icon

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

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.

Specified by:
paint in interface Painter<E extends javax.swing.JComponent>
Parameters:
g2d - component graphics
bounds - bounds for painter visual data
c - component to process

getCurrentBackgroundIcon

protected NinePatchIcon getCurrentBackgroundIcon()
Returns background 9-patch icon that should be painted right now.

Returns:
background 9-patch icon that should be painted right now

getCurrentTopSeparatorIcon

protected NinePatchIcon getCurrentTopSeparatorIcon()
Returns top separator 9-patch icon that should be painted according to provided icons.

Returns:
top separator 9-patch icon that should be painted according to provided icons

getCurrentLeftSeparatorIcon

protected NinePatchIcon getCurrentLeftSeparatorIcon()
Returns left separator 9-patch icon that should be painted according to provided icons.

Returns:
left separator 9-patch icon that should be painted according to provided icons

getCurrentBottomSeparatorIcon

protected NinePatchIcon getCurrentBottomSeparatorIcon()
Returns bottom separator 9-patch icon that should be painted according to provided icons.

Returns:
bottom separator 9-patch icon that should be painted according to provided icons

getCurrentRightSeparatorIcon

protected NinePatchIcon getCurrentRightSeparatorIcon()
Returns right separator 9-patch icon that should be painted according to provided icons.

Returns:
right separator 9-patch icon that should be painted according to provided icons

isAnyLineShouldBePainted

protected boolean isAnyLineShouldBePainted()
Returns whether at least one side line should be painted or not. This method is used to optimize painting performance.

Returns:
true if at least one side line should be painted, false otherwise

isTopLineShouldBePainted

protected boolean isTopLineShouldBePainted()
Returns whether top side line should be painted or not.

Returns:
true if top side line should be painted, false otherwise

isLeftLineShouldBePainted

protected boolean isLeftLineShouldBePainted()
Returns whether left side line should be painted or not.

Returns:
true if left side line should be painted, false otherwise

isBottomLineShouldBePainted

protected boolean isBottomLineShouldBePainted()
Returns whether bottom side line should be painted or not.

Returns:
true if bottom side line should be painted, false otherwise

isRightLineShouldBePainted

protected boolean isRightLineShouldBePainted()
Returns whether right side line should be painted or not.

Returns:
true if right side line should be painted, false otherwise

getBackgroundBounds

protected java.awt.Rectangle getBackgroundBounds(NinePatchIcon icon,
                                                 java.awt.Rectangle b,
                                                 E c)
Returns bounds within which background 9-patch icon should be painted. These bounds might not always fit component bounds to make a clipped side trick.

Parameters:
icon - background 9-patch icon
b - component bounds
c - component instance
Returns:
bounds within which background 9-patch icon should be painted