Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.awt.geom

Class RectangularShape

java.lang.Object
|
+--java.awt.geom.RectangularShape

All Implemented Interfaces:

Shape, Cloneable


public abstract class RectangularShape

extends Object

implements Shape, Cloneable

This class provides a generic framework, and several helper methods, for subclasses which represent geometric objects inside a rectangular frame. This does not specify any geometry except for the bounding box.

Since:Authors:See Also:

Constructor Summary

RectangularShape()

Default constructor.

Method Summary

java.lang.Objectclone()

Create a new shape of the same run-time type with the same contents as this one.
booleancontains(java.awt.geom.Point2D p)

Tests if a point is inside the boundary of the shape.
booleancontains(java.awt.geom.Rectangle2D r)

Tests if the shape completely contains the given rectangle.
java.awt.RectanglegetBounds()

Returns a bounding box for this shape, in integer format.
doublegetCenterX()

Return the x coordinate of the center point of the framing rectangle.
doublegetCenterY()

Return the y coordinate of the center point of the framing rectangle.
java.awt.geom.Rectangle2DgetFrame()

Return the frame around this object.
doublegetHeight()

Get the height of the framing rectangle.
doublegetMaxX()

Get the maximum x coordinate in the frame.
doublegetMaxY()

Get the maximum y coordinate in the frame.
doublegetMinX()

Get the minimum x coordinate in the frame.
doublegetMinY()

Get the minimum y coordinate in the frame.
java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at, double flatness)

Return an iterator along the shape boundary.
doublegetWidth()

Get the width of the framing rectangle.
doublegetX()

Get the x coordinate of the upper-left corner of the framing rectangle.
doublegetY()

Get the y coordinate of the upper-left corner of the framing rectangle.
booleanintersects(java.awt.geom.Rectangle2D r)

Tests if a rectangle and this shape share common internal points.
booleanisEmpty()

Test if the shape is empty, meaning that no points are inside it.
voidsetFrame(double x, double y, double w, double h)

Set the framing rectangle of this shape to the given coordinate and size.
voidsetFrame(java.awt.geom.Point2D p, java.awt.geom.Dimension2D d)

Set the framing rectangle of this shape to the given coordinate and size.
voidsetFrame(java.awt.geom.Rectangle2D r)

Set the framing rectangle of this shape to the given rectangle.
voidsetFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)

Set the framing rectangle of this shape using the center of the frame, and one of the four corners.
voidsetFrameFromCenter(java.awt.geom.Point2D center, java.awt.geom.Point2D corner)

Set the framing rectangle of this shape using the center of the frame, and one of the four corners.
voidsetFrameFromDiagonal(double x1, double y1, double x2, double y2)

Set the framing rectangle of this shape using two points on a diagonal.
voidsetFrameFromDiagonal(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)

Set the framing rectangle of this shape using two points on a diagonal.

Constructor Details

RectangularShape

protected RectangularShape()

Default constructor.


Method Details

clone

public Object clone()

Create a new shape of the same run-time type with the same contents as this one.

Returns:


contains

public boolean contains(java.awt.geom.Point2D p)

Tests if a point is inside the boundary of the shape.

Parameters:

Returns:

Throws:

See Also:


contains

public boolean contains(java.awt.geom.Rectangle2D r)

Tests if the shape completely contains the given rectangle.

Parameters:

Returns:

Throws:

See Also:


getBounds

public Rectangle getBounds()

Returns a bounding box for this shape, in integer format. Notice that you may get a tighter bound with getBounds2D. If the frame is empty, the box is the default empty box at the origin.

Returns:


getCenterX

public double getCenterX()

Return the x coordinate of the center point of the framing rectangle.

Returns:


getCenterY

public double getCenterY()

Return the y coordinate of the center point of the framing rectangle.

Returns:


getFrame

public Rectangle2D getFrame()

Return the frame around this object. Note that this may be a looser bounding box than getBounds2D.

Returns:

See Also:


getHeight

public double getHeight()

Get the height of the framing rectangle.

Returns:


getMaxX

public double getMaxX()

Get the maximum x coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getX()+getWidth() even when getWidth() is negative.

Returns:


getMaxY

public double getMaxY()

Get the maximum y coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getY()+getHeight() even when getHeight() is negative.

Returns:


getMinX

public double getMinX()

Get the minimum x coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getX() even when getWidth() is negative.

Returns:


getMinY

public double getMinY()

Get the minimum y coordinate in the frame. This is misnamed, or else Sun has a bug, because the implementation returns getY() even when getHeight() is negative.

Returns:


getPathIterator

public PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)

Return an iterator along the shape boundary. If the optional transform is provided, the iterator is transformed accordingly. The path is flattened until all segments differ from the curve by at most the value of the flatness parameter, within the limits of the default interpolation recursion limit of 1024 segments between actual points. Each call returns a new object, independent from others in use. The result is threadsafe if and only if the iterator returned by #getPathIterator(AffineTransform) is as well.

Since:Parameters:

Returns:

Throws:


getWidth

public double getWidth()

Get the width of the framing rectangle.

Returns:


getX

public double getX()

Get the x coordinate of the upper-left corner of the framing rectangle.

Returns:


getY

public double getY()

Get the y coordinate of the upper-left corner of the framing rectangle.

Returns:


intersects

public boolean intersects(java.awt.geom.Rectangle2D r)

Tests if a rectangle and this shape share common internal points.

Parameters:

Returns:

Throws:

See Also:


isEmpty

public boolean isEmpty()

Test if the shape is empty, meaning that no points are inside it.

Returns:


setFrame

public void setFrame(double x, double y, double w, double h)

Set the framing rectangle of this shape to the given coordinate and size.

Parameters:

See Also:


setFrame

public void setFrame(java.awt.geom.Point2D p, java.awt.geom.Dimension2D d)

Set the framing rectangle of this shape to the given coordinate and size.

Parameters:

Throws:

See Also:


setFrame

public void setFrame(java.awt.geom.Rectangle2D r)

Set the framing rectangle of this shape to the given rectangle.

Parameters:

Throws:

See Also:


setFrameFromCenter

public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)

Set the framing rectangle of this shape using the center of the frame, and one of the four corners. The area will be positive.

Parameters:


setFrameFromCenter

public void setFrameFromCenter(java.awt.geom.Point2D center, java.awt.geom.Point2D corner)

Set the framing rectangle of this shape using the center of the frame, and one of the four corners. The area will be positive.

Parameters:

Throws:


setFrameFromDiagonal

public void setFrameFromDiagonal(double x1, double y1, double x2, double y2)

Set the framing rectangle of this shape using two points on a diagonal. The area will be positive.

Parameters:


setFrameFromDiagonal

public void setFrameFromDiagonal(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)

Set the framing rectangle of this shape using two points on a diagonal. The area will be positive.

Parameters:

Throws: