diva.canvas
Class FigureDecorator

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by diva.canvas.AbstractFigureContainer
          extended by diva.canvas.FigureDecorator
All Implemented Interfaces:
CanvasComponent, Figure, FigureContainer, FigureSet, VisibleComponent, UserObjectContainer
Direct Known Subclasses:
BasicEdgeHighlighter, BasicHighlighter, Manipulator, TypedDecorator

public abstract class FigureDecorator
extends AbstractFigureContainer

A FigureDecorator is a figure container that contains a single child figure. The purpose of a FigureDecorator is to change or affect the way in which the child is rendered, and so this class behaves somewhat differently to other figures.

This class is a reasonable example of the Decorator design pattern, hence its name.

Version:
$Id: FigureDecorator.java 38798 2005-07-08 20:00:01Z cxh $
Author:
John Reekie
Accepted Rating:
Red

Field Summary
private  Figure _child
          The child
 
Constructor Summary
FigureDecorator()
           
 
Method Summary
 void add(Figure f)
          Add a figure.
 boolean contains(Figure f)
          Test if the given figure is the one contained by this decorator.
 java.util.Iterator figures()
          Return an iteration containing the one child.
 java.util.Iterator figuresFromBack()
          Return an iteration containing the one child.
 java.util.Iterator figuresFromFront()
          Return an iteration containing the one child.
 java.awt.geom.Rectangle2D getBounds()
          Get the bounds of this figure, which is by default the same as the child figure, if there is one, or a very small rectangle if there isn't.
 Figure getChild()
          Get the child figure, or null if there isn't one.
 FigureContainer getContainer()
          Get the container, which is defined as the lowest ancestor that is not a FigureDecorator.
 Figure getDecoratedFigure()
          Get the decorated figure, which is defined as the highest descendent that is not a decorator.
 int getFigureCount()
          Return zero if there is no child, or one if there is.
 java.awt.Shape getShape()
          Get the outline shape of this figure, which is by default the same as the child figure, if there is one, or a very small rectangle if there isn't.
 boolean hit(java.awt.geom.Rectangle2D r)
          Test if the child is hit.
abstract  FigureDecorator newInstance(Figure f)
          Create a new instance of this figure decorator, modeled on this one.
 void paint(java.awt.Graphics2D g)
          Paint the figure.
 void remove(Figure f)
          Remove a figure.
protected  void replaceChild(Figure child, Figure replacement)
          Replace the first figure, which must be a child, with the second, which must not be a child.
 void setChild(Figure f)
          Set the child figure.
 void transform(java.awt.geom.AffineTransform at)
          Transform the figure with the supplied transform.
 void translate(double x, double y)
          Translate the figure by the given distance.
 
Methods inherited from class diva.canvas.AbstractFigureContainer
decorate, pick, pick, repaint, undecorate
 
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, intersects, isVisible, paint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.canvas.VisibleComponent
isVisible, paint, setVisible
 
Methods inherited from interface diva.canvas.CanvasComponent
getParent, getTransformContext, repaint
 

Field Detail

_child

private Figure _child
The child

Constructor Detail

FigureDecorator

public FigureDecorator()
Method Detail

add

public void add(Figure f)
Add a figure. This method does not make too much sense for Decorators, but has to be here anyway. This method is set same as calling setChild(f).


contains

public boolean contains(Figure f)
Test if the given figure is the one contained by this decorator.

Specified by:
contains in interface FigureContainer
Specified by:
contains in interface FigureSet
Specified by:
contains in class AbstractFigureContainer

figures

public java.util.Iterator figures()
Return an iteration containing the one child.

Specified by:
figures in interface FigureSet
Specified by:
figures in class AbstractFigureContainer

figuresFromBack

public java.util.Iterator figuresFromBack()
Return an iteration containing the one child.

Specified by:
figuresFromBack in interface FigureSet
Specified by:
figuresFromBack in class AbstractFigureContainer

figuresFromFront

public java.util.Iterator figuresFromFront()
Return an iteration containing the one child.

Specified by:
figuresFromFront in interface FigureSet
Specified by:
figuresFromFront in class AbstractFigureContainer

getBounds

public java.awt.geom.Rectangle2D getBounds()
Get the bounds of this figure, which is by default the same as the child figure, if there is one, or a very small rectangle if there isn't.

Specified by:
getBounds in interface Figure
Overrides:
getBounds in class AbstractFigure

getChild

public Figure getChild()
Get the child figure, or null if there isn't one.


getContainer

public FigureContainer getContainer()
Get the container, which is defined as the lowest ancestor that is not a FigureDecorator.


getDecoratedFigure

public Figure getDecoratedFigure()
Get the decorated figure, which is defined as the highest descendent that is not a decorator.


getFigureCount

public int getFigureCount()
Return zero if there is no child, or one if there is.

Specified by:
getFigureCount in interface FigureContainer
Specified by:
getFigureCount in class AbstractFigureContainer

getShape

public java.awt.Shape getShape()
Get the outline shape of this figure, which is by default the same as the child figure, if there is one, or a very small rectangle if there isn't.

Specified by:
getShape in interface Figure
Specified by:
getShape in class AbstractFigure

hit

public boolean hit(java.awt.geom.Rectangle2D r)
Test if the child is hit.

Specified by:
hit in interface Figure
Overrides:
hit in class AbstractFigure

newInstance

public abstract FigureDecorator newInstance(Figure f)
Create a new instance of this figure decorator, modeled on this one. This is used by interaction code that needs to dynamically create new manipulators. The figure argument can be used by this method to initialize the new instance; however, the new instance must not be wrapped around the figure, since that should be done by the caller.


paint

public void paint(java.awt.Graphics2D g)
Paint the figure. By default, this method simply forwards the paint request to the contained figure.

Specified by:
paint in interface VisibleComponent
Overrides:
paint in class AbstractFigureContainer

setChild

public void setChild(Figure f)
Set the child figure. If there is already a child figure, remove it from this container.


remove

public void remove(Figure f)
Remove a figure. This method does not make too much sense for Decorators, but has to be here anyway. If the passed figure is the same as the child figure, then this method is the same as calling setChild(null). Otherwise, it does nothing.


replaceChild

protected void replaceChild(Figure child,
                            Figure replacement)
Replace the first figure, which must be a child, with the second, which must not be a child.

Specified by:
replaceChild in class AbstractFigureContainer

transform

public void transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform. By default, this method simply forwards the paint request to the child figure.

Specified by:
transform in interface Figure
Overrides:
transform in class AbstractFigureContainer

translate

public void translate(double x,
                      double y)
Translate the figure by the given distance. By default, this method simply forwards the paint request to the child figure.

Specified by:
translate in interface Figure
Overrides:
translate in class AbstractFigureContainer