Draw2D v2.0

org.eclipse.draw2d.geometry
Class Rectangle

java.lang.Object
  |
  +--org.eclipse.draw2d.geometry.Rectangle
All Implemented Interfaces:
Cloneable, Serializable, Translatable

public class Rectangle
extends Object
implements Cloneable, Serializable, Translatable

Provides support for a rectangle.

See Also:
Serialized Form

Field Summary
 int height
           
static Rectangle SINGLETON
           
 int width
           
 int x
           
 int y
           
 
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 location coordinates, width and height provided as input.
Rectangle(Point pt, Dimension d)
          Constructs a Rectangle given its upper left hand corner and its dimensions.
Rectangle(Point p1, Point p2)
          Constructs a Rectangle provided it upper left and lower right points.
Rectangle(Rectangle copy)
          Constructs a Rectangle with the location and size of the input Rectangle.
Rectangle(Rectangle r)
          Constructs a Rectangle with the same location and size of the SWT Rectangle provided as input.
 
Method Summary
 int bottom()
          Returns the y-coordinate of the bottom of this Rectangle
 boolean contains(int x, int y)
          Returns whether the given coordinates are within the boundaries of the rectangle, inclusive of the top and left boundary lines.
 boolean contains(Point pt)
          Returns whether the given point is within the boundaries of the rectangle, inclusive of the top and left boundary.
 Rectangle crop(Insets insets)
          Removes the space provided by the Insets from this Rectangle, and returns this for convenience.
 boolean equals(Object o)
          Returns whether the input object is equal to this Rectangle or not.
 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)
          Returns a new Rectangle with the specified insets cropped.
 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 horizonatal 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 Rectangle 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 pt)
          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(int w, int h)
          Returns a new rectangle with its width and height augmented.
 Point getRight()
          Returns a new Point which represents the middle point of the right hand side of this Rectangle.
 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(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 input Point supplied.
 Rectangle getTransposed()
          Returns a new rectangle whose width and height have been interchanged.
 Rectangle getUnion(Rectangle rect)
          Returns the rectangular area which contains both this Rectangle and the Rectangle supplied as input.
 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 if the input Rectangle intersects this Rectangle.
 boolean isEmpty()
          Returns whether this Rectangle has any dimensions.
 void performScale(float factor)
          Scales this object by the scale factor.
 void performTranslate(int dx, int dy)
          Translates this Rectangle by (dx,dy).
 Rectangle resize(Dimension sizeDelta)
          Resizes this Rectangle by the dimensions provided as input, and returns this for convenience.
 Rectangle resize(int dw, int dh)
          Resizes this Rectangle by the dimension values supplied as input, and returns this for convenience.
 int right()
          Returns the right end of the rectangle along the X axis.
 Rectangle scale(float scaleFactor)
          Scales the location and size of this Rectangle by the given scale.
 Rectangle scale(float scaleX, float scaleY)
          Scales the location and size of this Rectangle by the given scales.
 Rectangle setBounds(Rectangle rect)
          Sets the parameters of this Rectangle from the Rectangle passed in.
 Rectangle setLocation(int x1, int y1)
          Sets the location of this Rectangle to the coordinates given as input.
 Rectangle setLocation(Point p)
          Sets the location of this Rectangle to the point given as input.
 Rectangle setSize(Dimension d)
          Sets the dimensions of this Rectangle to the input Dimension values.
 Rectangle setSize(int w, int h)
          Sets the dimensions of this Rectangle to the values given as input.
 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.
 String toString()
          Returns the description of this Rectangle.
 boolean touches(Rectangle rect)
          Returns whether the input Rectangle touches this Rectangle.
 Rectangle translate(int dx, int dy)
          Returns this Rectangle after moving the center of the coordinate system by the values specified along each axis.
 Rectangle translate(Point p)
          Returns this Rectangle after moving the center of the coordinate system Point p.
 void transpose()
          Switches the location and the dimension of this Rectangle.
 void union(Dimension d)
          Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the supplied Dimension.
 void union(int x1, int y1)
          Updates this Rectangle's Dimensions to the minimum size which can hold both this Rectangle and the supplied point, given its X and Y coordinates.
 void 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 passed parameters.
 void union(Point p)
          Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the supplied Point.
 void union(Rectangle rect)
          Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the passed Rectangle rect.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x

y

public int y

width

public int width

height

public int height

SINGLETON

public static Rectangle SINGLETON
Constructor Detail

Rectangle

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

Rectangle

public Rectangle(Point pt,
                 Dimension d)
Constructs a Rectangle given its upper left hand corner and its dimensions.
Parameters:
pt - Upper left corner point
d - Dimensions of the Rectangle.
Since:
2.0

Rectangle

public Rectangle(Rectangle copy)
Constructs a Rectangle with the location and size of the input Rectangle.
Parameters:
copy - Rectangle supplying the initial values.
Since:
2.0

Rectangle

public Rectangle(Rectangle r)
Constructs a Rectangle with the same location and size of the SWT Rectangle provided as input.
Parameters:
r - SWT Rectangle supplying the location and dimensions.
Since:
2.0
See Also:
Rectangle

Rectangle

public Rectangle(int _x,
                 int _y,
                 int _width,
                 int _height)
Constructs a Rectangle with the location coordinates, width and height provided as input.
Parameters:
_x - X position of the upper left hand corner of the Rectangle.
_y - Y position of the upper left hand corner of the Rectangle.
_width - Width of the rectangle.
_height - Height of the rectangle.
Since:
2.0

Rectangle

public Rectangle(Point p1,
                 Point p2)
Constructs a Rectangle provided it upper left and lower right points.
Parameters:
p1 - Upper left hand corner point.
p2 - Lower right hand corner point.
Since:
2.0
Method Detail

union

public void union(Dimension d)
Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the supplied Dimension.
Parameters:
d - Dimension against which union is performed.
Since:
2.0
See Also:
union(int,int), union(Point), union(Rectangle)

union

public void union(int x1,
                  int y1)
Updates this Rectangle's Dimensions to the minimum size which can hold both this Rectangle and the supplied point, given its X and Y coordinates.
Parameters:
x1 - Position along X axis against which union is performed.
y1 - Position along Y axis against which union is performed.
Since:
2.0
See Also:
union(Dimension), union(Point), union(Rectangle)

union

public final void union(Point p)
Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the supplied Point.
Parameters:
p - Point against which union is to be performed.
Since:
2.0
See Also:
union(int,int), union(Dimension), union(Rectangle)

union

public final void union(Rectangle rect)
Updates this Rectangle's dimensions to the minimum size which can hold both this Rectangle and the passed Rectangle rect.
Parameters:
rect - Rectangle against which union is performed.
Since:
2.0
See Also:
union(int,int), union(Point), union(Dimension)

union

public void 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 passed parameters.
Parameters:
_x - X coordiante of desired union.
_y - Y coordiante of desired union.
_w - Width of desired union.
_h - Height of desired union.
Since:
2.0
See Also:
union(int,int), union(Point), union(Dimension)

bottom

public int bottom()
Returns the y-coordinate of the bottom of this Rectangle
Returns:
The bottom of this rectangle as an integer.
Since:
2.0

contains

public boolean contains(Point pt)
Returns whether the given point is within the boundaries of the rectangle, inclusive of the top and left boundary.
Parameters:
pt - Point being tested for containment.
Returns:
Returns the result of the containment test.
Since:
2.0
See Also:
contains(int,int)

contains

public boolean contains(int x,
                        int y)
Returns whether the given coordinates are within the boundaries of the rectangle, inclusive of the top and left boundary lines.
Parameters:
pt - Point being tested for containment.
Returns:
Returns the result of the containment test.
Since:
2.0
See Also:
contains(Point)

crop

public Rectangle crop(Insets insets)
Removes the space provided by the Insets from this Rectangle, and returns this for convenience. The center of the Rectangle is kept constant.
Parameters:
insets - Insets to be removed from the Rectangle
Returns:
This Rectangle with the modified properties.
Since:
2.0

equals

public boolean equals(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 Object
Parameters:
o - Object being tested for equality.
Returns:
Returns the result of the equality test.
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 Rectangle with the modified height and width.
Since:
2.0

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. The location of its center is kept constant.
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)
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(int h,
                             int v)
Returns a new incremented Rectangle, where the sides are expanded by the horizonatal and vertical values provided. The center of the Rectangle is maintained constant.
Parameters:
h - Horizontal increment.
v - Vertical Inrement.
Returns:
A new expanded Rectangle.
Since:
2.0

getExpanded

public Rectangle getExpanded(Insets insets)
Creates and returns a new Rectangle with the bounds of this Rectangle, expanded by the given Insets. The location of its center is kept constant.
Since:
2.0
See Also:
expand(Insets)

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 interection.
Parameters:
rect - Rectangle provided to test for intersection.
Returns:
A new Rectangle representing the intersection.
Since:
2.0

getResized

public Rectangle getResized(int w,
                            int h)
Returns a new rectangle with its width and height augmented.

getTranslated

public Rectangle getTranslated(Point pt)
Returns a new Rectangle which is shifted by the position of the input Point supplied.
Parameters:
pt - Point providing the amount of shift along each axis.
Returns:
The new translated Rectangle.
Since:
2.0

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 translated rectangle.
Since:
2.0

getTransposed

public Rectangle getTransposed()
Returns a new rectangle whose width and height have been interchanged. This can be useful in orientation changes.
Returns:
The transposed rectangle.
Since:
2.0

getLeft

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

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 pt)
Returns an integer which represents the position of the given point with respect to this rectangle. Possible return values are WEST, EAST, NORTH, and SOUTH as found in PositionConstants Returns PositionConstant.NONE if the given point is in this Rectangle.
Parameters:
pt - 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

