APIdia Launch Partner
Top Description Constructors Methods
java.awt.geom

public abstract Class RectangularShape

extends Object
implements Shape, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.awt.Shape
Known Direct Subclasses
java.awt.geom.RoundRectangle2D, com.sun.java.swing.plaf.gtk.Metacity.RoundRectClipShape, java.awt.geom.Arc2D, java.awt.geom.Ellipse2D, java.awt.geom.Rectangle2D
Imports
java.awt.Shape, .Rectangle, java.beans.Transient

RectangularShape is the base class for a number of 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.
Author
Jim Graham
Since
1.2

Constructor Summary

AccessConstructor and Description
protected
RectangularShape()

This is an abstract class that cannot be instantiated directly.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a clone of this instance.
clone
()

Overrides java.lang.Object.clone.

Creates a new object of the same class and with the same contents as this object.

public boolean
contains(Point2D p)

Implements java.awt.Shape.contains.

Tests if a specified Point2D is inside the boundary of the Shape, as described by the definition of insideness.

public boolean
contains(Rectangle2D r)

Implements java.awt.Shape.contains.

Tests if the interior of the Shape entirely contains the specified Rectangle2D.

public Rectangle
getBounds()

Implements java.awt.Shape.getBounds.

Returns an integer Rectangle that completely encloses the Shape.

public double

Returns:

the X coordinate of the center of the framing rectangle of the Shape.
getCenterX
()

Returns the X coordinate of the center of the framing rectangle of the Shape in double precision.

public double

Returns:

the Y coordinate of the center of the framing rectangle of the Shape.
getCenterY
()

Returns the Y coordinate of the center of the framing rectangle of the Shape in double precision.

public Rectangle2D

Returns:

a Rectangle2D, specified in double coordinates.
getFrame
()

Returns the framing Rectangle2D that defines the overall shape of this object.

public abstract double

Returns:

the height of the framing rectangle.
getHeight
()

Returns the height of the framing rectangle in double precision.

public double

Returns:

the largest X coordinate of the framing rectangle of the Shape.
getMaxX
()

Returns the largest X coordinate of the framing rectangle of the Shape in double precision.

public double

Returns:

the largest Y coordinate of the framing rectangle of the Shape.
getMaxY
()

Returns the largest Y coordinate of the framing rectangle of the Shape in double precision.

public double

Returns:

the smallest X coordinate of the framing rectangle of the Shape.
getMinX
()

Returns the smallest X coordinate of the framing rectangle of the Shape in double precision.

public double

Returns:

the smallest Y coordinate of the framing rectangle of the Shape.
getMinY
()

Returns the smallest Y coordinate of the framing rectangle of the Shape in double precision.

public PathIterator

Returns:

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

Implements java.awt.Shape.getPathIterator.

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.

public abstract double

Returns:

the width of the framing rectangle.
getWidth
()

Returns the width of the framing rectangle in double precision.

public abstract double

Returns:

the X coordinate of the upper-left corner of the framing rectangle.
getX
()

Returns the X coordinate of the upper-left corner of the framing rectangle in double precision.

public abstract double

Returns:

the Y coordinate of the upper-left corner of the framing rectangle.
getY
()

Returns the Y coordinate of the upper-left corner of the framing rectangle in double precision.

public boolean
intersects(Rectangle2D r)

Implements java.awt.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified Rectangle2D.

public abstract boolean

Returns:

true if the RectangularShape is empty; false otherwise.
isEmpty
()

Determines whether the RectangularShape is empty.

public abstract void
setFrame(double
the X coordinate of the upper-left corner of the specified rectangular shape
x
,
double
the Y coordinate of the upper-left corner of the specified rectangular shape
y
,
double
the width of the specified rectangular shape
w
,
double
the height of the specified rectangular shape
h
)

Sets the location and size of the framing rectangle of this Shape to the specified rectangular values.

public void
setFrame(Point2D
the specified Point2D
loc
,
Dimension2D
the specified Dimension2D
size
)

Sets the location and size of the framing rectangle of this Shape to the specified Point2D and Dimension2D, respectively.

public void
setFrame(Rectangle2D
the specified Rectangle2D
r
)

Sets the framing rectangle of this Shape to be the specified Rectangle2D.

public void
setFrameFromCenter(double
the X coordinate of the specified center point
centerX
,
double
the Y coordinate of the specified center point
centerY
,
double
the X coordinate of the specified corner point
cornerX
,
double
the Y coordinate of the specified corner point
cornerY
)

