Class RectangularShape
- Direct Known Subclasses:
Arc2D,Ellipse2D,Rectangle2D,RoundRectangle2D
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.- Since:
- 1.2
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThis is an abstract class that cannot be instantiated directly. -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a new object of the same class and with the same contents as this object.booleanTests if a specifiedPoint2Dis inside the boundary of theShape, as described by the definition of insideness.booleanTests if the interior of theShapeentirely contains the specifiedRectangle2D.Returns an integerRectanglethat completely encloses theShape.doubleReturns the X coordinate of the center of the framing rectangle of theShapeindoubleprecision.doubleReturns the Y coordinate of the center of the framing rectangle of theShapeindoubleprecision.getFrame()Returns the framingRectangle2Dthat defines the overall shape of this object.abstract doubleReturns the height of the framing rectangle indoubleprecision.doublegetMaxX()Returns the largest X coordinate of the framing rectangle of theShapeindoubleprecision.doublegetMaxY()Returns the largest Y coordinate of the framing rectangle of theShapeindoubleprecision.doublegetMinX()Returns the smallest X coordinate of the framing rectangle of theShapeindoubleprecision.doublegetMinY()Returns the smallest Y coordinate of the framing rectangle of theShapeindoubleprecision.getPathIterator(AffineTransform at, double flatness) Returns an iterator object that iterates along theShapeobject's boundary and provides access to a flattened view of the outline of theShapeobject's geometry.abstract doublegetWidth()Returns the width of the framing rectangle indoubleprecision.abstract doublegetX()Returns the X coordinate of the upper-left corner of the framing rectangle indoubleprecision.abstract doublegetY()Returns the Y coordinate of the upper-left corner of the framing rectangle indoubleprecision.booleanTests if the interior of theShapeintersects the interior of a specifiedRectangle2D.abstract booleanisEmpty()Determines whether theRectangularShapeis empty.abstract voidsetFrame(double x, double y, double w, double h) Sets the location and size of the framing rectangle of thisShapeto the specified rectangular values.voidsetFrame(Point2D loc, Dimension2D size) Sets the location and size of the framing rectangle of thisShapeto the specifiedPoint2DandDimension2D, respectively.voidSets the framing rectangle of thisShapeto be the specifiedRectangle2D.voidsetFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) Sets the framing rectangle of thisShapebased on the specified center point coordinates and corner point coordinates.voidsetFrameFromCenter(Point2D center, Point2D corner) Sets the framing rectangle of thisShapebased on a specified centerPoint2Dand cornerPoint2D.voidsetFrameFromDiagonal(double x1, double y1, double x2, double y2) Sets the diagonal of the framing rectangle of thisShapebased on the two specified coordinates.voidsetFrameFromDiagonal(Point2D p1, Point2D p2) Sets the diagonal of the framing rectangle of thisShapebased on two specifiedPoint2Dobjects.Methods declared in class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface java.awt.Shape
contains, contains, getBounds2D, getPathIterator, intersects
-
Constructor Details
-
RectangularShape
protected RectangularShape()This is an abstract class that cannot be instantiated directly.- Since:
- 1.2
- See Also:
-
-
Method Details
-
getX
public abstract double getX()Returns the X coordinate of the upper-left corner of the framing rectangle indoubleprecision.- Returns:
- the X coordinate of the upper-left corner of the framing rectangle.
- Since:
- 1.2
-
getY
public abstract double getY()Returns the Y coordinate of the upper-left corner of the framing rectangle indoubleprecision.- Returns:
- the Y coordinate of the upper-left corner of the framing rectangle.
- Since:
- 1.2
-
getWidth
public abstract double getWidth()Returns the width of the framing rectangle indoubleprecision.- Returns:
- the width of the framing rectangle.
- Since:
- 1.2
-
getHeight
public abstract double getHeight()Returns the height of the framing rectangle indoubleprecision.- Returns:
- the height of the framing rectangle.
- Since:
- 1.2
-
getMinX
public double getMinX()Returns the smallest X coordinate of the framing rectangle of theShapeindoubleprecision.- Returns:
- the smallest X coordinate of the framing
rectangle of the
Shape. - Since:
- 1.2
-
getMinY
public double getMinY()Returns the smallest Y coordinate of the framing rectangle of theShapeindoubleprecision.- Returns:
- the smallest Y coordinate of the framing
rectangle of the
Shape. - Since:
- 1.2
-
getMaxX
public double getMaxX()Returns the largest X coordinate of the framing rectangle of theShapeindoubleprecision.- Returns:
- the largest X coordinate of the framing
rectangle of the
Shape. - Since:
- 1.2
-
getMaxY
public double getMaxY()Returns the largest Y coordinate of the framing rectangle of theShapeindoubleprecision.- Returns:
- the largest Y coordinate of the framing
rectangle of the
Shape. - Since:
- 1.2
-
getCenterX
public double getCenterX()Returns the X coordinate of the center of the framing rectangle of theShapeindoubleprecision.- Returns:
- the X coordinate of the center of the framing rectangle
of the
Shape. - Since:
- 1.2
-
getCenterY
public double getCenterY()Returns the Y coordinate of the center of the framing rectangle of theShapeindoubleprecision.- Returns:
- the Y coordinate of the center of the framing rectangle
of the
Shape. - Since:
- 1.2
-
getFrame
Returns the framingRectangle2Dthat defines the overall shape of this object.- Returns:
- a
Rectangle2D, specified indoublecoordinates. - Since:
- 1.2
- See Also:
-
isEmpty
public abstract boolean isEmpty()Determines whether theRectangularShapeis empty. When theRectangularShapeis empty, it encloses no area.- Returns:
trueif theRectangularShapeis empty;falseotherwise.- Since:
- 1.2
-
setFrame
public abstract void setFrame(double x, double y, double w, double h) Sets the location and size of the framing rectangle of thisShapeto the specified rectangular values.- Parameters:
x- the X coordinate of the upper-left corner of the specified rectangular shapey- the Y coordinate of the upper-left corner of the specified rectangular shapew- the width of the specified rectangular shapeh- the height of the specified rectangular shape- Since:
- 1.2
- See Also:
-
setFrame
Sets the location and size of the framing rectangle of thisShapeto the specifiedPoint2DandDimension2D, respectively. The framing rectangle is used by the subclasses ofRectangularShapeto define their geometry.- Parameters:
loc- the specifiedPoint2Dsize- the specifiedDimension2D- Since:
- 1.2
- See Also:
-
setFrame
Sets the framing rectangle of thisShapeto be the specifiedRectangle2D. The framing rectangle is used by the subclasses ofRectangularShapeto define their geometry.- Parameters:
r- the specifiedRectangle2D- Since:
- 1.2
- See Also:
-
setFrameFromDiagonal
public void setFrameFromDiagonal(double x1, double y1, double x2, double y2) Sets the diagonal of the framing rectangle of thisShapebased on the two specified coordinates. The framing rectangle is used by the subclasses ofRectangularShapeto define their geometry.- Parameters:
x1- the X coordinate of the start point of the specified diagonaly1- the Y coordinate of the start point of the specified diagonalx2- the X coordinate of the end point of the specified diagonaly2- the Y coordinate of the end point of the specified diagonal- Since:
- 1.2
-
setFrameFromDiagonal
Sets the diagonal of the framing rectangle of thisShapebased on two specifiedPoint2Dobjects. The framing rectangle is used by the subclasses ofRectangularShapeto define their geometry.- Parameters:
p1- the startPoint2Dof the specified diagonalp2- the endPoint2Dof the specified diagonal- Since:
- 1.2
-
setFrameFromCenter
public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) Sets the framing rectangle of thisShapebased on the specified center point coordinates and corner point coordinates. The framing rectangle is used by the subclasses ofRectangularShapeto define their geometry.- Parameters:
centerX- the X coordinate of the specified center pointcenterY- the Y coordinate of the specified center pointcornerX- the X coordinate of the specified corner pointcornerY- the Y coordinate of the specified corner point- Since:
- 1.2
-
setFrameFromCenter
Sets the framing rectangle of thisShapebased on a specified centerPoint2Dand cornerPoint2D. The framing rectangle is used by the subclasses ofRectangularShapeto define their geometry.- Parameters:
center- the specified centerPoint2Dcorner- the specified cornerPoint2D- Since:
- 1.2
-
contains
Tests if a specifiedPoint2Dis inside the boundary of theShape, as described by the definition of insideness. -
intersects
Tests if the interior of theShapeintersects the interior of a specifiedRectangle2D. TheShape.intersects()method allows aShapeimplementation to conservatively returntruewhen:-
there is a high probability that the
Rectangle2Dand theShapeintersect, but - the calculations to accurately determine this intersection are prohibitively expensive.
Shapesthis method might returntrueeven though theRectangle2Ddoes not intersect theShape. TheAreaclass performs more accurate computations of geometric intersection than mostShapeobjects and therefore can be used if a more precise answer is required.- Specified by:
intersectsin interfaceShape- Parameters:
r- the specifiedRectangle2D- Returns:
trueif the interior of theShapeand the interior of the specifiedRectangle2Dintersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform;falseotherwise.- Since:
- 1.2
- See Also:
-
there is a high probability that the
-
contains
Tests if the interior of theShapeentirely contains the specifiedRectangle2D. TheShape.contains()method allows aShapeimplementation to conservatively returnfalsewhen:-
the
intersectmethod returnstrueand -
the calculations to determine whether or not the
Shapeentirely contains theRectangle2Dare prohibitively expensive.
Shapesthis method might returnfalseeven though theShapecontains theRectangle2D. TheAreaclass performs more accurate geometric computations than mostShapeobjects and therefore can be used if a more precise answer is required.- Specified by:
containsin interfaceShape- Parameters:
r- The specifiedRectangle2D- Returns:
trueif the interior of theShapeentirely contains theRectangle2D;falseotherwise or, if theShapecontains theRectangle2Dand theintersectsmethod returnstrueand the containment calculations would be too expensive to perform.- Since:
- 1.2
- See Also:
-
the
-
getBounds
Returns an integerRectanglethat completely encloses theShape. Note that there is no guarantee that the returnedRectangleis the smallest bounding box that encloses theShape, only that theShapelies entirely within the indicatedRectangle. The returnedRectanglemight also fail to completely enclose theShapeif theShapeoverflows the limited range of the integer data type. ThegetBounds2Dmethod 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
shapemay not be considered contained in the returnedboundsobject, but only in cases where those points are also not considered contained in the originalshape.If a
pointis inside theshapeaccording to thecontains(point)method, then it must be inside the returnedRectanglebounds object according to thecontains(point)method of thebounds. Specifically:shape.contains(x,y)requiresbounds.contains(x,y)If a
pointis not inside theshape, then it might still be contained in theboundsobject:bounds.contains(x,y)does not implyshape.contains(x,y) -
getPathIterator
Returns an iterator object that iterates along theShapeobject's boundary and provides access to a flattened view of the outline of theShapeobject'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
flatnessparameter, which specifies the maximum distance that any point on the unflattened transformed curve can deviate from the returned flattened path segments. An optionalAffineTransformcan be specified so that the coordinates returned in the iteration are transformed accordingly.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif untransformed coordinates are desired.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- Returns:
- a
PathIteratorobject that provides access to theShapeobject's flattened geometry. - Since:
- 1.2
-
clone
Creates a new object of the same class and with the same contents as this object.- Overrides:
clonein classObject- Returns:
- a clone of this instance.
- Throws:
OutOfMemoryError- if there is not enough memory.- Since:
- 1.2
- See Also:
-