Package org.apache.batik.ext.awt.geom
Class RectListManager
- java.lang.Object
-
- org.apache.batik.ext.awt.geom.RectListManager
-
- All Implemented Interfaces:
java.lang.Iterable
,java.util.Collection
public class RectListManager extends java.lang.Object implements java.util.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).- Version:
- $Id: RectListManager.java 1733416 2016-03-03 07:07:13Z gadams $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RectListManager.RectXComparator
Comparator for ordering rects in X.private class
RectListManager.RLMIterator
-
Field Summary
Fields Modifier and Type Field Description (package private) java.awt.Rectangle
bounds
static java.util.Comparator
comparator
The comparator used to sort the elements of this List.(package private) java.awt.Rectangle[]
rects
(package private) int
size
-
Constructor Summary
Constructors Constructor Description RectListManager()
Construct an initially emptyRectListManager
.RectListManager(int capacity)
Construct an initially emptyRectListManager
, with initialcapacity
.RectListManager(java.awt.Rectangle rect)
Construct aRectListManager
with one rectangleRectListManager(java.awt.Rectangle[] rects)
Construct aRectListManager
from an Array ofRectangles
RectListManager(java.awt.Rectangle[] rects, int off, int sz)
Construct aRectListManager
from an Array ofRectangles
RectListManager(java.util.Collection rects)
Construct aRectListManager
from a Collection of RectanglesRectListManager(RectListManager rlm)
Construct aRectListManager
from anotherRectListManager
(data is copied).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.awt.Rectangle rect)
Ensures that this collection contains the specified elementprotected void
add(java.awt.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.boolean
add(java.lang.Object o)
void
add(RectListManager rlm)
Adds the contents ofrlm
to this RectListManager.boolean
addAll(java.util.Collection c)
void
clear()
java.lang.Object
clone()
StandardObject
clone method.boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection c)
Returns true if this collection contains all of the elements in the specified collection.boolean
containsAll(RectListManager rlm)
RectListManager
copy()
Similar to clone only strongly typed TODO Java 5: The use of covariant return types on clone() can eliminate this method.void
dump()
void
ensureCapacity(int sz)
java.awt.Rectangle
getBounds()
protected void
insertRects(java.awt.Rectangle[] rects, int srcPos, int dstPos, int len)
boolean
isEmpty()
Returns true if this collection contains no elements.java.util.Iterator
iterator()
Returns an iterator over the elements in this collectionjava.util.ListIterator
listIterator()
Returns a list iterator of the elements in this list (in proper sequence).void
mergeRects(int overhead, int lineOverhead)
boolean
remove(java.awt.Rectangle rect)
Removes a single instance of the specified Rectangle from this collection, if it is present.boolean
remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present.boolean
removeAll(java.util.Collection c)
boolean
removeAll(RectListManager rlm)
boolean
retainAll(java.util.Collection c)
boolean
retainAll(RectListManager rlm)
int
size()
Returns the number of elements currently stored in this collection.protected void
splitRect(java.awt.Rectangle r, java.awt.Rectangle sr, java.awt.Rectangle[] splits)
void
subtract(RectListManager rlm, int overhead, int lineOverhead)
java.lang.Object[]
toArray()
java.lang.Object[]
toArray(java.lang.Object[] a)
fill the given array a with values from my internalrects
.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
RectListManager
public RectListManager(java.util.Collection rects)
Construct aRectListManager
from a Collection of Rectangles- Parameters:
rects
- Collection that must only contain rectangles.
-
RectListManager
public RectListManager(java.awt.Rectangle[] rects)
Construct aRectListManager
from an Array ofRectangles
- Parameters:
rects
- Array ofRectangles
, must not contain any null entries.
-
RectListManager
public RectListManager(java.awt.Rectangle[] rects, int off, int sz)
Construct aRectListManager
from an Array ofRectangles
- Parameters:
rects
- Array ofRectangles
, 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 aRectListManager
from anotherRectListManager
(data is copied).- Parameters:
rlm
- RectListManager to copy.
-
RectListManager
public RectListManager(java.awt.Rectangle rect)
Construct aRectListManager
with one rectangle- Parameters:
rect
- The rectangle to put in this rlm.
-
RectListManager
public RectListManager()
Construct an initially emptyRectListManager
.
-
RectListManager
public RectListManager(int capacity)
Construct an initially emptyRectListManager
, with initialcapacity
.- Parameters:
capacity
- The inital capacity for the list. Setting this appropriately can save reallocations.
-
-
Method Detail
-
dump
public void dump()
-
getBounds
public java.awt.Rectangle getBounds()
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
StandardObject
clone method.- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
copy
public RectListManager copy()
Similar to clone only strongly typed TODO Java 5: The use of covariant return types on clone() can eliminate this method.
-
size
public int size()
Returns the number of elements currently stored in this collection.- Specified by:
size
in interfacejava.util.Collection
-
isEmpty
public boolean isEmpty()
Returns true if this collection contains no elements.- Specified by:
isEmpty
in interfacejava.util.Collection
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection
-
iterator
public java.util.Iterator iterator()
Returns an iterator over the elements in this collection- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
-
listIterator
public java.util.ListIterator listIterator()
Returns a list iterator of the elements in this list (in proper sequence).
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
fill the given array a with values from my internalrects
. 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.- Specified by:
toArray
in interfacejava.util.Collection
- Parameters:
a
- array to fill (must not be null!)- Returns:
- the content of rects, either in a[] or a fresh array.
-
add
public boolean add(java.lang.Object o)
- Specified by:
add
in interfacejava.util.Collection
-
add
public void add(java.awt.Rectangle rect)
Ensures that this collection contains the specified element- Parameters:
rect
- The rectangle to add
-
add
protected void add(java.awt.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 addl
- the lowest possible index for a rect with greater 'x' coord.r
- the highest possible index for a rect with greater 'x' coord.
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAll
in interfacejava.util.Collection
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection
-
containsAll
public boolean containsAll(java.util.Collection c)
Returns true if this collection contains all of the elements in the specified collection.- Specified by:
containsAll
in interfacejava.util.Collection
-
containsAll
public boolean containsAll(RectListManager rlm)
-
remove
public boolean remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present.- Specified by:
remove
in interfacejava.util.Collection
- Parameters:
o
- Object to remove an matching instance of.
-
remove
public boolean remove(java.awt.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(java.util.Collection c)
- Specified by:
removeAll
in interfacejava.util.Collection
-
removeAll
public boolean removeAll(RectListManager rlm)
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAll
in interfacejava.util.Collection
-
retainAll
public boolean retainAll(RectListManager rlm)
-
add
public void add(RectListManager rlm)
Adds the contents ofrlm
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.
-
mergeRects
public void mergeRects(int overhead, int lineOverhead)
-
subtract
public void subtract(RectListManager rlm, int overhead, int lineOverhead)
-
splitRect
protected void splitRect(java.awt.Rectangle r, java.awt.Rectangle sr, java.awt.Rectangle[] splits)
-
insertRects
protected void insertRects(java.awt.Rectangle[] rects, int srcPos, int dstPos, int len)
-
ensureCapacity
public void ensureCapacity(int sz)
-
-