edu.neu.ccs
Class XRoundRect

java.lang.Object
  extended byjava.awt.geom.RectangularShape
      extended byjava.awt.geom.RoundRectangle2D
          extended byjava.awt.geom.RoundRectangle2D.Double
              extended byedu.neu.ccs.XRoundRect
All Implemented Interfaces:
Cloneable, JPTConstants, Serializable, Shape, Stringable, SwingConstants
Direct Known Subclasses:
XRoundSquare

public class XRoundRect
extends RoundRectangle2D.Double
implements Serializable, Stringable, JPTConstants

Class XRoundRect extends RoundRectangle2D.Double in order to provide a much shorter name that does not explicitly refer to an inner class, to add error checking that prevents the widths and heights from being set to negative values, and to support Stringable.

Since:
2.4.0
Version:
2.4.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.geom.RoundRectangle2D
RoundRectangle2D.Double, RoundRectangle2D.Float
 
Field Summary
private static String[] BLANK
          The data array with blank names "", "", "", "", "", "".
protected  SwingPropertyChangeSupport changeAdapter
          Helper object for property change API.
static String standardMessage
          The standard error message for fromStringData.
private static String[] XYRSArcs
          The data array with names "xc", "yc", "r", "s", "arcr", "arcs".
private static String[] XYWHArcs
          The data array with names "x", "y", "w", "h", "arcw", "arch".
 
Fields inherited from class java.awt.geom.RoundRectangle2D.Double
archeight, arcwidth, 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
XRoundRect()
          Constructs a new XRoundRect initialized to location (0, 0), size (0, 0), and arc data (0, 0).
XRoundRect(double r, double s, double arcr, double arcs)
          Constructs a new XRoundRect initialized to center (0, 0), with the given radii: r = half-width and s = half-height, and the given arc data: arcr = arc-half-width and arcs = arc-half-height.
XRoundRect(double x, double y, double w, double h, double arcw, double arch)
          Constructs and initializes an XRoundRect from the specified double coordinates.
XRoundRect(RoundRectangle2D roundrect)
          Constructs and initializes an XRoundRect from the specified RoundRectangle2D 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 XRoundRect object from a String representation of the data state.
 void move(double dx, double dy)
          Moves the round rectangle by a translation using the data in the point specified by coordinates.
 void move(Point2D p)
          Moves the round rectangle 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 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 setRect(double x, double y, double w, double h)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setRect(Rectangle2D rect)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setRoundRect(double x, double y, double w, double h, double arcw, double arch)
          Overrides the corresponding inherited method to use the method setXYWHArcs.
 void setRoundRect(RoundRectangle2D roundrect)
          Overrides the corresponding inherited method to use the method setXYWHArcs.
 void setX1Y1X2Y2(double x1, double y1, double x2, double y2)
          Sets the parameters of the XRoundRect with error checking using the coordinates of any pair of opposite corners.
 void setXYRS(double xc, double yc, double r, double s)
          Sets the parameters of the XRoundRect with error checking using the center (xc,yc) and the inner radii: r = half-width and s = half-height.
 void setXYRSArcs(double xc, double yc, double r, double s, double arcr, double arcs)
          Sets the parameters of the XRoundRect with error checking using the center (xc,yc), the inner object radii: r = half-width and s = half-height, and the arc radii: arcr = arc-half-width and arcs = arc-half-height.
 void setXYWH(double x, double y, double w, double h)
          Sets the parameters of the XRoundRect with error checking.
 void setXYWHArcs(double x, double y, double w, double h, double arcw, double arch)
          Sets the parameters of the XRoundRect with error checking.
 String toString()
          Returns a human readable String representing the data state of this XRoundRect as an annotated string.
 String toStringAsXYRSArcs()
          Returns a human readable String representing the data state of this XRoundRect as an annotated string.
 String toStringData()
          Returns a human readable String representing the data state of this XRoundRect as a simple string.
 
Methods inherited from class java.awt.geom.RoundRectangle2D.Double
getArcHeight, getArcWidth, getBounds2D, getHeight, getWidth, getX, getY, isEmpty
 
Methods inherited from class java.awt.geom.RoundRectangle2D
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 "", "", "", "", "", "".


XYWHArcs

private static String[] XYWHArcs
The data array with names "x", "y", "w", "h", "arcw", "arch".


XYRSArcs

private static String[] XYRSArcs
The data array with names "xc", "yc", "r", "s", "arcr", "arcs".


standardMessage

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

See Also:
Constant Field Values

changeAdapter

protected SwingPropertyChangeSupport changeAdapter
Helper object for property change API.

Constructor Detail

XRoundRect

public XRoundRect()
Constructs a new XRoundRect initialized to location (0, 0), size (0, 0), and arc data (0, 0).


XRoundRect

public XRoundRect(double x,
                  double y,
                  double w,
                  double h,
                  double arcw,
                  double arch)
Constructs and initializes an XRoundRect from the specified double coordinates. Calls setXYWHArcs.

Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height
arcw - the proposed arc width
arch - the proposed arc height

XRoundRect

public XRoundRect(RoundRectangle2D roundrect)

