diva.canvas
Class BasicZList

java.lang.Object
  extended by diva.canvas.BasicZList
All Implemented Interfaces:
FigureSet, ZList

public class BasicZList
extends 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:
$Revision: 1.30 $
Author:
John Reekie

Constructor Summary
BasicZList()
           
 
Method Summary
 void add(Figure f)
          Add a figure to the container.
 void add(int index, Figure f)
          Insert a figure at the given position.
 void clear()
          Removes all of the figures from this list.
 boolean contains(Figure f)
          Test if the z-list contains the given figure.
 Iterator figures()
          Return an iteration of the figures in this container.
 Iterator figuresFromBack()
          Return an iteration of the figures in this container, from highest index to lowest index.
 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.
 Rectangle2D getBounds()
          Get the bounding box of all the figures in this list.
 GeometricSet getContainedFigures(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(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(Figure f)
          Remove the given figure from this container.
 void remove(int index)
          Remove the figure at the given position in the list.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicZList

public BasicZList()
Method Detail

add

public void add(Figure f)
Add a figure to the container. See the implemented method for a detailed description.

Specified by:
add in interface ZList

add

public void add(int index,
                Figure f)
Insert a figure at the given position. See the implemented method for a detailed description.

Specified by:
add in interface ZList

clear

public void clear()
Removes all of the figures from this list.

Specified by:
clear in interface ZList

getBounds

public Rectangle2D getBounds()
Get the bounding box of all the figures in this list.

Specified by:
getBounds in interface ZList

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.

Specified by:
contains in interface FigureSet
Specified by:
contains in interface ZList

figures

public 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.

Specified by:
figures in interface FigureSet

figuresFromBack

public 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 interface FigureSet

figuresFromFront

public 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 interface FigureSet

get

public Figure get(int index)
Get the figure at the given index.

Specified by:
get in interface ZList

getFigureCount

public int getFigureCount()
Return the number of figures in this list.

Specified by:
getFigureCount in interface ZList

getContainedFigures

public GeometricSet getContainedFigures(Rectangle2D region)
Get the figures that are entirely contained by the given region.

Specified by:
getContainedFigures in interface ZList

getIntersectedFigures

public GeometricSet getIntersectedFigures(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 interface ZList

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.

Specified by:
indexOf in interface ZList
Returns:
The index of the given figure, or -1 if the figure is not in this list.

remove

public void remove(Figure f)
Remove the given figure from this container. See the implemented method for a detailed description.

Specified by:
remove in interface ZList

remove

public void remove(int index)
Remove the figure at the given position in the list. See the implemented method for a detailed description.

Specified by:
remove in interface ZList

set

public void set(int index,
                Figure f)
Replace the figure at the given index with the passed-in figure.

Specified by:
set in interface ZList

setIndex

public void setIndex(int index,
                     Figure f)
Set the index of the given figure. See the implemented method for a detailed description.

Specified by:
setIndex in interface ZList


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.