/*
 * FSFillStyle.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;

/**
 * FSFillStyle is an abstract base class for the different types of fill style
 * that can be applied to shapes.
 */
public abstract class FSFillStyle extends FSTransformObject
{
	/** Defines the type for a solid fill style. */
	public static final int Solid = 0;

	/** Defines the type for a linear gradient fill style. */
	public static final int Linear = 16;

	/** Defines the type for a radial gradient fill style. */
	public static final int Radial = 18;

	/** Defines the type for a tiled bitmap fill style. */
	public static final int Tiled = 64;

	/** Defines the type for a clipped bitmap fill style. */
	public static final int Clipped = 65;

	/** Defines the type for a tiled bitmap fill style - added in Flash 7. */
	public static final int Unsmoothed_Tiled = 66;

	/** Defines the type for a clipped bitmap fill style - added in Flash 7. */
	public static final int Unsmoothed_Clipped = 67;

	protected int type = 0;

	FSFillStyle()
	{
	}

	protected FSFillStyle(FSCoder coder)
	{
		decode(coder);
	}

	protected FSFillStyle(FSFillStyle obj)
	{
		type = obj.type;
	}

	protected FSFillStyle(int aType)
	{
		setType(aType);
	}

	/**
	 * Gets the type of the fill style. The type attribute is read-only and may
	 * be used when iterating through an array of fill style objects to identify
	 * the type of fill style without using run-time type checking provided by
	 * the compiler.
	 * 
	 * @return the type of fill.
	 */
	public int getType()
	{
		return type;
	}

	/**
	 * Sets the type of the fill style.
	 * 
	 * @param aType
	 *            the type of fill.
	 */
	public void setType(int aType)
	{
		type = aType;
	}

	/**
	 * Returns true if anObject is equal to this one. Objects are considered
	 * equal if they would generate identical binary data when they are encoded
	 * to a Flash file.
	 * 
	 * @return true if this object would be identical to anObject when encoded.
	 */
	public boolean equals(Object anObject)
	{
		boolean result = false;

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

			result = type == typedObject.type;
		}

		return result;
	}

	public int length(FSCoder coder)
	{
		int length = 1;

		return length;
	}

	public void encode(FSCoder coder)
	{
		coder.writeWord(type, 1);
	}

	public void decode(FSCoder coder)
	{
		type = coder.readWord(1, false);
	}
}
