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 voidadd(Figure f)Add a figure.booleancontains(Figure f)Test if the given figure is the one contained by this decorator.java.util.Iteratorfigures()Return an iteration containing the one child.java.util.IteratorfiguresFromBack()Return an iteration containing the one child.java.util.IteratorfiguresFromFront()Return an iteration containing the one child.java.awt.geom.Rectangle2DgetBounds()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.FiguregetChild()Get the child figure, or null if there isn't one.FigureContainergetContainer()Get the container, which is defined as the lowest ancestor that is not a FigureDecorator.FiguregetDecoratedFigure()Get the decorated figure, which is defined as the highest descendent that is not a decorator.intgetFigureCount()Return zero if there is no child, or one if there is.java.awt.ShapegetShape()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.booleanhit(java.awt.geom.Rectangle2D r)Test if the child is hit.abstract FigureDecoratornewInstance(Figure f)Create a new instance of this figure decorator, modeled on this one.voidpaint(java.awt.Graphics2D g)Paint the figure.voidremove(Figure f)Remove a figure.protected voidreplaceChild(Figure child, Figure replacement)Replace the first figure, which must be a child, with the second, which must not be a child.voidsetChild(Figure f)Set the child figure.voidtransform(java.awt.geom.AffineTransform at)Transform the figure with the supplied transform.voidtranslate(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:
containsin interfaceFigureContainer- Specified by:
containsin interfaceFigureSet- Specified by:
containsin 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:
figuresin interfaceFigureSet- Specified by:
figuresin classAbstractFigureContainer- Returns:
- The iterator.
-
figuresFromBack
public java.util.Iterator figuresFromBack()
Return an iteration containing the one child.- Specified by:
figuresFromBackin interfaceFigureSet- Specified by:
figuresFromBackin classAbstractFigureContainer- Returns:
- The iterator
-
figuresFromFront
public java.util.Iterator figuresFromFront()
Return an iteration containing the one child.- Specified by:
figuresFromFrontin interfaceFigureSet- Specified by:
figuresFromFrontin 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:
getBoundsin interfaceFigure- Overrides:
getBoundsin 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:
getFigureCountin interfaceFigureContainer- Specified by:
getFigureCountin 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:
getShapein interfaceFigure- Specified by:
getShapein 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:
hitin interfaceFigure- Overrides:
hitin 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:
paintin interfaceVisibleComponent- Overrides:
paintin 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:
replaceChildin 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:
transformin interfaceFigure- Overrides:
transformin 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:
translatein interfaceFigure- Overrides:
translatein classAbstractFigureContainer- Parameters:
x- The x value to be moved.y- The y value to be moved.
-
-