edu.neu.ccs
Class XSquare

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

public class XSquare
extends XRect
implements Serializable, Stringable, JPTConstants

Class XSquare extends XRect but requires that its location be specifed by its center and its size be specified by the radius of the inscribed circle. The side of the square is twice this radius and is the value returned by either getWidth or getHeight.

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

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.Rectangle2D
Rectangle2D.Double, Rectangle2D.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.XRect
 
Fields inherited from class java.awt.geom.Rectangle2D.Double
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
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
XSquare()
          Constructs a new XSquare initialized to center (0, 0) and radius 0.
XSquare(double r)
          Constructs a new XSquare initialized to center (0, 0) and with the given inner radius: r = half-width.
XSquare(double x, double y, double r)
          Constructs and initializes a XSquare from the specified double coordinates.
XSquare(XSquare square)
          Constructs and initializes a XSquare from the specified XSquare 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 XSquare object from a String representation of the data state.
 double getRadius()
          Returns the radius.
 void move(double dx, double dy)
          Moves the square by a translation using the data in the point specified by coordinates.
 void move(Point2D p)
          Moves the square 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 setSquare(XSquare square)
          Uses the data from the given square to set the parameters of this square.
 void setXYR(double xc, double yc, double r)
          Sets the parameters of the XSquare with error checking.
 void setXYWH(double x, double y, double w, double h)
          Overrides the inherited method to do nothing since a square cannot have a distinct width and height.
 String toString()
          Returns a human readable String representing the data state of this XSquare as an annotated string.
 String toStringData()
          Returns a human readable String representing the data state of this XSquare as a simple string.
 
Methods inherited from class edu.neu.ccs.XRect
createIntersectionRect, createUnionRect, setFrame, setFrame, setFrame, setRect, setRect, setX1Y1X2Y2, setXYRS, toStringAsX1Y1X2Y2, toStringAsXYRS
 
Methods inherited from class java.awt.geom.Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, 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

XSquare

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


XSquare

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

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

XSquare

public XSquare(double r)

Constructs a new XSquare initialized to center (0, 0) and with the given inner radius: r = half-width. Calls setXYR

Parameters:
r - the proposed inner radius or half-width

XSquare

public XSquare(XSquare square)

Constructs and initializes a XSquare from the specified XSquare object. Calls setXYR indirectly.

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

Parameters:
square - the XSquare object to copy
Method Detail

toString

public String toString()

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

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

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

Overrides:
toString in class XRect

toStringData

public String toStringData()

Returns a human readable String representing the data state of this XSquare 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 XRect

fromStringData

public void fromStringData(String data)
                    throws ParseException

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

Fires property change VALUE.

Specified by:
fromStringData in interface Stringable
Overrides:
fromStringData in class XRect
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 XSquare with error checking.

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

The square is then set up as a rectangle 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 inner radius

setSquare

public void setSquare(XSquare square)

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

Does nothing if the given square is null.

Fires property change VALUE.

Parameters:
square - the XSquare 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 square cannot have a distinct width and height.

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

Overrides:
setXYWH in class XRect
Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height

move

public void move(double dx,
                 double dy)

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

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

move

public void move(Point2D p)

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

Overrides:
move in class XRect
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 XRect
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 XRect
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 XRect
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 XRect
Parameters:
propertyName - the name of the desired property
listener - the listener to be deregistered