Fix setting a route relation role (forward/backward) via the simple interface - was...
[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         <mx:Image source="@Embed('../../../../../embedded/delete.svg')" click='event.stopPropagation();removeFromRelation()'
15         buttonMode="true" useHandCursor="true" />
16     
17     <mx:Script><![CDATA[
18     import net.systemeD.halcyon.connection.*;
19     import net.systemeD.halcyon.styleparser.RuleSet;
20     import net.systemeD.potlatch2.mapfeatures.*;
21     import flash.events.*;
22
23     import mx.collections.ArrayCollection;
24
25     [Bindable]
26     public var routeDirs:ArrayCollection = new ArrayCollection(
27         [ {label:">>", data:"forward"}, 
28           {label:"<<", data:"backward"}, 
29           {label:"<>", data:""} ]);
30
31     private var _iconImage:String = null;
32     private var _iconHTML:String = "";
33     private var _bg:String = "white";
34     private var _fg:String = "black";
35     private var _route:Object;
36     
37     private function findSelected(role:String):Object {
38         for each ( var item:Object in routeDirs ) {
39             if ( item.data == role )
40                 return item;
41         }
42         return routeDirs[2];
43     }
44          
45     public function setRoute(route:Object, icon:XMLList):void {   
46         _route = route;
47         var relation:Relation = route["relation"];
48         _iconHTML = Feature.makeHTMLIcon(icon, relation);
49
50         if ( icon.length() > 0 ) {
51             if (icon[0].hasOwnProperty("@image"))
52                 _iconImage = icon[0].@image;
53             if (icon[0].hasOwnProperty("@foreground"))
54                 _fg = icon[0].@foreground;
55             if (icon[0].hasOwnProperty("@background"))
56                 _bg = icon[0].@background;
57         }    
58
59         dispatchEvent(new Event("route_changed"));
60     }
61     
62     [Bindable(event="route_changed")]
63     private function get iconImage():String {
64         return _iconImage;
65     }
66     
67     [Bindable(event="route_changed")]
68     private function get iconHTML():String {
69         return _iconHTML;
70     }
71
72     [Bindable(event="route_changed")]
73     private function get role():String {
74         return _route["role"];
75     }
76
77     [Bindable(event="route_changed")]
78     private function get fg():uint {
79         return RuleSet.parseCSSColor(_fg);
80     }
81
82     [Bindable(event="route_changed")]
83     private function get bg():uint {
84         return RuleSet.parseCSSColor(_bg);
85     }
86     
87     public function get route():Object {
88         return _route;
89     }
90     
91     private function setRole(role:String):void {
92         var member:RelationMember = new RelationMember(_route["entity"], role);
93         Relation(_route["relation"]).setMember(_route["index"], member, MainUndoStack.getGlobalStack().addAction);
94     }
95
96         private function removeFromRelation():void {
97                 Relation(_route["relation"]).removeMember(_route["entity"], MainUndoStack.getGlobalStack().addAction);
98         }
99     
100     ]]></mx:Script>
101 </mx:HBox>
102