Package diva.canvas
Class AbstractFigureContainer
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.AbstractFigureContainer
-
- All Implemented Interfaces:
CanvasComponent
,Figure
,FigureContainer
,FigureSet
,VisibleComponent
,UserObjectContainer
- Direct Known Subclasses:
CompositeFigure
,FigureDecorator
public abstract class AbstractFigureContainer extends AbstractFigure implements FigureContainer
AbstractFigureContainer is an abstract class that roots the tree of figure-containing classes.- Version:
- $Id$
- Author:
- John Reekie
- Pt.AcceptedRating:
- Yellow
-
-
Constructor Summary
Constructors Constructor Description AbstractFigureContainer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
contains(Figure f)
Test if the given figure is a child of this composite.void
decorate(Figure child, FigureDecorator decorator)
Decorate a child figure, replacing the reference to the child figure with the decorator.abstract java.util.Iterator
figures()
Return an iteration of the children, in an undefined order.abstract java.util.Iterator
figuresFromBack()
Return an iteration of the children, from back to front.abstract java.util.Iterator
figuresFromFront()
Return an iteration of the children, from front to back.abstract int
getFigureCount()
Return the number of child figures in this container.void
paint(java.awt.Graphics2D g)
Paint this composite figure onto a 2D graphics object.Figure
pick(java.awt.geom.Rectangle2D region)
Given a rectangle, return the top-most descendent figure that it hits.Figure
pick(java.awt.geom.Rectangle2D region, Filter filter)
Given a rectangle, return the top-most descendent figure that it hits that is accepted by the given filter.void
repaint(DamageRegion d)
Accept notification that a repaint has occurred somewhere in the hierarchy below this container.protected abstract void
replaceChild(Figure child, Figure replacement)
Replace the first figure with the second.void
transform(java.awt.geom.AffineTransform at)
Transform this figure with the supplied transform.void
translate(double x, double y)
Translate this figure by the given distance.void
undecorate(FigureDecorator decorator)
Remove a figure from the given decorator and add it back into this container.-
Methods inherited from class diva.canvas.AbstractFigure
contains, getBounds, getInteractor, getLayer, getOrigin, getParent, getShape, getToolTipText, getTransformContext, getUserObject, hit, 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.FigureContainer
add, remove
-
Methods inherited from interface diva.canvas.VisibleComponent
isVisible, paint, setVisible
-
-
-
-
Method Detail
-
decorate
public void decorate(Figure child, FigureDecorator decorator)
Decorate a child figure, replacing the reference to the child figure with the decorator.- Specified by:
decorate
in interfaceFigureContainer
- Parameters:
child
- The child figure.decorator
- The decorator.
-
contains
public abstract boolean contains(Figure f)
Test if the given figure is a child of this composite.- Specified by:
contains
in interfaceFigureContainer
- Specified by:
contains
in interfaceFigureSet
- Parameters:
f
- The figure to be searched for- Returns:
- true if the figure is contained.
-
figures
public abstract java.util.Iterator figures()
Return an iteration of the children, in an undefined order.
-
figuresFromBack
public abstract java.util.Iterator figuresFromBack()
Return an iteration of the children, from back to front. This is the order in which the children are painted.- Specified by:
figuresFromBack
in interfaceFigureSet
- Returns:
- The iterator
-
figuresFromFront
public abstract java.util.Iterator figuresFromFront()
Return an iteration of the children, from front to back. This is the order in which events are intercepted.- Specified by:
figuresFromFront
in interfaceFigureSet
- Returns:
- The iterator
-
getFigureCount
public abstract int getFigureCount()
Return the number of child figures in this container.- Specified by:
getFigureCount
in interfaceFigureContainer
- Returns:
- The number of figures.
-
paint
public void paint(java.awt.Graphics2D g)
Paint this composite figure onto a 2D graphics object. If the layer is not visible, return immediately. Otherwise paint all children from back to front.- Specified by:
paint
in interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.
-
pick
public Figure pick(java.awt.geom.Rectangle2D region)
Given a rectangle, return the top-most descendent figure that it hits. If none does, return null.- Specified by:
pick
in interfaceFigureContainer
- Parameters:
region
- The rectangle- Returns:
- The figure
-
pick
public Figure pick(java.awt.geom.Rectangle2D region, Filter filter)
Given a rectangle, return the top-most descendent figure that it hits that is accepted by the given filter. If none does, return null.- Specified by:
pick
in interfaceFigureContainer
- Parameters:
region
- The rectanglefilter
- The filter- Returns:
- the Figure or null.
-
repaint
public void repaint(DamageRegion d)
Accept notification that a repaint has occurred somewhere in the hierarchy below this container. This default implementation simply forwards the notification to its parent.- Specified by:
repaint
in interfaceCanvasComponent
- Overrides:
repaint
in classAbstractFigure
- Parameters:
d
- The region where a repaint has occurred.
-
replaceChild
protected abstract void replaceChild(Figure child, Figure replacement)
Replace the first figure with the second. This is a hook method for the decorate() and undecorate() methods, and should not be called by other methods. Implementors can assume that the first figure is a child of this container, and that the second is not.- Parameters:
child
- The figure to be replaced.replacement
- The replacement figure.
-
transform
public void transform(java.awt.geom.AffineTransform at)
Transform this figure with the supplied transform. This default implementation simply forwards the transform call to each child.- Specified by:
transform
in interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
at
- The transform to be used.
-
translate
public void translate(double x, double y)
Translate this figure by the given distance. This default implementation simply forwards the translate call to each child.- Specified by:
translate
in interfaceFigure
- Overrides:
translate
in classAbstractFigure
- Parameters:
x
- The x value to be moved.y
- The y value to be moved.
-
undecorate
public void undecorate(FigureDecorator decorator)
Remove a figure from the given decorator and add it back into this container.- Specified by:
undecorate
in interfaceFigureContainer
- Parameters:
decorator
- The decorator
-
-