fix horrid merge bug (yay!). Implement suspend/resume events for redrawing, to speed...
authorRichard Fairhurst <richard@systemed.net>
Wed, 10 Mar 2010 00:49:11 +0000 (00:49 +0000)
committerRichard Fairhurst <richard@systemed.net>
Wed, 10 Mar 2010 00:49:11 +0000 (00:49 +0000)
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/Tag.as
net/systemeD/halcyon/connection/Way.as
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/mapfeatures/editors/SingleTagEditor.as

index b652fbf..284fe9c 100644 (file)
@@ -6,6 +6,7 @@ package net.systemeD.halcyon {
        import flash.text.GridFitType;
        import net.systemeD.halcyon.Globals;
        import net.systemeD.halcyon.styleparser.StyleList;
+    import net.systemeD.halcyon.connection.EntityEvent;
 
        public class EntityUI {
 
@@ -13,6 +14,9 @@ package net.systemeD.halcyon {
         protected var listenSprite:Sprite;                             // clickable sprite to receive events
                protected var stateClasses:Object=new Object(); // special context-sensitive classes, e.g. :hover
                protected var layer:int=0;                                              // map layer
+               protected var suspended:Boolean=false;                  // suspend redrawing?
+               protected var redrawDue:Boolean=false;                  // redraw called while suspended?
+               protected var redrawStyleList:StyleList;                // stylelist to be used when redrawing?
                public var map:Map;                                                             // reference to parent map
 
                protected const FILLSPRITE:uint=0;
@@ -88,9 +92,31 @@ package net.systemeD.halcyon {
                        return tags;
                }
                
+               // Redraw control
+               
                public function redraw(sl:StyleList=null):Boolean {
+                       if (suspended) { redrawStyleList=sl; redrawDue=true; return false; }
+                       return doRedraw(sl);
+               }
+               
+               public function doRedraw(sl:StyleList):Boolean {
+                       // to be overwritten
                        return false;
                }
+               
+               public function suspendRedraw(event:EntityEvent):void {
+                       suspended=true;
+                       redrawDue=false;
+               }
+               
+               public function resumeRedraw(event:EntityEvent):void {
+                       suspended=false;
+                       if (redrawDue) { 
+                               doRedraw(redrawStyleList);
+                               redrawDue=false;
+                               redrawStyleList=null; 
+                       }
+               }
 
        }
 
index b9cd326..1e11226 100644 (file)
@@ -28,6 +28,8 @@ package net.systemeD.halcyon {
                        this.heading = heading;
                        node.addEventListener(Connection.NODE_MOVED, nodeMoved);
                        node.addEventListener(Connection.NODE_DELETED, nodeDeleted);
+                       node.addEventListener(Connection.SUSPEND_REDRAW, suspendRedraw);
+                       node.addEventListener(Connection.RESUME_REDRAW, resumeRedraw);
                }
                
                public function nodeMoved(event:Event):void {
@@ -38,7 +40,7 @@ package net.systemeD.halcyon {
                        removeSprites();
                }
                
-               override public function redraw(sl:StyleList=null):Boolean {
+               override public function doRedraw(sl:StyleList):Boolean {
                        var tags:Object = node.getTagsCopy();
                        tags=applyStateClasses(tags);
                        if (!node.hasParentWays) { tags[':poi']='yes'; }
index 533acb1..597de3f 100755 (executable)
@@ -29,12 +29,14 @@ package net.systemeD.halcyon {
                        this.way = way;
                        this.map = map;
             init();
-            way.addEventListener(Connection.TAG_CHANGE, wayTagChanged);
+            way.addEventListener(Connection.TAG_CHANGED, wayTagChanged);
             way.addEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded);
             way.addEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
                        way.addEventListener(Connection.WAY_DELETED, wayDeleted);
                        way.addEventListener(Connection.ADDED_TO_RELATION, wayRelationAdded);
                        way.addEventListener(Connection.REMOVED_FROM_RELATION, wayRelationRemoved);
+                       way.addEventListener(Connection.SUSPEND_REDRAW, suspendRedraw);
+                       way.addEventListener(Connection.RESUME_REDRAW, resumeRedraw);
             attachNodeListeners();
             attachRelationListeners();
                }
@@ -48,17 +50,17 @@ package net.systemeD.halcyon {
                private function attachRelationListeners():void {
                    var relations:Array = way.parentRelations;
             for each(var relation:Relation in relations ) {
-                relation.addEventListener(Connection.TAG_CHANGE, relationTagChanged);
+                relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
             }
                }
                
                private function wayRelationAdded(event:RelationMemberEvent):void {
-                   event.relation.addEventListener(Connection.TAG_CHANGE, relationTagChanged);
+                   event.relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
                    redraw();
                }
                
                private function wayRelationRemoved(event:RelationMemberEvent):void {
-                   event.relation.removeEventListener(Connection.TAG_CHANGE, relationTagChanged);
+                   event.relation.removeEventListener(Connection.TAG_CHANGED, relationTagChanged);
                    redraw();
                }
                
@@ -140,7 +142,7 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                // Redraw
 
-               override public function redraw(sl:StyleList=null):Boolean {
+               override public function doRedraw(sl:StyleList):Boolean {
                        removeSprites();
                        if (way.length==0) { return false; }
 
index fa11a69..14d48a1 100755 (executable)
@@ -59,7 +59,7 @@ package net.systemeD.halcyon.connection {
         public static var NEW_WAY:String = "new_way";
         public static var NEW_RELATION:String = "new_relation";
         public static var NEW_POI:String = "new_poi";
-        public static var TAG_CHANGE:String = "tag_change";
+        public static var TAG_CHANGED:String = "tag_change";
         public static var NODE_MOVED:String = "node_moved";
         public static var WAY_NODE_ADDED:String = "way_node_added";
         public static var WAY_NODE_REMOVED:String = "way_node_removed";
@@ -70,6 +70,8 @@ package net.systemeD.halcyon.connection {
                public static var RELATION_MEMBER_REMOVED:String = "relation_member_deleted";
                public static var ADDED_TO_RELATION:String = "added_to_relation";
                public static var REMOVED_FROM_RELATION:String = "removed_from_relation";
+               public static var SUSPEND_REDRAW:String = "suspend_redraw";
+               public static var RESUME_REDRAW:String = "resume_redraw";
 
         // store the data we download
         private var negativeID:Number = -1;
index 3f1db95..1d2feb4 100644 (file)
@@ -59,7 +59,7 @@ package net.systemeD.halcyon.connection {
                 else
                     tags[key] = value;
                 markDirty();
-                dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, key, key, old, value));
+                dispatchEvent(new TagEvent(Connection.TAG_CHANGED, this, key, key, old, value));
             }
         }
 
@@ -69,7 +69,7 @@ package net.systemeD.halcyon.connection {
                 delete tags[oldKey];
                 tags[newKey] = value;
                 markDirty();
-                dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, oldKey, newKey, value, value));
+                dispatchEvent(new TagEvent(Connection.TAG_CHANGED, this, oldKey, newKey, value, value));
             }
         }
 
@@ -192,7 +192,17 @@ package net.systemeD.halcyon.connection {
                public function hasParent(entity:Entity):Boolean {
             return parents[entity] == true;
         }
-        
+
+               // Resume/suspend redraw
+               
+               public function suspend():void {
+                       dispatchEvent(new EntityEvent(Connection.SUSPEND_REDRAW, this));
+               }
+               
+               public function resume():void {
+                       dispatchEvent(new EntityEvent(Connection.RESUME_REDRAW, this));
+               }
+
                // To be overridden
 
         public function getType():String {
index acb3ee5..9f45e0a 100644 (file)
@@ -7,7 +7,7 @@ package net.systemeD.halcyon.connection {
 
         public function Tag(entity:Entity, key:String, value:String) {
             this.entity = entity;
-            entity.addEventListener(Connection.TAG_CHANGE, tagChanged, false, 0, true);
+            entity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
             this._key = key;
             this._value = value;
         }
index f04a6c5..832d09b 100644 (file)
@@ -85,6 +85,7 @@ package net.systemeD.halcyon.connection {
 
                public function mergeWith(way:Way,topos:int,frompos:int):void {
                        var i:int;
+                       suspend();
 
                        // merge relations
                        for each (var r:Relation in way.parentRelations) {
@@ -111,6 +112,7 @@ package net.systemeD.halcyon.connection {
 
                        // delete way
                        way.remove();
+                       resume();
                }
                
                private function addToEnd(topos:int,node:Node):void {
@@ -181,17 +183,17 @@ package net.systemeD.halcyon.connection {
                
                public override function remove():void {
                        var node:Node;
+                       suspend();
                        removeFromParents();
                        while (nodes.length) { 
                                node=nodes.pop();
                                dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, node, this, 0));
-                               // ** the event mechanism calls redraw once per wayNodeRemoved, which isn't too efficient
-                               //    so we should probably add a 'redraw' flag to WayNodeEvent
                                node.removeParent(this);
                                if (!node.hasParents) { node.remove(); }
                        }
                        deleted=true;
             dispatchEvent(new EntityEvent(Connection.WAY_DELETED, this));
+                       resume();
                }
 
                internal override function isEmpty():Boolean {
index 98f864e..92941c0 100644 (file)
       public function setEntity(entity:Entity):void {
           if ( selectedEntity != entity ) {
               if ( selectedEntity != null )
-                  selectedEntity.removeEventListener(Connection.TAG_CHANGE, tagChanged);
+                  selectedEntity.removeEventListener(Connection.TAG_CHANGED, tagChanged);
               selectedEntity = entity;
               if ( selectedEntity != null )
-                  selectedEntity.addEventListener(Connection.TAG_CHANGE, tagChanged);
+                  selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged);
           }
 
           if ( advancedID != null )
 
       private function removeRelationListeners():void {
           for each( var rel:Relation in listeningToRelations ) {
-              rel.removeEventListener(Connection.TAG_CHANGE, relationTagChanged);
+              rel.removeEventListener(Connection.TAG_CHANGED, relationTagChanged);
               rel.removeEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
               rel.removeEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
           }
                   relations.push(props);
               }
               
-              rel.addEventListener(Connection.TAG_CHANGE, relationTagChanged);
+              rel.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
               rel.addEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
               rel.addEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
               listeningToRelations.push(rel);
index bbfe8fa..0417654 100644 (file)
@@ -37,7 +37,7 @@ package net.systemeD.potlatch2.mapfeatures.editors {
       
       public function set entity(entity:Entity):void {
           _entity = entity;
-          entity.addEventListener(Connection.TAG_CHANGE, tagChanged, false, 0, true);
+          entity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
           dispatchEvent(new Event("tag_changed"));
       }