Adjust behaviour of numberEditor - add clear button, and explanitory text for when...
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / RouteIcon.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:HBox
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
5         xmlns:flexlib="flexlib.controls.*"
6         borderStyle="inset" verticalAlign="middle" width="100%" paddingLeft="3"
7         backgroundColor="{bg}" color="{fg}" backgroundAlpha="1.0">
8         
9         <mx:Image source="{iconImage}"/>
10     <mx:Text condenseWhite="true" width="100%" htmlText="{iconHTML}" selectable="false"/>
11     <mx:ComboBox id="dir" color="black" dataProvider="{routeDirs}" selectedItem="{findSelected(role)}"
12         click="event.stopPropagation()"
13         change="setRole(dir.selectedItem.data)" />
14     
15     <mx:Script><![CDATA[
16     import net.systemeD.halcyon.connection.*;
17     import net.systemeD.halcyon.styleparser.RuleSet;
18     import net.systemeD.potlatch2.mapfeatures.*;
19     import flash.events.*;
20
21     import mx.collections.ArrayCollection;
22
23     [Bindable]
24     public var routeDirs:ArrayCollection = new ArrayCollection(
25         [ {label:">>", data:"forward"}, 
26           {label:"<<", data:"backward"}, 
27           {label:"<>", data:""} ]);
28
29     private var _iconImage:String = null;
30     private var _iconHTML:String = "";
31     private var _bg:String = "white";
32     private var _fg:String = "black";
33     private var _route:Object;
34     
35     private function findSelected(role:String):Object {
36         for each ( var item:Object in routeDirs ) {
37             if ( item.data == role )
38                 return item;
39         }
40         return routeDirs[2];
41     }
42          
43     public function setRoute(route:Object, icon:XMLList):void {   
44         _route = route;
45         var relation:Relation = route["relation"];
46         _iconHTML = Feature.makeHTMLIcon(icon, relation);
47
48         if ( icon.length() > 0 ) {
49             if (icon[0].hasOwnProperty("@image"))
50                 _iconImage = icon[0].@image;
51             if (icon[0].hasOwnProperty("@foreground"))
52                 _fg = icon[0].@foreground;
53             if (icon[0].hasOwnProperty("@background"))
54                 _bg = icon[0].@background;
55         }    
56
57         dispatchEvent(new Event("route_changed"));
58     }
59     
60     [Bindable(event="route_changed")]
61     private function get iconImage():String {
62         return _iconImage;
63     }
64     
65     [Bindable(event="route_changed")]
66     private function get iconHTML():String {
67         return _iconHTML;
68     }
69
70     [Bindable(event="route_changed")]
71     private function get role():String {
72         return _route["role"];
73     }
74
75     [Bindable(event="route_changed")]
76     private function get fg():uint {
77         return RuleSet.parseCSSColor(_fg);
78     }
79
80     [Bindable(event="route_changed")]
81     private function get bg():uint {
82         return RuleSet.parseCSSColor(_bg);
83     }
84     
85     public function get route():Object {
86         return _route;
87     }
88     
89     private function setRole(role:String):void {
90         var member:RelationMember = new RelationMember(_route["entity"], role);
91         _route["relation"].setMember(_route["index"], member);
92     }
93     
94     ]]></mx:Script>
95 </mx:HBox>
96