getRight

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

getSize

public Dimension getSize()
Retuns the dimensions of this Rectangle.
Returns:
Size of this Rectangle as a Dimension.
Since:
2.0
See Also:
setSize(Dimension), setSize(int,int)

getTop

public Point getTop()
Returns a new Point which represents the middle point of the top side of this Rectangle.
Returns:
The point requested.
Since:
2.0

getTopLeft

public Point getTopLeft()
Returns a new Point which represents the top left hand corner of this Rectangle.
Returns:
The requested point.
Since:
2.0

getTopRight

public Point getTopRight()
Returns a new Point which represents the top right hand corner of this Rectangle.
Returns:
The requested point.
Since:
2.0

getUnion

public Rectangle getUnion(Rectangle rect)
Returns the rectangular area which contains both this Rectangle and the Rectangle supplied as input.
Parameters:
rect - Rectangle for calculating union.
Returns:
Rectangular union region.
Since:
2.0

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:
Rectangular area of intersection.
Since:
2.0
See Also:
intersects(Rectangle)

intersects

public boolean intersects(Rectangle rect)
Returns if the input Rectangle intersects this Rectangle.
Parameters:
rect - Rectangle for the intersetion test.
Returns:
Result of the intersection test.
Since:
2.0
See Also:
intersects(Rectangle)

