java.awt.geom
Class RectangularShape
java.lang.Object
|
+--java.awt.geom.RectangularShape
All Implemented Interfaces:
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:- Tom Tromey <tromey@cygnus.com>
- Eric Blake <ebb9@email.byu.edu>
See Also:
java.lang.Object | clone()
|
boolean | contains(java.awt.geom.Point2D p)
|
boolean | contains(java.awt.geom.Rectangle2D r)
|
java.awt.Rectangle | getBounds()
|
double | getCenterX()
|
double | getCenterY()
|
java.awt.geom.Rectangle2D | getFrame()
|
double | getHeight()
|
double | getMaxX()
|
double | getMaxY()
|
double | getMinX()
|
double | getMinY()
|
java.awt.geom.PathIterator | getPathIterator(java.awt.geom.AffineTransform at, double flatness)
|
double | getWidth()
|
double | getX()
|
double | getY()
|
boolean | intersects(java.awt.geom.Rectangle2D r)
|
boolean | isEmpty()
|
void | setFrame(double x, double y, double w, double h)
|
void | setFrame(java.awt.geom.Point2D p, java.awt.geom.Dimension2D d)
|
void | setFrame(java.awt.geom.Rectangle2D r)
|
void | setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY)
|
void | setFrameFromCenter(java.awt.geom.Point2D center, java.awt.geom.Point2D corner)
|
void | setFrameFromDiagonal(double x1, double y1, double x2, double y2)
|
void | setFrameFromDiagonal(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
|
RectangularShape
protected RectangularShape()
Default constructor.
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:
- true if the point is inside the shape
Throws:
See Also:
contains
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the shape completely contains the given rectangle.
Parameters:
Returns:
- true if r is contained in this shape
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:
- the frame, in double precision
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:
- a new iterator over the boundary
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:
- true if the rectangle intersects this shpae
Throws:
See Also:
isEmpty
public boolean isEmpty()
Test if the shape is empty, meaning that no points are inside it.
Returns:
- true if the shape is empty
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: