org.apache.batik.ext.awt.geom

Class RectListManager

public class RectListManager extends Object implements Collection

RectListManager is a class to manage a list of rectangular regions. This class contains methods to add new rectangles to the List, to merge rectangles in the list (based on a cost function), and functions to subract one RectListManager from another. The main purpose of this class is to manage dirty regions on a display (for this reason it uses Rectangle not Rectangle2D).
Field Summary
static Comparatorcomparator
The comparator used to sort the elements of this List.
Constructor Summary
RectListManager(Collection rects)
Construct a RectListManager from a Collection of Rectangles
RectListManager(Rectangle[] rects)
Construct a RectListManager from an Array of Rectangles
RectListManager(Rectangle[] rects, int off, int sz)
Construct a RectListManager from an Array of Rectangles
RectListManager(RectListManager rlm)
Construct a RectListManager from another RectListManager (data is copied).
RectListManager(Rectangle rect)
Construct a RectListManager with one rectangle
RectListManager()
Construct an initially empty RectListManager.
RectListManager(int capacity)
Construct an initially empty RectListManager, with initial capacity.
Method Summary
booleanadd(Object o)
voidadd(Rectangle rect)
Ensures that this collection contains the specified element
protected voidadd(Rectangle rect, int l, int r)
Ensures that this collection contains the specified element l is the lower bound index for insertion r is upper bound index for insertion.
voidadd(RectListManager rlm)
Adds the contents of rlm to this RectListManager.
booleanaddAll(Collection c)
voidclear()
Objectclone()
Standard Object clone method.
booleancontains(Object o)
booleancontainsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection.
booleancontainsAll(RectListManager rlm)
RectListManagercopy()
Similar to clone only strongly typed
voiddump()
voidensureCapacity(int sz)
RectanglegetBounds()
protected voidinsertRects(Rectangle[] rects, int srcPos, int dstPos, int len)
booleanisEmpty()
Returns true if this collection contains no elements.
Iteratoriterator()
Returns an iterator over the elements in this collection
ListIteratorlistIterator()
Returns a list iterator of the elements in this list (in proper sequence).
voidmergeRects(int overhead, int lineOverhead)
booleanremove(Object o)
Removes a single instance of the specified element from this collection, if it is present.
booleanremove(Rectangle rect)
Removes a single instance of the specified Rectangle from this collection, if it is present.
booleanremoveAll(Collection c)
booleanremoveAll(RectListManager rlm)
booleanretainAll(Collection c)
booleanretainAll(RectListManager rlm)
intsize()
Returns the number of elements currently stored in this collection.
protected voidsplitRect(Rectangle r, Rectangle sr, Rectangle[] splits)
voidsubtract(RectListManager rlm, int overhead, int lineOverhead)
Object[]toArray()
Object[]toArray(Object[] a)
fill the given array a with values from my internal rects. when a is not large enough, a new array is allocated, filled and returned. the method works only, when a is a Object[] or a Rectange[].

Field Detail

comparator

public static Comparator comparator
The comparator used to sort the elements of this List. Sorts on x value of Rectangle.

Constructor Detail

RectListManager

public RectListManager(Collection rects)
Construct a RectListManager from a Collection of Rectangles

Parameters: rects Collection that must only contain rectangles.

RectListManager

public RectListManager(Rectangle[] rects)
Construct a RectListManager from an Array of Rectangles

Parameters: rects Array of Rectangles, must not contain any null entries.

RectListManager

public RectListManager(Rectangle[] rects, int off, int sz)
Construct a RectListManager from an Array of Rectangles

Parameters: rects Array of Rectangles, must not contain any null entries in the range [off, off+sz-1]. off The offset to start copying from in rects. sz The number of entries to copy from rects.

RectListManager

public RectListManager(RectListManager rlm)
Construct a RectListManager from another RectListManager (data is copied).

Parameters: rlm RectListManager to copy.

RectListManager

public RectListManager(Rectangle rect)
Construct a RectListManager with one rectangle

Parameters: rect The rectangle to put in this rlm.

RectListManager

public RectListManager()
Construct an initially empty RectListManager.

RectListManager

public RectListManager(int capacity)
Construct an initially empty RectListManager, with initial capacity.

Parameters: capacity The inital capacity for the list. Setting this appropriately can save reallocations.

Method Detail

add

public boolean add(Object o)

add

public void add(Rectangle rect)
Ensures that this collection contains the specified element

Parameters: rect The rectangle to add

add

protected void add(Rectangle rect, int l, int r)
Ensures that this collection contains the specified element l is the lower bound index for insertion r is upper bound index for insertion.

Parameters: rect The rectangle to add l the lowest possible index for a rect with greater 'x' coord. r the highest possible index for a rect with greater 'x' coord.

add

public void add(RectListManager rlm)
Adds the contents of rlm to this RectListManager. No collapsing of rectangles is done here the contents are simply added (you should generally call 'mergeRects' some time after this operation before using the contents of this RectListManager.

Parameters: rlm The RectListManager to add the contents of.

addAll

public boolean addAll(Collection c)

clear

public void clear()

clone

public Object clone()
Standard Object clone method.

contains

public boolean contains(Object o)

containsAll

public boolean containsAll(Collection c)
Returns true if this collection contains all of the elements in the specified collection.

containsAll

public boolean containsAll(RectListManager rlm)

copy

public RectListManager copy()
Similar to clone only strongly typed

dump

public void dump()

ensureCapacity

public void ensureCapacity(int sz)

getBounds

public Rectangle getBounds()

insertRects

protected void insertRects(Rectangle[] rects, int srcPos, int dstPos, int len)

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.

iterator

public Iterator iterator()
Returns an iterator over the elements in this collection

listIterator

public ListIterator listIterator()
Returns a list iterator of the elements in this list (in proper sequence).

mergeRects

public void mergeRects(int overhead, int lineOverhead)

remove

public boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present.

Parameters: o Object to remove an matching instance of.

remove

public boolean remove(Rectangle rect)
Removes a single instance of the specified Rectangle from this collection, if it is present.

Parameters: rect Rectangle to remove an matching instance of.

removeAll

public boolean removeAll(Collection c)

removeAll

public boolean removeAll(RectListManager rlm)

retainAll

public boolean retainAll(Collection c)

retainAll

public boolean retainAll(RectListManager rlm)

size

public int size()
Returns the number of elements currently stored in this collection.

splitRect

protected void splitRect(Rectangle r, Rectangle sr, Rectangle[] splits)

subtract

public void subtract(RectListManager rlm, int overhead, int lineOverhead)

toArray

public Object[] toArray()

toArray

public Object[] toArray(Object[] a)
fill the given array a with values from my internal rects. when a is not large enough, a new array is allocated, filled and returned. the method works only, when a is a Object[] or a Rectange[]. When this is not the case, the a[] is just cleared.

Parameters: a array to fill (must not be null!)

Returns: the content of rects, either in a[] or a fresh array.

Copyright B) 2008 Apache Software Foundation. All Rights Reserved.