public abstract class FigureDecorator extends AbstractFigureContainer
This class is a reasonable example of the Decorator design pattern, hence its name.
Constructor and Description |
---|
FigureDecorator() |
Modifier and Type | Method and 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.
|
decorate, pick, pick, repaint, undecorate
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, intersects, isVisible, paint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isVisible, paint, setVisible
getParent, getTransformContext, repaint
public void add(Figure f)
f
- The figure to be added.public boolean contains(Figure f)
contains
in interface FigureContainer
contains
in interface FigureSet
contains
in class AbstractFigureContainer
f
- The figure to be searched forpublic java.util.Iterator figures()
figures
in interface FigureSet
figures
in class AbstractFigureContainer
public java.util.Iterator figuresFromBack()
figuresFromBack
in interface FigureSet
figuresFromBack
in class AbstractFigureContainer
public java.util.Iterator figuresFromFront()
figuresFromFront
in interface FigureSet
figuresFromFront
in class AbstractFigureContainer
public java.awt.geom.Rectangle2D getBounds()
getBounds
in interface Figure
getBounds
in class AbstractFigure
public Figure getChild()
public FigureContainer getContainer()
public Figure getDecoratedFigure()
public int getFigureCount()
getFigureCount
in interface FigureContainer
getFigureCount
in class AbstractFigureContainer
public java.awt.Shape getShape()
getShape
in interface Figure
getShape
in class AbstractFigure
public boolean hit(java.awt.geom.Rectangle2D r)
hit
in interface Figure
hit
in class AbstractFigure
r
- The rectangle to be checked.public abstract FigureDecorator newInstance(Figure f)
f
- The figurepublic void paint(java.awt.Graphics2D g)
paint
in interface VisibleComponent
paint
in class AbstractFigureContainer
g
- The Graphics contextpublic void setChild(Figure f)
f
- The child figure.public void remove(Figure f)
f
- The figure to be removedprotected void replaceChild(Figure child, Figure replacement)
replaceChild
in class AbstractFigureContainer
child
- The figure to be replaced.replacement
- The replacement figure.public void transform(java.awt.geom.AffineTransform at)
transform
in interface Figure
transform
in class AbstractFigureContainer
at
- The transform to be used.public void translate(double x, double y)
translate
in interface Figure
translate
in class AbstractFigureContainer
x
- The x value to be moved.y
- The y value to be moved.