GNU Classpath (0.95) | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
java.awt.Rectangle
contains
or intersects
is
undefined unless the rectangle has positive width and height.
There are some public fields; if you mess with them in an inconsistent
manner, it is your own fault when you get NullPointerException,
ArrayIndexOutOfBoundsException, or invalid results. Also, this class is
not threadsafe.
Nested Class Summary |
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D | |
Rectangle2D.Double , Rectangle2D.Float |
Field Summary | |
int |
|
int |
|
int |
|
int |
|
Fields inherited from class java.awt.geom.Rectangle2D | |
OUT_BOTTOM , OUT_LEFT , OUT_RIGHT , OUT_TOP |
Constructor Summary | |
| |
| |
| |
Method Summary | |
void |
|
void | |
void | |
boolean |
|
boolean |
|
boolean | |
boolean | |
Rectangle2D |
|
Rectangle2D |
|
boolean | |
Rectangle |
|
Rectangle2D |
|
double |
|
Point |
|
Dimension |
|
double |
|
double |
|
double |
|
void |
|
boolean |
|
Rectangle |
|
boolean |
|
boolean |
|
void |
|
int |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void | |
String |
|
void |
|
Rectangle |
Methods inherited from class java.awt.geom.Rectangle2D | |
add , add , add , contains , contains , createIntersection , createUnion , equals , getBounds2D , getPathIterator , getPathIterator , hashCode , intersect , intersects , intersectsLine , intersectsLine , outcode , outcode , setFrame , setRect , setRect , union |
Methods inherited from class java.awt.geom.RectangularShape | |
clone , contains , contains , getBounds , getCenterX , getCenterY , getFrame , getHeight , getMaxX , getMaxY , getMinX , getMinY , getPathIterator , getWidth , getX , getY , intersects , isEmpty , setFrame , setFrame , setFrame , setFrameFromCenter , setFrameFromCenter , setFrameFromDiagonal , setFrameFromDiagonal |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public int x
The X coordinate of the top-left corner of the rectangle.
- See Also:
setLocation(int,int)
,getLocation()
public int y
The Y coordinate of the top-left corner of the rectangle.
- See Also:
setLocation(int,int)
,getLocation()
public Rectangle()
Initializes a new instance ofRectangle
with a top left corner at (0,0) and a width and height of 0.
public Rectangle(int width, int height)
Initializes a new instance ofRectangle
with the specified width and height. The upper left corner of the rectangle will be at the origin (0,0).
- Parameters:
width
- the width of the rectangleheight
- the height of the rectange
public Rectangle(int x, int y, int width, int height)
Initializes a new instance ofRectangle
from the specified inputs.
- Parameters:
x
- the X coordinate of the top left cornery
- the Y coordinate of the top left cornerwidth
- the width of the rectangleheight
- the height of the rectangle
public Rectangle(Dimension d)
Initializes a new instance ofRectangle
with an upper left corner at the origin (0,0) and a width and height represented by the specified dimension.
- Parameters:
d
- the width and height of the rectangle
public Rectangle(Point p)
Initializes a new instance ofRectangle
with a top left corner at the specified point and a width and height of zero.
- Parameters:
p
- the upper left corner of the rectangle
public Rectangle(Point p, Dimension d)
Initializes a new instance ofRectangle
with a top-left corner represented by the specified point and the width and height represented by the specified dimension.
- Parameters:
p
- the upper left corner of the rectangled
- the width and height of the rectangle
public void add(int x, int y)
Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified point. However, if the point falls on one of the two borders which are not inside the rectangle, a subsequent call tocontains
may return false.
- Parameters:
x
- the X coordinate of the point to add to this rectangley
- the Y coordinate of the point to add to this rectangle
public void add(Point p)
Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified point. However, if the point falls on one of the two borders which are not inside the rectangle, a subsequent call tocontains
may return false.
- Parameters:
p
- the point to add to this rectangle
- Throws:
NullPointerException
- if p is null
public void add(Rectangle r)
Modifies this rectangle so that it represents the smallest rectangle that contains both the existing rectangle and the specified rectangle.
- Parameters:
r
- the rectangle to add to this rectangle
- Throws:
NullPointerException
- if r is null
- See Also:
union(Rectangle)
public boolean contains(int x, int y)
Tests whether or not the specified point is inside this rectangle. According to the contract of Shape, a point on the border is in only if it has an adjacent point inside the rectangle in either the increasing x or y direction.
- Parameters:
x
- the X coordinate of the point to testy
- the Y coordinate of the point to test
- Returns:
- true if the point is inside the rectangle
- Since:
- 1.1
public boolean contains(int x, int y, int w, int h)
Checks whether all points in the given rectangle are contained in this rectangle.
- Parameters:
x
- the x coordinate of the rectangle to checky
- the y coordinate of the rectangle to checkw
- the width of the rectangle to checkh
- the height of the rectangle to check
- Returns:
- true if the parameters are contained in this rectangle
- Since:
- 1.1
public boolean contains(Point p)
Tests whether or not the specified point is inside this rectangle. According to the contract of Shape, a point on the border is in only if it has an adjacent point inside the rectangle in either the increasing x or y direction.
- Parameters:
p
- the point to test
- Returns:
- true if the point is inside the rectangle
- Throws:
NullPointerException
- if p is null
- Since:
- 1.1
- See Also:
contains(int,int)
public boolean contains(Rectangle r)
Checks whether all points in the given rectangle are contained in this rectangle.
- Parameters:
r
- the rectangle to check
- Returns:
- true if r is contained in this rectangle
- Throws:
NullPointerException
- if r is null
- Since:
- 1.1
- See Also:
contains(int,int,int,int)
public Rectangle2D createIntersection(Rectangle2D r)
Determines the rectangle which is formed by the intersection of this rectangle with the specified rectangle. If the two do not intersect, an empty rectangle will be returned (meaning the width and/or height will be non-positive).
- Overrides:
- createIntersection in interface Rectangle2D
- Parameters:
r
- the rectange to calculate the intersection with
- Returns:
- a new rectangle bounding the intersection
- Throws:
NullPointerException
- if r is null
- Since:
- 1.2
public Rectangle2D createUnion(Rectangle2D r)
Returns the smallest rectangle that contains both this rectangle and the specified rectangle.
- Overrides:
- createUnion in interface Rectangle2D
- Parameters:
r
- the rectangle to compute the union with
- Returns:
- the smallest rectangle containing both rectangles
- Throws:
NullPointerException
- if r is null
- Since:
- 1.2
public boolean equals(Object obj)
Tests this rectangle for equality against the specified object. This will be true if an only if the specified object is an instance of Rectangle2D with the same coordinates and dimensions.
- Overrides:
- equals in interface Rectangle2D
- Parameters:
obj
- the object to test against for equality
- Returns:
- true if the specified object is equal to this one
public Rectangle getBounds()
Returns the bounds of this rectangle. A pretty useless method, as this is already a rectangle; it is included to mimic thegetBounds
method in Component.
- Overrides:
- getBounds in interface RectangularShape
- Returns:
- a copy of this rectangle
- Since:
- 1.1
- See Also:
setBounds(Rectangle)
public Rectangle2D getBounds2D()
Returns the high-precision bounds of this rectangle. A pretty useless method, as this is already a rectangle.
- Specified by:
- getBounds2D in interface Shape
- Overrides:
- getBounds2D in interface Rectangle2D
- Returns:
- a copy of this rectangle
- Since:
- 1.2
- See Also:
setBounds(Rectangle)
public double getHeight()
Get the height of the rectangle.
- Overrides:
- getHeight in interface RectangularShape
- Returns:
- the value of height, as a double
public Point getLocation()
Returns the location of this rectangle, which is the coordinates of its upper left corner.
- Returns:
- the point where this rectangle is located
- Since:
- 1.1
- See Also:
setLocation(Point)
public Dimension getSize()
Returns the size of this rectangle.
- Returns:
- the size of this rectangle
- Since:
- 1.1
- See Also:
setSize(Dimension)
public double getWidth()
Get the width of the rectangle.
- Overrides:
- getWidth in interface RectangularShape
- Returns:
- the value of width, as a double
public double getX()
Get the X coordinate of the upper-left corner.
- Overrides:
- getX in interface RectangularShape
- Returns:
- the value of x, as a double
public double getY()
Get the Y coordinate of the upper-left corner.
- Overrides:
- getY in interface RectangularShape
- Returns:
- the value of y, as a double
public void grow(int h, int v)
Expands the rectangle by the specified amount. The horizontal and vertical expansion values are applied both to the X,Y coordinate of this rectangle, and its width and height. Thus the width and height will increase by 2h and 2v accordingly.
- Parameters:
h
- the horizontal expansion valuev
- the vertical expansion value
public boolean inside(int x, int y)
Deprecated. use
contains(int,int)
insteadTests whether or not the specified point is inside this rectangle.
- Parameters:
x
- the X coordinate of the point to testy
- the Y coordinate of the point to test
- Returns:
- true if the point is inside the rectangle
public Rectangle intersection(Rectangle r)
Determines the rectangle which is formed by the intersection of this rectangle with the specified rectangle. If the two do not intersect, an empty rectangle will be returned (meaning the width and/or height will be non-positive).
- Parameters:
r
- the rectange to calculate the intersection with
- Returns:
- a new rectangle bounding the intersection
- Throws:
NullPointerException
- if r is null
public boolean intersects(Rectangle r)
Tests whether or not the specified rectangle intersects this rectangle. This means the two rectangles share at least one internal point.
- Parameters:
r
- the rectangle to test against
- Returns:
- true if the specified rectangle intersects this one
- Throws:
NullPointerException
- if r is null
- Since:
- 1.2
public boolean isEmpty()
Tests whether or not this rectangle is empty. An empty rectangle has a non-positive width or height.
- Overrides:
- isEmpty in interface RectangularShape
- Returns:
- true if the rectangle is empty
public void move(int x, int y)
Deprecated. use
setLocation(int,int)
insteadMoves the location of this rectangle by setting its upper left corner to the specified coordinates.
- Parameters:
x
- the new X coordinate for this rectangley
- the new Y coordinate for this rectangle
public int outcode(double x, double y)
Determine where the point lies with respect to this rectangle. The result will be the binary OR of the appropriate bit masks.
- Overrides:
- outcode in interface Rectangle2D
- Parameters:
x
- the x coordinate to checky
- the y coordinate to check
- Returns:
- the binary OR of the result
- Since:
- 1.2
public void reshape(int x, int y, int width, int height)
Deprecated. use
setBounds(int,int,int,int)
insteadUpdates this rectangle to have the specified dimensions.
- Parameters:
x
- the new X coordinate of the upper left hand cornery
- the new Y coordinate of the upper left hand cornerwidth
- the new width of this rectangleheight
- the new height of this rectangle
public void resize(int width, int height)
Deprecated. use
setSize(int,int)
insteadSets the size of this rectangle based on the specified dimensions.
- Parameters:
width
- the new width of the rectangleheight
- the new height of the rectangle
public void setBounds(int x, int y, int width, int height)
Updates this rectangle to have the specified dimensions.
- Parameters:
x
- the new X coordinate of the upper left hand cornery
- the new Y coordinate of the upper left hand cornerwidth
- the new width of this rectangleheight
- the new height of this rectangle
- Since:
- 1.1
public void setBounds(Rectangle r)
Updates this rectangle to match the dimensions of the specified rectangle.
- Parameters:
r
- the rectangle to update from
- Throws:
NullPointerException
- if r is null
- Since:
- 1.1
- See Also:
setBounds(int,int,int,int)
public void setLocation(int x, int y)
Moves the location of this rectangle by setting its upper left corner to the specified coordinates.
- Parameters:
x
- the new X coordinate for this rectangley
- the new Y coordinate for this rectangle
- Since:
- 1.1
public void setLocation(Point p)
Moves the location of this rectangle by setting its upper left corner to the specified point.
- Parameters:
p
- the point to move the rectangle to
- Throws:
NullPointerException
- if p is null
- Since:
- 1.1
- See Also:
getLocation()
public void setRect(double x, double y, double width, double height)
Updates this rectangle to have the specified dimensions, rounded to the integer precision used by this class (the values are rounded "outwards" so that the stored rectangle completely encloses the specified double precision rectangle).
- Overrides:
- setRect in interface Rectangle2D
- Parameters:
x
- the new X coordinate of the upper left hand cornery
- the new Y coordinate of the upper left hand cornerwidth
- the new width of this rectangleheight
- the new height of this rectangle
- Since:
- 1.2
public void setSize(int width, int height)
Sets the size of this rectangle based on the specified dimensions.
- Parameters:
width
- the new width of the rectangleheight
- the new height of the rectangle
- Since:
- 1.1
public void setSize(Dimension d)
Sets the size of this rectangle based on the specified dimensions.
- Parameters:
d
- the new dimensions of the rectangle
- Throws:
NullPointerException
- if d is null
- Since:
- 1.1
- See Also:
getSize()
public String toString()
Returns a string representation of this rectangle. This is in the formgetClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + ']'
.
- Returns:
- a string representation of this rectangle
public void translate(int dx, int dy)
Translate the location of this rectangle by the given amounts.
- Parameters:
dx
- the x distance to move bydy
- the y distance to move by
- See Also:
setLocation(int,int)
public Rectangle union(Rectangle r)
Returns the smallest rectangle that contains both this rectangle and the specified rectangle.
- Parameters:
r
- the rectangle to compute the union with
- Returns:
- the smallest rectangle containing both rectangles
- Throws:
NullPointerException
- if r is null
GNU Classpath (0.95) |