/*****************************************************************************
 *                         (c) j3d.org 2002 - 2006
 *                               Java Source
 *
 * This source is licensed under the GNU LGPL v2.1
 * Please read http://www.gnu.org/copyleft/lgpl.html for more information
 *
 ****************************************************************************/

package org.j3d.loaders.c3d;

// External imports
// None

// Local imports
// None

/**
 * A single parameter instance that represents String (character) data.
 * <p>
 *
 * @author  Justin Couch
 * @version $Revision: 1.2 $
 */
public class C3DStringParameter extends C3DParameter
{
    /**
     * Construct a new group that represents the given name
     *
     * @param name The name this parameter represents
     * @param locked true if this is a locked group
     * @param id The ID of this parameter
     */
    public C3DStringParameter(String name, boolean locked, int id)
    {
        super(CHAR_TYPE, name, locked, id);
    }

    //----------------------------------------------------------
    // Methods defined by Object
    //----------------------------------------------------------

    /**
     * Generate a string representation of this header.
     *
     * @return Information about the header
     */
    public String toString()
    {
        StringBuffer buf = new StringBuffer("C3DStringParameter: ");
        buf.append(name);
        buf.append(" ID: ");
        buf.append(id);
        buf.append(" locked? ");
        buf.append(locked ? "Yes" : "No");
        buf.append("\n Dimensions: ");
        buf.append(dimensions.length);
        buf.append(" (");

        if(dimensions.length > 0)
        {
            buf.append(dimensions[0]);

            for(int i = 1; i < dimensions.length; i++)
            {
                buf.append(", ");
                buf.append(dimensions[i]);
            }
        }

        buf.append(")");
        buf.append("\n Description: ");

        if(description != null);
            buf.append(description);

        return buf.toString();
    }

    //----------------------------------------------------------
    // Local Methods
    //----------------------------------------------------------

    /**
     * Set the parameter value as a single value. A string of length 1 (a
     * single character) is treated as a zero dimenioned object.
     *
     * @param str The string to use as the value
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String str)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        if(str.length() == 1)
            dimensions = null;
        else
        {
            dimensions = new int[1];
            dimensions[0] = str.length();
        }

        data = str;
    }

    /**
     * Set the parameter value as a single dimensioned array value. When
     * setting the value, all items are assumed to be the same length as the
     * first elements of the array.
     *
     * @param str The string to use as the value
     * @param dim The dimensions of each value length
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String[] str, int[] dim)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        dimensions = dim;
        data = str;
    }


    /**
     * Set the parameter value as a two dimensioned array value. When
     * setting the value, all items are assumed to be the same length as the
     * first elements of the array.
     *
     * @param str The string to use as the value
     * @param dim The dimensions of each value length
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String[][] str, int[] dim)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        dimensions = dim;
        data = str;
    }


    /**
     * Set the parameter value as a three dimensioned array value. When
     * setting the value, all items are assumed to be the same length as the
     * first elements of the array.
     *
     * @param str The string to use as the value
     * @param dim The dimensions of each value length
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String[][][] str, int[] dim)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        dimensions = dim;
        data = str;
    }


    /**
     * Set the parameter value as a four dimensioned array value. When
     * setting the value, all items are assumed to be the same length as the
     * first elements of the array.
     *
     * @param str The string to use as the value
     * @param dim The dimensions of each value length
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String[][][][] str, int[] dim)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        dimensions = dim;
        data = str;
    }


    /**
     * Set the parameter value as a five dimensioned array value. When
     * setting the value, all items are assumed to be the same length as the
     * first elements of the array.
     *
     * @param str The string to use as the value
     * @param dim The dimensions of each value length
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String[][][][][] str, int[] dim)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        dimensions = dim;
        data = str;
    }


    /**
     * Set the parameter value as a six dimensioned array value. When
     * setting the value, all items are assumed to be the same length as the
     * first elements of the array.
     *
     * @param str The string to use as the value
     * @param dim The dimensions of each value length
     * @throws IllegalStateException The object is locked and cannot be
     *    changed
     */
    public void setValue(String[][][][][][] str, int[] dim)
        throws IllegalStateException
    {
        if(locked)
            throw new IllegalStateException(LOCKED_PARAM_MSG);

        dimensions = dim;
        data = str;
    }
}
