element
Class Rect

java.lang.Object
  |
  +--element.Rect
Direct Known Subclasses:
Oval, RoundRect

public class Rect
extends java.lang.Object
implements Drawable

An implementation of a simple graphics rectangle.


Field Summary
protected  int height
          The height of the rectangle.
protected  int left
          The left side of the rectangle.
protected  int top
          The top side of the rectangle.
protected  int width
          The width of the rectangle.
 
Constructor Summary
Rect()
          Constructs a trivial rectangle, about the origin.
Rect(Drawable o)
          Construct a rectangle from the bounding box of another drawable object.
Rect(int cx, int cy, int r)
          Construct a square centered about (cx,cy), with radius r.
Rect(int x, int y, int w, int h)
          Construct a rectangle with upper left (x,y) and dimensions (w,h).
Rect(Pt p, int r)
          Construct a square with radius r, centered about a point p.
Rect(Pt p1, Pt p2)
          Constructs the rectangle determined by two points, p1 and p2.
 
Method Summary
 int bottom()
          Returns the bottom coordinate of the rectangle
 void bottom(int y)
          Sets the bottom side of rectangle.
 Pt center()
          Returns the center point of the rectangle.
 void center(Pt p)
          Sets the center point of the rectangle.
 void clearOn(DrawingWindow d)
          Erase rectangle from the drawing window d.
 java.lang.Object clone()
          return a distinct copy of this rectangle
 boolean contains(Pt p)
          Returns true if p is contained within rectangle
 void drawOn(DrawingWindow d)
          Draw (in the current mode) the rectangle on the drawing window
 boolean equals(java.lang.Object other)
          Return true iff this rectangle equals the other
 void extend(int dx, int dy)
          Moves the sides of the rectangle outward by dx and dy.
 void fillOn(DrawingWindow d)
          Draw a filled rectangle (in the current mode) on drawing window d.
 int hashCode()
          Return an integer for use as a hash code
 int height()
          Returns the height of the rectangle.
 void height(int h)
          Sets the height of the rectangle.
 int left()
          Return the left coordinate of the rectangle.
 void left(int x)
          Sets the left side of the rectangle.
 void move(int dx, int dy)
          Moves the rectangle in the direction (dx,dy).
 void moveTo(int left, int top)
          Moves the top-left coordinate of the rectangle to (left,top).
 void moveTo(Pt p)
          Moves the top-left coordinate to point p
 java.awt.Rectangle Rectangle()
          Construct an AWT rectangle from this rect.
 int right()
          Returns right coordinate of the rectangle
 void right(int x)
          Sets the right coordinate of rectangle.
 int top()
          Returns the top coordinate of the rectangle
 void top(int y)
          Sets the top side of the rectangle.
 java.lang.String toString()
          Construct a string representation of this rectangle
 int width()
          Returns the width of the rectangle.
 void width(int w)
          Sets the width of the rectangle.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

left

protected int left
The left side of the rectangle.

top

protected int top
The top side of the rectangle.

width

protected int width
The width of the rectangle.

height

protected int height
The height of the rectangle.
Constructor Detail

Rect

public Rect()
Constructs a trivial rectangle, about the origin.

Rect

public Rect(Pt p1,
            Pt p2)
Constructs the rectangle determined by two points, p1 and p2.
Parameters:
p1 - one corner of the rectangle
p2 - the opposite corner of the rectangle

Rect

public Rect(Drawable o)
Construct a rectangle from the bounding box of another drawable object.
Parameters:
o - an object to be used as the basis for the constructed rect.

Rect

public Rect(int cx,
            int cy,
            int r)
Construct a square centered about (cx,cy), with radius r.
Parameters:
cx - the x coordinate of the center
cy - the y coordinate of the center
r - the radius of the rectangle

Rect

public Rect(Pt p,
            int r)
Construct a square with radius r, centered about a point p.
Parameters:
p - the center of the square
r - the radius of the square

Rect

public Rect(int x,
            int y,
            int w,
            int h)
Construct a rectangle with upper left (x,y) and dimensions (w,h).
Parameters:
x - the left of the rectangle
y - the top of the rectangle
w - the width of the rectangle
h - the height of the rectangle
Method Detail

contains

public boolean contains(Pt p)
Returns true if p is contained within rectangle
Parameters:
p - the point to be considered
Returns:
true iff p is contained within the rectangle

