edu.neu.ccs
Class XCircle

java.lang.Object
  extended byjava.awt.geom.RectangularShape
      extended byjava.awt.geom.Ellipse2D
          extended byjava.awt.geom.Ellipse2D.Double
              extended byedu.neu.ccs.XOval
                  extended byedu.neu.ccs.XCircle
All Implemented Interfaces:
Cloneable, JPTConstants, Serializable, Shape, Stringable, SwingConstants

public class XCircle
extends XOval
implements Serializable, Stringable, JPTConstants

Class XCircle extends XOval but requires that its location be specifed by its center and its size be specified by its radius. The diameter of the circle is twice the radius and is the value returned by either getWidth or getHeight.

The design of this class makes it similar to the class Square.

Inherited methods that would permit the caller to make the width and height have different values are overridden to do nothing.

Since:
2.4.0
Version:
2.4.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Ellipse2D
Ellipse2D.Double, Ellipse2D.Float
 
Field Summary
private static String[] BLANK
          The data array with blank names "", "", "".
protected  SwingPropertyChangeSupport changeAdapter
          Helper object for property change API.
private  double r
          The radius.
static String standardMessage
          The standard error message for fromStringData.
private static String[] XYR
          The data array with names "xc", "yc", "r".
 
Fields inherited from class edu.neu.ccs.XOval
 
Fields inherited from class java.awt.geom.Ellipse2D.Double
height, width, x, y
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
XCircle()
          Constructs a new XCircle initialized to center (0, 0) and radius 0.
XCircle(double r)
          Constructs a new XCircle initialized to center (0, 0) and with the given radius r.
XCircle(double x, double y, double r)
          Constructs and initializes a XCircle from the specified double coordinates.
XCircle(XCircle circle)
          Constructs and initializes a XCircle from the specified XCircle object.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Registers the given object to listen for property change events generated by this object.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Registers the given object to listen for property change events generated by this object with the given property name.
 void fromStringData(String data)
          Defines the data state for this XCircle object from a String representation of the data state.
 double getRadius()
          Returns the radius.
 void move(double dx, double dy)
          Moves the circle by a translation using the data in the point specified by coordinates.
 void move(Point2D p)
          Moves the circle by a translation using the data in the point.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Deregisters the given object from listening for property change events generated by this object.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Deregisters the given object from listening for property change events generated by this object with the given property name.
 void setCircle(XCircle circle)
          Uses the data from the given circle to set the parameters of this circle.
 void setXYR(double xc, double yc, double r)
          Sets the parameters of the XCircle with error checking.
 void setXYWH(double x, double y, double w, double h)
          Overrides the inherited method to do nothing since a circle cannot have a distinct width and height.
 String toString()
          Returns a human readable String representing the data state of this XCircle as an annotated string.
 String toStringData()
          Returns a human readable String representing the data state of this XCircle as a simple string.
 
Methods inherited from class edu.neu.ccs.XOval
setFrame, setFrame, setFrame, setOval, setX1Y1X2Y2, setXYRS, toStringAsX1Y1X2Y2, toStringAsXYRS
 
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
 

Field Detail

BLANK

private static String[] BLANK
The data array with blank names "", "", "".


XYR

private static String[] XYR
The data array with names "xc", "yc", "r".


standardMessage

public static final String standardMessage
The standard error message for fromStringData.

See Also:
Constant Field Values

r

private double r
The radius.


changeAdapter

protected SwingPropertyChangeSupport changeAdapter
Helper object for property change API.

Constructor Detail

XCircle

public XCircle()
Constructs a new XCircle initialized to center (0, 0) and radius 0.


XCircle

public XCircle(double x,
               double y,
               double r)
Constructs and initializes a XCircle from the specified double coordinates. Calls setXYR.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed radius

XCircle

public XCircle(double r)

Constructs a new XCircle initialized to center (0, 0) and with the given radius r. Calls setXYR

Parameters:
r - the proposed radius

XCircle

public XCircle(XCircle circle)

Constructs and initializes a XCircle from the specified XCircle object. Calls setXYR.

Initializes to center (0, 0) and radius 0 if the given circle is null.

Parameters:
circle - the XCircle object to copy
Method Detail

toString

public String toString()

Returns a human readable String representing the data state of this XCircle as an annotated string.

XCircle[xc=...;yc=...;r=...]

where the dots stand for the xc,yc center data and the radius r.

Overrides:
toString in class XOval

toStringData

public String toStringData()

Returns a human readable String representing the data state of this XCircle as a simple string.

[...;...;...]

where the dots stand for the xc,yc center data and the radius r.

Specified by:
toStringData in interface Stringable
Overrides:
toStringData in class XOval

fromStringData

public void fromStringData(String data)
                    throws ParseException

Defines the data state for this XCircle object from a String representation of the data state.

Fires property change VALUE.

Specified by:
fromStringData in interface Stringable
Overrides:
fromStringData in class XOval
Parameters:
data - String representation of the data state
Throws:
ParseException - if the data is malformed

setXYR

public void setXYR(double xc,
                   double yc,
                   double r)

Sets the parameters of the XCircle with error checking.

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

The circle is then set up as an oval with center location xc,yc and common width and height equal to 2*r.

Fires property change VALUE.

Parameters:
xc - the proposed center x-coordinate
yc - the proposed center y-coordinate
r - the proposed radius

setCircle

public void setCircle(XCircle circle)

Uses the data from the given circle to set the parameters of this circle.

Does nothing if the given circle is null.

Fires property change VALUE.

Parameters:
circle - the XCircle object to copy

getRadius

public double getRadius()
Returns the radius.


setXYWH

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

Overrides the inherited method to do nothing since a circle cannot have a distinct width and height.

The fact that this method does nothing implies that the following methods inherited from XOval and other base classes also do nothing.

Overrides:
setXYWH in class XOval
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

move

public void move(double dx,
                 double dy)

Moves the circle by a translation using the data in the point specified by coordinates.

Overrides:
move in class XOval
Parameters:
dx - the x-coordinate of the translation
dy - the y-coordinate of the translation

move

public void move(Point2D p)

Moves the circle by a translation using the data in the point.

Overrides:
move in class XOval
Parameters:
p - the translation vector

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Registers the given object to listen for property change events generated by this object.

Overrides:
addPropertyChangeListener in class XOval
Parameters:
listener - the listener to be registered

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Registers the given object to listen for property change events generated by this object with the given property name.

Overrides:
addPropertyChangeListener in class XOval
Parameters:
propertyName - the name of the desired property
listener - the listener to be registered

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Deregisters the given object from listening for property change events generated by this object.

Overrides:
removePropertyChangeListener in class XOval
Parameters:
listener - the listener to be deregistered

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Deregisters the given object from listening for property change events generated by this object with the given property name.

Overrides:
removePropertyChangeListener in class XOval
Parameters:
propertyName - the name of the desired property
listener - the listener to be deregistered