public class FigureLayer extends CanvasLayer implements FigureContainer, EventAcceptor
FigureLayer responds to events on figures themselves by forwarding the events to interactors attached to a hit figure. It does not support events on the layer itself (see EventLayer for that).
_containingPane
Constructor and Description |
---|
FigureLayer()
Create a new figure layer that is not in a pane.
|
FigureLayer(CanvasPane pane)
Create a new figure layer within the given pane.
|
FigureLayer(CanvasPane pane,
ZList zlist)
Create a new figure layer within the given pane and with
the given ZList to hold the figures it contains.
|
FigureLayer(ZList zlist)
Create a new figure layer with
the given ZList to hold its figures.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Figure f)
Add a figure to the layer.
|
void |
add(int index,
Figure f)
Insert a figure into the layer at the given position.
|
void |
clear()
Removes all of the figures from this layer.
|
boolean |
contains(Figure f)
Test if the layer contains the given figure.
|
void |
decorate(Figure child,
FigureDecorator decorator)
Decorate a child figure, replacing the child figure with the
decorator.
|
void |
dispatchEvent(java.awt.AWTEvent event)
Dispatch an AWT event on this layer.
|
java.util.Iterator |
figures()
Return an iteration of the figures in this container.
|
java.util.Iterator |
figuresFromBack()
Return an iteration of the figures in this container, from
back to front.
|
java.util.Iterator |
figuresFromFront()
Return an iteration of the figures in this container, from
front to back.
|
Figure |
get(int index)
Get the figure at the given index.
|
Figure |
getCurrentFigure()
Return the figure that the mouse pointer is currently over,
or null if none.
|
protected Figure |
getFigure(LayerEvent e)
Return the figure pointed to by the given LayerEvent.
|
int |
getFigureCount()
Return the number of figures in this layer.
|
ZList |
getFigures()
Get the internal z-list.
|
java.awt.geom.Rectangle2D |
getLayerBounds()
Get the bounds of the shapes draw in this layer.
|
double |
getPickHalo()
Get the "pick halo".
|
java.lang.String |
getToolTipText(LayerEvent e)
Get the toolTipText for the point in the given LayerEvent.
|
void |
grabPointer(LayerEvent e,
Figure f)
"Grab" the pointer.
|
int |
indexOf(Figure f)
Return the index of the given figure.
|
boolean |
isEnabled()
Test the enabled flag of this layer.
|
boolean |
isVisible()
Test the visibility flag of this layer.
|
void |
paint(java.awt.Graphics2D g)
Paint this layer onto a 2D graphics object.
|
void |
paint(java.awt.Graphics2D g,
java.awt.geom.Rectangle2D region)
Paint this layer onto a 2D graphics object, within the given
region.
|
Figure |
pick(java.awt.geom.Rectangle2D region)
Get the picked figure.
|
Figure |
pick(java.awt.geom.Rectangle2D region,
Filter filter)
Get the picked figure.
|
protected void |
processLayerEvent(LayerEvent e)
Process a layer event.
|
protected void |
processLayerMotionEvent(LayerEvent e)
Process a layer motion event.
|
void |
remove(Figure f)
Remove the given figure from this layer.
|
void |
remove(int index)
Remove the figure at the given position in the list.
|
void |
repaint(java.awt.geom.Rectangle2D region)
Repaint all figures that intersect the given rectangle.
|
void |
setEnabled(boolean flag)
Set the enabled flag of this layer.
|
void |
setIndex(int index,
Figure f)
Set the index of the given figure.
|
void |
setPickHalo(double halo)
Set the "pick halo".
|
void |
setVisible(boolean flag)
Set the visibility flag of this layer.
|
void |
undecorate(FigureDecorator decorator)
Remove a figure from the given decorator and add
it back into this container.
|
getCanvasPane, getParent, getTransformContext, repaint, repaint, setParent
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getParent, getTransformContext, repaint, repaint
public FigureLayer()
public FigureLayer(CanvasPane pane)
pane
- The given pane.public FigureLayer(CanvasPane pane, ZList zlist)
pane
- The given pane.zlist
- The given zlist.public FigureLayer(ZList zlist)
zlist
- The given zlist.public void add(Figure f)
add
in interface FigureContainer
f
- The figure to be addedpublic void add(int index, Figure f)
Clients should assume that an implementation of this method does not check if the figure is already contained -- clients are therefore responsible for being bug-free.
index
- The indexf
- The figure to be added.public void clear()
public boolean contains(Figure f)
contains
in interface FigureContainer
contains
in interface FigureSet
f
- The figure to be checked.public void decorate(Figure child, FigureDecorator decorator)
decorate
in interface FigureContainer
child
- The child figure.decorator
- The decorator.public void dispatchEvent(java.awt.AWTEvent event)
dispatchEvent
in interface EventAcceptor
event
- the event.public java.util.Iterator figures()
public java.util.Iterator figuresFromBack()
figuresFromBack
in interface FigureSet
public java.util.Iterator figuresFromFront()
figuresFromFront
in interface FigureSet
public Figure get(int index)
index
- The given indexpublic int getFigureCount()
getFigureCount
in interface FigureContainer
public Figure getCurrentFigure()
public ZList getFigures()
public java.awt.geom.Rectangle2D getLayerBounds()
getLayerBounds
in class CanvasLayer
public final double getPickHalo()
setPickHalo(double)
public void grabPointer(LayerEvent e, Figure f)
e
- The LayerEventf
- The figurepublic java.lang.String getToolTipText(LayerEvent e)
getToolTipText
in class CanvasLayer
e
- The layer event, ignored in this class.public int indexOf(Figure f)
f
- The figurepublic final boolean isEnabled()
isEnabled
in interface EventAcceptor
public final boolean isVisible()
isVisible
in interface VisibleComponent
public void paint(java.awt.Graphics2D g)
paint
in interface VisibleComponent
g
- The 2D graphics object that this object
it to be painted upon.public void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D region)
paint
in interface VisibleComponent
g
- The 2D graphics object that this object
it to be painted upon.region
- The region.public Figure pick(java.awt.geom.Rectangle2D region)
pick
in interface FigureContainer
region
- The rectanglepublic Figure pick(java.awt.geom.Rectangle2D region, Filter filter)
pick
in interface FigureContainer
region
- The rectanglefilter
- The filterpublic void remove(Figure f)
remove
in interface FigureContainer
f
- The figure to be removedpublic void remove(int index)
index
- The given position.public void repaint(java.awt.geom.Rectangle2D region)
region
- The given rectanglepublic final void setEnabled(boolean flag)
setEnabled
in interface EventAcceptor
flag
- True if the object is prepared to handle
events with processEvent();public final void setPickHalo(double halo)
halo
- The pick halogetPickHalo()
public void setIndex(int index, Figure f)
Note that this method does not check if the figure is already contained -- clients are therefore responsible for being bug-free.
index
- The index to be setf
- The figurejava.lang.IndexOutOfBoundsException
- The new index is out of range.public final void setVisible(boolean flag)
setVisible
in interface VisibleComponent
flag
- True if this object is to be visible.public void undecorate(FigureDecorator decorator)
undecorate
in interface FigureContainer
decorator
- The decoratorprotected final Figure getFigure(LayerEvent e)
e
- The given LayerEventprotected void processLayerEvent(LayerEvent e)
If the event type is MOUSE_DRAGGED or MOUSE_RELEASED, then the downwards recursion is skipped, and the upwards propagation is begun from the figure remembered from the MOUSE_PRESSED processing. Again, the propagation stops when the event is consumed.
Note: the above strategy will not work with more than one input device. Is there anything in MouseEvent that allows us to identify the input device?
e
- The LayerEventprotected void processLayerMotionEvent(LayerEvent e)
e
- The LayerEvent