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 voidadd(int index, Figure f)Insert a figure at the given position.voidadd(Figure f)Add a figure to the container.voidclear()Removes all of the figures from this list.booleancontains(Figure f)Test if the z-list contains the given figure.java.util.Iteratorfigures()Return an iteration of the figures in this container.java.util.IteratorfiguresFromBack()Return an iteration of the figures in this container, from highest index to lowest index.java.util.IteratorfiguresFromFront()Return an iteration of the figures in this container, from lowest index to highest index.Figureget(int index)Get the figure at the given index.java.awt.geom.Rectangle2DgetBounds()Get the bounding box of all the figures in this list.GeometricSetgetContainedFigures(java.awt.geom.Rectangle2D region)Get the figures that are entirely contained by the given region.intgetFigureCount()Return the number of figures in this list.GeometricSetgetIntersectedFigures(java.awt.geom.Rectangle2D region)Get the figures with bounding boxes that intersect the given region.intindexOf(Figure f)Return the index of the given figure in the Z-list.voidremove(int index)Remove the figure at the given position in the list.voidremove(Figure f)Remove the given figure from this container.voidset(int index, Figure f)Replace the figure at the given index with the passed-in figure.voidsetIndex(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:
figuresFromBackin 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:
figuresFromFrontin 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:
getFigureCountin 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:
getContainedFiguresin 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:
getIntersectedFiguresin 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.
-
-