home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / styles / Style.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  4.3 KB  |  142 lines

  1. package com.livebrush.styles
  2. {
  3.    import com.livebrush.data.Settings;
  4.    import com.livebrush.data.Storable;
  5.    import com.livebrush.utils.ColorObj;
  6.    import flash.events.EventDispatcher;
  7.    
  8.    public class Style extends EventDispatcher implements Storable
  9.    {
  10.       public static var idList:Array = [];
  11.       
  12.       public var decoStyle:DecoStyle;
  13.       
  14.       public var name:String;
  15.       
  16.       public var lineStyle:LineStyle;
  17.       
  18.       public var strokeStyle:StrokeStyle;
  19.       
  20.       public var id:int;
  21.       
  22.       public var styleManager:StyleManager;
  23.       
  24.       public function Style(styleManager:StyleManager)
  25.       {
  26.          super();
  27.          this.id = getNewID();
  28.          this.name = "Style_" + this.id;
  29.          this.styleManager = styleManager;
  30.          this.decoStyle = new DecoStyle(this);
  31.          this.lineStyle = new LineStyle(this);
  32.          this.strokeStyle = new StrokeStyle(this);
  33.       }
  34.       
  35.       public static function propEnabledListToXML(list:Array, valuePropName:String = "value", enabledPropName:String = "enabled", propName:String = "Properties", groupSuffix:String = "List") : XML
  36.       {
  37.          var propXML:XML = new XML(new XML("<" + (propName + groupSuffix) + "/>"));
  38.          for(var i:int = 0; i < list.length; i++)
  39.          {
  40.             propXML.appendChild(<{propName} {valuePropName}={list[i][valuePropName]} {enabledPropName}={list[i][enabledPropName]}/>);
  41.          }
  42.          return propXML;
  43.       }
  44.       
  45.       public static function propEnabledXMLToList(xml:XMLList) : Array
  46.       {
  47.          var element:XML = null;
  48.          var list:Array = [];
  49.          for each(element in xml)
  50.          {
  51.             list.push({
  52.                "value":String(element.@value),
  53.                "enabled":(element.@enabled == "true" ? true : false)
  54.             });
  55.          }
  56.          return list;
  57.       }
  58.       
  59.       public static function getNewID() : int
  60.       {
  61.          var newID:int = 0;
  62.          var highestID:int = 0;
  63.          for(var i:int = 0; i < idList.length; i++)
  64.          {
  65.             if(idList[i] >= highestID)
  66.             {
  67.                highestID = int(idList[i]);
  68.             }
  69.          }
  70.          newID = highestID + 1;
  71.          idList.push(newID);
  72.          return newID;
  73.       }
  74.       
  75.       public static function objToColorObj(o:Object) : ColorObj
  76.       {
  77.          return new ColorObj(o.value,o.enabled);
  78.       }
  79.       
  80.       public static function objListToColorObjList(list:Array) : Array
  81.       {
  82.          var colorList:Array = [];
  83.          for(var i:int = 0; i < list.length; i++)
  84.          {
  85.             colorList.push(objToColorObj(list[i]));
  86.          }
  87.          return colorList;
  88.       }
  89.       
  90.       public function die() : void
  91.       {
  92.          this.lineStyle.die();
  93.          this.strokeStyle.die();
  94.          this.decoStyle.die();
  95.       }
  96.       
  97.       public function getXML() : XML
  98.       {
  99.          var styleXML:XML = new XML(<style name={this.name} type="style"/>);
  100.          styleXML.appendChild(this.lineStyle.getXML());
  101.          styleXML.appendChild(this.strokeStyle.getXML());
  102.          styleXML.appendChild(this.decoStyle.getXML());
  103.          return styleXML;
  104.       }
  105.       
  106.       public function get settings() : Settings
  107.       {
  108.          var settings:Settings = new Settings();
  109.          settings.line = this.lineStyle.settings;
  110.          settings.stroke = this.strokeStyle.settings;
  111.          settings.deco = this.decoStyle.settings;
  112.          return settings;
  113.       }
  114.       
  115.       public function set settings(settings:Settings) : void
  116.       {
  117.          this.lineStyle.settings = settings.line;
  118.          this.strokeStyle.settings = settings.stroke;
  119.          this.decoStyle.settings = settings.deco;
  120.       }
  121.       
  122.       public function setXML(xml:String) : void
  123.       {
  124.          var styleXML:XML = new XML(xml);
  125.          this.name = styleXML.name;
  126.          this.decoStyle.setXML(styleXML.deco);
  127.          this.lineStyle.setXML(styleXML.line);
  128.          this.strokeStyle.setXML(styleXML.stroke);
  129.       }
  130.       
  131.       public function clone() : Style
  132.       {
  133.          var style:Style = new Style(this.styleManager);
  134.          style.lineStyle = this.lineStyle.clone(style);
  135.          style.strokeStyle = this.strokeStyle.clone(style);
  136.          style.decoStyle = this.decoStyle.clone(style);
  137.          return style;
  138.       }
  139.    }
  140. }
  141.  
  142.