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