Richard told you to go away, now go away
[potlatch2.git] / net / systemeD / halcyon / styleparser / Style.as
1 package net.systemeD.halcyon.styleparser {
2
3         import flash.utils.ByteArray;
4         import flash.net.*;
5
6         public class Style {
7
8                 public var merged:Boolean=false;
9                 public var edited:Boolean=false;                // true once a property has been set from a string
10                 public var sublayer:uint=5;
11
12                 // Return an exact copy of this object
13                 // ** this needs some benchmarking - may be quicker to iterate over .properties, copying each one
14
15                 public function deepCopy():* {
16                         registerClassAlias("net.systemeD.halcyon.styleparser.ShapeStyle",ShapeStyle);
17                         registerClassAlias("net.systemeD.halcyon.styleparser.TextStyle",TextStyle);
18                         registerClassAlias("net.systemeD.halcyon.styleparser.PointStyle",PointStyle);
19                         registerClassAlias("net.systemeD.halcyon.styleparser.ShieldStyle",ShieldStyle);
20                         registerClassAlias("net.systemeD.halcyon.styleparser.InstructionStyle",InstructionStyle);
21                         var a:ByteArray=new ByteArray();
22                         a.writeObject(this);
23                         a.position=0;
24                         return (a.readObject());
25                 }
26
27                 // Add properties from another object
28
29                 public function mergeWith(additional:Style):void {
30                         for each (var prop:String in properties) {
31                                 if (additional[prop]) {
32                                         this[prop]=additional[prop];
33                                 }
34                         }
35                         this.merged=true;
36                 }
37
38                 // Getter (to be overridden) for property list
39
40                 public function get properties():Array {
41                         return [];
42                 }
43
44                 // Set property and cast as correct type (used in stylesheet imports)
45                 
46                 public function setPropertyFromString(k:String,v:*):Boolean {
47                         if (!this.hasOwnProperty(k)) { return false; }
48                         // ** almost certainly need to do more here, e.g. true|1|yes=Boolean true
49                         switch (typeof(this[k])) {
50                                 case "number":  this[k]=Number(v) ; edited=true; return true;
51                                 case "object":  // **for some reason, typeof(string class variables) returns "object".
52                                                                 // We'll probably need to fix this in future if we have more complex
53                                                                 // properties
54                                 case "string":  this[k]=String(v) ; edited=true; return true;
55                                 case "boolean": this[k]=Boolean(v); edited=true; return true;
56                         }
57                         return false;
58                 }
59         }
60 }