FileDocCategorySizeDatePackage
RectangularShape.javaAPI DocAndroid 1.5 API9175Wed May 06 22:41:54 BST 2009java.awt.geom

RectangularShape

public abstract class RectangularShape extends Object implements Shape, Cloneable
The Class RectangularShape represents a Shape whose data is (at least partially) described by a rectangular frame. This includes shapes which are obviously rectangular (such as Rectangle2D) as well as shapes like Arc2D which are largely determined by the rectangle they fit inside.
since
Android 1.0

Fields Summary
Constructors Summary
protected RectangularShape()
Instantiates a new rectangular shape.

    
Methods Summary
public java.lang.Objectclone()

        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new InternalError();
        }
    
public booleancontains(java.awt.geom.Point2D point)

        return contains(point.getX(), point.getY());
    
public booleancontains(java.awt.geom.Rectangle2D rect)

        return contains(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    
public java.awt.RectanglegetBounds()

        int x1 = (int)Math.floor(getMinX());
        int y1 = (int)Math.floor(getMinY());
        int x2 = (int)Math.ceil(getMaxX());
        int y2 = (int)Math.ceil(getMaxY());
        return new Rectangle(x1, y1, x2 - x1, y2 - y1);
    
public doublegetCenterX()
Gets the x coordinate of the center of the rectangle.

return
the x coordinate of the center of the rectangle.

        return getX() + getWidth() / 2.0;
    
public doublegetCenterY()
Gets the y coordinate of the center of the rectangle.

return
the y coordinate of the center of the rectangle.

        return getY() + getHeight() / 2.0;
    
public java.awt.geom.Rectangle2DgetFrame()
Places the rectangle's size and location data in a new Rectangle2D object and returns it.

return
the bounding rectangle as a new Rectangle2D object.

        return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
    
public abstract doublegetHeight()
Gets the height of the rectangle.

return
the height of the rectangle.

public doublegetMaxX()
Gets the maximum x value of the bounding rectangle (the x coordinate of the upper left corner of the rectangle plus the rectangle's width).

return
the maximum x value of the bounding rectangle.

        return getX() + getWidth();
    
public doublegetMaxY()
Gets the maximum y value of the bounding rectangle (the y coordinate of the upper left corner of the rectangle plus the rectangle's height).

return
the maximum y value of the bounding rectangle.

        return getY() + getHeight();
    
public doublegetMinX()
Gets the minimum x value of the bounding rectangle (the x coordinate of the upper left corner of the rectangle).

return
the minimum x value of the bounding rectangle.

        return getX();
    
public doublegetMinY()
Gets the minimum y value of the bounding rectangle (the y coordinate of the upper left corner of the rectangle).

return
the minimum y value of the bounding rectangle.

        return getY();
    
public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform t, double flatness)

        return new FlatteningPathIterator(getPathIterator(t), flatness);
    
public abstract doublegetWidth()
Gets the width of the rectangle.

return
the width of the rectangle.

public abstract doublegetX()
Gets the x coordinate of the upper left corner of the rectangle.

return
the x coordinate of the upper left corner of the rectangle.

public abstract doublegetY()
Gets the y coordinate of the upper left corner of the rectangle.

return
the y coordinate of the upper left corner of the rectangle.

public booleanintersects(java.awt.geom.Rectangle2D rect)

        return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    
public abstract booleanisEmpty()
Checks if this is an empty rectangle: one with zero as its width or height.

return
true, if the width or height is empty.

public voidsetFrame(java.awt.geom.Point2D loc, java.awt.geom.Dimension2D size)
Sets the bounding rectangle in terms of a Point2D which gives its upper left corner and a Dimension2D object giving its width and height.

param
loc the new upper left corner coordinate.
param
size the new size dimensions.

        setFrame(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
    
public voidsetFrame(java.awt.geom.Rectangle2D r)
Sets the bounding rectangle to match the data contained in the specified Rectangle2D.

param
r the rectangle that gives the new frame data.

        setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public abstract voidsetFrame(double x, double y, double w, double h)
Sets the data for the bounding rectangle in terms of double values.

param
x the x coordinate of the upper left corner of the rectangle.
param
y the y coordinate of the upper left corner of the rectangle.
param
w the width of the rectangle.
param
h the height of the rectangle.

public voidsetFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)
Sets the framing rectangle given the center point and one corner. Any corner may be used.

param
centerX the x coordinate of the center point.
param
centerY the y coordinate of the center point.
param
cornerX the x coordinate of one of the corner points.
param
cornerY the y coordinate of one of the corner points.

        double width = Math.abs(cornerX - centerX);
        double height = Math.abs(cornerY - centerY);
        setFrame(centerX - width, centerY - height, width * 2.0, height * 2.0);
    
public voidsetFrameFromCenter(java.awt.geom.Point2D center, java.awt.geom.Point2D corner)
Sets the framing rectangle given the center point and one corner. Any corner may be used.

param
center the center point.
param
corner a corner point.

        setFrameFromCenter(center.getX(), center.getY(), corner.getX(), corner.getY());
    
public voidsetFrameFromDiagonal(double x1, double y1, double x2, double y2)
Sets the framing rectangle given two opposite corners. Any two corners may be used in any order as long as they are diagonally opposite one another.

param
x1 the x coordinate of one of the corner points.
param
y1 the y coordinate of one of the corner points.
param
x2 the x coordinate of the other corner point.
param
y2 the y coordinate of the other corner point.

        double rx, ry, rw, rh;
        if (x1 < x2) {
            rx = x1;
            rw = x2 - x1;
        } else {
            rx = x2;
            rw = x1 - x2;
        }
        if (y1 < y2) {
            ry = y1;
            rh = y2 - y1;
        } else {
            ry = y2;
            rh = y1 - y2;
        }
        setFrame(rx, ry, rw, rh);
    
public voidsetFrameFromDiagonal(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Sets the framing rectangle given two opposite corners. Any two corners may be used in any order as long as they are diagonally opposite one another.

param
p1 one of the corner points.
param
p2 the other corner point.

        setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY());