/*
 * FSQuicktimeMovie.java
 * Transform
 * 
 * Copyright (c) 2001-2008 Flagstone Software Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *  * Neither the name of Flagstone Software Ltd. nor the names of its contributors 
 *    may be used to endorse or promote products derived from this software 
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.flagstone.transform;

/**
 * The FSQuicktimeMovie defines the name of an external Quicktime movie to be
 * played.
 * 
 * <p>
 * The name of the movie can be a reference to a file or to a URL.
 * </p>
 * 
 * <table class="datasheet">
 * 
 * <tr>
 * <th align="left" colspan="2">Attributes</th>
 * </tr>
 * 
 * <tr>
 * <td>type</td>
 * <td>Identifies the data structure when it is encoded. Read-only.</td>
 * </tr>
 * 
 * <tr>
 * <td>name</td>
 * <td>The name of a file or a URL referencing the file to be displayed by the
 * Flash Player.</td>
 * </tr>
 * 
 * </table>
 * 
 * <h1 class="datasheet">History</h1>
 * 
 * <p>
 * The FSQuicktimeMovie class represents the QuicktimeMovie structure from the
 * Macromedia Flash (SWF) File Format Specification. This structure is
 * undocumented in later versions of the specification. It is not known when it
 * was introduced.
 * </p>
 */
public class FSQuicktimeMovie extends FSMovieObject
{
	private String name = null;

	/**
	 * Construct an FSQuicktimeMovie object, initialising it with values decoded
	 * from an encoded object.
	 * 
	 * @param coder
	 *            an FSCoder containing the binary data.
	 */
	public FSQuicktimeMovie(FSCoder coder)
	{
		super(QuicktimeMovie);
		decode(coder);
	}

	/**
	 * Constructs an FSQuicktimeMovie object referencing the specified file.
	 * 
	 * @param aString
	 *            the file or URL where the file is located.
	 */
	public FSQuicktimeMovie(String aString)
	{
		super(QuicktimeMovie);
		setName(aString);
	}

	/**
	 * Constructs an FSQuicktimeMovie object by copying values from an existing
	 * object.
	 * 
	 * @param obj
	 *            an FSQuicktimeMovie object.
	 */
	public FSQuicktimeMovie(FSQuicktimeMovie obj)
	{
		super(obj);
		name = new String(obj.name);
	}

	/**
	 * Gets the reference to the file containing the movie.
	 * 
	 * @return the location of the file or URL.
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Sets the reference to the file containing the movie.
	 * 
	 * @param aString
	 *            the file or URL where the file is located.
	 */
	public void setName(String aString)
	{
		name = aString;
	}

	public boolean equals(Object anObject)
	{
		boolean result = false;

		if (super.equals(anObject))
		{
			FSQuicktimeMovie typedObject = (FSQuicktimeMovie) anObject;

			if (name != null)
				result = name.equals(typedObject.name);
			else
				result = name == typedObject.name;
		}
		return result;
	}

	public void appendDescription(StringBuffer buffer, int depth)
	{
		buffer.append(name());

		if (depth > 0)
		{
			buffer.append(": { ");
			Transform.append(buffer, "name", name);
			buffer.append("}");
		}
	}

	public int length(FSCoder coder)
	{
		super.length(coder);

		length += coder.strlen(name, true);

		return length;
	}

	public void encode(FSCoder coder)
	{
		super.encode(coder);
		coder.writeString(name);
		coder.writeWord(0, 1);
		coder.endObject(name());
	}

	public void decode(FSCoder coder)
	{
		super.decode(coder);
		name = coder.readString();
		coder.endObject(name());
	}
}
