/* * @(#)XPoint2D.java 1.0 14 July 2001 * * Copyright 2001 * College of Computer Science * Northeastern University * Boston, MA 02115 * * This software may be used for educational purposes as long as * this copyright notice is retained intact at the top of all files. * * Should this software be modified, the words "Modified from * Original" must be included as a comment below this notice. * * All publication rights are retained. This software or its * documentation may not be published in any media either in whole * or in part without explicit permission. * * Contact information: * Richard Rasala rasala@ccs.neu.edu * Viera Proulx vkp@ccs.neu.edu * Jeff Raab jmr@ccs.neu.edu * * Telephone: 617-373-2462 * * This software was created with support from Northeastern * University and from NSF grant DUE-9950829. */ import edu.neu.ccs.*; import edu.neu.ccs.codec.*; import java.text.ParseException; import java.awt.geom.*; /** *
Data model representing a point in graphics, containing a double * x coordinate and a double y coordinate.
* * @author Viera K. Proulx * @author Richard Rasala * @version 14 July 2001 */ public final class XPoint2D extends Point2D.Double implements Stringable { /** * Constructs a wrapper for the default *Point2D.Double
value.
*
* @see #XPoint2D(Point2D.Double)
* @see #XPoint2D(String)
*/
public XPoint2D() {}
/**
* Constructs a wrapper for the given
* Point2D.Double
value.
*
* @param p2D the value to be wrapped
* @see #XPoint2D()
* @see #XPoint2D(double, double)
* @see #XPoint2D(String)
*/
public XPoint2D(Point2D.Double p2D) {
setValue(p2D);
}
/**
* Constructs a wrapper for the given
* Point2D.Double
value.
*
* @param p2D the value to be wrapped
* @see #XPoint2D()
* @see #XPoint2D(String)
* @see #XPoint2D(Point2D.Double)
*/
public XPoint2D(double X, double Y) {
setValue(X, Y);
}
/**
* Constructs a wrapper for the XPoint2D
pvalue
* whose state information is encapsulated
* in the given String
data.
*
* @param s a String
representation
* of the desired value
* @throws ParseException if the data is malformed
* @see #XPoint2D()
* @see #XPoint2D(double, double)
* @see #XPoint2D(Point2D.Double)
*/
public XPoint2D(String data) throws ParseException {
fromStringData(data);
}
////////////////
// Stringable //
////////////////
/**
* Extracts a String
representation of the data state
* for this XPoint2D object from a String
representation.
*/
public void fromStringData(String data) throws ParseException {
String[] terms = CodecUtilities.decode(data);
x = XDouble.parseDouble(terms[0]);
y = XDouble.parseDouble(terms[1]);
}
/**
* Returns a String
representation of the data state
* for this XPoint2D object.
*/
public String toStringData() {
return CodecUtilities.encode(
new String[] {x + "", y + ""});
}
///////////////////
// Other methods //
///////////////////
/**
* Returns a human readable String
representing the
* data state of this point.
*/
public String toString() {
return "(" + x + ", " + y + ")";
}
////////////////
// Public API //
////////////////
/**
* Sets the value wrapped by this object
* to the given value.
*
* @param p2D the value to be wrapped
* @see #setValue(double, double)
*/
public void setValue(Point2D.Double p2D) {
if (p2D != null)
setValue(p2D.x, p2D.y);
}
/**
* Sets the value wrapped by this object
* to the given value.
*
* @param X the x coordinate
* @param Y the y coordinate
* @see #setValue(Point2D.Double)
*/
public void setValue(double X, double Y) {
x = X;
y = Y;
}
}