/*
 * @(#)SimpleDialog.java    1.0  18 February 2001
 *
 * Copyright 2004
 * 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.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.util.*;

/**
 * <P>Provides only static convenience methods 
 * for simple modal dialog box input.</P>
 *
 * @author  Jeff Raab
 * @author  Richard Rasala
 * @author  Viera K. Proulx
 * @version 2.2
 * @since   1.0
 */
public class SimpleDialog implements JPTConstants {

    ////////////////////////////////
    // Demand and Request for int //
    ////////////////////////////////

    /**
     * Returns an <CODE>int</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandInt(String, String, String)
     * @see #demandInt(String, String, String, StringableFilter)
     * @see #requestInt(String, String)
     * @see #requestInt(String, String, String)
     * @see #requestInt(String, String, String, StringableFilter)
     */
    public static int demandInt(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandInt(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns an <CODE>int</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandInt(String, String)
     * @see #demandInt(String, String, String, StringableFilter)
     * @see #requestInt(String, String)
     * @see #requestInt(String, String, String)
     * @see #requestInt(String, String, String, StringableFilter)
     */
    public static int demandInt(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandInt(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns an <CODE>int</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandInt(String, String)
     * @see #demandInt(String, String, String)
     * @see #requestInt(String, String)
     * @see #requestInt(String, String, String)
     * @see #requestInt(String, String, String, StringableFilter)
     */
    public static int demandInt(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XInt.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XInt model = (XInt)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns an <CODE>int</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestInt(String, String, String)
     * @see #requestInt(String, String, String, StringableFilter)
     * @see #demandInt(String, String)
     * @see #demandInt(String, String, String)
     * @see #demandInt(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static int requestInt(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestInt(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns an <CODE>int</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestInt(String, String)
     * @see #requestInt(String, String, String, StringableFilter)
     * @see #demandInt(String, String, String)
     * @see #demandInt(String, String)
     * @see #demandInt(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static int requestInt(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestInt(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns an <CODE>int</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestInt(String, String)
     * @see #requestInt(String, String, String)
     * @see #demandInt(String, String, String)
     * @see #demandInt(String, String)
     * @see #demandInt(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static int requestInt(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XInt.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XInt model = (XInt)requestObject(view);
        return model.getValue();
    }

    /////////////////////////////////
    // Demand and Request for byte //
    /////////////////////////////////

    /**
     * Returns a <CODE>byte</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandByte(String, String, String)
     * @see #demandByte(String, String, String, StringableFilter)
     * @see #requestByte(String, String)
     * @see #requestByte(String, String, String)
     * @see #requestByte(String, String, String, StringableFilter)
     */
    public static byte demandByte(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandByte(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>byte</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandByte(String, String)
     * @see #demandByte(String, String, String, StringableFilter)
     * @see #requestByte(String, String)
     * @see #requestByte(String, String, String)
     * @see #requestByte(String, String, String, StringableFilter)
     */
    public static byte demandByte(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandByte(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>byte</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandByte(String, String)
     * @see #demandByte(String, String, String)
     * @see #requestByte(String, String)
     * @see #requestByte(String, String, String)
     * @see #requestByte(String, String, String, StringableFilter)
     */
    public static byte demandByte(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XByte.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XByte model = (XByte)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>byte</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestByte(String, String, String)
     * @see #requestByte(String, String, String, StringableFilter)
     * @see #demandByte(String, String)
     * @see #demandByte(String, String, String)
     * @see #demandByte(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static byte requestByte(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestByte(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>byte</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestByte(String, String)
     * @see #requestByte(String, String, String, StringableFilter)
     * @see #demandByte(String, String, String)
     * @see #demandByte(String, String)
     * @see #demandByte(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static byte requestByte(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestByte(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>byte</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestByte(String, String)
     * @see #requestByte(String, String, String)
     * @see #demandByte(String, String, String)
     * @see #demandByte(String, String)
     * @see #demandByte(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static byte requestByte(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XByte.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XByte model = (XByte)requestObject(view);
        return model.getValue();
    }

    //////////////////////////////////
    // Demand and Request for short //
    //////////////////////////////////

    /**
     * Returns a <CODE>short</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandShort(String, String, String)
     * @see #demandShort(String, String, String, StringableFilter)
     * @see #requestShort(String, String)
     * @see #requestShort(String, String, String)
     * @see #requestShort(String, String, String, StringableFilter)
     */
    public static short demandShort(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandShort(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>short</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandShort(String, String)
     * @see #demandShort(String, String, String, StringableFilter)
     * @see #requestShort(String, String)
     * @see #requestShort(String, String, String)
     * @see #requestShort(String, String, String, StringableFilter)
     */
    public static short demandShort(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandShort(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>short</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandShort(String, String)
     * @see #demandShort(String, String, String)
     * @see #requestShort(String, String)
     * @see #requestShort(String, String, String)
     * @see #requestShort(String, String, String, StringableFilter)
     */
    public static short demandShort(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XShort.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XShort model = (XShort)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>short</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestShort(String, String, String)
     * @see #requestShort(String, String, String, StringableFilter)
     * @see #demandShort(String, String)
     * @see #demandShort(String, String, String)
     * @see #demandShort(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static short requestShort(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestShort(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>short</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestShort(String, String)
     * @see #requestShort(String, String, String, StringableFilter)
     * @see #demandShort(String, String, String)
     * @see #demandShort(String, String)
     * @see #demandShort(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static short requestShort(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestShort(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>short</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestShort(String, String)
     * @see #requestShort(String, String, String)
     * @see #demandShort(String, String, String)
     * @see #demandShort(String, String)
     * @see #demandShort(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static short requestShort(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XShort.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XShort model = (XShort)requestObject(view);
        return model.getValue();
    }

    /////////////////////////////////
    // Demand and Request for long //
    /////////////////////////////////

    /**
     * Returns a <CODE>long</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandLong(String, String, String)
     * @see #demandLong(String, String, String, StringableFilter)
     * @see #requestLong(String, String)
     * @see #requestLong(String, String, String)
     * @see #requestLong(String, String, String, StringableFilter)
     */
    public static long demandLong(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandLong(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>long</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandLong(String, String)
     * @see #demandLong(String, String, String, StringableFilter)
     * @see #requestLong(String, String)
     * @see #requestLong(String, String, String)
     * @see #requestLong(String, String, String, StringableFilter)
     */
    public static long demandLong(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandLong(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>long</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandLong(String, String)
     * @see #demandLong(String, String, String)
     * @see #requestLong(String, String)
     * @see #requestLong(String, String, String)
     * @see #requestLong(String, String, String, StringableFilter)
     */
    public static long demandLong(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XLong.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XLong model = (XLong)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>long</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestLong(String, String, String)
     * @see #requestLong(String, String, String, StringableFilter)
     * @see #demandLong(String, String)
     * @see #demandLong(String, String, String)
     * @see #demandLong(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static long requestLong(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestLong(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>long</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestLong(String, String)
     * @see #requestLong(String, String, String, StringableFilter)
     * @see #demandLong(String, String, String)
     * @see #demandLong(String, String)
     * @see #demandLong(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static long requestLong(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestLong(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>long</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestLong(String, String)
     * @see #requestLong(String, String, String)
     * @see #demandLong(String, String, String)
     * @see #demandLong(String, String)
     * @see #demandLong(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static long requestLong(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XLong.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XLong model = (XLong)requestObject(view);
        return model.getValue();
    }

    ///////////////////////////////////
    // Demand and Request for double //
    ///////////////////////////////////

    /**
     * Returns a <CODE>double</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandDouble(String, String, String)
     * @see #demandDouble(String, String, String, StringableFilter)
     * @see #requestDouble(String, String)
     * @see #requestDouble(String, String, String)
     * @see #requestDouble(String, String, String, StringableFilter)
     */
    public static double demandDouble(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandDouble(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>double</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandDouble(String, String)
     * @see #demandDouble(String, String, String, StringableFilter)
     * @see #requestDouble(String, String)
     * @see #requestDouble(String, String, String)
     * @see #requestDouble(String, String, String, StringableFilter)
     */
    public static double demandDouble(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandDouble(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>double</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandDouble(String, String)
     * @see #demandDouble(String, String, String)
     * @see #requestDouble(String, String)
     * @see #requestDouble(String, String, String)
     * @see #requestDouble(String, String, String, StringableFilter)
     */
    public static double demandDouble(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XDouble.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XDouble model = (XDouble)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>double</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestDouble(String, String, String)
     * @see #requestDouble(String, String, String, StringableFilter)
     * @see #demandDouble(String, String)
     * @see #demandDouble(String, String, String)
     * @see #demandDouble(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static double requestDouble(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestDouble(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>double</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestDouble(String, String)
     * @see #requestDouble(String, String, String, StringableFilter)
     * @see #demandDouble(String, String, String)
     * @see #demandDouble(String, String)
     * @see #demandDouble(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static double requestDouble(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestDouble(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>double</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestDouble(String, String)
     * @see #requestDouble(String, String, String)
     * @see #demandDouble(String, String, String)
     * @see #demandDouble(String, String)
     * @see #demandDouble(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static double requestDouble(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XDouble.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XDouble model = (XDouble)requestObject(view);
        return model.getValue();
    }

    //////////////////////////////////
    // Demand and Request for float //
    //////////////////////////////////

    /**
     * Returns a <CODE>float</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandFloat(String, String, String)
     * @see #demandFloat(String, String, String, StringableFilter)
     * @see #requestFloat(String, String)
     * @see #requestFloat(String, String, String)
     * @see #requestFloat(String, String, String, StringableFilter)
     */
    public static float demandFloat(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandFloat(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>float</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandFloat(String, String)
     * @see #demandFloat(String, String, String, StringableFilter)
     * @see #requestFloat(String, String)
     * @see #requestFloat(String, String, String)
     * @see #requestFloat(String, String, String, StringableFilter)
     */
    public static float demandFloat(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandFloat(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>float</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandFloat(String, String)
     * @see #demandFloat(String, String, String)
     * @see #requestFloat(String, String)
     * @see #requestFloat(String, String, String)
     * @see #requestFloat(String, String, String, StringableFilter)
     */
    public static float demandFloat(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XFloat.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XFloat model = (XFloat)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>float</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestFloat(String, String, String)
     * @see #requestFloat(String, String, String, StringableFilter)
     * @see #demandFloat(String, String)
     * @see #demandFloat(String, String, String)
     * @see #demandFloat(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static float requestFloat(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestFloat(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>float</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestFloat(String, String)
     * @see #requestFloat(String, String, String, StringableFilter)
     * @see #demandFloat(String, String, String)
     * @see #demandFloat(String, String)
     * @see #demandFloat(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static float requestFloat(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestFloat(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>float</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestFloat(String, String)
     * @see #requestFloat(String, String, String)
     * @see #demandFloat(String, String, String)
     * @see #demandFloat(String, String)
     * @see #demandFloat(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static float requestFloat(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XFloat.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XFloat model = (XFloat)requestObject(view);
        return model.getValue();
    }

    /////////////////////////////////
    // Demand and Request for char //
    /////////////////////////////////

    /**
     * Returns a <CODE>char</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandChar(String, String, String)
     * @see #demandChar(String, String, String, StringableFilter)
     * @see #requestChar(String, String)
     * @see #requestChar(String, String, String)
     * @see #requestChar(String, String, String, StringableFilter)
     */
    public static char demandChar(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandChar(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>char</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandChar(String, String)
     * @see #demandChar(String, String, String, StringableFilter)
     * @see #requestChar(String, String)
     * @see #requestChar(String, String, String)
     * @see #requestChar(String, String, String, StringableFilter)
     */
    public static char demandChar(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandChar(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>char</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandChar(String, String)
     * @see #demandChar(String, String, String)
     * @see #requestChar(String, String)
     * @see #requestChar(String, String, String)
     * @see #requestChar(String, String, String, StringableFilter)
     */
    public static char demandChar(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XChar.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XChar model = (XChar)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>char</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestChar(String, String, String)
     * @see #requestChar(String, String, String, StringableFilter)
     * @see #demandChar(String, String)
     * @see #demandChar(String, String, String)
     * @see #demandChar(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static char requestChar(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestChar(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>char</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestChar(String, String)
     * @see #requestChar(String, String, String, StringableFilter)
     * @see #demandChar(String, String, String)
     * @see #demandChar(String, String)
     * @see #demandChar(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static char requestChar(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestChar(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>char</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestChar(String, String)
     * @see #requestChar(String, String, String)
     * @see #demandChar(String, String, String)
     * @see #demandChar(String, String)
     * @see #demandChar(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static char requestChar(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XChar.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XChar model = (XChar)requestObject(view);
        return model.getValue();
    }

    ////////////////////////////////////
    // Demand and Request for boolean //
    ////////////////////////////////////

    /**
     * Returns a <CODE>boolean</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandBoolean(String, String, String)
     * @see #demandBoolean(String, String, String, StringableFilter)
     * @see #requestBoolean(String, String)
     * @see #requestBoolean(String, String, String)
     * @see #requestBoolean(String, String, String, StringableFilter)
     */
    public static boolean demandBoolean(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandBoolean(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>boolean</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandBoolean(String, String)
     * @see #demandBoolean(String, String, String, StringableFilter)
     * @see #requestBoolean(String, String)
     * @see #requestBoolean(String, String, String)
     * @see #requestBoolean(String, String, String, StringableFilter)
     */
    public static boolean demandBoolean(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandBoolean(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>boolean</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandBoolean(String, String)
     * @see #demandBoolean(String, String, String)
     * @see #requestBoolean(String, String)
     * @see #requestBoolean(String, String, String)
     * @see #requestBoolean(String, String, String, StringableFilter)
     */
    public static boolean demandBoolean(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XBoolean.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XBoolean model = (XBoolean)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>boolean</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestBoolean(String, String, String)
     * @see #requestBoolean(String, String, String, StringableFilter)
     * @see #demandBoolean(String, String)
     * @see #demandBoolean(String, String, String)
     * @see #demandBoolean(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static boolean requestBoolean(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestBoolean(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>boolean</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestBoolean(String, String)
     * @see #requestBoolean(String, String, String, StringableFilter)
     * @see #demandBoolean(String, String, String)
     * @see #demandBoolean(String, String)
     * @see #demandBoolean(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static boolean requestBoolean(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestBoolean(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>boolean</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestBoolean(String, String)
     * @see #requestBoolean(String, String, String)
     * @see #demandBoolean(String, String, String)
     * @see #demandBoolean(String, String)
     * @see #demandBoolean(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static boolean requestBoolean(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XBoolean.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XBoolean model = (XBoolean)requestObject(view);
        return model.getValue();
    }

    ///////////////////////////////////
    // Demand and Request for String //
    ///////////////////////////////////

    /**
     * Returns a <CODE>String</CODE> using the mandatory model of IO.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #demandString(String, String, String)
     * @see #demandString(String, String, String, StringableFilter)
     * @see #requestString(String, String)
     * @see #requestString(String, String, String)
     * @see #requestString(String, String, String, StringableFilter)
     */
    public static String demandString(
        String inputPrompt, 
        String dialogTitle) 
    {
        return demandString(inputPrompt, dialogTitle, "", null);
    }
    
    /**
     * Returns a <CODE>String</CODE> using the mandatory model of IO, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #demandString(String, String)
     * @see #demandString(String, String, String, StringableFilter)
     * @see #requestString(String, String)
     * @see #requestString(String, String, String)
     * @see #requestString(String, String, String, StringableFilter)
     */
    public static String demandString(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue) 
    {
        return demandString(
            inputPrompt, 
            dialogTitle, 
            defaultValue, 
            null);
    }

    /**
     * Returns a <CODE>String</CODE> using the mandatory model of IO, 
     * with the given default value and input filter.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #demandString(String, String)
     * @see #demandString(String, String, String)
     * @see #requestString(String, String)
     * @see #requestString(String, String, String)
     * @see #requestString(String, String, String, StringableFilter)
     */
    public static String demandString(
        String inputPrompt, 
        String dialogTitle, 
        String defaultValue,
        StringableFilter filter) 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XString.class);
        
        if (filter != null)
            view.setFilter(filter);
            
        XString model = (XString)demandObject(view);
        return model.getValue();
    }

    /**
     * Returns a <CODE>String</CODE> or throws an exception
     * if the user cancels the operation.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @see #requestString(String, String, String)
     * @see #requestString(String, String, String, StringableFilter)
     * @see #demandString(String, String)
     * @see #demandString(String, String, String)
     * @see #demandString(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static String requestString(
        String inputPrompt, 
            String dialogTitle)
        throws CancelledException 
    {
        return requestString(inputPrompt, dialogTitle, "", null);
    }

    /**
     * Returns a <CODE>String</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @see #requestString(String, String)
     * @see #requestString(String, String, String, StringableFilter)
     * @see #demandString(String, String, String)
     * @see #demandString(String, String)
     * @see #demandString(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static String requestString(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue)
        throws CancelledException 
    {
        return requestString(
            inputPrompt, 
            dialogTitle, 
            defaultValue,
            null);
    }

    /**
     * Returns a <CODE>String</CODE> or throws an exception
     * if the user cancels the operation, 
     * with the given default value.
     *
     * If the given filter is <CODE>null</CODE>,
     * no input filter is used.
     *
     * @param inputPrompt the prompt for the text field
     * @param dialogTitle the title of the dialog box
     * @param defaultValue the default value for the input
     * @param filter the input filter to be used
     * @see #requestString(String, String)
     * @see #requestString(String, String, String)
     * @see #demandString(String, String, String)
     * @see #demandString(String, String)
     * @see #demandString(String, String, String, StringableFilter)
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static String requestString(
        String inputPrompt, 
            String dialogTitle, 
            String defaultValue,
            StringableFilter filter)
        throws CancelledException 
    {
        TextFieldView view = 
            new TextFieldView(
                defaultValue, 
                inputPrompt, 
                dialogTitle);
        view.setDataType(XString.class);
            
        if (filter != null)
            view.setFilter(filter);
            
        XString model = (XString)requestObject(view);
        return model.getValue();
    }

    /////////////////
    // General API //
    /////////////////

    /**
     * Returns the object produced by the given input view
     * using mandatory dialog box input.
     *
     * @param viewObject the view to use for the input operation
     */
    public static Stringable demandObject(TypedView viewObject) {

        // set the input model to mandatory
        viewObject.getInputProperties().setInputModel(MANDATORY);

        // create and show modal dialog
        InputDialog d = new InputDialog(viewObject);
        d.setVisible(true);
        
        // return user input
        return d.getModel();
    }

    /**
     * Returns the object produced by the given input view
     * using optional dialog box input,
     * or throws an exception if the operation is cancelled.
     *
     * @param viewObject the view to use for the input operation
     * @throws CancelledException
     *      if the user cancels the input operation
     */
    public static Stringable requestObject(TypedView viewObject)
        throws CancelledException 
    {
        // set the input model to optional
        viewObject.getInputProperties().setInputModel(OPTIONAL);

        // create and show modal dialog
        InputDialog d = new InputDialog(viewObject);
        d.setVisible(true);
        
        // return user input or throw an exception
        if (d.wasCancelled())
            throw new CancelledException();
        else    
            return d.getModel();
    }
}

