Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Draw2d
3.3

org.eclipse.draw2d.geometry
Class Rectangle

java.lang.Object
  extended by
org.eclipse.draw2d.geometry.Rectangle
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, 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 Rectangle.
 
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 this Rectangle.
 boolean contains ( Point pt)
          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)
          Crops this rectangle by the amount specified in insets.
 boolean equals (java.lang.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 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 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 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.
  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 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 ( Rectangle rect)
          Returns a new Rectangle which contains both this Rectangle and the Rectangle supplied as input.
 int hashCode ()
           
  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 sizeDelta)
          Resizes this Rectangle by the Dimension provided as input and returns this for convenience.
  Rectangle resize (int dw, int dh)
          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 ( Rectangle rect)
          Sets the parameters of this Rectangle from the Rectangle passed in and returns this for convenience.
  Rectangle setLocation (int x1, int y1)
          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 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 (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)
          Unions this Rectangle's width and height with the specified Dimension.
  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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x
the X value


y

public int y
the Y value


width

public int width
the width


height

public int height
the height


SINGLETON

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

Constructor Detail

Rectangle

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

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(
Rectangle rect)
Constructs a copy of the provided Rectangle.

Parameters:
rect - Rectangle supplying the initial values
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(
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
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(
Point pt)
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:
pt - 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

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

crop

public 
Rectangle crop(
Insets insets)
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(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.

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 for convenience
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.

Parameters:
insets - contains the amounts to expand on each side
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)
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.

Parameters:
insets - The insets used to expand this rectangle
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 interection.

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 pt)

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:
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(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

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:
Point at the right of the Rectangle
Since:
2.0

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(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(
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()
See Also:
Object.hashCode()

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 intersetion 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)

resize

public 
Rectangle resize(
Dimension sizeDelta)
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:
sizeDelta - Resize data as a Dimension
Returns:
this for convenience
Since:
2.0

resize

public 
Rectangle resize(int dw,
                        int dh)
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:
dw - Amount by which width is to be resized
dh - 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(
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

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

setLocation

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

Parameters:
x1 - The new X coordinate
y1 - The new Y coordinate
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

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.

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(
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

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

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)
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(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 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

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 coordiante of desired union.
y - Y coordiante of desired union.
w - Width of desired union.
h - Height of desired union.
Returns:
this for convenience
Since:
2.0

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

preciseWidth

public double preciseWidth()
Returns double width

Returns:
double width
Since:
3.4

preciseHeight

public double preciseHeight()
Returns double height

Returns:
double height
Since:
3.4

Eclipse Draw2d
3.3

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

 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire