|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.ui.XYRect
public final class XYRect
Represents a two dimensional rectangle.
Typically these objects are used to represent a drawing extent. It's handy to remember that the top left corner of the rectangle is considered the origin point, and that the size of the rectangle is determine by a width of pixels to the right, and a height of pixels below the point of origin.
This means, therefore, that if you use two XYPoint
objects to
construct a rectangle, the second point (assumed to be below and to the right
of the first), the second point is actually used to measure the number of
pixels (height and width) from the origin. This places the second point one
pixel outside the bottom right corner of the rectangle.
Warning! It is possible, but certainly not advisable to create a rectangle with a negative width, negative height, or both.
Note that it is also possible to create an empty rectangle: one with a height of zero, width of zero, or both. This is permissible, and sometimes useful.
Field Summary | ||
---|---|---|
int |
height
Height of rect. |
|
int |
width
Width of rect. |
|
int |
x
Horizontal position of top left point. |
|
int |
y
Vertical position of top left point. |
Constructor Summary | ||
---|---|---|
XYRect()
Constructs a new XYRect instance and sets all fields to 0. |
||
XYRect(int x,
int y,
int width,
int height)
Constructs a specified rectangle. |
||
XYRect(XYPoint topLeft,
XYPoint bottomBound)
Constructs a rectangle from two points. |
||
XYRect(XYRect rect)
Constructs a copy of a rectangle. |
Method Summary | ||
---|---|---|
int |
X2()
Retrieves position of rectangle's right edge within the plane. |
|
int |
Y2()
Retrieves position of rectangle's bottom edge within the plane. |
|
void |
add(XYEdges edges)
Adds edges to this rectangle. |
|
boolean |
contains(int x,
int y)
Determines if this rectangle entirely contains specified point. |
|
boolean |
contains(int x,
int y,
int width,
int height)
Determines if this rectangle entirely contains specified coordinates. |
|
boolean |
contains(XYPoint point)
Determines if this rectangle contains specified point. |
|
boolean |
contains(XYRect rect)
Determines if this rectangle entirely contains another rectangle. |
|
boolean |
equals(Object obj)
Determines if provided object has the same dimensions as this rectangle. |
|
int |
hashCode()
Returns the hash code based on XYRect. |
|
void |
intersect(XYRect rect)
Intersects this rectangle with another rectangle. |
|
boolean |
intersects(XYRect rect)
Determines if this rectangle intersects another rectangle. |
|
void |
reset()
Resets all fields to 0. |
|
void |
set(int x,
int y,
int width,
int height)
Sets this rectangle to have a new extent. |
|
void |
set(XYRect rect)
Sets this rectangle to have the same extent as another rectangle. |
|
void |
setLocation(int x,
int y)
Moves this rectangle to new location in the plane. |
|
void |
setLocation(XYPoint topLeft)
Moves this rectangle to new location based on provided point. |
|
void |
setSize(int width,
int height)
Resizes this rectangle. |
|
void |
subtract(XYEdges edges)
Substracts edges to this rectangle. |
|
void |
translate(int horizontal,
int vertical)
Translates this rectangle to new location in plane. |
|
void |
translate(XYPoint point)
Translates this rectangle to new location in plane using a point as a reference. |
|
void |
union(int ox,
int oy,
int owidth,
int oheight)
Unites this rectangle with specified coordinates. |
|
void |
union(XYRect rect)
Unites this rectangle with another rectangle. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int x
public int y
public int width
public int height
Constructor Detail |
---|
public XYRect()
public XYRect(XYPoint topLeft, XYPoint bottomBound)
Use this constructor to build a rectangle from two
XYPoint
objects.
Warning! You must ensure that the
bottomRight
actually describes a point that is below and to
the right of the first, topLeft
parameter. It is possible,
but not advisable to create a rectangle with a negative height or width.
However, it certainly is permissable (and sometimes useful) to
provide a bottomRight
point that is on the same horizontal
axis and/or same vertical axis as the topLeft
point: in this
case, the created rectangle is simply empty.
topLeft
- Point marking origin of rectangle (point at the top left
corner).bottomBound
- Point one below and one to the right of the bottom
right corner of the rectangle (that is, this point describes the height
and width of the rectangle relative to the provided top-left point).public XYRect(XYRect rect)
Provide an existing rectangle to this contructor to build a new rectangle of identical size.
rect
- Rectangle to copy.public XYRect(int x, int y, int width, int height)
Pass a point of origin, width, and height to build a rectangle within the plane.
x
- Horizontal location of rectangle's origin.y
- Vertical location of rectangle's origin.width
- Distance in pixels to the right edge of the rectangle.height
- Distance in pixels to the bottom edge of the rectangle.Method Detail |
---|
public void add(XYEdges edges) throws NullPointerException
NullPointerException
- If null parameter is provided.public boolean contains(int x, int y, int width, int height)
Invoke this method to determine if this rectangle entirely contains a virtual retangle described by your parameters.
x
- Left edge of the virtual rectangle.y
- Top edge of the virtual rectangle.width
- Distance in pixels to right edge of virtual rectangle.height
- Distance in pixels to bottom edge of virtual rectangle.
public boolean contains(int x, int y)
x
- X-coordinate of point.y
- Y-coordinate of point.
public boolean contains(XYPoint point)
point
- Point that may be contained within this rectangle.
public boolean contains(XYRect rect)
rect
- Rectangle that may be contained within this rectangle.
public boolean equals(Object obj)
equals
in class Object
obj
- Object to compare to this rectangle.
Boolean.hashCode()
,
Hashtable
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
Hashtable
public void intersect(XYRect rect)
Invoke this method to change the extent of this rectangle to pixels shared in common with another rectangle you provide.
If the regions are disjoint this method produces a zero-width and zero-height region. This method then sets the origin to a point (within the original rectangle) closest to the other rectangle.
rect
- Rectangle to intersect with this one.public boolean intersects(XYRect rect)
public void reset()
public void set(int x, int y, int width, int height)
x
- New left edge for this rectangle.y
- New top edge for this rectangle.width
- New distance (in pixels) to right edge of this rectangle.height
- New distance (in pixels) to bottom edge of this rectangle.public void set(XYRect rect)
rect
- Rectangle representing the new coordinates for this
rectangle.public void setLocation(int x, int y)
x
- New left edge for this rectangle.y
- New top edge for this rectangle.public void setLocation(XYPoint topLeft)
topLeft
- Point describing new left edge and new top edge for this
rectangle.public void setSize(int width, int height)
width
- New distance (in pixels) from left to right edge of this
rectangle.height
- New distance (in pixels) from top to bottom edge of this
rectangle.public void subtract(XYEdges edges)
NullPointerException
- If null parameter is provided.public void translate(int horizontal, int vertical)
Invoke this method to move this rectangle within the plane by specifying a horizontal and vertical distance.
horizontal
- Number of pixels to move this rectangle's left edge
along the horizontal axis.vertical
- Number of pixels to move this rectangle's top edge along
the vertical axis.public void translate(XYPoint point)
point
- Horizontal position of parameter point used as distance to
move this rectangle's left edge along the horizontal axis; the vertical
position of parameter point used as distance to move this rectangle's top
edge along the vertical axis.public void union(int ox, int oy, int owidth, int oheight)
Invoke this method to change the extent of this rectangle to unite it with coordinates you provide (origin and width and height of a new, virtual rectangle).
ox
- Left edge of the new area to unite with this rectangle.oy
- Top edge of the new area to unite with this rectangle.owidth
- Distance in pixels to the right edge of the new area.oheight
- Distance in pixels to the bottom edge of the new area.public void union(XYRect rect)
Invoke this method to change the extent of this rectangle to unite it with another rectangle you provide.
rect
- Rectangle to unite with this rectangle.public int X2()
public int Y2()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal