MapCSS in progress. Vast amounts still to do, but the meat of it is here. POIs are...
[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         import net.systemeD.halcyon.Globals;
6
7         public class Style {
8
9                 public var merged:Boolean=false;
10                 public var edited:Boolean=false;                // true once a property has been set from a string
11                 public var sublayer:uint=5;
12
13                 // Return an exact copy of this object
14                 // ** this needs some benchmarking - may be quicker to iterate over .properties, copying each one
15
16                 public function deepCopy():* {
17                         registerClassAlias("net.systemeD.halcyon.styleparser.ShapeStyle",ShapeStyle);
18                         registerClassAlias("net.systemeD.halcyon.styleparser.TextStyle",TextStyle);
19                         registerClassAlias("net.systemeD.halcyon.styleparser.PointStyle",PointStyle);
20                         registerClassAlias("net.systemeD.halcyon.styleparser.ShieldStyle",ShieldStyle);
21                         registerClassAlias("net.systemeD.halcyon.styleparser.InstructionStyle",InstructionStyle);
22                         var a:ByteArray=new ByteArray();
23                         a.writeObject(this);
24                         a.position=0;
25                         return (a.readObject());
26                 }
27
28                 // Add properties from another object
29
30                 public function mergeWith(additional:Style):void {
31                         for each (var prop:String in properties) {
32                                 if (additional[prop]) {
33                                         this[prop]=additional[prop];
34                                 }
35                         }
36                         this.merged=true;
37                 }
38
39                 // Getter (to be overridden) for property list
40
41                 public function get properties():Array {
42                         return [];
43                 }
44
45                 // Set property and cast as correct type (used in stylesheet imports)
46                 
47                 public function setPropertyFromString(k:String,v:*):Boolean {
48                         if (!this.hasOwnProperty(k)) { return false; }
49                         // ** almost certainly need to do more here, e.g. true|1|yes=Boolean true
50                         switch (typeof(this[k])) {
51                                 case "number":  this[k]=Number(v) ; edited=true; return true;
52                                 case "string":  this[k]=String(v) ; edited=true; return true;
53                                 case "boolean": this[k]=Boolean(v); edited=true; return true;
54                         }
55                         return false;
56                 }
57         }
58 }