Draw2d
3.9.0.201305060205

org.eclipse.draw2d.geometry
Class Rectangle

java.lang.Object
  extended by org.eclipse.draw2d.geometry.Rectangle
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Translatable
Direct Known Subclasses:
PrecisionRectangle

public class Rectangle
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, Translatable

Represents a Rectangle(x, y, width, height). This class provides various methods for manipulating this Rectangle or creating new derived geometrical Objects.

See Also:
Serialized Form

Field Summary
 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 Summary
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.
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SINGLETON

public static final Rectangle SINGLETON
A singleton for use in short calculations. Use to avoid newing unnecessary objects.


height

public int height
The height


width

public int width
The width


x

public int x
The x value


y

public int y
The y value

Constructor Detail

Rectangle

public Rectangle()
Constructs a Rectangle at the origin with zero width and height.

Since:
2.0

Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Constructs a Rectangle with the provided values.

Parameters:
x - X location
y - Y location
width - Width of the rectangle
height - Height of the rectangle
Since:
2.0

Rectangle

public Rectangle(Rectangle rect)
Constructs a copy of the provided SWT Rectangle.

Parameters:
rect - The SWT Rectangle being copied
Since:
2.0

Rectangle

public Rectangle(Point p,
                 Dimension size)
Constructs a Rectangle given a location and size.

Parameters:
p - the location
size - the size
Since:
2.0

Rectangle

public Rectangle(Point p1,
                 Point p2)
Constructs the smallest Rectangle that contains the specified Points.

Parameters:
p1 - Upper left hand corner
p2 - Lower right hand corner
Since:
2.0

Rectangle

public Rectangle(Rectangle rect)
Constructs a copy of the provided Rectangle.

Parameters:
rect - Rectangle supplying the initial values
Since:
2.0
Method Detail

bottom

public int bottom()
Returns the y-coordinate of the bottom of this Rectangle.

Returns:
The Y coordinate of the bottom
Since:
2.0

contains

public boolean contains(double x,
                        double y)
Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.

Parameters:
x - X value
y - Y value
Returns:
true if the coordinates are within this Rectangle
Since:
3.8

contains

public boolean contains(int x,
                        int y)
Returns whether the given coordinates are within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.

Parameters:
x - X value
y - Y value
Returns:
true if the coordinates are within this Rectangle
Since:
2.0

contains

public boolean contains(Point p)
Returns whether the given point is within the boundaries of this Rectangle. The boundaries are inclusive of the top and left edges, but exclusive of the bottom and right edges.

Parameters:
p - Point being tested for containment
Returns:
true if the Point is within this Rectangle
Since:
2.0

contains

public boolean contains(Rectangle rect)
Returns true if the given rectangle is contained within the boundaries of this Rectangle.

Parameters:
rect - the Rectangle to test
Returns:
true if the Rectangle is within this Rectangle

crop

public Rectangle crop(Insets insets)
Deprecated. Use shrink(Insets) instead.

Crops this rectangle by the amount specified in insets.

Parameters:
insets - Insets to be removed from the Rectangle
Returns:
this for convenience
Since:
2.0

equals

public 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.

Parameters:
x - The x value to test
y - The y value to test
width - The width value to test
height - The height value to test
Returns:
true if this Rectangle's x, y, width, and height values are identical to the provided ones, false otherwise
Since:
3.7

equals

public boolean equals(java.lang.Object o)
Returns whether the input object is equal to this Rectangle or not. Rectangles are equivalent if their x, y, height, and width values are the same.

Overrides:
equals in class java.lang.Object
Parameters:
o - Object being tested for equality
Returns:
Returns the result of the equality test
Since:
2.0

expand

public 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. The location of its center is kept constant.

Parameters:
h - Horizontal increment
v - Vertical increment
Returns:
this for convenience
Since:
3.8

expand

public 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.