Sets the framing rectangle of this Shape based on the specified center point coordinates and corner point coordinates.

public void
setFrameFromCenter(Point2D
the specified center Point2D
center
,
Point2D
the specified corner Point2D
corner
)

Sets the framing rectangle of this Shape based on a specified center Point2D and corner Point2D.

public void
setFrameFromDiagonal(double
the X coordinate of the start point of the specified diagonal
x1
,
double
the Y coordinate of the start point of the specified diagonal
y1
,
double
the X coordinate of the end point of the specified diagonal
x2
,
double
the Y coordinate of the end point of the specified diagonal
y2
)

Sets the diagonal of the framing rectangle of this Shape based on the two specified coordinates.

public void
setFrameFromDiagonal(Point2D
the start Point2D of the specified diagonal
p1
,
Point2D
the end Point2D of the specified diagonal
p2
)

Sets the diagonal of the framing rectangle of this Shape based on two specified Point2D objects.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RectangularShapeback to summary
protected RectangularShape()

This is an abstract class that cannot be instantiated directly.

Since
1.2
See Also
Arc2D, Ellipse2D, Rectangle2D, RoundRectangle2D

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Creates a new object of the same class and with the same contents as this object.

Returns:Object

a clone of this instance.

Exceptions
OutOfMemoryError:
if there is not enough memory.
Since
1.2
See Also
java.lang.Cloneable
containsback to summary
public boolean contains(Point2D p)

Implements java.awt.Shape.contains.

Doc from java.awt.Shape.contains.

Tests if a specified Point2D is inside the boundary of the Shape, as described by the definition of insideness.

Since
1.2
containsback to summary
public boolean contains(Rectangle2D r)

Implements java.awt.Shape.contains.

Doc from java.awt.Shape.contains.

Tests if the interior of the Shape entirely contains the specified Rectangle2D. The Shape.contains() method allows a Shape implementation to conservatively return false when:

  • the intersect method returns true and
  • the calculations to determine whether or not the Shape entirely contains the Rectangle2D are prohibitively expensive.
This means that for some Shapes this method might return false even though the Shape contains the Rectangle2D. The Area class performs more accurate geometric computations than most Shape objects and therefore can be used if a more precise answer is required.
Since
1.2
getBoundsback to summary
public Rectangle getBounds()

Implements java.awt.Shape.getBounds.

Doc from java.awt.Shape.getBounds.

Returns an integer Rectangle that completely encloses the Shape. Note that there is no guarantee that the returned Rectangle is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle. The returned Rectangle might also fail to completely enclose the Shape if the Shape overflows the limited range of the integer data type. The getBounds2D method generally returns a tighter bounding box due to its greater flexibility in representation.

Note that the definition of insideness can lead to situations where points on the defining outline of the shape may not be considered contained in the returned bounds object, but only in cases where those points are also not considered contained in the original shape.

If a point is inside the shape according to the contains(point) method, then it must be inside the returned Rectangle bounds object according to the contains(point) method of the bounds. Specifically:

shape.contains(x,y) requires bounds.contains(x,y)

If a point is not inside the shape, then it might still be contained in the bounds object:

bounds.contains(x,y) does not imply shape.contains(x,y)

Since
1.2
getCenterXback to summary
public double getCenterX()

Returns the X coordinate of the center of the framing rectangle of the Shape in double precision.

Returns:double

the X coordinate of the center of the framing rectangle of the Shape.

Since
1.2
getCenterYback to summary
public double getCenterY()

Returns the Y coordinate of the center of the framing rectangle of the Shape in double precision.

Returns:double

the Y coordinate of the center of the framing rectangle of the Shape.

Since
1.2
getFrameback to summary
public Rectangle2D getFrame()

Returns the framing Rectangle2D that defines the overall shape of this object.

Returns:Rectangle2D

a Rectangle2D, specified in double coordinates.

Annotations
@Transient
Since
1.2
See Also
setFrame(double, double, double, double), setFrame(Point2D, Dimension2D), setFrame(Rectangle2D)
getHeightback to summary
public abstract double getHeight()

Returns the height of the framing rectangle in double precision.

Returns:double

the height of the framing rectangle.

Since
1.2
getMaxXback to summary
public double getMaxX()

Returns the largest X coordinate of the framing rectangle of the Shape in double precision.

Returns:double

the largest X coordinate of the framing rectangle of the Shape.

Since
1.2
getMaxYback to summary
public double getMaxY()

