Package diva.canvas

Class BasicZList

  • All Implemented Interfaces:
    FigureSet, ZList

    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.
      • 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
        Parameters:
        f - The figure to be inserted.
      • 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
        Parameters:
        index - The index at which the figure shall be inserted.
        f - The figure to be inserted.
      • clear

        public void clear()
        Removes all of the figures from this list.
        Specified by:
        clear in interface ZList
      • getBounds

        public java.awt.geom.Rectangle2D getBounds()
        Get the bounding box of all the figures in this list.
        Specified by:
        getBounds in interface ZList
        Returns:
        the bounding box.
      • 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
        Parameters:
        f - The figure
        Returns:
        true if the figure is contained by this list.
      • 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.
        Specified by:
        figures in interface FigureSet
        Returns:
        The iterator.
      • 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 interface FigureSet
        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 interface FigureSet
        Returns:
        The iterator
      • get

        public Figure get​(int index)
        Get the figure at the given index.
        Specified by:
        get in interface ZList
        Parameters:
        index - The given index
        Returns:
        the Figure at the given index.
      • getFigureCount

        public int getFigureCount()
        Return the number of figures in this list.
        Specified by:
        getFigureCount in interface ZList
        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 interface ZList
        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 interface ZList
        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.
        Specified by:
        indexOf in interface ZList
        Parameters:
        f - The figure.
        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
        Parameters:
        f - The figure.
      • 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
        Parameters:
        index - The index of the figure.
      • 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
        Parameters:
        index - The index of the figure.
        f - The figure
      • 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
        Parameters:
        index - The index of the figure.
        f - The figure