isEmpty

public boolean isEmpty()
Returns whether this Rectangle has any dimensions.
Returns:
Result of the emptiness test.
Since:
2.0

performScale

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

performTranslate

public void performTranslate(int dx,
                             int dy)
Translates this Rectangle by (dx,dy).
Specified by:
performTranslate in interface Translatable
Since:
2.0
See Also:
translate(int, int)

resize

public Rectangle resize(Dimension sizeDelta)
Resizes this Rectangle by the dimensions provided as input, and returns this for convenience. This Rectange's width will become this.width += sizeDelta.width. Likewise for height.
Parameters:
sizeDelta - Resize data as a Dimension.
Since:
2.0
See Also:
resize(int,int)

resize

public Rectangle resize(int dw,
                        int dh)
Resizes this Rectangle by the dimension 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:
dw - Amount by which width is to be resized.
dh - Amount by which height is to be resized.
Returns:
Resized rectangle.
Since:
2.0
See Also:
resize(Dimension)

right

public int right()
Returns the right end of the rectangle along the X axis.
Returns:
The requestion location.
Since:
2.0

scale

public final Rectangle scale(float scaleFactor)
Scales the location and size of this Rectangle by the given scale. Returns itself for convenience.
Parameters:
scaleFactor - The factor by which this rectangle will be scaled
Since:
2.0

scale

public Rectangle scale(float scaleX,
                       float scaleY)
Scales the location and size of this Rectangle by the given scales. Returns itself 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
Since:
2.0

setBounds

public Rectangle setBounds(Rectangle rect)
Sets the parameters of this Rectangle from the Rectangle passed in.
Parameters:
rect - Rectangle providing the bounding values.
Since:
2.0

setLocation

public Rectangle setLocation(Point p)
Sets the location of this Rectangle to the point given as input.
Parameters:
p - New position of this Rectangle.
Since:
2.0

setLocation

public Rectangle setLocation(int x1,
                             int y1)
Sets the location of this Rectangle to the coordinates given as input.
Parameters:
x1 - Position of rectangle along X axis.
y1 - Position of rectangle along Y axis.
Since:
2.0
See Also:
getLocation()

setSize

public Rectangle setSize(Dimension d)
Sets the dimensions of this Rectangle to the input Dimension values.
Parameters:
d - New Dimensions.
Since:
2.0
See Also:
setSize(int,int), getSize()

setSize

public Rectangle setSize(int w,
                         int h)
Sets the dimensions of this Rectangle to the values given as input.
Parameters:
w - New width.
h - New height.
Since:
2.0
See Also:
setSize(Dimension), getSize()

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 rectangle with the modified parameters.
Since:
2.0

toString

public String toString()
Returns the description of this Rectangle.
Overrides:
toString in class Object
Returns:
String containing the description.
Since:
2.0

touches

public boolean touches(Rectangle rect)
Returns whether the input Rectangle touches this Rectangle.
Parameters:
rect - Rectangle being checked for contact.
Returns:
Result of the contact test.
Since:
2.0

translate

public Rectangle translate(Point p)
Returns this Rectangle after moving the center of the coordinate system Point p.
Parameters:
p - Point which provides translation information.
Returns:
This Rectangle with the modified values.
See Also:
translate(int,int)

translate

public Rectangle translate(int dx,
                           int dy)
Returns this Rectangle after moving the center of the coordinate system by the values specified along each axis.
Parameters:
dx - Shift along X axis.
dy - Shift along Y axis.
Returns:
This Rectangle with the modified values.
Since:
2.0
See Also:
translate(Point)

transpose

public void transpose()
Switches the location and the dimension of this Rectangle. Useful for orientation changes.
Since:
2.0

Draw2D v2.0