Parameters:
insets - contains the amounts to expand on each side
Returns:
this for convenience
Since:
2.0

expand

public 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. The location of its center is kept constant.

Parameters:
h - Horizontal increment
v - Vertical increment
Returns:
this for convenience
Since:
2.0

getBottom

public Point getBottom()
Returns a new Point representing the middle point of the bottom side of this Rectangle.

Returns:
Point at the bottom of the Rectangle
Since:
2.0

getBottomLeft

public Point getBottomLeft()
Returns a new Point representing the bottom left point of this Rectangle.

Returns:
Point at the bottom left of the rectangle
Since:
2.0

getBottomRight

public Point getBottomRight()
Returns a new Point representing the bottom right point of this Rectangle.

Returns:
Point at the bottom right of the rectangle
Since:
2.0

getCenter

public Point getCenter()
Returns a new point representing the center of this Rectangle.

Returns:
Point at the center of the rectangle

getCopy

public Rectangle getCopy()
Returns a new Rectangle which has the exact same parameters as this Rectangle.

Returns:
Copy of this Rectangle
Since:
2.0

getCropped

public Rectangle getCropped(Insets insets)
Deprecated. Use getShrinked(Insets) instead.

Returns a new Rectangle with the specified insets cropped.

Parameters:
insets - Insets being cropped from the Rectangle
Returns:
Cropped new Rectangle

getExpanded

public Rectangle getExpanded(double h,
                             double v)
Returns a new incremented Rectangle, where the sides are expanded by the horizontal and vertical values provided. The center of the Rectangle is maintained constant.

Parameters:
h - Horizontal increment
v - Vertical increment
Returns:
A new expanded Rectangle
Since:
3.8

getExpanded

public Rectangle getExpanded(Insets insets)
Creates and returns a new Rectangle with the bounds of this Rectangle, expanded by the given Insets.

Parameters:
insets - The insets used to expand this rectangle
Returns:
A new expanded Rectangle
Since:
2.0

getExpanded

public Rectangle getExpanded(int h,
                             int v)
Returns a new incremented Rectangle, where the sides are expanded by the horizontal and vertical values provided. The center of the Rectangle is maintained constant.

Parameters:
h - Horizontal increment
v - Vertical increment
Returns:
A new expanded Rectangle
Since:
2.0

getIntersection

public Rectangle getIntersection(Rectangle rect)
Returns a new Rectangle which has the intersection of this Rectangle and the rectangle provided as input. Returns an empty Rectangle if there is no intersection.

Parameters:
rect - Rectangle provided to test for intersection
Returns:
A new Rectangle representing the intersection
Since:
2.0

getLeft

public Point getLeft()
Returns a new Point representing the middle point of the left hand side of this Rectangle.

Returns:
Point at the left of the Rectangle

getLocation

public Point getLocation()
Returns the upper left hand corner of the rectangle.

Returns:
Location of the rectangle
See Also:
setLocation(Point)

getPosition

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.

Parameters:
p - The Point whose position has to be determined
Returns:
An int which is a PositionConstant
Since:
2.0
See Also:
PositionConstants

getResized

public Rectangle getResized(Dimension d)
Returns a new Rectangle which is equivalent to this Rectangle with its dimensions modified by the passed Dimension d.

Parameters:
d - Dimensions by which the rectangle's size should be modified
Returns:
The new rectangle with the modified dimensions
Since:
2.0

getResized

public 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.

Parameters:
w - Amount by which width is to be resized
h - Amount by which height is to be resized
Returns:
a new rectangle with its width and height modified
Since:
3.8

getResized

public 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.

Parameters:
w - Amount by which width is to be resized
h - Amount by which height is to be resized
Returns:
a new rectangle with its width and height modified

getRight

public Point getRight()
Returns a new Point which represents the middle point of the right hand side of this Rectangle.

Returns:
Point at the right of the Rectangle
Since:
2.0

getShrinked

