package flater.blogsamples.degrafabutton.skins
{
import flash.net.URLVariables;
import flash.utils.describeType;
    
    
/**
 *  A singleton data model for the dynamic skin data
 */
[Bindable] public class ButtonDynamicPersistentSkinData
{

    //--------------------------------------------------------------------------
    //
    //  Class variables
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  The var holding the singleton instance of Model.
     */
    private static var instance : ButtonDynamicPersistentSkinData = null;


    //--------------------------------------------------------------------------
    //
    //  Class methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Returns the singleton instance of Model
     */
    public static function getInstance() : ButtonDynamicPersistentSkinData
    {
        if ( instance == null ) 
        {
            instance = new ButtonDynamicPersistentSkinData( new SingletonBlocker() );
        }
        return instance;
    }


    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor.
     */    
    public function ButtonDynamicPersistentSkinData( singletonBlocker : SingletonBlocker ) : void 
    {
        super();
    }


    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    public var upFillColor         : uint         = 0x951717;
    public var overFillColor    : uint         = 0x951717;
    public var downFillColor    : uint         = 0x954040;

    public var upFillAlpha         : Number    = 1;
    public var overFillAlpha    : Number    = .6
    public var downFillAlpha    : Number     = .6;

    public var upCornerRadius    : int        = 8;
    public var overCornerRadius    : int        = 16;
    public var downCornerRadius : int        = 32;
    
    
    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Converts the model to URLVariables
     */
    public function toUrlVariables() : URLVariables
    {
        var urlVars         : URLVariables     = new URLVariables();
        var typeDescript    : XML             = describeType( this );
        
        for each ( var propNode : XML in typeDescript.accessor )
        {
            urlVars[ propNode.@name ] = this[ propNode.@name ];
        }
        
        return urlVars;
    }
    
    /**
     *  Sets the values of the model based on urlVariables
     */
    public function setValues( urlVariables : URLVariables ) : void
    {
        var typeDescript    : XML            = describeType( this );
        
        for each ( var propNode : XML in typeDescript.accessor )
        {
            if ( urlVariables.hasOwnProperty( propNode.@name ) )
            {
                this[ propNode.@name ] = urlVariables[ propNode.@name ];
            }
        }
    }
    

} //  end class
} //  end package

internal class SingletonBlocker {}