Package diva.canvas
Class BasicZList
- java.lang.Object
-
- diva.canvas.BasicZList
-
public class BasicZList extends java.lang.Object implements ZList
A basic implementation of the figure z-list, provided for initial implementations of figure containers. This implementation uses java.util.ArrayList internally. In the internal implementation, the order of indexes is reversed, so that low-index elements in the external interface are high-index elements in the internal ArrayList. This is done on grounds of "performance": the redraw iterator is more important than the event-handling iterator.- Version:
- $Id$
- Author:
- John Reekie
- Pt.AcceptedRating:
- Yellow
-
-
Constructor Summary
Constructors Constructor Description BasicZList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, Figure f)
Insert a figure at the given position.void
add(Figure f)
Add a figure to the container.void
clear()
Removes all of the figures from this list.boolean
contains(Figure f)
Test if the z-list contains the given figure.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 highest index to lowest index.java.util.Iterator
figuresFromFront()
Return an iteration of the figures in this container, from lowest index to highest index.Figure
get(int index)
Get the figure at the given index.java.awt.geom.Rectangle2D
getBounds()
Get the bounding box of all the figures in this list.GeometricSet
getContainedFigures(java.awt.geom.Rectangle2D region)
Get the figures that are entirely contained by the given region.int
getFigureCount()
Return the number of figures in this list.GeometricSet
getIntersectedFigures(java.awt.geom.Rectangle2D region)
Get the figures with bounding boxes that intersect the given region.int
indexOf(Figure f)
Return the index of the given figure in the Z-list.void
remove(int index)
Remove the figure at the given position in the list.void
remove(Figure f)
Remove the given figure from this container.void
set(int index, Figure f)
Replace the figure at the given index with the passed-in figure.void
setIndex(int index, Figure f)
Set the index of the given figure.
-
-
-
Method Detail
-
add
public void add(Figure f)
Add a figure to the container. See the implemented method for a detailed description.
-
add
public void add(int index, Figure f)
Insert a figure at the given position. See the implemented method for a detailed description.
-
clear
public void clear()
Removes all of the figures from this list.
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of all the figures in this list.
-
contains
public boolean contains(Figure f)
Test if the z-list contains the given figure. See the implemented method for a detailed description.Clients should note that, in general, a much better way of making this same test is to check if the parent of the figure is the same object as this container.
-
figures
public java.util.Iterator figures()
Return an iteration of the figures in this container. In this particular implementation, the figures are in redraw order -- that is, from front to back. Clients must not rely on this, though, and use figuresFromBack() if they require that order.
-
figuresFromBack
public java.util.Iterator figuresFromBack()
Return an iteration of the figures in this container, from highest index to lowest index. This is the order in which figures should normally be painted, so that figures at lower indexes are painted over the top of figures at higher indexes.- Specified by:
figuresFromBack
in interfaceFigureSet
- Returns:
- The iterator
-
figuresFromFront
public java.util.Iterator figuresFromFront()
Return an iteration of the figures in this container, from lowest index to highest index. This is the order in which events should normally be intercepted.- Specified by:
figuresFromFront
in interfaceFigureSet
- Returns:
- The iterator
-
get
public Figure get(int index)
Get the figure at the given index.
-
getFigureCount
public int getFigureCount()
Return the number of figures in this list.- Specified by:
getFigureCount
in interfaceZList
- Returns:
- The figure count.
-
getContainedFigures
public GeometricSet getContainedFigures(java.awt.geom.Rectangle2D region)
Get the figures that are entirely contained by the given region.- Specified by:
getContainedFigures
in interfaceZList
- Parameters:
region
- The region.- Returns:
- The figures with bounding boxes that are entirely contained by given region.
-
getIntersectedFigures
public GeometricSet getIntersectedFigures(java.awt.geom.Rectangle2D region)
Get the figures with bounding boxes that intersect the given region. Note that the returned set may contained figures that do not intersect the region -- this method only looks at the bounding boxes.- Specified by:
getIntersectedFigures
in interfaceZList
- Parameters:
region
- The region.- Returns:
- The figures with bounding boxes that intersect the given region.
-
indexOf
public int indexOf(Figure f)
Return the index of the given figure in the Z-list. See the implemented method for a detailed description.
-
remove
public void remove(Figure f)
Remove the given figure from this container. See the implemented method for a detailed description.
-
remove
public void remove(int index)
Remove the figure at the given position in the list. See the implemented method for a detailed description.
-
set
public void set(int index, Figure f)
Replace the figure at the given index with the passed-in figure.
-
-