public Rectangle getShrinked(double h,
                             double v)
Returns a new Rectangle, where the sides are shrinked by the horizontal and vertical values supplied. The center of this Rectangle is kept constant.

Parameters:
h - Horizontal reduction amount
v - Vertical reduction amount
Returns:
this for convenience
Since:
3.8

getShrinked

public Rectangle getShrinked(Insets insets)
Returns a new Rectangle shrinked by the specified insets.

Parameters:
insets - Insets being cropped from the Rectangle
Returns:
Shrinked new Rectangle
Since:
3.7

getShrinked

public Rectangle getShrinked(int h,
                             int v)
Returns a new Rectangle, where the sides are shrinked by the horizontal and vertical values supplied. The center of this Rectangle is kept constant.

Parameters:
h - Horizontal reduction amount
v - Vertical reduction amount
Returns:
this for convenience
Since:
3.7

getSize

public Dimension getSize()
Retuns the dimensions of this Rectangle.

Returns:
Size of this Rectangle as a Dimension
Since:
2.0

getTop

public Point getTop()
Returns a new Point which represents the middle point of the top side of this Rectangle.

Returns:
Point at the top of the Rectangle
Since:
2.0

getTopLeft

public Point getTopLeft()
Returns a new Point which represents the top left hand corner of this Rectangle.

Returns:
Point at the top left of the rectangle
Since:
2.0

getTopRight

public Point getTopRight()
Returns a new Point which represents the top right hand corner of this Rectangle.

Returns:
Point at the top right of the rectangle
Since:
2.0

getTranslated

public Rectangle getTranslated(double dx,
                               double dy)
Returns a new Rectangle which is shifted along each axis by the passed values.

Parameters:
dx - Displacement along X axis
dy - Displacement along Y axis
Returns:
The new translated rectangle
Since:
3.8

getTranslated

public Rectangle getTranslated(int dx,
                               int dy)
Returns a new Rectangle which is shifted along each axis by the passed values.

Parameters:
dx - Displacement along X axis
dy - Displacement along Y axis
Returns:
The new translated rectangle
Since:
2.0

getTranslated

public Rectangle getTranslated(Point pt)
Returns a new Rectangle which is shifted by the position of the given Point.

Parameters:
pt - Point providing the amount of shift along each axis
Returns:
The new translated Rectangle
Since:
2.0

getTransposed

public Rectangle getTransposed()
Returns a new rectangle whose width and height have been interchanged, as well as its x and y values. This can be useful in orientation changes.

Returns:
The transposed rectangle
Since:
2.0

getUnion

public Rectangle getUnion(Point p)
Returns a new Rectangle which contains both this Rectangle and the Point supplied as input.

Parameters:
p - Point for calculating union
Returns:
A new unioned Rectangle
Since:
3.7

getUnion

public Rectangle getUnion(Rectangle rect)
Returns a new Rectangle which contains both this Rectangle and the Rectangle supplied as input.

Parameters:
rect - Rectangle for calculating union
Returns:
A new unioned Rectangle
Since:
2.0

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

height

public int height()
Returns the current height of this Rectangle

Returns:
The current height
Since:
3.7

intersect

public 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. The location and dimensions are set to zero if there is no intersection with the input Rectangle.

Parameters:
rect - Rectangle for the calculating intersection.
Returns:
this for convenience
Since:
2.0

intersects

public boolean intersects(Rectangle rect)
Returns true if the input Rectangle intersects this Rectangle.

Parameters:
rect - Rectangle for the intersection test
Returns:
true if the input Rectangle intersects this Rectangle
Since:
2.0

isEmpty

public boolean isEmpty()
Returns true if this Rectangle's width or height is less than or equal to 0.

Returns:
true if this Rectangle is empty
Since:
2.0

performScale

public void performScale(double factor)
Description copied from interface: Translatable
Scales this object by the scale factor.

