public class Rectangle extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable, Translatable
Modifier and Type | Field and Description |
---|---|
int |
height
The height
|
static Rectangle |
SINGLETON
A singleton for use in short calculations.
|
int |
width
The width
|
int |
x
The x value
|
int |
y
The y value
|
Constructor and Description |
---|
Rectangle()
Constructs a Rectangle at the origin with zero width and height.
|
Rectangle(int x,
int y,
int width,
int height)
Constructs a Rectangle with the provided values.
|
Rectangle(Point p,
Dimension size)
Constructs a Rectangle given a location and size.
|
Rectangle(Point p1,
Point p2)
Constructs the smallest Rectangle that contains the specified Points.
|
Rectangle(Rectangle rect)
Constructs a copy of the provided SWT
Rectangle . |
Rectangle(Rectangle rect)
Constructs a copy of the provided Rectangle.
|
Modifier and Type | Method and Description |
---|---|
int |
bottom()
Returns the y-coordinate of the bottom of this Rectangle.
|
boolean |
contains(double x,
double y)
Returns whether the given coordinates are within the boundaries of this
Rectangle.
|
boolean |
contains(int x,
int y)
Returns whether the given coordinates are within the boundaries of this
Rectangle.
|
boolean |
contains(Point p)
Returns whether the given point is within the boundaries of this
Rectangle.
|
boolean |
contains(Rectangle rect)
Returns
true if the given rectangle is contained within the
boundaries of this Rectangle. |
Rectangle |
crop(Insets insets)
Deprecated.
Use
shrink(Insets) instead. |
boolean |
equals(int x,
int y,
int width,
int height)
Returns
true if this Rectangle's x, y, width, and height
values are identical to the provided ones. |
boolean |
equals(java.lang.Object o)
Returns whether the input object is equal to this Rectangle or not.
|
Rectangle |
expand(double h,
double v)
Expands the horizontal and vertical sides of this Rectangle with the
values provided as input, and returns this for convenience.
|
Rectangle |
expand(Insets insets)
Expands the horizontal and vertical sides of this Rectangle by the width
and height of the given Insets, and returns this for convenience.
|
Rectangle |
expand(int h,
int v)
Expands the horizontal and vertical sides of this Rectangle with the
values provided as input, and returns this for convenience.
|
Point |
getBottom()
Returns a new Point representing the middle point of the bottom side of
this Rectangle.
|
Point |
getBottomLeft()
Returns a new Point representing the bottom left point of this Rectangle.
|
Point |
getBottomRight()
Returns a new Point representing the bottom right point of this
Rectangle.
|
Point |
getCenter()
Returns a new point representing the center of this Rectangle.
|
Rectangle |
getCopy()
Returns a new Rectangle which has the exact same parameters as this
Rectangle.
|
Rectangle |
getCropped(Insets insets)
Deprecated.
Use
getShrinked(Insets) instead. |
Rectangle |
getExpanded(double h,
double v)
Returns a new incremented Rectangle, where the sides are expanded by the
horizontal and vertical values provided.
|
Rectangle |
getExpanded(Insets insets)
Creates and returns a new Rectangle with the bounds of
this
Rectangle, expanded by the given Insets. |
Rectangle |
getExpanded(int h,
int v)
Returns a new incremented Rectangle, where the sides are expanded by the
horizontal and vertical values provided.
|
Rectangle |
getIntersection(Rectangle rect)
Returns a new Rectangle which has the intersection of this Rectangle and
the rectangle provided as input.
|
Point |
getLeft()
Returns a new Point representing the middle point of the left hand side
of this Rectangle.
|
Point |
getLocation()
Returns the upper left hand corner of the rectangle.
|
int |
getPosition(Point p)
Returns an integer which represents the position of the given point with
respect to this rectangle.
|
Rectangle |
getResized(Dimension d)
Returns a new Rectangle which is equivalent to this Rectangle with its
dimensions modified by the passed Dimension d.
|
Rectangle |
getResized(double w,
double h)
Returns a new Rectangle which is equivalent to this Rectangle with its
dimensions modified by the passed width w and height h.
|
Rectangle |
getResized(int w,
int h)
Returns a new Rectangle which is equivalent to this Rectangle with its
dimensions modified by the passed width w and height h.
|
Point |
getRight()
Returns a new Point which represents the middle point of the right hand
side of this Rectangle.
|
Rectangle |
getShrinked(double h,
double v)
Returns a new Rectangle, where the sides are shrinked by the horizontal
and vertical values supplied.
|
Rectangle |
getShrinked(Insets insets)
Returns a new Rectangle shrinked by the specified insets.
|
Rectangle |
getShrinked(int h,
int v)
Returns a new Rectangle, where the sides are shrinked by the horizontal
and vertical values supplied.
|
Dimension |
getSize()
Retuns the dimensions of this Rectangle.
|
Point |
getTop()
Returns a new Point which represents the middle point of the top side of
this Rectangle.
|
Point |
getTopLeft()
Returns a new Point which represents the top left hand corner of this
Rectangle.
|
Point |
getTopRight()
Returns a new Point which represents the top right hand corner of this
Rectangle.
|
Rectangle |
getTranslated(double dx,
double dy)
Returns a new Rectangle which is shifted along each axis by the passed
values.
|
Rectangle |
getTranslated(int dx,
int dy)
Returns a new Rectangle which is shifted along each axis by the passed
values.
|
Rectangle |
getTranslated(Point pt)
Returns a new Rectangle which is shifted by the position of the given
Point.
|
Rectangle |
getTransposed()
Returns a new rectangle whose width and height have been interchanged, as
well as its x and y values.
|
Rectangle |
getUnion(Point p)
Returns a new Rectangle which contains both this Rectangle and the Point
supplied as input.
|
Rectangle |
getUnion(Rectangle rect)
Returns a new Rectangle which contains both this Rectangle and the
Rectangle supplied as input.
|
int |
hashCode() |
int |
height()
Returns the current height of this Rectangle
|
Rectangle |
intersect(Rectangle rect)
Sets the size of this Rectangle to the intersection region with the
Rectangle supplied as input, and returns this for convenience.
|
boolean |
intersects(Rectangle rect)
Returns
true if the input Rectangle intersects this
Rectangle. |
boolean |
isEmpty()
Returns
true if this Rectangle's width or height is less
than or equal to 0. |
void |
performScale(double factor)
Scales this object by the scale factor.
|
void |
performTranslate(int dx,
int dy)
Translates this object horizontally by
dx and vertically by
dy . |
double |
preciseHeight()
Returns
double height |
double |
preciseWidth()
Returns
double width |
double |
preciseX()
Returns
double x coordinate |
double |
preciseY()
Returns
double y coordinate |
Rectangle |
resize(Dimension d)
Resizes this Rectangle by the Dimension provided as input and returns
this for convenience.
|
Rectangle |
resize(double w,
double h)
Resizes this Rectangle by the values supplied as input and returns this
for convenience.
|
Rectangle |
resize(int w,
int h)
Resizes this Rectangle by the values supplied as input and returns this
for convenience.
|
int |
right()
Returns the x-coordinate of the right side of this Rectangle.
|
Rectangle |
scale(double scaleFactor)
Scales the location and size of this Rectangle by the given scale and
returns this for convenience.
|
Rectangle |
scale(double scaleX,
double scaleY)
Scales the location and size of this Rectangle by the given scales and
returns this for convenience.
|
Rectangle |
setBounds(int x,
int y,
int width,
int height)
Sets the x, y, width, and height values of this Rectangle to the provided
values.
|
Rectangle |
setBounds(Point location,
Dimension size)
Sets the location and size of this rectangle to the provided ones.
|
Rectangle |
setBounds(Rectangle rect)
Sets the parameters of this Rectangle from the Rectangle passed in and
returns this for convenience.
|
Rectangle |
setHeight(int height)
Sets the height of this Rectangle to the specified one.
|
Rectangle |
setLocation(int x,
int y)
Sets the location of this Rectangle to the coordinates given as input and
returns this for convenience.
|
Rectangle |
setLocation(Point p)
Sets the location of this Rectangle to the point given as input and
returns this for convenience.
|
Rectangle |
setSize(Dimension d)
Sets the width and height of this Rectangle to the width and height of
the given Dimension and returns this for convenience.
|
Rectangle |
setSize(int w,
int h)
Sets the width of this Rectangle to w and the height of this
Rectangle to h and returns this for convenience.
|
Rectangle |
setWidth(int width)
Sets the width of this Rectangle to the specified one.
|
Rectangle |
setX(int x)
Sets the x value of the Rectangle and returns this for convenience.
|
Rectangle |
setY(int y)
Sets the y value of the Rectangle and returns this for convenience.
|
Rectangle |
shrink(double h,
double v)
Shrinks the sides of this Rectangle by the horizontal and vertical values
provided as input, and returns this Rectangle for convenience.
|
Rectangle |
shrink(Insets insets)
Shrinks this rectangle by the amount specified in
insets . |
Rectangle |
shrink(int h,
int v)
Shrinks the sides of this Rectangle by the horizontal and vertical values
provided as input, and returns this Rectangle for convenience.
|
java.lang.String |
toString()
Returns the description of this Rectangle.
|
boolean |
touches(Rectangle rect)
Returns
true if the input Rectangle touches this Rectangle. |
Rectangle |
translate(double dx,
double dy)
Moves this Rectangle horizontally by dx and vertically by dy, then
returns this Rectangle for convenience.
|
Rectangle |
translate(int dx,
int dy)
Moves this Rectangle horizontally by dx and vertically by dy, then
returns this Rectangle for convenience.
|
Rectangle |
translate(Point p)
Moves this Rectangle horizontally by the x value of the given Point and
vertically by the y value of the given Point, then returns this Rectangle
for convenience.
|
Rectangle |
transpose()
Switches the x and y values, as well as the width and height of this
Rectangle.
|
Rectangle |
union(Dimension d)
Deprecated.
Union with a dimension generally does not make much sense,
thus deprecating this. Use
Dimension.max(Dimension, Dimension) and
setSize(Dimension) to implement the desired behavior
instead. |
Rectangle |
union(double x,
double y)
Updates this Rectangle's bounds to the minimum size which can hold both
this Rectangle and the coordinate (x,y).
|
Rectangle |
union(double x,
double y,
double w,
double h)
Updates this Rectangle's dimensions to the minimum size which can hold
both this Rectangle and the rectangle (x, y, w, h).
|
Rectangle |
union(int x1,
int y1)
Updates this Rectangle's bounds to the minimum size which can hold both
this Rectangle and the coordinate (x,y).
|
Rectangle |
union(int x,
int y,
int w,
int h)
Updates this Rectangle's dimensions to the minimum size which can hold
both this Rectangle and the rectangle (x, y, w, h).
|
void |
union(Point p)
Updates this Rectangle's bounds to the minimum size which can hold both
this Rectangle and the given Point.
|
Rectangle |
union(Rectangle rect)
Updates this Rectangle's dimensions to the minimum size which can hold
both this Rectangle and the given Rectangle.
|
int |
width()
Returns the current width of this Rectangle
|
int |
x()
Returns the x value of this Rectangle.
|
int |
y()
Returns the y value of the Rectangle
|
public static final Rectangle SINGLETON
public int height
public int width
public int x
public int y
public Rectangle()
public Rectangle(int x, int y, int width, int height)
x
- X locationy
- Y locationwidth
- Width of the rectangleheight
- Height of the rectanglepublic Rectangle(Rectangle rect)
Rectangle
.rect
- The SWT Rectangle being copiedpublic Rectangle(Point p, Dimension size)
p
- the locationsize
- the sizepublic Rectangle(Point p1, Point p2)
p1
- Upper left hand cornerp2
- Lower right hand cornerpublic Rectangle(Rectangle rect)
rect
- Rectangle supplying the initial valuespublic int bottom()
public boolean contains(double x, double y)
x
- X valuey
- Y valuepublic boolean contains(int x, int y)
x
- X valuey
- Y valuepublic boolean contains(Point p)
p
- Point being tested for containmentpublic boolean contains(Rectangle rect)
true
if the given rectangle is contained within the
boundaries of this Rectangle.rect
- the Rectangle to testpublic Rectangle crop(Insets insets)
shrink(Insets)
instead.insets
.insets
- Insets to be removed from the Rectanglethis
for conveniencepublic boolean equals(int x, int y, int width, int height)
true
if this Rectangle's x, y, width, and height
values are identical to the provided ones.x
- The x value to testy
- The y value to testwidth
- The width value to testheight
- The height value to testtrue
if this Rectangle's x, y, width, and height
values are identical to the provided ones, false
otherwisepublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object being tested for equalitypublic Rectangle expand(double h, double v)
h
- Horizontal incrementv
- Vertical incrementthis
for conveniencepublic Rectangle expand(Insets insets)
insets
- contains the amounts to expand on each sidethis
for conveniencepublic Rectangle expand(int h, int v)
h
- Horizontal incrementv
- Vertical incrementthis
for conveniencepublic Point getBottom()
public Point getBottomLeft()
public Point getBottomRight()
public Point getCenter()
public Rectangle getCopy()
public Rectangle getCropped(Insets insets)
getShrinked(Insets)
instead.insets
- Insets being cropped from the Rectanglepublic Rectangle getExpanded(double h, double v)
h
- Horizontal incrementv
- Vertical incrementpublic Rectangle getExpanded(Insets insets)
this
Rectangle, expanded by the given Insets.insets
- The insets used to expand this rectanglepublic Rectangle getExpanded(int h, int v)
h
- Horizontal incrementv
- Vertical incrementpublic Rectangle getIntersection(Rectangle rect)
rect
- Rectangle provided to test for intersectionpublic Point getLeft()
public Point getLocation()
setLocation(Point)
public int getPosition(Point p)
Returns an integer which represents the position of the given point with
respect to this rectangle. Possible return values are bitwise ORs of the
constants WEST, EAST, NORTH, and SOUTH as found in
PositionConstants
.
Returns PositionConstant.NONE if the given point is inside this Rectangle.
p
- The Point whose position has to be determinedint
which is a PositionConstantPositionConstants
public Rectangle getResized(Dimension d)
d
- Dimensions by which the rectangle's size should be modifiedpublic Rectangle getResized(double w, double h)
w
- Amount by which width is to be resizedh
- Amount by which height is to be resizedpublic Rectangle getResized(int w, int h)
w
- Amount by which width is to be resizedh
- Amount by which height is to be resizedpublic Point getRight()
public Rectangle getShrinked(double h, double v)
h
- Horizontal reduction amountv
- Vertical reduction amountthis
for conveniencepublic Rectangle getShrinked(Insets insets)
insets
- Insets being cropped from the Rectanglepublic Rectangle getShrinked(int h, int v)
h
- Horizontal reduction amountv
- Vertical reduction amountthis
for conveniencepublic Dimension getSize()
public Point getTop()
public Point getTopLeft()
public Point getTopRight()
public Rectangle getTranslated(double dx, double dy)
dx
- Displacement along X axisdy
- Displacement along Y axispublic Rectangle getTranslated(int dx, int dy)
dx
- Displacement along X axisdy
- Displacement along Y axispublic Rectangle getTranslated(Point pt)
pt
- Point providing the amount of shift along each axispublic Rectangle getTransposed()
public Rectangle getUnion(Point p)
p
- Point for calculating unionpublic Rectangle getUnion(Rectangle rect)
rect
- Rectangle for calculating unionpublic int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public int height()
public Rectangle intersect(Rectangle rect)
rect
- Rectangle for the calculating intersection.this
for conveniencepublic boolean intersects(Rectangle rect)
true
if the input Rectangle intersects this
Rectangle.rect
- Rectangle for the intersection testtrue
if the input Rectangle intersects this
Rectanglepublic boolean isEmpty()
true
if this Rectangle's width or height is less
than or equal to 0.true
if this Rectangle is emptypublic void performScale(double factor)
Translatable
performScale
in interface Translatable
factor
- The scale factorTranslatable.performScale(double)
public void performTranslate(int dx, int dy)
Translatable
dx
and vertically by
dy
.performTranslate
in interface Translatable
dx
- The amount to translate horizontallydy
- The amount to translate verticallyTranslatable.performTranslate(int, int)
public double preciseHeight()
double
heightdouble
heightpublic double preciseWidth()
double
widthdouble
widthpublic double preciseX()
double
x coordinatedouble
x coordinatepublic double preciseY()
double
y coordinatedouble
y coordinatepublic Rectangle resize(Dimension d)
d
- Resize data as a Dimensionthis
for conveniencepublic Rectangle resize(double w, double h)
w
- Amount by which width is to be resizedh
- Amount by which height is to be resizedthis
for conveniencepublic Rectangle resize(int w, int h)
w
- Amount by which width is to be resizedh
- Amount by which height is to be resizedthis
for conveniencepublic int right()
public final Rectangle scale(double scaleFactor)
scaleFactor
- The factor by which this rectangle will be scaledthis
for conveniencepublic Rectangle scale(double scaleX, double scaleY)
scaleX
- the factor by which the X dimension has to be scaledscaleY
- the factor by which the Y dimension has to be scaledthis
for conveniencepublic Rectangle setBounds(int x, int y, int width, int height)
x
- The new xy
- The new ywidth
- The new widthheight
- The new heightpublic Rectangle setBounds(Point location, Dimension size)
location
- The new locationsize
- The new sizepublic Rectangle setBounds(Rectangle rect)
rect
- Rectangle providing the bounding valuesthis
for conveniencepublic Rectangle setHeight(int height)
height
- The new heightpublic Rectangle setLocation(int x, int y)
x
- The new X coordinatey
- The new Y coordinatethis
for conveniencepublic Rectangle setLocation(Point p)
p
- New position of this Rectanglethis
for conveniencepublic Rectangle setSize(Dimension d)
d
- The new Dimensionthis
for conveniencepublic Rectangle setSize(int w, int h)
w
- The new widthh
- The new heightthis
for conveniencepublic Rectangle setWidth(int width)
width
- The new widthpublic Rectangle setX(int x)
x
- The new x valuethis
for conveniencepublic Rectangle setY(int y)
y
- The new y valuethis
for conveniencepublic Rectangle shrink(double h, double v)
h
- Horizontal reduction amountv
- Vertical reduction amountthis
for conveniencepublic Rectangle shrink(Insets insets)
insets
.insets
- Insets to be removed from the Rectanglethis
for conveniencepublic Rectangle shrink(int h, int v)
h
- Horizontal reduction amountv
- Vertical reduction amountthis
for conveniencepublic java.lang.String toString()
toString
in class java.lang.Object
public boolean touches(Rectangle rect)
true
if the input Rectangle touches this Rectangle.rect
- Rectangle being checked for contacttrue
if rect touches this Rectanglepublic Rectangle translate(double dx, double dy)
dx
- Shift along X axisdy
- Shift along Y axisthis
for conveniencepublic Rectangle translate(int dx, int dy)
dx
- Shift along X axisdy
- Shift along Y axisthis
for conveniencepublic Rectangle translate(Point p)
p
- Point which provides translation informationthis
for conveniencepublic Rectangle transpose()
this
for conveniencepublic Rectangle union(Dimension d)
Dimension.max(Dimension, Dimension)
and
setSize(Dimension)
to implement the desired behavior
instead.d
- Dimension being unionedthis
for conveniencepublic Rectangle union(double x, double y)
x
- X coordinatey
- Y coordinatethis
for conveniencepublic Rectangle union(double x, double y, double w, double h)
x
- X coordinate of desired union.y
- Y coordinate of desired union.w
- Width of desired union.h
- Height of desired union.this
for conveniencepublic Rectangle union(int x1, int y1)
x1
- X coordinatey1
- Y coordinatethis
for conveniencepublic Rectangle union(int x, int y, int w, int h)
x
- X coordinate of desired union.y
- Y coordinate of desired union.w
- Width of desired union.h
- Height of desired union.this
for conveniencepublic void union(Point p)
p
- Point to be unioned with this Rectanglepublic Rectangle union(Rectangle rect)
rect
- Rectangle to be unioned with this Rectanglethis
for conveniencepublic int width()
public int x()
public int y()
Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.