Constructs and initializes an XRoundRect from the specified RoundRectangle2D object. Calls setXYWHArcs.

Initializes to location (0, 0), size (0, 0), and arc data (0, 0) if the given roundrect is null.

Parameters:
roundrect - the RoundRectangle2D object to copy

XRoundRect

public XRoundRect(double r,
                  double s,
                  double arcr,
                  double arcs)

Constructs a new XRoundRect initialized to center (0, 0), with the given radii: r = half-width and s = half-height, and the given arc data: arcr = arc-half-width and arcs = arc-half-height. Calls setXYRSArcs

Parameters:
r - the proposed x-radius or half-width
s - the proposed y-radius or half-height
arcr - the proposed arc-half-width
arcs - the proposed arc-half-height
Method Detail

toString

public String toString()

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

XRoundRect[x=...;y=...;w=...;h=...;arcw=...;arch=...]

where the dots stand for the corner data x,y, the dimension data w,h, and the arc data arcw,arch.


toStringAsXYRSArcs

public String toStringAsXYRSArcs()

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

XRoundRect[xc=...;yc=...;r=...;s=...;arcr=...;arcs=...]

where the dots stand for the center data xc,yc, the radii r,s, and the arc radii arcr,arcs.


toStringData

public String toStringData()

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

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

where the dots stand for the corner data x,y, the dimension data w,h, and the arc data arcw,arch.

Specified by:
toStringData in interface Stringable
See Also:
Stringable.fromStringData(String)

fromStringData

public void fromStringData(String data)
                    throws ParseException

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

Fires property change VALUE.

Specified by:
fromStringData in interface Stringable
Parameters:
data - String representation of the data state
Throws:
ParseException - if the data is malformed
See Also:
Stringable.toStringData()

setXYWHArcs

public void setXYWHArcs(double x,
                        double y,
                        double w,
                        double h,
                        double arcw,
                        double arch)

Sets the parameters of the XRoundRect 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.

If arcw is negative, then arcw is replaced by its absolute value and is then forced to be less than or equal to w.

If arch is negative, then arch is replaced by its absolute value and is then forced to be less than or equal to h.

Fires property change VALUE.

Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height
arcw - the proposed arc width
arch - the proposed arc height

setXYRSArcs

public void setXYRSArcs(double xc,
                        double yc,
                        double r,
                        double s,
                        double arcr,
                        double arcs)

Sets the parameters of the XRoundRect with error checking using the center (xc,yc), the inner object radii: r = half-width and s = half-height, and the arc radii: arcr = arc-half-width and arcs = arc-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.

If arcr is negative, then arcr is replaced by its absolute value and is then forced to be less than or equal to r.

If arcs is negative, then arcs is replaced by its absolute value and is then forced to be less than or equal to s.

Fires property change VALUE.

Parameters:
xc - the proposed center x-coordinate
yc - the proposed center y-coordinate
r - the proposed x-radius or half-width
s - the proposed y-radius or half-height
arcr - the proposed arc-half-width
arcs - the proposed arc-half-height

setXYWH

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

Sets the parameters of the XRoundRect 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.

Calls setXYWHArcs with the current arc settings.

Fires property change VALUE.

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

setXYRS

public void setXYRS(double xc,
                    double yc,
                    double r,
                    double s)

Sets the parameters of the XRoundRect with error checking using the center (xc,yc) 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.

Calls setXYWH which calls setXYWHArcs with the current arc settings.

Fires property change VALUE.

Parameters:
xc - the proposed center x-coordinate
yc - 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 XRoundRect with error checking using the coordinates of any pair of opposite corners.

Calls setYWWH which calls setXYWHArcs with the current arc settings.

Fires property change VALUE.

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

setRoundRect

public void setRoundRect(double x,
                         double y,
                         double w,
                         double h,
                         double arcw,
                         double arch)

Overrides the corresponding inherited method to use the method setXYWHArcs.

Fires property change VALUE.

Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height
arcw - the proposed arc width
arch - the proposed arc height

setRoundRect

public void setRoundRect(RoundRectangle2D roundrect)

Overrides the corresponding inherited method to use the method setXYWHArcs.

Does nothing if the given roundrect is null.

Fires property change VALUE.

Parameters:
roundrect - the Rectangle2D 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.

Fires property change VALUE.

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.

Fires property change VALUE.

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

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.

Fires property change VALUE.

Parameters:
point - the top-left corner
dimension - the dimension with the width and height

setRect

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

Overrides the corresponding inherited method to use the method setXYWH.

Fires property change VALUE.

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

setRect

public void setRect(Rectangle2D rect)

Overrides the corresponding inherited method to use the method setXYWH.

Does nothing if the given rect is null.

Fires property change VALUE.

Parameters:
rect - the Rectangle2D object to copy

move

public void move(double dx,
                 double dy)

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

Parameters:
dx - the x-coordinate of the translation
dy - the y-coordinate of the translation

move

public void move(Point2D p)

Moves the round rectangle by a translation using the data in the point.

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.

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.

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.

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.

Parameters:
propertyName - the name of the desired property
listener - the listener to be deregistered