Specified by:
performScale in interface Translatable
Parameters:
factor - The scale factor
See Also:
Translatable.performScale(double)

performTranslate

public void performTranslate(int dx,
                             int dy)
Description copied from interface: Translatable
Translates this object horizontally by dx and vertically by dy.

Specified by:
performTranslate in interface Translatable
Parameters:
dx - The amount to translate horizontally
dy - The amount to translate vertically
See Also:
Translatable.performTranslate(int, int)

preciseHeight

public double preciseHeight()
Returns double height

Returns:
double height
Since:
3.4

preciseWidth

public double preciseWidth()
Returns double width

Returns:
double width
Since:
3.4

preciseX

public double preciseX()
Returns double x coordinate

Returns:
double x coordinate
Since:
3.4

preciseY

public double preciseY()
Returns double y coordinate

Returns:
double y coordinate
Since:
3.4

resize

public Rectangle resize(Dimension d)
Resizes this Rectangle by the Dimension provided as input and returns this for convenience. This Rectange's width will become this.width + sizeDelta.width. Likewise for height.

Parameters:
d - Resize data as a Dimension
Returns:
this for convenience
Since:
2.0

resize

public Rectangle resize(double w,
                        double h)
Resizes this Rectangle by the values supplied as input and returns this for convenience. This Rectangle's width will become this.width + dw. This Rectangle's height will become this.height + dh.

Parameters:
w - Amount by which width is to be resized
h - Amount by which height is to be resized
Returns:
this for convenience
Since:
3.8

resize

public Rectangle resize(int w,
                        int h)
Resizes this Rectangle by the values supplied as input and returns this for convenience. This Rectangle's width will become this.width + dw. This Rectangle's height will become this.height + dh.

Parameters:
w - Amount by which width is to be resized
h - Amount by which height is to be resized
Returns:
this for convenience
Since:
2.0

right

public int right()
Returns the x-coordinate of the right side of this Rectangle.

Returns:
The X coordinate of the right side
Since:
2.0

scale

public final Rectangle scale(double scaleFactor)
Scales the location and size of this Rectangle by the given scale and returns this for convenience.

Parameters:
scaleFactor - The factor by which this rectangle will be scaled
Returns:
this for convenience
Since:
2.0

scale

public Rectangle scale(double scaleX,
                       double scaleY)
Scales the location and size of this Rectangle by the given scales and returns this for convenience.

Parameters:
scaleX - the factor by which the X dimension has to be scaled
scaleY - the factor by which the Y dimension has to be scaled
Returns:
this for convenience
Since:
2.0

setBounds

public 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.

Parameters:
x - The new x
y - The new y
width - The new width
height - The new height
Returns:
this for convenience
Since:
3.7

setBounds

public Rectangle setBounds(Point location,
                           Dimension size)
Sets the location and size of this rectangle to the provided ones.

Parameters:
location - The new location
size - The new size
Returns:
this for convenience
Since:
3.7

setBounds

public Rectangle setBounds(Rectangle rect)
Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.

Parameters:
rect - Rectangle providing the bounding values
Returns:
this for convenience
Since:
2.0

setHeight

public Rectangle setHeight(int height)
Sets the height of this Rectangle to the specified one.

Parameters:
height - The new height
Returns:
this for convenience.
Since:
3.7

setLocation

public Rectangle setLocation(int x,
                             int y)
Sets the location of this Rectangle to the coordinates given as input and returns this for convenience.

Parameters:
x - The new X coordinate
y - The new Y coordinate
Returns:
this for convenience
Since:
2.0

setLocation

public Rectangle setLocation(Point p)
Sets the location of this Rectangle to the point given as input and returns this for convenience.

Parameters:
p - New position of this Rectangle
Returns:
this for convenience
Since:
2.0

setSize

public 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.

Parameters:
d - The new Dimension
Returns:
this for convenience
Since:
2.0

setSize

public 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.