Returns the largest Y coordinate of the framing rectangle of the Shape in double precision.

Returns:double

the largest Y coordinate of the framing rectangle of the Shape.

Since
1.2
getMinXback to summary
public double getMinX()

Returns the smallest X coordinate of the framing rectangle of the Shape in double precision.

Returns:double

the smallest X coordinate of the framing rectangle of the Shape.

Since
1.2
getMinYback to summary
public double getMinY()

Returns the smallest Y coordinate of the framing rectangle of the Shape in double precision.

Returns:double

the smallest Y coordinate of the framing rectangle of the Shape.

Since
1.2
getPathIteratorback to summary
public PathIterator getPathIterator(AffineTransform at, double flatness)

Implements java.awt.Shape.getPathIterator.

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 AffineTransform can be specified so that the coordinates returned in the iteration are transformed accordingly.

Parameters
at:AffineTransform

an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired.

flatness:double

the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve

Returns:PathIterator

a PathIterator object that provides access to the Shape object's flattened geometry.

Since
1.2
getWidthback to summary
public abstract double getWidth()

Returns the width of the framing rectangle in double precision.

Returns:double

the width of the framing rectangle.

Since
1.2
getXback to summary
public abstract double getX()

Returns the X coordinate of the upper-left corner of the framing rectangle in double precision.

Returns:double

the X coordinate of the upper-left corner of the framing rectangle.

Since
1.2
getYback to summary
public abstract double getY()

Returns the Y coordinate of the upper-left corner of the framing rectangle in double precision.

Returns:double

the Y coordinate of the upper-left corner of the framing rectangle.

Since
1.2
intersectsback to summary
public boolean intersects(Rectangle2D r)

Implements java.awt.Shape.intersects.

Doc from java.awt.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified Rectangle2D. The Shape.intersects() method allows a Shape implementation to conservatively return true when:

  • there is a high probability that the Rectangle2D and the Shape intersect, but
  • the calculations to accurately determine this intersection are prohibitively expensive.
This means that for some Shapes this method might return true even though the Rectangle2D does not intersect the Shape. The Area class performs more accurate computations of geometric intersection than most Shape objects and therefore can be used if a more precise answer is required.
Since
1.2
isEmptyback to summary
public abstract boolean isEmpty()

Determines whether the RectangularShape is empty. When the RectangularShape is empty, it encloses no area.

Returns:boolean

true if the RectangularShape is empty; false otherwise.

Since
1.2
setFrameback to summary
public abstract void setFrame(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.

Parameters
x:double

the X coordinate of the upper-left corner of the specified rectangular shape

y:double

the Y coordinate of the upper-left corner of the specified rectangular shape

w:double

the width of the specified rectangular shape

h:double

the height of the specified rectangular shape

Since
1.2
See Also
getFrame
setFrameback to summary
public void setFrame(Point2D loc, Dimension2D size)

Sets the location and size of the framing rectangle of this Shape to the specified Point2D and Dimension2D, respectively. The framing rectangle is used by the subclasses of RectangularShape to define their geometry.

Parameters
loc:Point2D

the specified Point2D

size:Dimension2D

the specified Dimension2D

Since
1.2
See Also
getFrame
setFrameback to summary
public void setFrame(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.

Parameters
r:Rectangle2D

the specified Rectangle2D

Since
1.2
See Also
getFrame
setFrameFromCenterback to summary
public void setFrameFromCenter(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.

Parameters
centerX:double

the X coordinate of the specified center point

centerY:double

the Y coordinate of the specified center point

cornerX:double

the X coordinate of the specified corner point

cornerY:double

the Y coordinate of the specified corner point

Since
1.2
setFrameFromCenterback to summary
public void setFrameFromCenter(Point2D center, 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.

Parameters
center:Point2D

the specified center Point2D

corner:Point2D

the specified corner Point2D

Since
1.2
setFrameFromDiagonalback to summary
public void setFrameFromDiagonal(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.

Parameters
x1:double

the X coordinate of the start point of the specified diagonal

y1:double

the Y coordinate of the start point of the specified diagonal

x2:double

the X coordinate of the end point of the specified diagonal

y2:double

the Y coordinate of the end point of the specified diagonal

Since
1.2
setFrameFromDiagonalback to summary
public void setFrameFromDiagonal(Point2D p1, 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.

Parameters
p1:Point2D

the start Point2D of the specified diagonal

p2:Point2D

the end Point2D of the specified diagonal

Since
1.2