com.google.code.validationframework.swing.decoration
Class AbstractComponentDecoration

java.lang.Object
  extended by com.google.code.validationframework.swing.decoration.AbstractComponentDecoration
All Implemented Interfaces:
com.google.code.validationframework.api.common.Disposable
Direct Known Subclasses:
IconComponentDecoration

public abstract class AbstractComponentDecoration
extends Object
implements com.google.code.validationframework.api.common.Disposable

Abstract implementation of a decoration that can be attached to a component.

Concrete implementations will just need to provide the size and do the painting on the already-computed location.


Nested Class Summary
protected  class AbstractComponentDecoration.DecorationPainter
          Entity responsible of calling the paint(Graphics) method.
 
Field Summary
protected  AbstractComponentDecoration.DecorationPainter decorationPainter
          Decoration painter component.
 
Constructor Summary
AbstractComponentDecoration(JComponent decoratedComponent, AnchorLink anchorLink)
          Constructor specifying the component to be decorated and the anchor link between the decorated component and its decoration.
 
Method Summary
 void dispose()
           
 void followAndRepaint()
          Triggers a repaint of the component decoration.
protected  void followDecoratedComponent()
          Updates the decoration painter with respect to the decorated component.
 AnchorLink getAnchorLink()
          Gets the anchor link between the decorated component and its decoration.
 JComponent getClippingAncestor()
          Gets the custom clipping ancestor component that will be used to clip the decoration.
 JComponent getDecoratedComponent()
          Gets the decorated component to which the decoration is attached.
protected abstract  int getHeight()
          Returns the height of the decoration.
protected abstract  int getWidth()
          Returns the width of the decoration.
 boolean isVisible()
          States whether the decoration is visible or not.
abstract  void paint(Graphics g)
          Paints the decoration in the specified graphics.
 void setAnchorLink(AnchorLink anchorLink)
          Sets the anchor link between the component and its decoration.
 void setClippingAncestor(JComponent decorationClippingAncestor)
          Sets the custom clipping ancestor component that will be used to clip the decoration.
 void setVisible(boolean visible)
          Sets the visibility of the decoration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decorationPainter

protected AbstractComponentDecoration.DecorationPainter decorationPainter
Decoration painter component.

It is merely a hook into the Swing painting mechanism.

This is the component that is actually added to the layered pane.

See Also:
DECORATION_LAYER_OFFSET, attach(JComponent), getDecoratedComponentLayerInLayeredPane(javax.swing.JLayeredPane), decorationPainter
Constructor Detail

AbstractComponentDecoration

public AbstractComponentDecoration(JComponent decoratedComponent,
                                   AnchorLink anchorLink)
Constructor specifying the component to be decorated and the anchor link between the decorated component and its decoration.

Parameters:
decoratedComponent - Component to be decorated.
anchorLink - Anchor link between the decorated component and its decoration.
Method Detail

getDecoratedComponent

public JComponent getDecoratedComponent()
Gets the decorated component to which the decoration is attached.

Returns:
Decorated component.

getClippingAncestor

public JComponent getClippingAncestor()
Gets the custom clipping ancestor component that will be used to clip the decoration.

If null is returned, the parent container of the decorated component is used.

Returns:
Clipping ancestor or null.

setClippingAncestor

public void setClippingAncestor(JComponent decorationClippingAncestor)
Sets the custom clipping ancestor component that will be used to clip the decoration.

If set to null, the parent container of the decorated component will be used.

Note that the specified clipping component shall be an ancestor of the decorated component, or the component itself.

Parameters:
decorationClippingAncestor - Clipping ancestor or null to

getAnchorLink

public AnchorLink getAnchorLink()
Gets the anchor link between the decorated component and its decoration.

Returns:
Anchor link between the component and its decoration.

setAnchorLink

public void setAnchorLink(AnchorLink anchorLink)
Sets the anchor link between the component and its decoration.

Parameters:
anchorLink - Anchor link between the component and its decoration.

isVisible

public boolean isVisible()
States whether the decoration is visible or not.

Returns:
True if the decoration is visible, false otherwise.

setVisible

public void setVisible(boolean visible)
Sets the visibility of the decoration.

Parameters:
visible - True to make the decoration visible, false to make it invisible.

followDecoratedComponent

protected void followDecoratedComponent()
Updates the decoration painter with respect to the decorated component.

This method is to be called whenever changes on the decorated component have an impact on the decoration (for instance, its size, location, etc.).

This method has been made protected so that it can be easily called from the implementing sub-classes.


dispose

public void dispose()
Specified by:
dispose in interface com.google.code.validationframework.api.common.Disposable
See Also:
Disposable

followAndRepaint

public void followAndRepaint()
Triggers a repaint of the component decoration.

Note that this will also make the decoration follow the component.

See Also:
followDecoratedComponent()

getWidth

protected abstract int getWidth()
Returns the width of the decoration.

Returns:
Unclipped width of the decoration.

getHeight

protected abstract int getHeight()
Returns the height of the decoration.

Returns:
Unclipped height of the decoration.

paint

public abstract void paint(Graphics g)
Paints the decoration in the specified graphics.

Parameters:
g - Graphics to paint the decoration to.


Copyright © 2013. All Rights Reserved.