Parameters:
w - The new width
h - The new height
Returns:
this for convenience
Since:
2.0

setWidth

public Rectangle setWidth(int width)
Sets the width of this Rectangle to the specified one.

Parameters:
width - The new width
Returns:
this for convenience.
Since:
3.7

setX

public Rectangle setX(int x)
Sets the x value of the Rectangle and returns this for convenience.

Parameters:
x - The new x value
Returns:
this for convenience
Since:
3.7

setY

public Rectangle setY(int y)
Sets the y value of the Rectangle and returns this for convenience.

Parameters:
y - The new y value
Returns:
this for convenience
Since:
3.7

shrink

public 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. The center of this Rectangle is kept constant.

Parameters:
h - Horizontal reduction amount
v - Vertical reduction amount
Returns:
this for convenience
Since:
3.8

shrink

public Rectangle shrink(Insets insets)
Shrinks this rectangle by the amount specified in insets.

Parameters:
insets - Insets to be removed from the Rectangle
Returns:
this for convenience
Since:
3.7

shrink

public 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. The center of this Rectangle is kept constant.

Parameters:
h - Horizontal reduction amount
v - Vertical reduction amount
Returns:
this for convenience
Since:
2.0

toString

public java.lang.String toString()
Returns the description of this Rectangle.

Overrides:
toString in class java.lang.Object
Returns:
String containing the description
Since:
2.0

touches

public boolean touches(Rectangle rect)
Returns true if the input Rectangle touches this Rectangle.

Parameters:
rect - Rectangle being checked for contact
Returns:
true if rect touches this Rectangle
Since:
2.0

translate

public Rectangle translate(double dx,
                           double dy)
Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.

Parameters:
dx - Shift along X axis
dy - Shift along Y axis
Returns:
this for convenience
Since:
3.8

translate

public Rectangle translate(int dx,
                           int dy)
Moves this Rectangle horizontally by dx and vertically by dy, then returns this Rectangle for convenience.

Parameters:
dx - Shift along X axis
dy - Shift along Y axis
Returns:
this for convenience
Since:
2.0

translate

public 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.

Parameters:
p - Point which provides translation information
Returns:
this for convenience

transpose

public Rectangle transpose()
Switches the x and y values, as well as the width and height of this Rectangle. Useful for orientation changes.

Returns:
this for convenience
Since:
2.0

union

public 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.

Unions this Rectangle's width and height with the specified Dimension.

Parameters:
d - Dimension being unioned
Returns:
this for convenience
Since:
2.0

union

public 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).

Parameters:
x - X coordinate
y - Y coordinate
Returns:
this for convenience
Since:
3.8

union

public 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).

Parameters:
x - X coordinate of desired union.
y - Y coordinate of desired union.
w - Width of desired union.
h - Height of desired union.
Returns:
this for convenience
Since:
3.8

union

public 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).

Parameters:
x1 - X coordinate
y1 - Y coordinate
Returns:
this for convenience
Since:
2.0

union

public 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).

Parameters:
x - X coordinate of desired union.
y - Y coordinate of desired union.
w - Width of desired union.
h - Height of desired union.
Returns:
this for convenience
Since:
2.0

union

public void union(Point p)
Updates this Rectangle's bounds to the minimum size which can hold both this Rectangle and the given Point.

Parameters:
p - Point to be unioned with this Rectangle
Since:
2.0

union

public Rectangle union(Rectangle rect)
Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the given Rectangle.

Parameters:
rect - Rectangle to be unioned with this Rectangle
Returns:
this for convenience
Since:
2.0

width

public int width()
Returns the current width of this Rectangle

Returns:
The current width
Since:
3.7

x

public int x()
Returns the x value of this Rectangle.

Returns:
The current x value
Since:
3.7

y

public int y()
Returns the y value of the Rectangle

Returns:
The current y value
Since:
3.7

Draw2d
3.9.0.201305060205

Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.