/* * @(#)Point2DView.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.gui.*; import edu.neu.ccs.codec.*; import edu.neu.ccs.*; import edu.neu.ccs.util.*; import java.awt.*; import java.awt.geom.*; import java.text.NumberFormat; import java.text.DecimalFormat; import javax.swing.*; /** *
View for input of a Point2D.Double
object
* or an XPoint2D
object.
String
. Note that this data need not
* represent a well-formed point data.
*
* @param data the desired encoded data String
*/
public void setViewState(String data) {
String[] terms = CodecUtilities.decode(data);
xcoord.setViewState(terms[0]);
ycoord.setViewState(terms[1]);
}
/**
* Returns the data state for this view as an encoded
* String
. Note that the data state for this view
* need not represent a well-formed point data.
*/
public String getViewState() {
return CodecUtilities.encode(
new String[] {
xcoord.getViewState(),
ycoord.getViewState()});
}
/**
* Sets the default value for this view to the data encoded in
* the given String
. Note that this data need not
* represent a well-formed point data.
*
* @param data the desired encoded data String
*/
public void setDefaultViewState(String data) {
String[] terms = CodecUtilities.decode(data);
xcoord.setDefaultViewState(terms[0]);
ycoord.setDefaultViewState(terms[1]);
}
/**
* Returns the default view state for this view as an encoded
* String
. Note that the data state for this view
* need not represent a well-formed point data.
*/
public String getDefaultViewState() {
return CodecUtilities.encode(
new String[] {
xcoord.getDefaultViewState(),
ycoord.getDefaultViewState()});
}
//////////////////////////////////////////////////
// Variations of demandObject and requestObject //
//////////////////////////////////////////////////
/**
* Gets the data state for this view as a Point2D.Double object
*
* @see #demandObject()
* @see #requestObject()
* @see #requestPoint2D()
*/
public Point2D.Double demandPoint2D(){
return new Point2D.Double(
xcoord.demandDouble(),
ycoord.demandDouble());
}
/**
* Gets the data state for this view as a Point2D.Double object
* or throws an exception if the input operation is cancelled.
*
* @throws CancelledException if the user cancels the input operation
* @see #demandObject()
* @see #requestObject()
* @see #demandPoint2D()
*/
public Point2D.Double requestPoint2D() throws CancelledException {
return new Point2D.Double(
xcoord.requestDouble(),
ycoord.requestDouble());
}
////////////////////////////////
// Variations of setViewState //
////////////////////////////////
/**
* Sets the data state for this view to the data stored in
* the pair of strings passed. Note that this data need
* not represent a well-formed point data.
*
* @param x the string for the x coordinate
* @param y the string for the y coordinate
*/
public void setViewState(String x, String y) {
xcoord.setViewState(x);
ycoord.setViewState(y);
}
/**
* Sets the default view state for this view to the data stored in
* the pair of strings passed. Note that this data need
* not represent a well-formed point data.
*
* @param x the string for the x coordinate
* @param y the string for the y coordinate
*/
public void setDefaultViewState(String x, String y) {
xcoord.setDefaultViewState(x);
ycoord.setDefaultViewState(y);
}
/**
* Sets the data state for this view to the given
* Point2D.Double
object.
*
* @param p the desired Point2D.Double object
*/
public void setViewState(Point2D.Double p){
if (p != null)
setViewState(p.x, p.y);
}
/**
* Sets the data state for this view to the given
* x, y pair of doubles.
*
* @param x the desired x coordinate value
* @param y the desired y coordinate value
*/
public void setViewState(double x, double y){
setViewState(x + "", y + "");
}
/**
* Sets the data state for this view to the given
* Point2D.Double
object
* using the specified number format.
*
* @param p the desired Point2D.Double object
* @param f the desired number format object
*/
public void setViewState(Point2D.Double p, NumberFormat f) {
if (p != null)
setViewState(p.x, p.y, f);
}
/**
* Sets the data state for this view to the given
* x, y, coordinates
* using the specified number format.
*
* @param x the desired x coordinate value
* @param y the desired y coordinate value
* @param f the desired number format object
*/
public void setViewState(double x, double y, NumberFormat f) {
setViewState(f.format(x), f.format(y));
}
///////////////////
// Other Methods //
///////////////////
/**
* Returns the two coordinate views in an array.
*/
public TextFieldView[] getViews() {
return new TextFieldView[] {xcoord, ycoord};
}
/**
* Sets the preferred width for the two coordinate views
* to the desired value
*
* @param width the desired width
*/
public void setPreferredWidth(int width){
xcoord.setPreferredWidth(width);
ycoord.setPreferredWidth(width);
}
}