gishur.gui2
Class RectangleShape

java.lang.Object
  |
  +--java.awt.geom.RectangularShape
        |
        +--java.awt.geom.Rectangle2D
              |
              +--java.awt.Rectangle
                    |
                    +--gishur.gui2.RectangleShape
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, java.io.Serializable, Shape, java.awt.Shape

public class RectangleShape
extends java.awt.Rectangle
implements Shape

A RectangleShape specifies an area in a coordinate space that is defined by the rectangle's top-left point (x,y) in the coordinate space, its width, and its height. RectangleShape extends the Java AWT's Rectangle class in order to implement Shape.

Version:
1.0
Author:
Thomas Wolf
See Also:
Serialized Form

Inner classes inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Fields inherited from class java.awt.Rectangle
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
RectangleShape()
          Constructs a new RectangleShape whose top-left corner is at (0,0) in the coordinate space, and whose width and height are zero.
RectangleShape(int width, int height)
          Constructs a new RectangleShape whose top-left corner is at (0,0) and whose width and height are specified by the arguments of the same name.
RectangleShape(int x, int y, int width, int height)
          Constructs a new RectangleShape whose top-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.
RectangleShape(java.awt.Rectangle r)
          Constructs a new RectangleShape, initialized to match the values of the specificed rectangle.
 
Method Summary
 void clear()
           
 java.lang.Object clone()
          Creates a new object of the same class as this object.
 boolean contains(int x, int y, int w, int h)
          Tests if the interior of the RectangleShape entirely contains the specified rectangular area.
 void draw(java.awt.Graphics g)
          Strokes the outline of the RectangleShape using the settings of the Graphics context.
 void fill(java.awt.Graphics g)
          Fills the interior of the RectangleShape using the settings of the Graphics context.
 RectangleShape getBoundShape()
          Return the bounding box of the RectangleShape.
 java.awt.Point getCenter()
          Returns the center point of the framing rectangle of the RectangleShape.
 int getCenterX()
          Returns the X coordinate of the center of the framing rectangle of the RectangleShape.
 int getCenterY()
          Returns the Y coordinate of the center of the framing rectangle of the RectangleShape.
 boolean intersects(int x, int y, int w, int h)
          Tests if the interior of the RectangleShape intersects the interior of a specified rectangular area.
 void set(int x, int y, int width, int height)
          Sets the RectangleShape to the specified values.
 java.lang.String toString()
          Returns a string representation of the object.
 void translate(int dx, int dy)
          Translates this RectangleShape by the vector (x,y).
 RectangleShape uniteWith(int x, int y, int width, int height)
          Computes the union of this RectangleShape with the specified rectangular area.
 RectangleShape uniteWith(java.awt.Rectangle r)
          Computes the union of this RectangleShape with the specified Rectangle.
 
Methods inherited from class java.awt.Rectangle
add, add, add, contains, contains, contains, createIntersection, createUnion, equals, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, union
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
 
Methods inherited from class java.awt.geom.RectangularShape
contains, contains, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gishur.gui2.Shape
contains, contains, setLocation
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
 

Constructor Detail

RectangleShape

public RectangleShape()
Constructs a new RectangleShape whose top-left corner is at (0,0) in the coordinate space, and whose width and height are zero.

RectangleShape

public RectangleShape(int width,
                      int height)
Constructs a new RectangleShape whose top-left corner is at (0,0) and whose width and height are specified by the arguments of the same name.
Parameters:
width - the width.
height - the height.

RectangleShape

public RectangleShape(int x,
                      int y,
                      int width,
                      int height)
Constructs a new RectangleShape whose top-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.
Parameters:
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.

RectangleShape

public RectangleShape(java.awt.Rectangle r)
Constructs a new RectangleShape, initialized to match the values of the specificed rectangle.
Parameters:
r - a rectangle from which to copy initial values.
Method Detail

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class java.awt.Rectangle
Returns:
a string representation of the object.

clone

public java.lang.Object clone()
Creates a new object of the same class as this object.
Specified by:
clone in interface Cloneable
Overrides:
clone in class java.awt.geom.RectangularShape
Returns:
a clone of this instance.
Throws:
OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

clear

public void clear()

uniteWith

public final RectangleShape uniteWith(int x,
                                      int y,
                                      int width,
                                      int height)
Computes the union of this RectangleShape with the specified rectangular area. If the given rectangle has zero (or less) width or height, the whole rectangle will be ignored. If this RectangleShape has zero (or less) width or height, it will be set to the coordinates of the given Rectangle.
Parameters:
x,y - upper left point of the other rectangle
width - the width of the other rectangle
height - the height of the other rectangle
Returns:
this modified RectangleShape

uniteWith

public RectangleShape uniteWith(java.awt.Rectangle r)
Computes the union of this RectangleShape with the specified Rectangle. If the given Rectangle has zero (or less) width or height, the whole rectangle will be ignored. If this RectangleShape has zero (or less) width or height, it will be set to the coordinates of the given Rectangle.
Parameters:
r - the specified RectangleShape
Returns:
this modified RectangleShape

set

public void set(int x,
                int y,
                int width,
                int height)
Sets the RectangleShape to the specified values.
Parameters:
x,y - new position of the upper left corner
width - new width
height - new height

intersects

public boolean intersects(int x,
                          int y,
                          int w,
                          int h)
Tests if the interior of the RectangleShape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the RectangleShape if any point is contained in both the interior of the RectangleShape and the specified rectangular area.
Specified by:
intersects in interface Shape
Parameters:
x, y - the coordinates of the specified rectangular area
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
true if the interior of the Shape and the interior of the rectangular area intersect; false otherwise.

contains

public boolean contains(int x,
                        int y,
                        int w,
                        int h)
Tests if the interior of the RectangleShape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the RectangleShape for the entire rectanglar area to be considered contained within the Shape.
Specified by:
contains in interface Shape
Overrides:
contains in class java.awt.Rectangle
Parameters:
x, y - the coordinates of the specified rectangular area
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
true if the interior of the Shape entirely contains the specified rectangular area; false otherwise.
See Also:
intersects(int, int, int, int)

getBoundShape

public RectangleShape getBoundShape()
Return the bounding box of the RectangleShape.
Specified by:
getBoundShape in interface Shape
Returns:
bounding box.

getCenterX

public int getCenterX()
Returns the X coordinate of the center of the framing rectangle of the RectangleShape.
Specified by:
getCenterX in interface Shape
Overrides:
getCenterX in class java.awt.geom.RectangularShape
Returns:
X coordinate of the RectangleShape

getCenterY

public int getCenterY()
Returns the Y coordinate of the center of the framing rectangle of the RectangleShape.
Specified by:
getCenterY in interface Shape
Overrides:
getCenterY in class java.awt.geom.RectangularShape
Returns:
Y coordinate of the shape

getCenter

public java.awt.Point getCenter()
Returns the center point of the framing rectangle of the RectangleShape.
Specified by:
getCenter in interface Shape
Returns:
center point of the RectangleShape

translate

public void translate(int dx,
                      int dy)
Translates this RectangleShape by the vector (x,y).
Specified by:
translate in interface Shape
Overrides:
translate in class java.awt.Rectangle
Parameters:
dx - x coordinate of the translation vector
dy - y coordinate of the translation vector

draw

public void draw(java.awt.Graphics g)
Strokes the outline of the RectangleShape using the settings of the Graphics context.
Specified by:
draw in interface Shape
Parameters:
g - Graphics context

fill

public void fill(java.awt.Graphics g)
Fills the interior of the RectangleShape using the settings of the Graphics context.
Specified by:
fill in interface Shape
Parameters:
g - Graphics context