edu.neu.ccs.gui
Class Oval

java.lang.Object
  |
  +--java.awt.geom.RectangularShape
        |
        +--java.awt.geom.Ellipse2D
              |
              +--java.awt.geom.Ellipse2D.Double
                    |
                    +--edu.neu.ccs.gui.Oval
All Implemented Interfaces:
Cloneable, Shape
Direct Known Subclasses:
Circle

public class Oval
extends Ellipse2D.Double

Class Oval extends Ellipse2D.Double in order to provide a much shorter name that does not explicitly refer to an inner class and to add error checking that prevents the width and height from being set to negative values.

Since:
2.4.0

Field Summary
 
Fields inherited from class java.awt.geom.Ellipse2D.Double
height, width, x, y
 
Constructor Summary
Oval()
          Constructs a new Oval initialized to location (0, 0) and size (0, 0).
Oval(double r, double s)
          Constructs a new Oval initialized to center (0, 0) and with the given radii: r = half-width and s = half-height.
Oval(double x, double y, double w, double h)
          Constructs and initializes an Oval from the specified double coordinates.
Oval(Ellipse2D oval)
          Constructs and initializes a Oval from the specified Ellipse2D object.
Oval(Rectangle2D rect)
          Constructs and initializes an Oval from the specified Rectangle2D object.
 
Method Summary
 void setFrame(double x, double y, double w, double h)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setFrame(Point2D point, Dimension2D dimension)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setFrame(Rectangle2D rect)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setOval(Ellipse2D oval)
          Sets the data of this oval from the given oval.
 void setX1Y1X2Y2(double x1, double y1, double x2, double y2)
          Sets the parameters of the Oval with error checking using the coordinates of any pair of opposite corners of the frame.
 void setXYRS(double x, double y, double r, double s)
          Sets the parameters of the Oval with error checking using the center (x,y) and the inner radii: r = half-width and s = half-height.
 void setXYWH(double x, double y, double w, double h)
          Sets the parameters of the Oval with error checking.
 String toString()
          Returns a String representation of the data in this Oval.
 
Methods inherited from class java.awt.geom.Ellipse2D.Double
getBounds2D, getHeight, getWidth, getX, getY, isEmpty
 
Methods inherited from class java.awt.geom.Ellipse2D
contains, contains, getPathIterator, intersects
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, getPathIterator, intersects, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Oval

public Oval()
Constructs a new Oval initialized to location (0, 0) and size (0, 0).


Oval

public Oval(double x,
            double y,
            double w,
            double h)
Constructs and initializes an Oval from the specified double coordinates. Calls setXYWH.

Parameters:
x - the proposed top-left x-coordinate of the frame
y - the proposed top-left y-coordinate of the frame
w - the proposed width of the frame
h - the proposed height of the frame

Oval

public Oval(double r,
            double s)

Constructs a new Oval initialized to center (0, 0) and with the given radii: r = half-width and s = half-height. Calls setXYRS

Parameters:
r - the proposed x-radius or half-width
s - the proposed y-radius or half-height

Oval

public Oval(Rectangle2D rect)

Constructs and initializes an Oval from the specified Rectangle2D object. Calls setXYWH.

Initializes to location (0, 0) and size (0, 0) if the given rect is null.

Parameters:
rect - the Rectangle2D object to use for the frame

Oval

public Oval(Ellipse2D oval)

Constructs and initializes a Oval from the specified Ellipse2D object. Calls setXYWH.

Initializes to location (0, 0) and size (0, 0) if the given oval is null.

Parameters:
oval - the Ellipse2D object to copy
Method Detail

setXYWH

public void setXYWH(double x,
                    double y,
                    double w,
                    double h)

Sets the parameters of the Oval with error checking.

If the width w is negative, then w is replaced by its absolute value and then x is replaced by (x - w).

If the height h is negative, then h is replaced by its absolute value and then y is replaced by (y - h).

This method guarantees that the internal width and height are always greater than or equal to zero.

Parameters:
x - the proposed top-left x-coordinate of the frame
y - the proposed top-left y-coordinate of the frame
w - the proposed width of the frame
h - the proposed height of the frame

setXYRS

public void setXYRS(double x,
                    double y,
                    double r,
                    double s)

Sets the parameters of the Oval with error checking using the center (x,y) and the inner radii: r = half-width and s = half-height.

If the radius r is negative, then r is replaced by its absolute value.

If the radius s is negative, then s is replaced by its absolute value.

This method guarantees that the internal width and height are always greater than or equal to zero.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed x-radius or half-width
s - the proposed y-radius or half-height

setX1Y1X2Y2

public void setX1Y1X2Y2(double x1,
                        double y1,
                        double x2,
                        double y2)

Sets the parameters of the Oval with error checking using the coordinates of any pair of opposite corners of the frame.

Parameters:
x1 - the x-coordinate of one corner of the frame
y1 - the y-coordinate of one corner of the frame
x2 - the x-coordinate of the opposite corner of the frame
y2 - the y-coordinate of the opposite corner of the frame

setOval

public void setOval(Ellipse2D oval)

Sets the data of this oval from the given oval.

Does nothing if the given oval is null.

Parameters:
oval - the Ellipse2D object to copy

setFrame

public void setFrame(double x,
                     double y,
                     double w,
                     double h)

Overrides the corresponding inherited method to use the method setXYWH.

Overrides:
setFrame in class Ellipse2D.Double
Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height

setFrame

public void setFrame(Rectangle2D rect)

Overrides the corresponding inherited method to use the method setXYWH.

Does nothing if the given rect is null.

Overrides:
setFrame in class RectangularShape
Parameters:
rect - the Rectangle2D object to copy

setFrame

public void setFrame(Point2D point,
                     Dimension2D dimension)

Overrides the corresponding inherited method to use the method setXYWH.

Does nothing if the given point or dimension is null.

Overrides:
setFrame in class RectangularShape
Parameters:
point - the top-left corner
dimension - the dimension with the width and height

toString

public String toString()

Returns a String representation of the data in this Oval.

The format is similar to that used by Java but simpler:

Oval[x=...,y=...,w=...,h=...]

where (x,y) is the top-left corner of the bounding frame and (w,h) is the dimension of that frame.

Overrides:
toString in class Object