forward & backward in route roles
authorDave Stubbs <osm@randomjunk.co.uk>
Sun, 10 Jan 2010 14:29:55 +0000 (14:29 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sun, 10 Jan 2010 14:29:55 +0000 (14:29 +0000)
net/systemeD/halcyon/connection/Relation.as
net/systemeD/potlatch2/mapfeatures/editors/RelationMemberEditor.as
net/systemeD/potlatch2/mapfeatures/editors/RouteEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/RouteIcon.mxml

index 7d804d63c24a6cca8de55a757c357486693864e1..59524d061bb94b04718dc6c5a454a22cebdd93a9 100644 (file)
@@ -45,6 +45,9 @@ package net.systemeD.halcyon.connection {
         }
 
         public function setMember(index:uint, member:RelationMember):void {
+            var oldMember:RelationMember = getMember(index);
+            oldMember.entity.removeParent(this);
+            
                        member.entity.addParent(this);
                        members.splice(index, 1, member);
                        markDirty();
index b8fd1744b6a11ae40a8d00c7c1b4b9fbc8c91773..8d371fb924447099d1b52dd2f0bbc35b07dafabe 100644 (file)
@@ -34,8 +34,17 @@ package net.systemeD.potlatch2.mapfeatures.editors {
                   if ( relVal != relationTags[k] )
                       addable = false;
               }
-              if (addable)
-                  matched.push(relation);
+              if (addable) {
+                  for each( var memberIndex:int in relation.findEntityMemberIndexes(_entity)) {
+                      var props:Object = {};
+                      props["relation"] = relation;
+                      props["id"] = relation.id;
+                      props["index"] = memberIndex;
+                      props["role"] = relation.getMember(memberIndex).role;
+                      props["entity"] = _entity;
+                      matched.push(props);
+                  }
+              }
           }
           return matched;
       }
index 9599620301d0e36946870cc095c5e0b571bdebce..33e308b0280835ec7a40626ba503773caef1453e 100644 (file)
@@ -19,7 +19,7 @@
     import mx.core.*;
    
     public function addRoutes():void {
-        for each(var relation:Relation in matchedRelations) {
+        for each(var relation:Object in matchedRelations) {
             var icon:RouteIcon = new RouteIcon();
             icon.setRoute(relation, RouteEditorFactory(_factory).icon);
             
     }
     
     public function routeClicked(event:Event):void {
-        var relation:Relation = RouteIcon(event.currentTarget).route;
+        var relation:Object = RouteIcon(event.currentTarget).route;
         trace(relation+" is clicked");
         var panel:RelationEditorPanel = RelationEditorPanel(
             PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
-        panel.setRelation(relation);
+        panel.setRelation(relation["relation"]);
         PopUpManager.centerPopUp(panel);
     }
     
index 08b0b95f8f46b622c05abb510c511a81cfa986ca..7ad95f1e70f4cc8ab89f680da7a943f8028c66a4 100644 (file)
@@ -8,6 +8,9 @@
        
        <mx:Image source="{iconImage}"/>
     <mx:Text condenseWhite="true" width="100%" htmlText="{iconHTML}" selectable="false"/>
+    <mx:ComboBox id="dir" color="black" dataProvider="{routeDirs}" selectedItem="{findSelected(role)}"
+        click="event.stopPropagation()"
+        change="setRole(dir.selectedItem.data)" />
     
     <mx:Script><![CDATA[
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.mapfeatures.*;
     import flash.events.*;
 
+    import mx.collections.ArrayCollection;
+
+    [Bindable]
+    public var routeDirs:ArrayCollection = new ArrayCollection(
+        [ {label:">>", data:"forward"}, 
+          {label:"<<", data:"backward"}, 
+          {label:"<>", data:""} ]);
+
     private var _iconImage:String = null;
     private var _iconHTML:String = "";
     private var _bg:String = "white";
     private var _fg:String = "black";
-    private var _relation:Relation;
+    private var _route:Object;
+    
+    private function findSelected(role:String):Object {
+        for each ( var item:Object in routeDirs ) {
+            if ( item.data == role )
+                return item;
+        }
+        return routeDirs[2];
+    }
          
-    public function setRoute(relation:Relation, icon:XMLList):void {   
-        _relation = relation;
+    public function setRoute(route:Object, icon:XMLList):void {   
+        _route = route;
+        var relation:Relation = route["relation"];
         _iconHTML = Feature.makeHTMLIcon(icon, relation);
 
         if ( icon.length() > 0 ) {
         return _iconHTML;
     }
 
+    [Bindable(event="route_changed")]
+    private function get role():String {
+        return _route["role"];
+    }
+
     [Bindable(event="route_changed")]
     private function get fg():uint {
         return MapCSS.parseCSSColor(_fg);
         return MapCSS.parseCSSColor(_bg);
     }
     
-    public function get route():Relation {
-        return _relation;
+    public function get route():Object {
+        return _route;
     }
+    
+    private function setRole(role:String):void {
+        var member:RelationMember = new RelationMember(_route["entity"], role);
+        _route["relation"].setMember(_route["index"], member);
+    }
+    
     ]]></mx:Script>
 </mx:HBox>