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).
Yellow |
_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)
public FigureLayer(CanvasPane pane, ZList zlist)
public FigureLayer(ZList zlist)
public void add(Figure f)
add
in interface FigureContainer
public 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.
public void clear()
public boolean contains(Figure f)
contains
in interface FigureContainer
contains
in interface FigureSet
public void decorate(Figure child, FigureDecorator decorator)
decorate
in interface FigureContainer
public void dispatchEvent(java.awt.AWTEvent event)
dispatchEvent
in interface EventAcceptor
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)
public 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()
public void grabPointer(LayerEvent e, Figure f)
public java.lang.String getToolTipText(LayerEvent e)
getToolTipText
in class CanvasLayer
public int indexOf(Figure f)
public 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
public Figure pick(java.awt.geom.Rectangle2D region, Filter filter)
pick
in interface FigureContainer
public void remove(Figure f)
remove
in interface FigureContainer
public void remove(int index)
public void repaint(java.awt.geom.Rectangle2D region)
public final void setEnabled(boolean flag)
setEnabled
in interface EventAcceptor
public final void setPickHalo(double halo)
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.
java.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
protected final Figure getFigure(LayerEvent e)
protected 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?
protected void processLayerMotionEvent(LayerEvent e)