left

public int left()
Return the left coordinate of the rectangle.
Specified by:
left in interface Drawable
Returns:
the left coordinate of the rectangle

top

public int top()
Returns the top coordinate of the rectangle
Specified by:
top in interface Drawable
Returns:
the top coordinate of the rectangle

right

public int right()
Returns right coordinate of the rectangle
Specified by:
right in interface Drawable
Returns:
the right coordinate of the rectangle

bottom

public int bottom()
Returns the bottom coordinate of the rectangle
Specified by:
bottom in interface Drawable
Returns:
the bottom coordinate of the rectangle

width

public int width()
Returns the width of the rectangle.
Specified by:
width in interface Drawable
Returns:
the width of the rectangle

height

public int height()
Returns the height of the rectangle.
Specified by:
height in interface Drawable
Returns:
the height of the rectangle

width

public void width(int w)
Sets the width of the rectangle. Center and height remain unchanged.
Parameters:
w - the desired width.

height

public void height(int h)
Sets the height of the rectangle. Center and width remain unchanged.
Parameters:
h - the desired height.

left

public void left(int x)
Sets the left side of the rectangle. Dimensions remain unchanged.
Parameters:
x - the desired left side.

top

public void top(int y)
Sets the top side of the rectangle. Dimensions remain unchanged.
Parameters:
y - the new top coordinate.

bottom

public void bottom(int y)
Sets the bottom side of rectangle. Dimensions remain unchanged.
Parameters:
y - the new bottom coordinate.

right

public void right(int x)
Sets the right coordinate of rectangle. Dimensions remain unchanged.
Parameters:
x - the new right coordinate.

center

public Pt center()
Returns the center point of the rectangle.
Specified by:
center in interface Drawable
Returns:
the center point of the rectangle

center

public void center(Pt p)
Sets the center point of the rectangle. The dimensions remain unchanged.
Specified by:
center in interface Drawable
Parameters:
p - the new center point of the rectangle

move

public void move(int dx,
                 int dy)
Moves the rectangle in the direction (dx,dy).
Parameters:
dx - the horizontal change in position
dy - the vertical change in position

moveTo

public void moveTo(int left,
                   int top)
Moves the top-left coordinate of the rectangle to (left,top). The dimensions remain unchanged.
Parameters:
left - the new left coordinate
top - the new top coordinate

moveTo

public void moveTo(Pt p)
Moves the top-left coordinate to point p
Parameters:
p - the new top left position

extend

public void extend(int dx,
                   int dy)
Moves the sides of the rectangle outward by dx and dy.
Parameters:
dx - the change in horizontal coordinates - positive is outward
dy - the change in vertical coordinates - positive is outward

fillOn

public void fillOn(DrawingWindow d)
Draw a filled rectangle (in the current mode) on drawing window d.
Specified by:
fillOn in interface Drawable
Parameters:
d - the target drawing window.
See Also:
DrawingWindow.fill(element.Drawable), DrawingWindow.paintMode(), DrawingWindow.invertMode()

clearOn

public void clearOn(DrawingWindow d)
Erase rectangle from the drawing window d.
Specified by:
clearOn in interface Drawable
Parameters:
d - the target drawing window
See Also:
DrawingWindow.clear(element.Drawable)

drawOn

public void drawOn(DrawingWindow d)
Draw (in the current mode) the rectangle on the drawing window
Specified by:
drawOn in interface Drawable
Parameters:
d - the target drawing window
See Also:
DrawingWindow.paintMode(), DrawingWindow.invertMode(), DrawingWindow.draw(element.Drawable)

hashCode

public int hashCode()
Return an integer for use as a hash code
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code

equals

public boolean equals(java.lang.Object other)
Return true iff this rectangle equals the other
Overrides:
equals in class java.lang.Object
Parameters:
other - another valid rectangle
Returns:
true if the two are equal valued, false otherwise

clone

public java.lang.Object clone()
return a distinct copy of this rectangle
Overrides:
clone in class java.lang.Object
Returns:
a distinct copy of this rectangle

Rectangle

public java.awt.Rectangle Rectangle()
Construct an AWT rectangle from this rect.
Returns:
an AWT rectangle
See Also:
Rectangle

toString

public java.lang.String toString()
Construct a string representation of this rectangle
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this rectangle