FileDocCategorySizeDatePackage
RectangularShape.javaAPI DocJava SE 5 API12804Fri Aug 26 14:56:52 BST 2005java.awt.geom

RectangularShape

public abstract class RectangularShape extends Object implements Shape, Cloneable
RectangularShape is the base class for a number of {@link Shape} objects whose geometry is defined by a rectangular frame. This class does not directly specify any specific geometry by itself, but merely provides manipulation methods inherited by a whole category of Shape objects. The manipulation methods provided by this class can be used to query and modify the rectangular frame, which provides a reference for the subclasses to define their geometry.
version
1.18, 12/19/03
author
Jim Graham

Fields Summary
Constructors Summary
protected RectangularShape()
This is an abstract class that cannot be instantiated directly.

see
Arc2D
see
Ellipse2D
see
Rectangle2D
see
RoundRectangle2D

    
Methods Summary
public java.lang.Objectclone()
Creates a new object of the same class and with the same contents as this object.

return
a clone of this instance.
exception
OutOfMemoryError if there is not enough memory.
see
java.lang.Cloneable
since
1.2

	try {
	    return super.clone();
	} catch (CloneNotSupportedException e) {
	    // this shouldn't happen, since we are Cloneable
	    throw new InternalError();
	}
    
public booleancontains(java.awt.geom.Point2D p)
Tests if a specified Point2D is inside the boundary of the Shape.

param
p the specified Point2D
return
true if the Point2D is inside the Shape object's boundary; false otherwise.

	return contains(p.getX(), p.getY());
    
public booleancontains(java.awt.geom.Rectangle2D r)
Tests if the interior of the Shape entirely contains the specified Rectangle2D.

param
r the specified Rectangle2D
return
true if the Shape entirely contains the specified Rectangle2D; false otherwise.

	return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public java.awt.RectanglegetBounds()
Returns the bounding box of the Shape.

return
a {@link Rectangle} object that bounds the Shape.

	double width = getWidth();
	double height = getHeight();
	if (width < 0 || height < 0) {
	    return new Rectangle();
	}
	double x = getX();
	double y = getY();
	double x1 = Math.floor(x);
	double y1 = Math.floor(y);
	double x2 = Math.ceil(x + width);
	double y2 = Math.ceil(y + height);
	return new Rectangle((int) x1, (int) y1,
				      (int) (x2 - x1), (int) (y2 - y1));
    
public doublegetCenterX()
Returns the X coordinate of the center of the framing rectangle of the Shape in double precision.

return
the x coordinate of the framing rectangle of the Shape object's center.

	return getX() + getWidth() / 2.0;
    
public doublegetCenterY()
Returns the Y coordinate of the center of the framing rectangle of the Shape in double precision.

return
the y coordinate of the framing rectangle of the Shape object's center.

	return getY() + getHeight() / 2.0;
    
public java.awt.geom.Rectangle2DgetFrame()
Returns the framing {@link Rectangle2D} that defines the overall shape of this object.

return
a Rectangle2D, specified in double coordinates.
see
#setFrame(double, double, double, double)
see
#setFrame(Point2D, Dimension2D)
see
#setFrame(Rectangle2D)

	return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
    
public abstract doublegetHeight()
Returns the height of the framing rectangle in double precision.

return
the height of the framing rectangle.

public doublegetMaxX()
Returns the largest X coordinate of the framing rectangle of the Shape in double precision.

return
the largest x coordinate of the framing rectangle of the Shape.

	return getX() + getWidth();
    
public doublegetMaxY()
Returns the largest Y coordinate of the framing rectangle of the Shape in double precision.

return
the largest y coordinate of the framing rectangle of the Shape.

	return getY() + getHeight();
    
public doublegetMinX()
Returns the smallest X coordinate of the framing rectangle of the Shape in double precision.

return
the smallest x coordinate of the framing rectangle of the Shape.

	return getX();
    
public doublegetMinY()
Returns the smallest Y coordinate of the framing rectangle of the Shape in double precision.

return
the smallest y coordinate of the framing rectangle of the Shape.

	return getY();
    
public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)
Returns an iterator object that iterates along the Shape object's boundary and provides access to a flattened view of the outline of the Shape object's geometry.

Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types will be returned by the iterator.

The amount of subdivision of the curved segments is controlled by the flatness parameter, which specifies the maximum distance that any point on the unflattened transformed curve can deviate from the returned flattened path segments. An optional {@link AffineTransform} can be specified so that the coordinates returned in the iteration are transformed accordingly.

param
at an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired.
param
flatness the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve
return
a PathIterator object that provides access to the Shape object's flattened geometry.

	return new FlatteningPathIterator(getPathIterator(at), flatness);
    
public abstract doublegetWidth()
Returns the width of the framing rectangle in double precision.

return
the width of the framing rectangle.

public abstract doublegetX()
Returns the X coordinate of the upper left corner of the framing rectangle in double precision.

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

public abstract doublegetY()
Returns the Y coordinate of the upper left corner of the framing rectangle in double precision.

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

public booleanintersects(java.awt.geom.Rectangle2D r)
Tests if the interior of theShape intersects the interior of a specified Rectangle2D.

param
r the specified Rectangle2D
return
true if the Shape and the specified Rectangle2D intersect each other; false otherwise.

	return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public abstract booleanisEmpty()
Determines whether the RectangularShape is empty. When the RectangularShape is empty, it encloses no area.

return
true if the RectangularShape is empty; false otherwise.

public abstract voidsetFrame(double x, double y, double w, double h)
Sets the location and size of the framing rectangle of this Shape to the specified rectangular values. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
x, y the coordinates of the upper-left corner of the specified rectangular shape
param
w the width of the specified rectangular shape
param
h the height of the specified rectangular shape
see
#getFrame

public voidsetFrame(java.awt.geom.Point2D loc, java.awt.geom.Dimension2D size)
Sets the location and size of the framing rectangle of this Shape to the specified {@link Point2D} and {@link Dimension2D}, respectively. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
loc the specified Point2D
param
size the specified Dimension2D
see
#getFrame

	setFrame(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
    
public voidsetFrame(java.awt.geom.Rectangle2D r)
Sets the framing rectangle of this Shape to be the specified Rectangle2D. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
r the specified Rectangle2D
see
#getFrame

	setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    
public voidsetFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)
Sets the framing rectangle of this Shape based on the specified center point coordinates and corner point coordinates. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
centerX, centerY the center point coordinates
param
cornerX, cornerY the corner point coordinates

	double halfW = Math.abs(cornerX - centerX);
	double halfH = Math.abs(cornerY - centerY);
	setFrame(centerX - halfW, centerY - halfH, halfW * 2.0, halfH * 2.0);
    
public voidsetFrameFromCenter(java.awt.geom.Point2D center, java.awt.geom.Point2D corner)
Sets the framing rectangle of this Shape based on a specified center Point2D and corner Point2D. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
center the specified center Point2D
param
corner the specified corner Point2D

	setFrameFromCenter(center.getX(), center.getY(),
			   corner.getX(), corner.getY());
    
public voidsetFrameFromDiagonal(double x1, double y1, double x2, double y2)
Sets the diagonal of the framing rectangle of this Shape based on the two specified coordinates. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
x1, y1 the first specified coordinates
param
x2, y2 the second specified coordinates

	if (x2 < x1) {
	    double t = x1;
	    x1 = x2;
	    x2 = t;
	}
	if (y2 < y1) {
	    double t = y1;
	    y1 = y2;
	    y2 = t;
	}
	setFrame(x1, y1, x2 - x1, y2 - y1);
    
public voidsetFrameFromDiagonal(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Sets the diagonal of the framing rectangle of this Shape based on two specified Point2D objects. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

param
p1, p2 the two specified Point2D objects

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