view
Class MyRectangle

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.Rectangle
              extended by view.MyRectangle
All Implemented Interfaces:
Shape, Serializable, Cloneable

public class MyRectangle
extends Rectangle

A Rectangle that allows construction with a string of the format

   ,;x
   
Supports all constructors from the super class plus a constructor with a single string.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
 
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
MyRectangle()
          Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.
MyRectangle(Dimension d)
          Constructs a new Rectangle whose top left corner is (0, 0) and whose width and height are specified by the Dimension argument.
MyRectangle(int width, int height)
          Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are specified by the arguments of the same name.
MyRectangle(int x, int y, int width, int height)
          Constructs a new Rectangle whose top-left corner is specified as (xy) and whose width and height are specified by the arguments of the same name.
MyRectangle(Point p)
          Constructs a new Rectangle whose top-left corner is the specified Point, and whose width and height are both zero.
MyRectangle(Point p, Dimension d)
          Constructs a new Rectangle whose top-left corner is specified by the Point argument, and whose width and height are specified by the Dimension argument.
MyRectangle(Rectangle r)
          Constructs a new Rectangle, initialized to match the values of the specified Rectangle.
MyRectangle(String desc)
          Constrcuts a new rectangle from a string like '300,200;20x40'.
 
Method Summary
 double distanceToEdge(Point2D inside)
          Returns the distance of this pixel to the closest edge.
static double distanceToEdge(Rectangle2D rec, Point2D inside)
          Returns the distance of this pixel to the closest edge.
static Rectangle parseRectangle(String desc)
          Parses a point from a String.
 String toString()
          Overrides the string representation.
static String toString(Rectangle p)
          Overrides the string representation.
 
Methods inherited from class java.awt.Rectangle
add, add, add, contains, 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, translate, 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
clone, contains, contains, getCenterX, getCenterY, 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 java.awt.Shape
contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
 

Constructor Detail

MyRectangle

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


MyRectangle

public MyRectangle(Rectangle r)
Constructs a new Rectangle, initialized to match the values of the specified Rectangle.

Parameters:
r - the Rectangle from which to copy initial values to a newly constructed Rectangle
Since:
JDK1.1

MyRectangle

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

Parameters:
x - the specified x coordinate
y - the specified y coordinate
width - the width of the Rectangle
height - the height of the Rectangle

MyRectangle

public MyRectangle(int width,
                   int height)
Constructs a new Rectangle whose top-left corner is at (0, 0) in the coordinate space, and whose width and height are specified by the arguments of the same name.

Parameters:
width - the width of the Rectangle
height - the height of the Rectangle

MyRectangle

public MyRectangle(Point p,
                   Dimension d)
Constructs a new Rectangle whose top-left corner is specified by the Point argument, and whose width and height are specified by the Dimension argument.

Parameters:
p - a Point that is the top-left corner of the Rectangle
d - a Dimension, representing the width and height of the Rectangle

MyRectangle

public MyRectangle(Point p)
Constructs a new Rectangle whose top-left corner is the specified Point, and whose width and height are both zero.

Parameters:
p - a Point that is the top left corner of the Rectangle

MyRectangle

public MyRectangle(Dimension d)
Constructs a new Rectangle whose top left corner is (0, 0) and whose width and height are specified by the Dimension argument.

Parameters:
d - a Dimension, specifying width and height

MyRectangle

public MyRectangle(String desc)
Constrcuts a new rectangle from a string like '300,200;20x40'. Throws an IllegalArgumentException if parsing fails.

Method Detail

parseRectangle

public static Rectangle parseRectangle(String desc)
Parses a point from a String. Throws an IllegalArgumentException if parsing fails.


toString

public static String toString(Rectangle p)
Overrides the string representation. Here, output is reduced to a simple four-integer string, like '300,200;20x40'. The output string is feasable for direct-passing it to the constructor of this class. The static version also works with the original Rectangle class.


toString

public String toString()
Overrides the string representation. Here, output is reduced to a simple four-integer string, like '300,200;20x40'. The output string is feasable for direct-passing it to the constructor of this class.

Overrides:
toString in class Rectangle

distanceToEdge

public double distanceToEdge(Point2D inside)
Returns the distance of this pixel to the closest edge. If the pixel is outside, -1 is returned. If the rectangle is null, also -1 is returned.


distanceToEdge

public static double distanceToEdge(Rectangle2D rec,
                                    Point2D inside)
Returns the distance of this pixel to the closest edge. If the pixel is outside, -1 is returned. If the rectangle is null, also -1 is returned.