Java Utililty Methods Rectangle

List of utility methods to do Rectangle

Description

The list of methods to do Rectangle are organized into topic(s).

Method

StringformatRect(Rectangle rc)
format Rect
return Integer.toString(rc.x) + "," + Integer.toString(rc.y) + "," + Integer.toString(rc.width) + ","
        + Integer.toString(rc.height);
StringformatRectangle(Rectangle rect)
format Rectangle
if (rect == null) {
    return "";
return RECTANGLE_FORMAT.format(new Object[] { rect.x, rect.y, rect.width, rect.height });
RectanglegetAbsoluteRectangle(Rectangle rect)
if rectangle has negative width or height, convert to equivalent rectangle with posititve width or height, else don't do anything
if (rect == null)
    return null;
Rectangle r = new Rectangle(rect);
if (r.width < 0) {
    r.width = -r.width;
    r.x = r.x - r.width;
if (r.height < 0) {
...
Rectangle[]getFrameOrientations(Rectangle parent)
Counts the possible orientations realtive to the parent's frame rectangle.
return new Rectangle[] { new Rectangle(parent.x + parent.width, parent.y, MIN_WIDTH, parent.height),
        new Rectangle(parent.x - MIN_WIDTH, parent.y, MIN_WIDTH, parent.height),
        new Rectangle(parent.x, parent.y + parent.height, parent.width, MIN_HEIGH),
        new Rectangle(parent.x, parent.y - MIN_HEIGH, parent.width, MIN_HEIGH) };
RectanglegetMaximalRectangle(Rectangle r1, Rectangle r2)
get Maximal Rectangle
int x0 = Math.min(r1.x, r2.x);
int y0 = Math.min(r1.y, r2.y);
int w = Math.max(r1.x + r1.width, r2.x + r2.width) - x0;
int h = Math.max(r1.y + r1.height, r2.y + r2.height) - y0;
return new Rectangle(x0, y0, w, h);
java.awt.RectanglegetRect(byte[] data, int i)
Gets a rectangle out of an array of bytes.
return new java.awt.Rectangle(getShort(data, i + 2), getShort(data, i + 0),
        getShort(data, i + 6) - getShort(data, i + 2), getShort(data, i + 4) - getShort(data, i + 0));
RectanglegetRectangleProperty(Map p, Object key, Rectangle defaultValue)
calling this is not thread safe
Object value = p.get(key);
if (value instanceof Rectangle)
    return (Rectangle) value;
else if (value instanceof String) {
    Rectangle r = parseRectangle((String) value);
    if (r != null)
        return r;
return defaultValue;
java.awt.RectanglegetRectLE(byte[] data, int i)
Gets a rectangle out of an array of bytes.
return new java.awt.Rectangle(getShortLE(data, i + 2), getShortLE(data, i + 0),
        getShortLE(data, i + 6) - getShortLE(data, i + 2),
        getShortLE(data, i + 4) - getShortLE(data, i + 0));
RectanglegetSubArea(Shape retangulo, int divisorx, int divisory, int offsetx, int offsety)
get Sub Area
double w = retangulo.getBounds().getWidth() / divisorx;
double h = retangulo.getBounds().getHeight() / divisory;
double x = retangulo.getBounds().getX() + (w * offsetx);
double y = retangulo.getBounds().getY() + (h * offsety);
Rectangle subRetangulo = new Rectangle((int) x, (int) y, (int) w, (int) h);
return subRetangulo;
voidinflateRectangle(Rectangle r, int x, int y)
Inflates the rectangle by the specified x/y value.
r.x -= x;
r.y -= y;
r.width += 2 * x;
r.height += 2 * y;