/* -*- mode: JavaScript; c-basic-offset: 2; -*- */

/*
 * Platform-specific DebugService
  *
  * @copyright Copyright 2001-2009 Laszlo Systems, Inc.  All Rights Reserved.
  *            Use is subject to license terms.

 */

class LzAS3DebugService extends LzDebugService {
    #passthrough (toplevel:true) {
    import flash.utils.describeType;
    import flash.utils.Dictionary;
    import flash.utils.getDefinitionByName
    import flash.utils.getQualifiedClassName
    }#

  /**
   * @access private
   */
  function LzAS3DebugService (base:LzBootstrapDebugService) {
    super(base);
  }

  /**
   ** Platform-specific implementation of debug I/O
   **/

  /**
   * Instantiates an instance of the user Debugger window
   * Called last thing by the compiler when the app is completely loaded.
   * @access private
   */
  function makeDebugWindow () {
    // Make the real console.  This is only called if the user code
    // did not actually instantiate a <debug /> tag
    var params:Object = LFCApplication.stage.loaderInfo.parameters;
    var remote =( params[ "lzconsoledebug" ] );
    if (remote == 'true') {
      // Open the remote debugger socket
      this.attachDebugConsole(new LzFlashRemoteDebugConsole());
    } else {
      // This will attach itself, once it is fully initialized.
      new lz.LzDebugWindow();
    }
  }

  // Map of object=>id
  var swf9_object_table:Dictionary = new Dictionary();
  // Map of id=>object
  var swf9_id_table:Array = [];

  override function IDForObject (obj:*, force:Boolean=false):* {
    var id:Number;
    // in swf9 we can use the flash.utils.Dictionary object to do hash table
    // lookups using === object equality, so we don't need to iterate over the
    // id_to_object_table to see if an object has been interned.
    var ot = this.swf9_object_table;
    if (ot[obj] != null) {
      return ot[obj];
    }
    if (!force) {
      // ID anything that has identity
      if (! this.isObjectLike(obj)) {
        return null;
      }
    }
    id = this.objseq++;
    this.swf9_object_table[obj] = id;
    this.swf9_id_table[id] = obj;
    return id;
  };

  override function ObjectForID (id) {
    return this.swf9_id_table[id];
  };

  /**
   * Predicate for deciding if an object is 'Object-like' (has
   * interesting properties)
   *
   * @access private
   */
  override function isObjectLike (obj:*):Boolean {
    // NOTE [2008-09-16 ptw] In JS2 all primitives (boolean, number,
    // string) are auto-wrapped, so you can't ask `obj is Object` to
    // distinguish primitives from objects
    return !!obj && (typeof(obj) == 'object');
  };

  /**
   * Predicate for deciding if an object is 'Array-like' (has a
   * non-negative integer length property)
   *
   * @access private
   */
  #passthrough {
  public override function isArrayLike (obj:*):Boolean {
    // Efficiency
    if (! obj) { return false; }
    if (obj is Array) { return true; }
    if (obj is String) { return true; }
    if (! (typeof obj == 'object')) { return false; }
    // NOTE [2008-09-20 ptw] In JS2 you can't ask obj['length'] if the
    // object's class doesn't have such a property, or is not dynamic
    var description:XML = describeType(obj);
    if ((description.@isDynamic == 'true') ||
        (description.variable.(@name == 'length').length() != 0)) {
      return super.isArrayLike(obj);
    }
    return false;
  };
  }#

  /**
   * Adds handling of swf9 Class
   *
   * @access private
   */
  override function __StringDescription (thing:*, escape:Boolean, limit:Number, readable:Boolean, depth:Number):Object {
    if (thing is Class) {
      var s = this.functionName(thing);
      if (s) {
        return {readable: false, description: s}
      }
    }
    return super.__StringDescription(thing, escape, limit, readable, depth);
  }

  /**
   * @access private
   * @devnote This is carefully constructed so that if there is a
   * preferred name but mustBeUnique cannot be satisfied, we return
   * null (because the debugger may re-call us without the unique
   * requirement, to get the preferred name).
   *
   * @devnote TODO: [2008-09-23 ptw] (LPP-7034) Remove public
   * declaration after 7034 is resolved
   */
#passthrough{
  // all methods are coerced to public when compiling for debug
  public override function functionName (fn, mustBeUnique:Boolean=false) {
    if (fn is Class) {
      // JS2 constructors are Class
      if (fn['tagname']) {
        // Handle tag classes
        if ((! mustBeUnique) || (fn === lz[fn.tagname])) {
          return '<' + fn.tagname + '>';
        } else {
          return null;
        }
      }
      // Display name takes precedence over the actual class name
      if (fn[Debug.FUNCTION_NAME]) {
        var n = fn[Debug.FUNCTION_NAME];
      } else {
        var n = getQualifiedClassName(fn);
      }
      if (! mustBeUnique) {
        return n;
      } else {
        try {
          if (fn == getDefinitionByName(n)) {
            return n;
          }
        } catch (e) {};
        return null;
      }
    }
    return super.functionName(fn, mustBeUnique);
  };
}#

  /**
   * Adds unenumerable object properties for DHMTL runtime
   *
   * @access private
   */
  #passthrough {
  // all methods are coerced to public when compiling for debug
  public override function objectOwnProperties (obj:*, names:Array=null, indices:Array=null, limit:Number=Infinity, nonEnumerable:Boolean=false) {
    // TODO [2008-09-11 hqm] not sure what to do here, we use the introspection API
    // flash.utils.describeType() to at least enumerate public properties...
    if (names != null) {
      var description:XML = describeType(obj);
      for each(var a:XML in description.variable) {
        names.push(a.@name);
      }
    }
    return super.objectOwnProperties(obj, names, indices, limit,nonEnumerable);
  }
  }#
}

// In AS3, we just build the whole debugger right now
Debug = new LzAS3DebugService(null);
var __LzDebug = Debug;

/* -*- mode: JavaScript; c-basic-offset: 2; -*- */

/*
 * Platform-specific DebugService
  *
  * @copyright Copyright 2001-2010 Laszlo Systems, Inc.  All Rights Reserved.
  *            Use is subject to license terms.

 */

class LzAS3DebugService extends LzDebugService {
    #passthrough (toplevel:true) {
    import flash.utils.describeType;
    import flash.utils.Dictionary;
    import flash.utils.getDefinitionByName
    import flash.utils.getQualifiedClassName
    import flash.system.Capabilities;
    }#

  /**
   * @access private
   */
  function LzAS3DebugService (base:LzBootstrapDebugService) {
    super(base);
  }

  /**
   ** Platform-specific implementation of debug I/O
   **/

  /**
   * Instantiates an instance of the user Debugger window
   * Called last thing by the compiler when the app is completely loaded.
   * @access private
   */
  function makeDebugWindow () {
    // Make the real console.  This is only called if the user code
    // did not actually instantiate a <debug /> tag
    var params:Object = LFCApplication.stage.loaderInfo.parameters;
    var remote =( params[ "lzconsoledebug" ] );
    if (remote == 'true') {
      // Open the remote debugger socket
      this.attachDebugConsole(new LzFlashRemoteDebugConsole());
    } else {
      // This will attach itself, once it is fully initialized.
      new lz.LzDebugWindow();
    }
    if (! Capabilities.isDebugger) {
      Debug.warn("Install the Flash debug player (http://www.adobe.com/support/flashplayer/downloads.html) for debugging.");
    }
  }

  // Map of object=>id
  var swf9_object_table:Dictionary = new Dictionary();
  // Map of id=>object
  var swf9_id_table:Array = [];

  override function IDForObject (obj:*, force:Boolean=false):* {
    var id:Number;
    // in swf9 we can use the flash.utils.Dictionary object to do hash table
    // lookups using === object equality, so we don't need to iterate over the
    // id_to_object_table to see if an object has been interned.
    var ot = this.swf9_object_table;
    if (ot[obj] != null) {
      return ot[obj];
    }
    if (!force) {
      // ID anything that has identity
      if (! this.isObjectLike(obj)) {
        return null;
      }
    }
    id = this.objseq++;
    this.swf9_object_table[obj] = id;
    this.swf9_id_table[id] = obj;
    return id;
  };

  override function ObjectForID (id) {
    return this.swf9_id_table[id];
  };

  /**
   * Predicate for deciding if an object is 'Object-like' (has
   * interesting properties)
   *
   * @access private
   */
  override function isObjectLike (obj:*):Boolean {
    // NOTE [2008-09-16 ptw] In JS2 all primitives (boolean, number,
    // string) are auto-wrapped, so you can't ask `obj is Object` to
    // distinguish primitives from objects
    return !!obj && (typeof(obj) == 'object');
  };

  /**
   * Predicate for deciding if an object is 'Array-like' (has a
   * non-negative integer length property)
   *
   * @access private
   */
  #passthrough {
  public override function isArrayLike (obj:*):Boolean {
    // Efficiency
    if (! obj) { return false; }
    if (obj is Array) { return true; }
    if (obj is String) { return true; }
    if (! (typeof obj == 'object')) { return false; }
    // NOTE [2008-09-20 ptw] In JS2 you can't ask obj['length'] if the
    // object's class doesn't have such a property, or is not dynamic
    var description:XML = describeType(obj);
    if ((description.@isDynamic == 'true') ||
        (description.variable.(@name == 'length').length() != 0)) {
      return super.isArrayLike(obj);
    }
    return false;
  };
  }#

  /**
   * Adds handling of swf9 Class
   *
   * @access private
   */
  override function __StringDescription (thing:*, escape:Boolean, limit:Number, readable:Boolean, depth:Number):Object {
    if (thing is Class) {
      var s = this.functionName(thing);
      if (s) {
        return {readable: false, description: s}
      }
    }
    return super.__StringDescription(thing, escape, limit, readable, depth);
  }

  /**
   * @access private
   * @devnote This is carefully constructed so that if there is a
   * preferred name but mustBeUnique cannot be satisfied, we return
   * null (because the debugger may re-call us without the unique
   * requirement, to get the preferred name).
   *
   * @devnote TODO: [2008-09-23 ptw] (LPP-7034) Remove public
   * declaration after 7034 is resolved
   */
#passthrough{
  // all methods are coerced to public when compiling for debug
  public override function functionName (fn, mustBeUnique:Boolean=false) {
    if (fn is Class) {
      // JS2 constructors are Class
      if (fn['tagname']) {
        // Handle tag classes
        if ((! mustBeUnique) || (fn === lz[fn.tagname])) {
          return '<' + fn.tagname + '>';
        } else {
          return null;
        }
      }
      // Display name takes precedence over the actual class name
      if (fn[Debug.FUNCTION_NAME]) {
        var n = fn[Debug.FUNCTION_NAME];
      } else {
        var n = getQualifiedClassName(fn);
      }
      if (! mustBeUnique) {
        return n;
      } else {
        try {
          if (fn == getDefinitionByName(n)) {
            return n;
          }
        } catch (e) {};
        return null;
      }
    }
    return super.functionName(fn, mustBeUnique);
  };
}#

  /**
   * Adds unenumerable object properties for DHMTL runtime
   *
   * @access private
   */
  #passthrough {
  // all methods are coerced to public when compiling for debug
  public override function objectOwnProperties (obj:*, names:Array=null, indices:Array=null, limit:Number=Infinity, nonEnumerable:Boolean=false) {
    // TODO [2008-09-11 hqm] not sure what to do here, we use the introspection API
    // flash.utils.describeType() to at least enumerate public properties...
    if (names != null) {
      var description:XML = describeType(obj);
      for each(var a:XML in description.variable) {
        names.push(a.@name);
      }
    }
    return super.objectOwnProperties(obj, names, indices, limit,nonEnumerable);
  }
  }#
}

// In AS3, we just build the whole debugger right now
Debug = new LzAS3DebugService(null);
var __LzDebug = Debug;

Change 20100208-ptw-K by ptw@repo-man.home on 2010-02-08 13:27:48 EST
    in /Users/ptw/OpenLaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Warn when swf9/10 & debug but not running debug player

Bugs Fixed:  LPP-8692 Debug console can't display the correct compile error in swf9

Technical Reviewer: hminsky (Message-ID: <8c61fad61002081152s24f66865ja0fdc1150beaf361@mail.gmail.com>)
QA Reviewer: max (Message-ID: <4B706D5C.2030907@laszlosystems.com>)

Release Notes:

    The debugger will issue a warning if you are using the swf9 or
    swf10 runtimes but do not have the debug Flash player installed.
    The debugger relies on the debug player for displaying
    human-readable error messages.

Details:
    When creating debug console, test for debug player and warn if not present.

Tests:
    Launch any application without the debug player installed and
    notice the warning.  Install the debug player and notice no
    warning.  (Good luck if you do it in the other order as the Adobe
    installer will apparently not let you downgrade.)

git-svn-id: d62bde4b5aa582fdf07c8d403e53e0399a7ed285@15653 fa20e4f9-1d0a-0410-b5f3-dc9c16b8b17c


package aerys.minko.render.material.basic
{
	import aerys.minko.render.Effect;
	import aerys.minko.render.material.Material;
	import aerys.minko.render.resource.texture.TextureResource;
	import aerys.minko.type.binding.IDataProvider;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	public class BasicMaterial extends Material
	{
		public static const DEFAULT_NAME			: String		= 'BasicMaterial';
		public static const DEFAULT_BASIC_SHADER	: BasicShader	= new BasicShader();
		public static const DEFAULT_EFFECT			: Effect		= new Effect(DEFAULT_BASIC_SHADER);

		public function get diffuseFormat() : uint
		{
			return getProperty(BasicProperties.DIFFUSE_FORMAT);
		}

		public function set diffuseFormat(value : uint) : void
		{
			setProperty(BasicProperties.DIFFUSE_FORMAT, value);
		}

		public function get blending() : uint
		{
			return getProperty(BasicProperties.BLENDING);
		}
		public function set blending(value : uint) : void
		{
			setProperty(BasicProperties.BLENDING, value);
		}

		public function get triangleCulling() : uint
		{
			return getProperty(BasicProperties.TRIANGLE_CULLING);
		}
		public function set triangleCulling(value : uint) : void
		{
			setProperty(BasicProperties.TRIANGLE_CULLING, value);
		}

		public function get diffuseColor() : uint
		{
			return getProperty(BasicProperties.DIFFUSE_COLOR);
		}
		public function set diffuseColor(value : uint) : void
		{
			setProperty(BasicProperties.DIFFUSE_COLOR, value);
		}

		public function get diffuseMap() : TextureResource
		{
			return getProperty(BasicProperties.DIFFUSE_MAP);
		}
		public function set diffuseMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP, value);
		}

		public function get alphaMap() : TextureResource
		{
			return getProperty(BasicProperties.ALPHA_MAP) as TextureResource;
		}
		public function set alphaMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.ALPHA_MAP, value);
		}

		public function get alphaThreshold() : Number
		{
			return getProperty(BasicProperties.ALPHA_THRESHOLD);
		}
		public function set alphaThreshold(value : Number) : void
		{
			setProperty(BasicProperties.ALPHA_THRESHOLD, value);
		}

		public function get depthTest() : uint
		{
			return getProperty(BasicProperties.DEPTH_TEST);
		}
		public function set depthTest(value : uint) : void
		{
			setProperty(BasicProperties.DEPTH_TEST, value);
		}

		public function get depthWriteEnabled() : Boolean
		{
			return getProperty(BasicProperties.DEPTH_WRITE_ENABLED);
		}
		public function set depthWriteEnabled(value : Boolean) : void
		{
			setProperty(BasicProperties.DEPTH_WRITE_ENABLED, value);
		}

		public function get stencilTriangleFace() : uint
		{
			return getProperty(BasicProperties.STENCIL_TRIANGLE_FACE);
		}
		public function set stencilTriangleFace(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_TRIANGLE_FACE, value);
		}

		public function get stencilCompareMode() : uint
		{
			return getProperty(BasicProperties.STENCIL_COMPARE_MODE);
		}
		public function set stencilCompareMode(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_COMPARE_MODE, value);
		}

		public function get stencilActionBothPass() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS);
		}
		public function set stencilActionBothPass(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS, value);
		}

		public function get stencilActionDepthFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL);
		}
		public function set stencilActionDepthFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL, value);
		}

		public function get stencilActionDepthPassStencilFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL);
		}
		public function set stencilActionDepthPassStencilFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL, value);
		}

		public function get stencilReferenceValue() : Number
		{
			return getProperty(BasicProperties.STENCIL_REFERENCE_VALUE);
		}
		public function set stencilReferenceValue(value : Number) : void
		{
			setProperty(BasicProperties.STENCIL_REFERENCE_VALUE, value);
		}

		public function get stencilReadMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_READ_MASK);
		}
		public function set stencilReadMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_READ_MASK, value);
		}

		public function get stencilWriteMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_WRITE_MASK);
		}
		public function set stencilWriteMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_WRITE_MASK, value);
		}

		public function get diffuseTransform() : Matrix4x4
		{
			return getProperty(BasicProperties.DIFFUSE_TRANSFORM);
		}
		public function set diffuseTransform(value : Matrix4x4) : void
		{
			setProperty(BasicProperties.DIFFUSE_TRANSFORM, value);
		}

        public function get uvOffset() : Vector4
        {
            return getProperty(BasicProperties.UV_OFFSET);
        }
        public function set uvOffset(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_OFFSET, value);
        }

        public function get uvScale() : Vector4
        {
            return getProperty(BasicProperties.UV_SCALE);
        }
        public function set uvScale(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_SCALE, value);
        }

		public function BasicMaterial(properties : Object = null, effect : Effect = null, name : String = DEFAULT_NAME)
		{
			super(effect || DEFAULT_EFFECT, properties, name);
		}

		override public function clone() : IDataProvider
		{
			var mat : BasicMaterial	= new BasicMaterial(this, effect, name);

			return mat;
		}
	}
}

package aerys.minko.render.material.basic
{
	import aerys.minko.render.Effect;
	import aerys.minko.render.material.Material;
	import aerys.minko.render.resource.texture.TextureResource;
	import aerys.minko.type.binding.IDataProvider;
	import aerys.minko.type.math.Matrix4x4;
	import aerys.minko.type.math.Vector4;

	public class BasicMaterial extends Material
	{
		public static const DEFAULT_NAME			: String		= 'BasicMaterial';
		public static const DEFAULT_BASIC_SHADER	: BasicShader	= new BasicShader();
		public static const DEFAULT_EFFECT			: Effect		= new Effect(DEFAULT_BASIC_SHADER);

		public function get diffuseFormat() : uint
		{
			return getProperty(BasicProperties.DIFFUSE_FORMAT);
		}

		public function set diffuseFormat(value : uint) : void
		{
			setProperty(BasicProperties.DIFFUSE_FORMAT, value);
		}

		public function get blending() : uint
		{
			return getProperty(BasicProperties.BLENDING);
		}
		public function set blending(value : uint) : void
		{
			setProperty(BasicProperties.BLENDING, value);
		}

		public function get triangleCulling() : uint
		{
			return getProperty(BasicProperties.TRIANGLE_CULLING);
		}
		public function set triangleCulling(value : uint) : void
		{
			setProperty(BasicProperties.TRIANGLE_CULLING, value);
		}

		public function get diffuseColor() : Object
		{
			return getProperty(BasicProperties.DIFFUSE_COLOR);
		}
		public function set diffuseColor(value : Object) : void
		{
			setProperty(BasicProperties.DIFFUSE_COLOR, value);
		}

		public function get diffuseMap() : TextureResource
		{
			return getProperty(BasicProperties.DIFFUSE_MAP);
		}
		public function set diffuseMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.DIFFUSE_MAP, value);
		}

		public function get alphaMap() : TextureResource
		{
			return getProperty(BasicProperties.ALPHA_MAP) as TextureResource;
		}
		public function set alphaMap(value : TextureResource) : void
		{
			setProperty(BasicProperties.ALPHA_MAP, value);
		}

		public function get alphaThreshold() : Number
		{
			return getProperty(BasicProperties.ALPHA_THRESHOLD);
		}
		public function set alphaThreshold(value : Number) : void
		{
			setProperty(BasicProperties.ALPHA_THRESHOLD, value);
		}

		public function get depthTest() : uint
		{
			return getProperty(BasicProperties.DEPTH_TEST);
		}
		public function set depthTest(value : uint) : void
		{
			setProperty(BasicProperties.DEPTH_TEST, value);
		}

		public function get depthWriteEnabled() : Boolean
		{
			return getProperty(BasicProperties.DEPTH_WRITE_ENABLED);
		}
		public function set depthWriteEnabled(value : Boolean) : void
		{
			setProperty(BasicProperties.DEPTH_WRITE_ENABLED, value);
		}

		public function get stencilTriangleFace() : uint
		{
			return getProperty(BasicProperties.STENCIL_TRIANGLE_FACE);
		}
		public function set stencilTriangleFace(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_TRIANGLE_FACE, value);
		}

		public function get stencilCompareMode() : uint
		{
			return getProperty(BasicProperties.STENCIL_COMPARE_MODE);
		}
		public function set stencilCompareMode(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_COMPARE_MODE, value);
		}

		public function get stencilActionBothPass() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS);
		}
		public function set stencilActionBothPass(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_BOTH_PASS, value);
		}

		public function get stencilActionDepthFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL);
		}
		public function set stencilActionDepthFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_FAIL, value);
		}

		public function get stencilActionDepthPassStencilFail() : uint
		{
			return getProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL);
		}
		public function set stencilActionDepthPassStencilFail(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_ACTION_DEPTH_PASS_STENCIL_FAIL, value);
		}

		public function get stencilReferenceValue() : Number
		{
			return getProperty(BasicProperties.STENCIL_REFERENCE_VALUE);
		}
		public function set stencilReferenceValue(value : Number) : void
		{
			setProperty(BasicProperties.STENCIL_REFERENCE_VALUE, value);
		}

		public function get stencilReadMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_READ_MASK);
		}
		public function set stencilReadMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_READ_MASK, value);
		}

		public function get stencilWriteMask() : uint
		{
			return getProperty(BasicProperties.STENCIL_WRITE_MASK);
		}
		public function set stencilWriteMask(value : uint) : void
		{
			setProperty(BasicProperties.STENCIL_WRITE_MASK, value);
		}

		public function get diffuseTransform() : Matrix4x4
		{
			return getProperty(BasicProperties.DIFFUSE_TRANSFORM);
		}
		public function set diffuseTransform(value : Matrix4x4) : void
		{
			setProperty(BasicProperties.DIFFUSE_TRANSFORM, value);
		}

        public function get uvOffset() : Vector4
        {
            return getProperty(BasicProperties.UV_OFFSET);
        }
        public function set uvOffset(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_OFFSET, value);
        }

        public function get uvScale() : Vector4
        {
            return getProperty(BasicProperties.UV_SCALE);
        }
        public function set uvScale(value : Vector4) : void
        {
            setProperty(BasicProperties.UV_SCALE, value);
        }

		public function BasicMaterial(properties : Object = null, effect : Effect = null, name : String = DEFAULT_NAME)
		{
			super(effect || DEFAULT_EFFECT, properties, name);
		}

		override public function clone() : IDataProvider
		{
			var mat : BasicMaterial	= new BasicMaterial(this, effect, name);

			return mat;
		}
	}
}

set BasicMaterial.diffuseColor to be Object in order to accept both uint and Vector4 color values


