Package diva.canvas
Class FigureDecorator
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.AbstractFigureContainer
-
- 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$
- Author:
- John Reekie
- Pt.AcceptedRating:
- Red
-
-
Constructor Summary
Constructors Constructor Description FigureDecorator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.CanvasComponent
getTransformContext, repaint
-
Methods inherited from interface diva.canvas.VisibleComponent
isVisible, paint, setVisible
-
-
-
-
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).- Parameters:
f
- The figure to be added.
-
contains
public boolean contains(Figure f)
Test if the given figure is the one contained by this decorator.- Specified by:
contains
in interfaceFigureContainer
- Specified by:
contains
in interfaceFigureSet
- Specified by:
contains
in classAbstractFigureContainer
- Parameters:
f
- The figure to be searched for- Returns:
- true if the figure is contained.
-
figures
public java.util.Iterator figures()
Return an iteration containing the one child.- Specified by:
figures
in interfaceFigureSet
- Specified by:
figures
in classAbstractFigureContainer
- Returns:
- The iterator.
-
figuresFromBack
public java.util.Iterator figuresFromBack()
Return an iteration containing the one child.- Specified by:
figuresFromBack
in interfaceFigureSet
- Specified by:
figuresFromBack
in classAbstractFigureContainer
- Returns:
- The iterator
-
figuresFromFront
public java.util.Iterator figuresFromFront()
Return an iteration containing the one child.- Specified by:
figuresFromFront
in interfaceFigureSet
- Specified by:
figuresFromFront
in classAbstractFigureContainer
- Returns:
- The iterator
-
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 interfaceFigure
- Overrides:
getBounds
in classAbstractFigure
- Returns:
- the bounding box of this figure.
-
getChild
public Figure getChild()
Get the child figure, or null if there isn't one.- Returns:
- The child figure
-
getContainer
public FigureContainer getContainer()
Get the container, which is defined as the lowest ancestor that is not a FigureDecorator.- Returns:
- the container
-
getDecoratedFigure
public Figure getDecoratedFigure()
Get the decorated figure, which is defined as the highest descendent that is not a decorator.- Returns:
- The decorated figure.
-
getFigureCount
public int getFigureCount()
Return zero if there is no child, or one if there is.- Specified by:
getFigureCount
in interfaceFigureContainer
- Specified by:
getFigureCount
in classAbstractFigureContainer
- Returns:
- The number of figures.
-
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 interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the outline shape of this figure
-
hit
public boolean hit(java.awt.geom.Rectangle2D r)
Test if the child is hit.- Specified by:
hit
in interfaceFigure
- Overrides:
hit
in classAbstractFigure
- Parameters:
r
- The rectangle to be checked.- Returns:
- true if the figure is hit by the given rectangle.
-
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.- Parameters:
f
- The figure- Returns:
- The new instance of the figure decorator.
-
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 interfaceVisibleComponent
- Overrides:
paint
in classAbstractFigureContainer
- Parameters:
g
- The Graphics context
-
setChild
public void setChild(Figure f)
Set the child figure. If there is already a child figure, remove it from this container.- Parameters:
f
- The child figure.
-
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.- Parameters:
f
- The figure to be removed
-
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 classAbstractFigureContainer
- Parameters:
child
- The figure to be replaced.replacement
- The replacement figure.
-
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 interfaceFigure
- Overrides:
transform
in classAbstractFigureContainer
- Parameters:
at
- The transform to be used.
-
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 interfaceFigure
- Overrides:
translate
in classAbstractFigureContainer
- Parameters:
x
- The x value to be moved.y
- The y value to be moved.
-
-