Methods Summary |
---|
public void | addRectangle(java.awt.Rectangle r)Adds a rectangle to the region. This method checks for intersecting
rectangles and merges them into one.
Rectangle current;
int position = 0;
while (position < rects.size())
{
current = (Rectangle)rects.elementAt(position);
// First check to see if the current rectangle
// already includes the new one
if ((r.x > current.x) && (r.y > current.y) &&
(right(r) <= right(current)) &&
(bottom(r) <= bottom(current)))
return;
if (r.intersects(current))
{
r = r.union(current);
rects.removeElementAt(position);
} else {
position++;
}
}
// Add it to the end of the list
rects.addElement(r);
|
public void | addRegion(com.sun.media.ui.Region r)Adds a region r to the current region.
for (Enumeration e = r.rectangles(); e.hasMoreElements(); )
{
addRectangle((Rectangle)e.nextElement());
}
|
public static int | bottom(java.awt.Rectangle r)Returns the y-coordinate of the bottom edge of a rectangle.
return r.y + r.height - 1;
|
public java.lang.Object | clone()Returns a clone of the region.
Region r = new Region();
r.rects = (Vector)rects.clone();
return r;
|
public java.awt.Rectangle | getBounds()
Rectangle r = new Rectangle();
for (int i = 0; i < rects.size(); i++) {
r = r.union((Rectangle)rects.elementAt(i));
}
return r;
|
public int | getNumRectangles()
return rects.size();
|
public void | intersect(java.awt.Rectangle r)Intersects all the rectangles in the region with rectangle r
and throws away any that dont intersect.
Rectangle rect;
int position = 0;
while (position < rects.size()) {
rect = (Rectangle)rects.elementAt(position);
rect = rect.intersection(r);
if (rect.isEmpty()) {
rects.removeElementAt(position);
} else {
rects.setElementAt(rect, position);
position++;
}
}
|
public boolean | intersects(java.awt.Rectangle r)Checks if the rectangle r intersects any of the rectangles
in the region.
Rectangle rect;
int position = 0;
while (position < rects.size()) {
rect = (Rectangle)rects.elementAt(position);
if (rect.intersects(r)) {
return true;
}
position++;
}
return false;
|
public boolean | isEmpty()Returns true if the region contains no rectangles.
return rects.isEmpty();
|
public java.util.Enumeration | rectangles()Returns an Enumeration of the list of rectangles.
return rects.elements();
|
public static int | right(java.awt.Rectangle r)Returns the x-coordinate of the right edge of a rectangle.
return r.x + r.width - 1;
|
public java.lang.String | toString()Converts the list of rectangles to a displayable string.
String s = getClass().getName() + " = [\n";
for (Enumeration e = rectangles(); e.hasMoreElements(); )
{
s += "(" + (Rectangle)e.nextElement() + ")\n";
}
return s + "]";
|
public void | translate(int dx, int dy)Translates all rectangles in the region by (dx,dy).
Rectangle r;
for (int p = 0; p < rects.size(); p++) {
r = (Rectangle)rects.elementAt(p);
r.translate(dx, dy);
}
|