////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package spark.components.windowClasses
{

import flash.display.DisplayObject;
import flash.display.NativeWindowDisplayState;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NativeWindowDisplayStateEvent;
import flash.system.Capabilities;

import mx.core.IWindow;
import mx.core.mx_internal;

import spark.components.Button;
import spark.components.supportClasses.SkinnableComponent;
import spark.components.supportClasses.TextBase;
import spark.events.SkinPartEvent;
import spark.primitives.BitmapImage;
import spark.skins.*;
import spark.skins.spark.windowChrome.MacTitleBarSkin;
import spark.skins.spark.windowChrome.TitleBarSkin;

use namespace mx_internal;

//--------------------------------------
//  SkinStates
//--------------------------------------

/**
 *  The title bar is enabled and the application is maximized.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
[SkinState("normalAndMaximized")]

/**
 *  The title bar is disabled and the application is maximized.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
[SkinState("disabledAndMaximized")]

//--------------------------------------
//  Excluded APIs
//--------------------------------------

[Exclude(name="focusBlendMode", kind="style")]
[Exclude(name="focusThickness", kind="style")]

/**
 *  The TitleBar class defines the default title bar for a
 *  WindowedApplication or a Window container.
 *
 *  @see mx.core.Window
 *  @see mx.core.WindowedApplication
 *
 *
 *  @langversion 3.0
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
public class TitleBar extends SkinnableComponent
{
    include "../../core/Version.as";

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

    /**
     *  @private
     */
    private static function isMac():Boolean
    {
        return Capabilities.os.substring(0, 3) == "Mac";
    }

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

    /**
     *  Constructor.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function TitleBar():void
    {
        super();

        doubleClickEnabled = true;

        addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler);
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  This is the actual object created from the _titleIcon class
     */
    mx_internal var titleIconObject:Object;

    //--------------------------------------------------------------------------
    //
    //  Skin Parts
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  closeButton
    //----------------------------------

    /**
     *  The skin part that defines the Button control that corresponds to the close button.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="true")]
    public var closeButton:Button;

    //----------------------------------
    //  maximizeButton
    //----------------------------------

    /**
     *  The skin part that defines the Button control that corresponds to the maximize button.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var maximizeButton:Button;

    //----------------------------------
    //  minimizeButton
    //----------------------------------

    /**
     *  The skin part that defines the Button control that corresponds to the minimize button.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var minimizeButton:Button;

    //----------------------------------
    //  titleIconImage
    //----------------------------------

    /**
     *  The title icon in the TitleBar.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var titleIconImage:BitmapImage;

    //----------------------------------
    //  titleTextField
    //----------------------------------

    /**
     *  The skin part that defines the UITextField control that displays the application title text.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var titleText:TextBase;

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

    //----------------------------------
    //  title
    //----------------------------------

    /**
     *  Storage for the title property.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    private var _title:String = "";

    /**
     *  @private
     */
    private var titleChanged:Boolean = false;

    /**
     *  The title that appears in the window title bar and
     *  the dock or taskbar.
     *
     *  @default ""
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function get title():String
    {
        return _title;
    }

    /**
     *  @private
     */
    public function set title(value:String):void
    {
        _title = value;
        titleChanged = true;

        invalidateProperties();
        invalidateSize();
        invalidateDisplayList();
    }

    //----------------------------------
    //  titleIcon
    //----------------------------------

    /**
     *  @private
     *  Storage for the titleIcon property.
     */
    private var _titleIcon:Class;

    /**
     *  @private
     */
    private var titleIconChanged:Boolean = false;

    /**
     *  The icon displayed in the title bar.
     *
     *  @default null
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function get titleIcon():Class
    {
        return _titleIcon;
    }

    /**
     *  @private
     */
    public function set titleIcon(value:Class):void
    {
        _titleIcon = value;
        titleIconChanged = true;

        invalidateProperties();
        invalidateSize();
    }

    //----------------------------------
    //  window
    //----------------------------------

    /**
     *  The IWindow that owns this TitleBar.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    private function get window():IWindow
    {
        var p:DisplayObject = parent;

        while (p && !(p is IWindow))
            p = p.parent;

        return IWindow(p);
    }

    //--------------------------------------------------------------------------
    //
    //  Overridden methods: SkinnableComponent
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *
     *  When we are running on the mac, switch to the mac skin and continue the load.
     *
     */
    override protected function attachSkin():void
    {
       if (isMac() && getStyle("skinClass") == TitleBarSkin)
       {
            setStyle("skinClass", MacTitleBarSkin);
       }

       super.attachSkin();
    }

    //--------------------------------------------------------------------------
    //
    //  Overridden methods: SkinnableContainer
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    override protected function partAdded(partName:String, instance:Object):void
    {
        super.partAdded(partName, instance);

        if (instance == titleText)
        {
            titleText.text = title;
        }
        else if (instance == closeButton)
        {
            closeButton.focusEnabled = false;
            closeButton.addEventListener(MouseEvent.MOUSE_DOWN, button_mouseDownHandler);
            closeButton.addEventListener(MouseEvent.CLICK, closeButton_clickHandler);
        }
        else if (instance == minimizeButton)
        {
            minimizeButton.focusEnabled = false;
            minimizeButton.enabled = window.minimizable;
            minimizeButton.addEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            minimizeButton.addEventListener(MouseEvent.CLICK,
                                            minimizeButton_clickHandler);
        }
        else if (instance == maximizeButton)
        {
            maximizeButton.focusEnabled = false;
            maximizeButton.enabled = window.maximizable;
            maximizeButton.addEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            maximizeButton.addEventListener(MouseEvent.CLICK,
                                            maximizeButton_clickHandler);

            var targetWindow:DisplayObject = DisplayObject(window);
            targetWindow.addEventListener(
                NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE,
                window_displayStateChangeHandler, false, 0, true);

            // Add this listener so we can remove the display state change handler
            // if our window is reskinned. This fixes an RTE when the titleBar
            // display state handler ran without a window after being reskinned.
            targetWindow.addEventListener(SkinPartEvent.PART_REMOVED, partRemovedHandler,
                false, 0, true);
        }
    }

    /**
     *  @private
     */
    override protected function partRemoved(partName:String, instance:Object):void
    {
        super.partRemoved(partName, instance);

        if (instance == closeButton)
        {
            closeButton.removeEventListener(MouseEvent.CLICK, closeButton_clickHandler);
        }
        else if (instance == minimizeButton)
        {
            minimizeButton.removeEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            minimizeButton.removeEventListener(MouseEvent.CLICK,
                                            minimizeButton_clickHandler);
        }
        else if (instance == maximizeButton)
        {
            maximizeButton.removeEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            maximizeButton.removeEventListener(MouseEvent.CLICK,
                                            maximizeButton_clickHandler);

            var targetWindow:DisplayObject = DisplayObject(window);
            targetWindow.removeEventListener(
                NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE,
                window_displayStateChangeHandler);
            targetWindow.removeEventListener(SkinPartEvent.PART_REMOVED, partRemovedHandler);
        }

    }

    /**
     *  @private
     */
    override protected function commitProperties():void
    {
        super.commitProperties();

        if (titleChanged)
        {
            titleText.text = _title;
            titleChanged = false;
        }

        if (titleIconChanged)
        {
            if (titleIconObject)
            {
                titleIconImage.source = null;
                titleIconObject = null;
            }

            if (_titleIcon && titleIconImage)
            {
                titleIconObject = new _titleIcon();
                titleIconImage.source = titleIconObject;
            }
            titleIconChanged = false;
        }

    }

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    //
    // Skin states support
    //
    //--------------------------------------------------------------------------

    /**
     *  Returns the name of the state to be applied to the skin. For example, a
     *  Button component could return the String "up", "down", "over", or "disabled"
     *  to specify the state.
     *
     *
A subclass of SkinnableComponent must override this method to return a value.

     *
     *  @return A string specifying the name of the state to apply to the skin.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    override protected function getCurrentSkinState():String
    {
        if (!window.nativeWindow.closed &&
            window.nativeWindow.displayState == NativeWindowDisplayState.MAXIMIZED)
        {
            return enabled ? "normalAndMaximized" : "disabledAndMaximized";
        }

        return enabled ? "normal" : "disabled";
    }

    //--------------------------------------------------------------------------
    //
    //  Event handlers
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    private function mouseDownHandler(event:MouseEvent):void
    {
        window.nativeWindow.startMove();

        event.stopPropagation();
    }

    /**
     *  The method that handles a doubleClick event in a platform-appropriate manner.
     *
     *  @param event The event object.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    protected function doubleClickHandler(event:MouseEvent):void
    {
        if (isMac())
        {
            window.minimize();
        }
        else
        {
            if (window.nativeWindow.displayState ==
                NativeWindowDisplayState.MAXIMIZED)
            {
                window.restore();
            }
            else
            {
                window.maximize();
            }
        }
    }

    /**
     *  @private
     *  Used to swallow mousedown so bar is not draggable from buttons
     */
    private function button_mouseDownHandler(event:MouseEvent):void
    {
        event.stopPropagation();
    }

    /**
     *  @private
     */
    private function minimizeButton_clickHandler(event:Event):void
    {
        window.minimize();
    }

    /**
     *  @private
     */
    private function maximizeButton_clickHandler(event:Event):void
    {
        if (window.nativeWindow.displayState ==
            NativeWindowDisplayState.MAXIMIZED)
        {
            window.restore();
        }
        else
        {
            window.maximize();
        }

        // work around for bugs SDK-9547 & SDK-21190
        maximizeButton.dispatchEvent(new MouseEvent(MouseEvent.ROLL_OUT));

    }

    /**
     *  @private
     */
    private function closeButton_clickHandler(event:Event):void
    {
        window.close();
    }

    /**
     *  @private
     */
    private function window_displayStateChangeHandler(
                       event:NativeWindowDisplayStateEvent):void
    {
        // If we have been minimized or maximized then invalidate our skin state
        // so the maximize and restore buttons will be updated.
        if (event.afterDisplayState == NativeWindowDisplayState.MAXIMIZED ||
            event.afterDisplayState == NativeWindowDisplayState.NORMAL)
        {
            invalidateSkinState();
        }
    }

    /**
     *  @private
     */
    private function partRemovedHandler(event:SkinPartEvent):void
    {
        if (event.instance == this)
        {
            var targetWindow:DisplayObject = DisplayObject(window);
            targetWindow.removeEventListener(
                NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE,
                window_displayStateChangeHandler);
            targetWindow.removeEventListener(SkinPartEvent.PART_REMOVED, partRemovedHandler);
        }
    }

}

}

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package spark.components.windowClasses
{

import flash.display.DisplayObject;
import flash.display.NativeWindowDisplayState;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NativeWindowDisplayStateEvent;
import flash.system.Capabilities;

import mx.core.IWindow;
import mx.core.mx_internal;

import spark.components.Button;
import spark.components.supportClasses.SkinnableComponent;
import spark.components.supportClasses.TextBase;
import spark.events.SkinPartEvent;
import spark.primitives.BitmapImage;
import spark.skins.*;
import spark.skins.spark.windowChrome.MacTitleBarSkin;
import spark.skins.spark.windowChrome.TitleBarSkin;

use namespace mx_internal;

//--------------------------------------
//  SkinStates
//--------------------------------------

/**
 *  The title bar is enabled and the application is maximized.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
[SkinState("normalAndMaximized")]

/**
 *  The title bar is disabled and the application is maximized.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
[SkinState("disabledAndMaximized")]

//--------------------------------------
//  Excluded APIs
//--------------------------------------

[Exclude(name="focusBlendMode", kind="style")]
[Exclude(name="focusThickness", kind="style")]

/**
 *  The TitleBar class defines the default title bar for a
 *  WindowedApplication or a Window container.
 *
 *  @see mx.core.Window
 *  @see mx.core.WindowedApplication
 *
 *
 *  @langversion 3.0
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
public class TitleBar extends SkinnableComponent
{
    include "../../core/Version.as";

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

    /**
     *  @private
     */
    private static function isMac():Boolean
    {
        return Capabilities.os.substring(0, 3) == "Mac";
    }

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

    /**
     *  Constructor.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function TitleBar():void
    {
        super();

        doubleClickEnabled = true;

        addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler);
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *  This is the actual object created from the _titleIcon class
     */
    mx_internal var titleIconObject:Object;

    //--------------------------------------------------------------------------
    //
    //  Skin Parts
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  closeButton
    //----------------------------------

    /**
     *  The skin part that defines the Button control that corresponds to the close button.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="true")]
    public var closeButton:Button;

    //----------------------------------
    //  maximizeButton
    //----------------------------------

    /**
     *  The skin part that defines the Button control that corresponds to the maximize button.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var maximizeButton:Button;

    //----------------------------------
    //  minimizeButton
    //----------------------------------

    /**
     *  The skin part that defines the Button control that corresponds to the minimize button.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var minimizeButton:Button;

    //----------------------------------
    //  titleIconImage
    //----------------------------------

    /**
     *  The title icon in the TitleBar.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var titleIconImage:BitmapImage;

    //----------------------------------
    //  titleTextField
    //----------------------------------

    /**
     *  The skin part that defines the UITextField control that displays the application title text.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart (required="false")]
    public var titleText:TextBase;

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

    //----------------------------------
    //  title
    //----------------------------------

    /**
     *  Storage for the title property.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    private var _title:String = "";

    /**
     *  @private
     */
    private var titleChanged:Boolean = false;

    /**
     *  The title that appears in the window title bar and
     *  the dock or taskbar.
     *
     *  @default ""
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function get title():String
    {
        return _title;
    }

    /**
     *  @private
     */
    public function set title(value:String):void
    {
        _title = value;
        titleChanged = true;

        invalidateProperties();
        invalidateSize();
        invalidateDisplayList();
    }

    //----------------------------------
    //  titleIcon
    //----------------------------------

    /**
     *  @private
     *  Storage for the titleIcon property.
     */
    private var _titleIcon:Class;

    /**
     *  @private
     */
    private var titleIconChanged:Boolean = false;

    /**
     *  The icon displayed in the title bar.
     *
     *  @default null
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function get titleIcon():Class
    {
        return _titleIcon;
    }

    /**
     *  @private
     */
    public function set titleIcon(value:Class):void
    {
        _titleIcon = value;
        titleIconChanged = true;

        invalidateProperties();
        invalidateSize();
    }

    //----------------------------------
    //  window
    //----------------------------------

    /**
     *  The IWindow that owns this TitleBar.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    private function get window():IWindow
    {
        var p:DisplayObject = parent;

        while (p && !(p is IWindow))
            p = p.parent;

        return IWindow(p);
    }

    //--------------------------------------------------------------------------
    //
    //  Overridden methods: SkinnableComponent
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     *
     *  When we are running on the mac, switch to the mac skin and continue the load.
     *
     */
    override protected function attachSkin():void
    {
       if (isMac() && getStyle("skinClass") == TitleBarSkin)
       {
            setStyle("skinClass", MacTitleBarSkin);
       }

       super.attachSkin();
    }

    //--------------------------------------------------------------------------
    //
    //  Overridden methods: SkinnableContainer
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    override protected function partAdded(partName:String, instance:Object):void
    {
        super.partAdded(partName, instance);

        if (instance == titleText)
        {
            titleText.text = title;
        }
        else if (instance == closeButton)
        {
            closeButton.focusEnabled = false;
            closeButton.addEventListener(MouseEvent.MOUSE_DOWN, button_mouseDownHandler);
            closeButton.addEventListener(MouseEvent.CLICK, closeButton_clickHandler);
        }
        else if (instance == minimizeButton)
        {
            minimizeButton.focusEnabled = false;
            minimizeButton.enabled = window.minimizable;
            minimizeButton.addEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            minimizeButton.addEventListener(MouseEvent.CLICK,
                                            minimizeButton_clickHandler);
        }
        else if (instance == maximizeButton)
        {
            maximizeButton.focusEnabled = false;
            maximizeButton.enabled = window.maximizable;
            maximizeButton.addEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            maximizeButton.addEventListener(MouseEvent.CLICK,
                                            maximizeButton_clickHandler);

            var targetWindow:DisplayObject = DisplayObject(window);
            targetWindow.addEventListener(
                NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE,
                window_displayStateChangeHandler, false, 0, true);

            // Add this listener so we can remove the display state change handler
            // if our window is reskinned. This fixes an RTE when the titleBar
            // display state handler ran without a window after being reskinned.
            targetWindow.addEventListener(SkinPartEvent.PART_REMOVED, partRemovedHandler,
                false, 0, true);
        }
    }

    /**
     *  @private
     */
    override protected function partRemoved(partName:String, instance:Object):void
    {
        super.partRemoved(partName, instance);

        if (instance == closeButton)
        {
            closeButton.removeEventListener(MouseEvent.CLICK, closeButton_clickHandler);
        }
        else if (instance == minimizeButton)
        {
            minimizeButton.removeEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            minimizeButton.removeEventListener(MouseEvent.CLICK,
                                            minimizeButton_clickHandler);
        }
        else if (instance == maximizeButton)
        {
            maximizeButton.removeEventListener(MouseEvent.MOUSE_DOWN,
                                            button_mouseDownHandler);
            maximizeButton.removeEventListener(MouseEvent.CLICK,
                                            maximizeButton_clickHandler);

            var targetWindow:DisplayObject = DisplayObject(window);
            targetWindow.removeEventListener(
                NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE,
                window_displayStateChangeHandler);
            targetWindow.removeEventListener(SkinPartEvent.PART_REMOVED, partRemovedHandler);
        }

    }

    /**
     *  @private
     */
    override protected function commitProperties():void
    {
        super.commitProperties();

        if (titleChanged)
        {
			if (titleText) {
            	titleText.text = _title;
			}
            titleChanged = false;
        }

        if (titleIconChanged)
        {
            if (titleIconObject)
            {
                titleIconImage.source = null;
                titleIconObject = null;
            }

            if (_titleIcon && titleIconImage)
            {
                titleIconObject = new _titleIcon();
                titleIconImage.source = titleIconObject;
            }
            titleIconChanged = false;
        }

    }

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    //
    // Skin states support
    //
    //--------------------------------------------------------------------------

    /**
     *  Returns the name of the state to be applied to the skin. For example, a
     *  Button component could return the String "up", "down", "over", or "disabled"
     *  to specify the state.
     *
     *
A subclass of SkinnableComponent must override this method to return a value.

     *
     *  @return A string specifying the name of the state to apply to the skin.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    override protected function getCurrentSkinState():String
    {
        if (!window.nativeWindow.closed &&
            window.nativeWindow.displayState == NativeWindowDisplayState.MAXIMIZED)
        {
            return enabled ? "normalAndMaximized" : "disabledAndMaximized";
        }

        return enabled ? "normal" : "disabled";
    }

    //--------------------------------------------------------------------------
    //
    //  Event handlers
    //
    //--------------------------------------------------------------------------

    /**
     *  @private
     */
    private function mouseDownHandler(event:MouseEvent):void
    {
        window.nativeWindow.startMove();

        event.stopPropagation();
    }

    /**
     *  The method that handles a doubleClick event in a platform-appropriate manner.
     *
     *  @param event The event object.
     *
     *  @langversion 3.0
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    protected function doubleClickHandler(event:MouseEvent):void
    {
        if (isMac())
        {
            window.minimize();
        }
        else
        {
            if (window.nativeWindow.displayState ==
                NativeWindowDisplayState.MAXIMIZED)
            {
                window.restore();
            }
            else
            {
                window.maximize();
            }
        }
    }

    /**
     *  @private
     *  Used to swallow mousedown so bar is not draggable from buttons
     */
    private function button_mouseDownHandler(event:MouseEvent):void
    {
        event.stopPropagation();
    }

    /**
     *  @private
     */
    private function minimizeButton_clickHandler(event:Event):void
    {
        window.minimize();
    }

    /**
     *  @private
     */
    private function maximizeButton_clickHandler(event:Event):void
    {
        if (window.nativeWindow.displayState ==
            NativeWindowDisplayState.MAXIMIZED)
        {
            window.restore();
        }
        else
        {
            window.maximize();
        }

        // work around for bugs SDK-9547 & SDK-21190
        maximizeButton.dispatchEvent(new MouseEvent(MouseEvent.ROLL_OUT));

    }

    /**
     *  @private
     */
    private function closeButton_clickHandler(event:Event):void
    {
        window.close();
    }

    /**
     *  @private
     */
    private function window_displayStateChangeHandler(
                       event:NativeWindowDisplayStateEvent):void
    {
        // If we have been minimized or maximized then invalidate our skin state
        // so the maximize and restore buttons will be updated.
        if (event.afterDisplayState == NativeWindowDisplayState.MAXIMIZED ||
            event.afterDisplayState == NativeWindowDisplayState.NORMAL)
        {
            invalidateSkinState();
        }
    }

    /**
     *  @private
     */
    private function partRemovedHandler(event:SkinPartEvent):void
    {
        if (event.instance == this)
        {
            var targetWindow:DisplayObject = DisplayObject(window);
            targetWindow.removeEventListener(
                NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE,
                window_displayStateChangeHandler);
            targetWindow.removeEventListener(SkinPartEvent.PART_REMOVED, partRemovedHandler);
        }
    }

}

}

