/*
 * @(#)PathNodeView.java    2.6.0a   25 October 2007
 *
 * Copyright 2007
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * 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.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.gui;

import edu.neu.ccs.Stringable;
import edu.neu.ccs.filter.StringableFilter;

/**
 * <p>Class <code>PathNodeView</code> uses a <code>TextFieldView</code> to
 * input the single line of text needed to define a <code>PathNode</code>.
 * The data type is fixed to be <code>PathNode.class</code>.</p>
 *
 * <p>The input format is one of the following:</p>
 *
 * <pre>MOVE[x1;y1]</pre>
 *
 * <pre>LINE[x1;y1]</pre>
 *
 * <pre>QUAD[x1;y1;x2;y2]</pre>
 *
 * <pre>CUBIC[x1;y1;x2;y2;x3;y3]</pre>
 *
 * <pre>CLOSE[]</pre>
 *
 * <p>where x1, y1, x2, y2, x3, y3 are floats.</p>
 * 
 * <p>As of 2.6.0a, the methods <code>demandObject</code> and
 * <code>requestObject</code> will return <code>null</code>
 * if the underlying <code>TextFieldView</code> view state
 * consists only of whitespace.  This convention is more
 * convenient when interacting with <code>PathListView</code>.</p>
 * 
 * @version 2.6.0a
 * @since   2.4.0
 */
public class PathNodeView extends TextFieldView {
    
    /** The default constructor. */
    public PathNodeView() {
        super("", TextFieldView.getSampleWidth(50, '0'));
        super.setDataType(PathNode.class);
    }
    
    
    /**
     * <p>Since the data type of this class is fixed to be
     * <code>PathNode.class</code>, this method overrides
     * the inherited method to do nothing.</p>
     */
    public void setDataType(Class dataType) { }
    
    
    /**
     * Returns true if the underlying <code>TextFieldView</code>
     * view state consists only of whitespace.
     */
    public boolean isEmpty() {
        String state = getViewState().trim();
        
        return state.length() == 0;
    }
    
    
    /**
     * Overrides the inherited method to return <code>null</code>
     * if the underlying <code>TextFieldView</code> view state
     * consists only of whitespace.
     */
    public Stringable demandObject() {
        if (isEmpty())
            return null;
        
        return super.demandObject();
    }
    
    
    /**
     * Overrides the inherited method to return <code>null</code>
     * if the underlying <code>TextFieldView</code> view state
     * consists only of whitespace.
     */
    public Stringable requestObject()
        throws CancelledException
    {
        if (isEmpty())
            return null;
        
        return super.requestObject();
    }
    
}