Fix RTE described in FLEX-33385. titeText is optional part.

git-svn-id: f8d5f742b420a6a114b58659a4f85f335318e53c@1454944 13f79535-47bb-0310-9956-ffa450edef68


////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.html.beads
{
	import org.apache.flex.core.IBead;
	import org.apache.flex.core.IBeadModel;
	import org.apache.flex.core.IBeadView;
	import org.apache.flex.core.IDataGridModel;
	import org.apache.flex.core.ISelectableItemRenderer;
	import org.apache.flex.core.ISelectionModel;
	import org.apache.flex.core.IStrand;
	import org.apache.flex.core.IUIBase;
	import org.apache.flex.core.UIBase;
	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.IEventDispatcher;
	import org.apache.flex.html.ButtonBar;
	import org.apache.flex.html.Container;
	import org.apache.flex.html.List;
	import org.apache.flex.html.beads.layouts.ButtonBarLayout;
	import org.apache.flex.html.beads.layouts.VerticalLayout;
	import org.apache.flex.html.beads.models.ArraySelectionModel;
	import org.apache.flex.html.beads.models.DataGridPresentationModel;
	import org.apache.flex.html.supportClasses.DataGridColumn;
	import org.apache.flex.html.supportClasses.ScrollingViewport;
	import org.apache.flex.html.supportClasses.Viewport;

	/**
	 *  The DataGridView class is the visual bead for the org.apache.flex.html.DataGrid.
	 *  This class constructs the items that make the DataGrid: Lists for each column and a
	 *  org.apache.flex.html.ButtonBar for the column headers.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 10.2
	 *  @playerversion AIR 2.6
	 *  @productversion FlexJS 0.0
	 */
	public class DataGridView implements IBeadView
	{
		/**
		 *  constructor.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		public function DataGridView()
		{
		}

		private var _strand:IStrand;
		private var _header:ButtonBar;
		private var _listArea:Container;
		private var _lists:Array;

		/**
		 * @private
		 */
		public function get host():IUIBase
		{
			return _strand as IUIBase;
		}

		/**
		 *  @copy org.apache.flex.core.IBead#strand
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		public function set strand(value:IStrand):void
		{
			_strand = value;

			var host:UIBase = value as UIBase;
			host.addEventListener("widthChanged", handleSizeChanges);
			host.addEventListener("heightChanged", handleSizeChanges);

			_header = new ButtonBar();
			_header.id = "dataGridHeader";

			var scrollPort:ScrollingViewport = new ScrollingViewport();
			scrollPort.showsHorizontalScrollBar = false;

			_listArea = new Container();
			_listArea.id = "dataGridListArea";
			_listArea.className = "DataGridListArea";
			_listArea.addBead(scrollPort);

			finishSetup(null);
		}

		/**
		 * @private
		 */
		private function finishSetup(event:Event):void
		{
			var host:UIBase = _strand as UIBase;

			// see if there is a presentation model already in place. if not, add one.
			var presentationModel:DataGridPresentationModel = _strand.getBeadByType(DataGridPresentationModel) as DataGridPresentationModel;
			if (presentationModel == null) {
				presentationModel = new DataGridPresentationModel();
				_strand.addBead(presentationModel);
			}

			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;
			IEventDispatcher(sharedModel).addEventListener("dataProviderChanged",handleDataProviderChanged);

			var columnLabels:Array = new Array();
			var buttonWidths:Array = new Array();

			for(var i:int=0; i < sharedModel.columns.length; i++) {
				var dgc:DataGridColumn = sharedModel.columns[i] as DataGridColumn;
				columnLabels.push(dgc.label);
				if (!isNaN(dgc.columnWidth)) buttonWidths.push(dgc.columnWidth);
			}

			var bblayout:ButtonBarLayout = new ButtonBarLayout();
			if (buttonWidths.length == sharedModel.columns.length) {
				bblayout.buttonWidths = buttonWidths;
			}

			var buttonBarModel:ArraySelectionModel = new ArraySelectionModel();
			buttonBarModel.dataProvider = columnLabels;

			_header.addBead(buttonBarModel);
			_header.addBead(bblayout);
			_header.addBead(new Viewport());
			host.addElement(_header);

			host.addElement(_listArea);

			// do we know what the size is? If not, wait to be sized

			if (host.isHeightSizedToContent() || host.isWidthSizedToContent()) {
				host.addEventListener("sizeChanged", handleSizeChanges);
			}

				// else size now
			else {
				handleDataProviderChanged(event);
			}
		}

		/**
		 * @private
		 */
		private function handleSizeChanges(event:Event):void
		{
			_header.x = 0;
			_header.y = 0;
			_header.width = host.width;
			_header.height = 25;

			_listArea.x = 0;
			_listArea.y = 26;
			_listArea.width = host.width;
			_listArea.height = host.height - _header.height;

			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;

			if (_lists != null && _lists.length > 0) {
				var xpos:Number = 0;
				var listWidth:Number = host.width / _lists.length;
				for (var i:int=0; i < _lists.length; i++) {
					var list:List = _lists[i] as List;
					list.x = xpos;
					list.y = 0;

					var dataGridColumn:DataGridColumn = sharedModel.columns[i] as DataGridColumn;
					var colWidth:Number = dataGridColumn.columnWidth;
					if (!isNaN(colWidth)) list.width = colWidth;
					else list.width = listWidth;

					xpos += list.width;
				}
			}
		}

		/**
		 * @private
		 */
		private function handleDataProviderChanged(event:Event):void
		{
			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;

			if (_lists == null || _lists.length == 0) {
				createLists();
			}

			for (var i:int=0; i < _lists.length; i++)
			{
				var list:List = _lists[i] as List;
				var listModel:ISelectionModel = list.getBeadByType(IBeadModel) as ISelectionModel;
				listModel.dataProvider = sharedModel.dataProvider;
			}

			handleSizeChanges(event);
		}

		/**
		 * @private
		 */
		private function handleColumnListChange(event:Event):void
		{
			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;
			var list:List = event.target as List;
			sharedModel.selectedIndex = list.selectedIndex;

			for(var i:int=0; i < _lists.length; i++) {
				if (list != _lists[i]) {
					var otherList:List = _lists[i] as List;
					otherList.selectedIndex = list.selectedIndex;
				}
			}

			IEventDispatcher(_strand).dispatchEvent(new Event('change'));
		}

		/**
		 * @private
		 */
		private function handleColumnListRollOver(event:Event):void
		{
			var itemRenderer:ISelectableItemRenderer = event.target as ISelectableItemRenderer;
			var list:List = event.currentTarget as List;
			if (list == null) return;
			for(var i:int=0; i < _lists.length; i++) {
				if (list != _lists[i]) {
					var otherList:List = _lists[i] as List;
					otherList.rollOverIndex = itemRenderer.index;
				}
			}

			IEventDispatcher(_strand).dispatchEvent(new Event('rollOver'));
		}

		/**
		 * @private
		 */
		private function handleColumnListRollOut(event:Event):void
		{
			for(var i:int=0; i < _lists.length; i++) {
				var otherList:List = _lists[i] as List;
				otherList.rollOverIndex = -1;
			}

			IEventDispatcher(_strand).dispatchEvent(new Event('rollOver'));
		}

		/**
		 * @private
		 */
		private function createLists():void
		{
			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;
			var presentationModel:DataGridPresentationModel = _strand.getBeadByType(DataGridPresentationModel) as DataGridPresentationModel;
			var listWidth:Number = host.width / sharedModel.columns.length;

			_lists = new Array();

			for (var i:int=0; i < sharedModel.columns.length; i++) {
				var dataGridColumn:DataGridColumn = sharedModel.columns[i] as DataGridColumn;

				var list:List = new List();
				list.id = "dataGridColumn"+String(i);
				list.className = "DataGridColumn";
				list.addBead(sharedModel);
				list.itemRenderer = dataGridColumn.itemRenderer;
				list.labelField = dataGridColumn.dataField;
				list.addEventListener('change',handleColumnListChange);
				list.addEventListener('rollover',handleColumnListRollOver);
				list.addEventListener('rollout',handleColumnListRollOut);
				list.addBead(presentationModel);

				var colWidth:Number = dataGridColumn.columnWidth;
				if (!isNaN(colWidth)) list.width = colWidth;
				else list.width = listWidth;

				_listArea.addElement(list);
				_lists.push(list);
			}

			_listArea.dispatchEvent(new Event("layoutNeeded"));
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
//
//  Licensed to the Apache Software Foundation (ASF) under one or more
//  contributor license agreements.  See the NOTICE file distributed with
//  this work for additional information regarding copyright ownership.
//  The ASF licenses this file to You under the Apache License, Version 2.0
//  (the "License"); you may not use this file except in compliance with
//  the License.  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.html.beads
{
	import org.apache.flex.core.IBead;
	import org.apache.flex.core.IBeadModel;
	import org.apache.flex.core.IBeadView;
	import org.apache.flex.core.IDataGridModel;
	import org.apache.flex.core.ISelectableItemRenderer;
	import org.apache.flex.core.ISelectionModel;
	import org.apache.flex.core.IStrand;
	import org.apache.flex.core.IUIBase;
	import org.apache.flex.core.UIBase;
	import org.apache.flex.core.ValuesManager;
	import org.apache.flex.events.Event;
	import org.apache.flex.events.IEventDispatcher;
	import org.apache.flex.html.ButtonBar;
	import org.apache.flex.html.Container;
	import org.apache.flex.html.List;
	import org.apache.flex.html.beads.layouts.ButtonBarLayout;
	import org.apache.flex.html.beads.layouts.VerticalLayout;
	import org.apache.flex.html.beads.models.ArraySelectionModel;
	import org.apache.flex.html.beads.models.DataGridPresentationModel;
	import org.apache.flex.html.supportClasses.DataGridColumn;
	import org.apache.flex.html.supportClasses.ScrollingViewport;
	import org.apache.flex.html.supportClasses.Viewport;

	/**
	 *  The DataGridView class is the visual bead for the org.apache.flex.html.DataGrid.
	 *  This class constructs the items that make the DataGrid: Lists for each column and a
	 *  org.apache.flex.html.ButtonBar for the column headers.
	 *
	 *  @langversion 3.0
	 *  @playerversion Flash 10.2
	 *  @playerversion AIR 2.6
	 *  @productversion FlexJS 0.0
	 */
	public class DataGridView implements IBeadView
	{
		/**
		 *  constructor.
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		public function DataGridView()
		{
		}

		private var _strand:IStrand;
		private var _header:ButtonBar;
		private var _listArea:Container;
		private var _lists:Array;

		/**
		 * @private
		 */
		public function get host():IUIBase
		{
			return _strand as IUIBase;
		}

		/**
		 *  @copy org.apache.flex.core.IBead#strand
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10.2
		 *  @playerversion AIR 2.6
		 *  @productversion FlexJS 0.0
		 */
		public function set strand(value:IStrand):void
		{
			_strand = value;

			var host:UIBase = value as UIBase;
			host.addEventListener("widthChanged", handleSizeChanges);
			host.addEventListener("heightChanged", handleSizeChanges);

			_header = new ButtonBar();
			_header.id = "dataGridHeader";

			var scrollPort:ScrollingViewport = new ScrollingViewport();
			scrollPort.showsHorizontalScrollBar = false;

			_listArea = new Container();
			_listArea.id = "dataGridListArea";
			_listArea.className = "DataGridListArea";
			_listArea.addBead(scrollPort);

			finishSetup(null);
		}

		/**
		 * @private
		 */
		private function finishSetup(event:Event):void
		{
			var host:UIBase = _strand as UIBase;

			// see if there is a presentation model already in place. if not, add one.
			var presentationModel:DataGridPresentationModel = _strand.getBeadByType(DataGridPresentationModel) as DataGridPresentationModel;
			if (presentationModel == null) {
				presentationModel = new DataGridPresentationModel();
				_strand.addBead(presentationModel);
			}

			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;
			IEventDispatcher(sharedModel).addEventListener("dataProviderChanged",handleDataProviderChanged);

			var columnLabels:Array = new Array();
			var buttonWidths:Array = new Array();

			for(var i:int=0; i < sharedModel.columns.length; i++) {
				var dgc:DataGridColumn = sharedModel.columns[i] as DataGridColumn;
				columnLabels.push(dgc.label);
				if (!isNaN(dgc.columnWidth)) buttonWidths.push(dgc.columnWidth);
			}

			var bblayout:ButtonBarLayout = new ButtonBarLayout();
			if (buttonWidths.length == sharedModel.columns.length) {
				bblayout.buttonWidths = buttonWidths;
			}

			var buttonBarModel:ArraySelectionModel = new ArraySelectionModel();
			buttonBarModel.dataProvider = columnLabels;

			_header.addBead(buttonBarModel);
			_header.addBead(bblayout);
			_header.addBead(new Viewport());
			host.addElement(_header);

			host.addElement(_listArea);

			// do we know what the size is? If not, wait to be sized

			if (host.isHeightSizedToContent() || host.isWidthSizedToContent()) {
				host.addEventListener("sizeChanged", handleSizeChanges);
			}

				// else size now
			else {
				handleDataProviderChanged(event);
			}
		}

		/**
		 * @private
		 */
		private function handleSizeChanges(event:Event):void
		{
			var useWidth:Number = _listArea.width;
			var useHeight:Number = _listArea.height;

			if (host.width > 0) {
				useWidth = host.width;
			}

			_header.x = 0;
			_header.y = 0;
			_header.width = useWidth;
			_header.height = 25;

			if (host.height > 0) {
				useHeight = host.height - _header.height;
			}

			_listArea.x = 0;
			_listArea.y = 26;
			_listArea.width = useWidth;
			_listArea.height = useHeight;

			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;

			if (_lists != null && _lists.length > 0) {
				var xpos:Number = 0;
				var listWidth:Number = host.width / _lists.length;
				for (var i:int=0; i < _lists.length; i++) {
					var list:List = _lists[i] as List;
					list.x = xpos;
					list.y = 0;

					var dataGridColumn:DataGridColumn = sharedModel.columns[i] as DataGridColumn;
					var colWidth:Number = dataGridColumn.columnWidth;
					if (!isNaN(colWidth)) list.width = colWidth;
					else list.width = listWidth;

					xpos += list.width;
				}
			}
		}

		/**
		 * @private
		 */
		private function handleDataProviderChanged(event:Event):void
		{
			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;

			if (_lists == null || _lists.length == 0) {
				createLists();
			}

			for (var i:int=0; i < _lists.length; i++)
			{
				var list:List = _lists[i] as List;
				var listModel:ISelectionModel = list.getBeadByType(IBeadModel) as ISelectionModel;
				listModel.dataProvider = sharedModel.dataProvider;
			}

			handleSizeChanges(event);
		}

		/**
		 * @private
		 */
		private function handleColumnListChange(event:Event):void
		{
			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;
			var list:List = event.target as List;
			sharedModel.selectedIndex = list.selectedIndex;

			for(var i:int=0; i < _lists.length; i++) {
				if (list != _lists[i]) {
					var otherList:List = _lists[i] as List;
					otherList.selectedIndex = list.selectedIndex;
				}
			}

			IEventDispatcher(_strand).dispatchEvent(new Event('change'));
		}

		/**
		 * @private
		 */
		private function handleColumnListRollOver(event:Event):void
		{
			var itemRenderer:ISelectableItemRenderer = event.target as ISelectableItemRenderer;
			var list:List = event.currentTarget as List;
			if (list == null) return;
			for(var i:int=0; i < _lists.length; i++) {
				if (list != _lists[i]) {
					var otherList:List = _lists[i] as List;
					otherList.rollOverIndex = itemRenderer.index;
				}
			}

			IEventDispatcher(_strand).dispatchEvent(new Event('rollOver'));
		}

		/**
		 * @private
		 */
		private function handleColumnListRollOut(event:Event):void
		{
			for(var i:int=0; i < _lists.length; i++) {
				var otherList:List = _lists[i] as List;
				otherList.rollOverIndex = -1;
			}

			IEventDispatcher(_strand).dispatchEvent(new Event('rollOver'));
		}

		/**
		 * @private
		 */
		private function createLists():void
		{
			var sharedModel:IDataGridModel = _strand.getBeadByType(IBeadModel) as IDataGridModel;
			var presentationModel:DataGridPresentationModel = _strand.getBeadByType(DataGridPresentationModel) as DataGridPresentationModel;
			var listWidth:Number = host.width / sharedModel.columns.length;

			_lists = new Array();

			for (var i:int=0; i < sharedModel.columns.length; i++) {
				var dataGridColumn:DataGridColumn = sharedModel.columns[i] as DataGridColumn;

				var list:List = new List();
				list.id = "dataGridColumn"+String(i);
				list.className = "DataGridColumn";
				list.addBead(sharedModel);
				list.itemRenderer = dataGridColumn.itemRenderer;
				list.labelField = dataGridColumn.dataField;
				list.addEventListener('change',handleColumnListChange);
				list.addEventListener('rollover',handleColumnListRollOver);
				list.addEventListener('rollout',handleColumnListRollOut);
				list.addBead(presentationModel);

				var colWidth:Number = dataGridColumn.columnWidth;
				if (!isNaN(colWidth)) list.width = colWidth;
				else list.width = listWidth;

				_listArea.addElement(list);
				_lists.push(list);
			}

			_listArea.dispatchEvent(new Event("layoutNeeded"));
		}
	}
}

Stop DataGridView from resizing if the size of the strand is 0x0.


package dolly {

import dolly.core.dolly_internal;
import dolly.core.metadata.MetadataName;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.IMetadataContainer;
import org.as3commons.reflect.Type;
import org.as3commons.reflect.Variable;

use namespace dolly_internal;

public class Copier {

	private static function getCopyableFieldsOfType(type:Type):Vector.<Field> {
		const result:Vector.<Field> = new Vector.<Field>();

		var variable:Variable;
		var accessor:Accessor;

		const isTypeCloneable:Boolean = type.hasMetadata(MetadataName.COPYABLE);
		if (isTypeCloneable) {
			for each(variable in type.variables) {
				if (!variable.isStatic) {
					result.push(variable);
				}
			}
			for each(accessor in type.accessors) {
				if (!accessor.isStatic && accessor.access == AccessorAccess.READ_WRITE) {
					result.push(accessor);
				}
			}
		} else {
			const metadataContainers:Array = type.getMetadataContainers(MetadataName.COPYABLE);
			for each(var metadataContainer:IMetadataContainer in metadataContainers) {
				if (metadataContainer is Variable) {
					variable = metadataContainer as Variable;
					if (!variable.isStatic && variable.hasMetadata(MetadataName.COPYABLE)) {
						result.push(variable);
					}
				} else if (metadataContainer is Accessor) {
					accessor = metadataContainer as Accessor;
					if (!accessor.isStatic
							&& accessor.access == AccessorAccess.READ_WRITE
							&& accessor.hasMetadata(MetadataName.COPYABLE)) {
						result.push(accessor);
					}
				}
			}
		}

		return result;
	}

	dolly_internal static function findCopyableFieldsForType(type:Type):Vector.<Field> {
		const result:Vector.<Field> = getCopyableFieldsOfType(type);

		return result;
	}

	public static function copy(source:*):* {
		const type:Type = Type.forInstance(source);
		const copy:* = new (type.clazz)();

		const fieldsToCopy:Vector.<Field> = findCopyableFieldsForType(type);
		var name:String;
		for each(var field:Field in fieldsToCopy) {
			name = field.name;
			copy[name] = source[name];
		}

		return copy;
	}
}
}

package dolly {

import dolly.core.dolly_internal;
import dolly.core.metadata.MetadataName;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.IMetadataContainer;
import org.as3commons.reflect.Type;
import org.as3commons.reflect.Variable;

use namespace dolly_internal;

public class Copier {

	private static function getCopyableFieldsOfType(type:Type):Vector.<Field> {
		const result:Vector.<Field> = new Vector.<Field>();

		var variable:Variable;
		var accessor:Accessor;

		const isTypeCloneable:Boolean = type.hasMetadata(MetadataName.COPYABLE);
		if (isTypeCloneable) {
			for each(variable in type.variables) {
				if (!variable.isStatic) {
					result.push(variable);
				}
			}
			for each(accessor in type.accessors) {
				if (!accessor.isStatic && accessor.access == AccessorAccess.READ_WRITE) {
					result.push(accessor);
				}
			}
		} else {
			const metadataContainers:Array = type.getMetadataContainers(MetadataName.COPYABLE);
			for each(var metadataContainer:IMetadataContainer in metadataContainers) {
				if (metadataContainer is Variable) {
					variable = metadataContainer as Variable;
					if (!variable.isStatic && variable.hasMetadata(MetadataName.COPYABLE)) {
						result.push(variable);
					}
				} else if (metadataContainer is Accessor) {
					accessor = metadataContainer as Accessor;
					if (!accessor.isStatic
							&& accessor.access == AccessorAccess.READ_WRITE
							&& accessor.hasMetadata(MetadataName.COPYABLE)) {
						result.push(accessor);
					}
				}
			}
		}

		return result;
	}

	dolly_internal static function findCopyableFieldsForType(type:Type):Vector.<Field> {
		var result:Vector.<Field> = getCopyableFieldsOfType(type);

		var superType:Type;
		var superTypeCopyableFields:Vector.<Field>;

		for each(var superTypeName:String in type.extendsClasses) {
			superType = Type.forName(superTypeName);
			superTypeCopyableFields = getCopyableFieldsOfType(superType);
			if (superTypeCopyableFields.length > 0) {
				result = result.concat(superTypeCopyableFields);
			}
		}

		return result;
	}

	public static function copy(source:*):* {
		const type:Type = Type.forInstance(source);
		const copy:* = new (type.clazz)();

		const fieldsToCopy:Vector.<Field> = findCopyableFieldsForType(type);
		var name:String;
		for each(var field:Field in fieldsToCopy) {
			name = field.name;
			copy[name] = source[name];
		}

		return copy;
	}
}
}

Add finding of copyable fields in superclasses.


package dolly {

import dolly.core.dolly_internal;
import dolly.core.metadata.MetadataName;

import flash.utils.Dictionary;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.IMetadataContainer;
import org.as3commons.reflect.Type;
import org.as3commons.reflect.Variable;

use namespace dolly_internal;

public class Copier {

	private static function getCopyableFieldsOfType(type:Type, foundFieldsMap:Dictionary):Vector.<Field> {
		const result:Vector.<Field> = new Vector.<Field>();

		var variable:Variable;
		var accessor:Accessor;

		const isTypeCloneable:Boolean = type.hasMetadata(MetadataName.COPYABLE);
		if (isTypeCloneable) {
			for each(variable in type.variables) {
				if (!foundFieldsMap[variable.name] && !variable.isStatic) {
					foundFieldsMap[variable.name] = variable;
					result.push(variable);
				}
			}
			for each(accessor in type.accessors) {
				if (!foundFieldsMap[accessor.name]
						&& !accessor.isStatic
						&& accessor.access == AccessorAccess.READ_WRITE) {
					foundFieldsMap[accessor.name] = accessor;
					result.push(accessor);
				}
			}
		} else {
			const metadataContainers:Array = type.getMetadataContainers(MetadataName.COPYABLE);
			for each(var metadataContainer:IMetadataContainer in metadataContainers) {
				if (metadataContainer is Variable) {
					variable = metadataContainer as Variable;
					if (!foundFieldsMap[variable.name]
							&& !variable.isStatic
							&& variable.hasMetadata(MetadataName.COPYABLE)) {
						foundFieldsMap[variable.name] = variable;
						result.push(variable);
					}
				} else if (metadataContainer is Accessor) {
					accessor = metadataContainer as Accessor;
					if (!foundFieldsMap[accessor.name]
							&& !accessor.isStatic
							&& accessor.access == AccessorAccess.READ_WRITE
							&& accessor.hasMetadata(MetadataName.COPYABLE)) {
						foundFieldsMap[accessor.name] = accessor;
						result.push(accessor);
					}
				}
			}
		}

		return result;
	}

	dolly_internal static function findCopyableFieldsForType(type:Type):Vector.<Field> {
		var foundFields:Dictionary = new Dictionary();
		var result:Vector.<Field> = getCopyableFieldsOfType(type, foundFields);

		var superType:Type;
		var superTypeCopyableFields:Vector.<Field>;

		for each(var superTypeName:String in type.extendsClasses) {
			superType = Type.forName(superTypeName);
			superTypeCopyableFields = getCopyableFieldsOfType(superType, foundFields);
			if (superTypeCopyableFields.length > 0) {
				result = result.concat(superTypeCopyableFields);
			}
		}

		return result;
	}

	public static function copy(source:*):* {
		const type:Type = Type.forInstance(source);
		const copy:* = new (type.clazz)();

		const fieldsToCopy:Vector.<Field> = findCopyableFieldsForType(type);
		var name:String;
		for each(var field:Field in fieldsToCopy) {
			name = field.name;
			copy[name] = source[name];
		}

		return copy;
	}
}
}

package dolly {

import dolly.core.dolly_internal;
import dolly.core.metadata.MetadataName;

import flash.utils.Dictionary;

import org.as3commons.reflect.Accessor;
import org.as3commons.reflect.AccessorAccess;
import org.as3commons.reflect.Field;
import org.as3commons.reflect.IMetadataContainer;
import org.as3commons.reflect.Type;
import org.as3commons.reflect.Variable;

use namespace dolly_internal;

public class Copier {

	private static function getCopyableFieldsOfType(type:Type, foundFields:Dictionary):Vector.<Field> {
		const result:Vector.<Field> = new Vector.<Field>();

		var variable:Variable;
		var accessor:Accessor;

		const isTypeCloneable:Boolean = type.hasMetadata(MetadataName.COPYABLE);
		if (isTypeCloneable) {
			for each(variable in type.variables) {
				if (!foundFields[variable.name] && !variable.isStatic) {
					foundFields[variable.name] = variable;
					result.push(variable);
				}
			}
			for each(accessor in type.accessors) {
				if (!foundFields[accessor.name]
						&& !accessor.isStatic
						&& accessor.access == AccessorAccess.READ_WRITE) {
					foundFields[accessor.name] = accessor;
					result.push(accessor);
				}
			}
		} else {
			const metadataContainers:Array = type.getMetadataContainers(MetadataName.COPYABLE);
			for each(var metadataContainer:IMetadataContainer in metadataContainers) {
				if (metadataContainer is Variable) {
					variable = metadataContainer as Variable;
					if (!foundFields[variable.name]
							&& !variable.isStatic
							&& variable.hasMetadata(MetadataName.COPYABLE)) {
						foundFields[variable.name] = variable;
						result.push(variable);
					}
				} else if (metadataContainer is Accessor) {
					accessor = metadataContainer as Accessor;
					if (!foundFields[accessor.name]
							&& !accessor.isStatic
							&& accessor.access == AccessorAccess.READ_WRITE
							&& accessor.hasMetadata(MetadataName.COPYABLE)) {
						foundFields[accessor.name] = accessor;
						result.push(accessor);
					}
				}
			}
		}

		return result;
	}

	dolly_internal static function findCopyableFieldsForType(type:Type):Vector.<Field> {
		var foundFields:Dictionary = new Dictionary();
		var result:Vector.<Field> = getCopyableFieldsOfType(type, foundFields);

		var superType:Type;
		var superTypeCopyableFields:Vector.<Field>;

		for each(var superTypeName:String in type.extendsClasses) {
			superType = Type.forName(superTypeName);
			superTypeCopyableFields = getCopyableFieldsOfType(superType, foundFields);
			if (superTypeCopyableFields.length > 0) {
				result = result.concat(superTypeCopyableFields);
			}
		}

		return result;
	}

	public static function copy(source:*):* {
		const type:Type = Type.forInstance(source);
		const copy:* = new (type.clazz)();

		const fieldsToCopy:Vector.<Field> = findCopyableFieldsForType(type);
		var name:String;
		for each(var field:Field in fieldsToCopy) {
			name = field.name;
			copy[name] = source[name];
		}

		return copy;
	}
}
}

Rename argument's name.

Rename argument's name.


// vim: tabstop=4 shiftwidth=4

// Copyright (c) 2010 , NetEase.com,Inc. All rights reserved.
//
// Author: Yang Bo (pop.atry@gmail.com)
//
// Use, modification and distribution are subject to the "New BSD License"
// as listed at <url: http://www.opensource.org/licenses/bsd-license.php >.

package com.netease.protobuf {
	import flash.net.*;
	import flash.utils.*;
	import flash.events.*;
	public final class SimpleWebRPC {
		private var urlPrefix:String
		public function SimpleWebRPC(urlPrefix:String) {
			this.urlPrefix = urlPrefix;
		}
		private static const REF:Dictionary = new Dictionary();
		public function send(qualifiedMethodName:String,
							 input:IExternalizable,
							 callback:Function,
							 outputType:Class):void {

			const loader:URLLoader = new URLLoader
			REF[loader] = true;
			loader.dataFormat = URLLoaderDataFormat.BINARY
			loader.addEventListener(Event.COMPLETE, function(event:Event):void {
				delete REF[loader]
				const output:IExternalizable = new outputType
				output.readExternal(loader.data)
				callback(output)
			})
			function errorEventHandler(event:Event):void {
				delete REF[loader]
				callback(event)
			}
			loader.addEventListener(IOErrorEvent.IO_ERROR, errorEventHandler)
			loader.addEventListener(
					SecurityErrorEvent.SECURITY_ERROR, errorEventHandler)
			const request:URLRequest = new URLRequest(
				urlPrefix + qualifiedMethodName)
			request.method = URLRequestMethod.POST
			const requestContent:ByteArray = new ByteArray
			input.writeExternal(requestContent)
			request.data = requestContent
			request.contentType = "application/x-protobuf"
			loader.load(request)
		}
	}
}

// vim: tabstop=4 shiftwidth=4

// Copyright (c) 2010 , NetEase.com,Inc. All rights reserved.
//
// Author: Yang Bo (pop.atry@gmail.com)
//
// Use, modification and distribution are subject to the "New BSD License"
// as listed at <url: http://www.opensource.org/licenses/bsd-license.php >.

package com.netease.protobuf {
	import flash.net.*;
	import flash.utils.*;
	import flash.events.*;
	public final class SimpleWebRPC {
		private var urlPrefix:String
		public function SimpleWebRPC(urlPrefix:String) {
			this.urlPrefix = urlPrefix;
		}
		private static const REF:Dictionary = new Dictionary();
		public function send(qualifiedMethodName:String,
							 input:IExternalizable,
							 rpcResult:Function,
							 outputType:Class):void {

			const loader:URLLoader = new URLLoader
			REF[loader] = true;
			loader.dataFormat = URLLoaderDataFormat.BINARY
			loader.addEventListener(Event.COMPLETE, function(event:Event):void {
				delete REF[loader]
				const output:IExternalizable = new outputType
				output.readExternal(loader.data)
				rpcResult(output)
			})
			function errorEventHandler(event:Event):void {
				delete REF[loader]
				rpcResult(event)
			}
			loader.addEventListener(IOErrorEvent.IO_ERROR, errorEventHandler)
			loader.addEventListener(
					SecurityErrorEvent.SECURITY_ERROR, errorEventHandler)
			const request:URLRequest = new URLRequest(
				urlPrefix + qualifiedMethodName)
			request.method = URLRequestMethod.POST
			const requestContent:ByteArray = new ByteArray
			input.writeExternal(requestContent)
			request.data = requestContent
			request.contentType = "application/x-protobuf"
			loader.load(request)
		}
	}
}

把另一处 callback 也改成其他名字

把另一处 callback 也改成其他名字