more selection fixes
authorRichard Fairhurst <richard@systemed.net>
Sun, 29 Nov 2009 15:44:01 +0000 (15:44 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 29 Nov 2009 15:44:01 +0000 (15:44 +0000)
net/systemeD/halcyon/EntityUI.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/CreateWay.as
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/NoSelection.as
net/systemeD/potlatch2/controller/SelectedPOINode.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 1cfb1bf..bf4cb76 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.halcyon {
        import flash.events.MouseEvent;
        import flash.text.AntiAliasType;
        import flash.text.GridFitType;
+       import net.systemeD.halcyon.Globals;
 
        public class EntityUI {
 
@@ -45,7 +46,8 @@ package net.systemeD.halcyon {
                
                public function removeSprites():void {
                        while (sprites.length>0) {
-                               var d:DisplayObject=sprites.pop(); d.parent.removeChild(d);
+                               var d:DisplayObject=sprites.pop();
+                               if (d.parent) { d.parent.removeChild(d); }
                        }
                }
 
@@ -69,9 +71,9 @@ package net.systemeD.halcyon {
         protected function mouseEvent(event:MouseEvent):void {
         }
 
-        public function setHighlight(stateType:String, isOn:Boolean):void {
+        public function setHighlight(stateType:String, isOn:*):void {
             if ( isOn && stateClasses[stateType] == null ) {
-                stateClasses[stateType] = true;
+                stateClasses[stateType] = isOn;
             } else if ( !isOn && stateClasses[stateType] != null ) {
                 delete stateClasses[stateType];
             }
index 59238ea..0467874 100644 (file)
@@ -41,7 +41,7 @@ package net.systemeD.halcyon {
                        // special tags
                        if (!node.hasParentWays) { tags[':poi']='yes'; }
             for (var stateKey:String in stateClasses) {
-                tags[":"+stateKey] = stateKey;
+                tags[":"+stateKey] = 'yes';
             }
 
                        if (!sl) { sl=map.ruleset.getStyles(this.node,tags); }
index 6933fd4..e1b6a43 100755 (executable)
@@ -194,12 +194,14 @@ package net.systemeD.halcyon {
                        var r:Number;
                        var nodetags:Object;
                        var highlight:Boolean=stateClasses["showNodes"]; // !=null
+                       var nodeSelected:int=stateClasses["nodeSelected"];
                        for (var i:uint = 0; i < way.length; i++) {
                 var node:Node = way.getNode(i);
                                nodetags=node.getTagsCopy();
                                if (i==0) { nodetags['_heading']= heading[i]; }
                                     else { nodetags['_heading']=(heading[i]+heading[i-1])/2; }
                                if (highlight) { nodetags[':selectedway']='yes'; }
+                               if (node.id==nodeSelected) { nodetags[':selected']='yes'; }
                                sl=map.ruleset.getStyles(node,nodetags);
                                if (sl.hasStyles()) {
                                        if (!map.pois[node.id]) { map.pois[node.id]=new NodeUI(node,map,r); }
index 7d6c5ca..f1a3671 100644 (file)
@@ -3,6 +3,7 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.halcyon.Map;
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.EditController;
+       import net.systemeD.halcyon.Globals;
 
     public class ControllerState {
 
index 91862e2..9f23934 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2.controller {
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.halcyon.Elastic;
+       import net.systemeD.halcyon.Globals;
 
     public class CreateWay extends ControllerState {
         private var start:Point;
@@ -54,11 +55,13 @@ package net.systemeD.potlatch2.controller {
             mouse.y = controller.map.coord2latp(mouse.y);
             
             elastic = new Elastic(controller.map, start, mouse);
+                       Globals.vars.root.addDebug("**** -> "+this);
         }
         
         override public function exitState():void {
             elastic.removeSprites();
             elastic = null;
+                       Globals.vars.root.addDebug("**** <- "+this);
         }
 
         override public function toString():String {
index 1955479..abf22e8 100644 (file)
@@ -8,6 +8,7 @@ package net.systemeD.potlatch2.controller {
         private var selectedWay:Way;
         private var draggingNode:Node;
         private var isDraggingStarted:Boolean = false;
+               private var isNew:Boolean = false;
 
         private var downX:Number;
         private var downY:Number;
@@ -16,11 +17,12 @@ package net.systemeD.potlatch2.controller {
                private const NOT_MOVED:uint=1;
                private const DRAGGING:uint=2;
         
-        public function DragWayNode(way:Way, node:Node, event:MouseEvent) {
+        public function DragWayNode(way:Way, node:Node, event:MouseEvent, newNode:Boolean) {
             selectedWay = way;
             draggingNode = node;
             downX = event.localX;
             downY = event.localY;
+                       isNew = newNode;
         }
  
        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
@@ -30,13 +32,14 @@ package net.systemeD.potlatch2.controller {
                                        // mouse-up while dragging, so end drag
                        return new SelectedWayNode(selectedWay,draggingNode);
 //                     return endDrag();
-                               } else if (event.shiftKey) {
+                               } else if (event.shiftKey && !isNew) {
                                        // start new way
                                        var way:Way = controller.connection.createWay({}, [entity, entity]);
                                        return new DrawWay(way, true);
+                               } else if (event.shiftKey && isNew) {
+                       return new SelectedWayNode(selectedWay,draggingNode);
                                } else {
                                        // select node
-                                       Globals.vars.root.addDebug("- select node from DragWayNode");
                                        dragstate=NOT_DRAGGING;
                        return new SelectedWayNode(selectedWay,draggingNode);
                                }
@@ -72,10 +75,12 @@ package net.systemeD.potlatch2.controller {
                }
 
         override public function enterState():void {
-            controller.map.setHighlight(selectedWay, {showNodes: true } );
+            controller.map.setHighlight(selectedWay, { showNodes: true } );
+                       Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState():void {
-            controller.map.setHighlight(selectedWay, {showNodes: false } );
+            controller.map.setHighlight(selectedWay, { showNodes: false } );
+                       Globals.vars.root.addDebug("**** <- "+this);
         }
         override public function toString():String {
             return "DragWayNode";
index f5da8ce..934822b 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2.controller {
        import net.systemeD.potlatch2.EditController;
        import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.Elastic;
+       import net.systemeD.halcyon.Globals;
 
        public class DrawWay extends SelectedWay {
                private var elastic:Elastic;
@@ -72,11 +73,13 @@ package net.systemeD.potlatch2.controller {
                        var node:Node = selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0);
                        var start:Point = new Point(node.lon, node.latp);
                        elastic = new Elastic(controller.map, start, start);
+                       Globals.vars.root.addDebug("**** -> "+this);
                }
                override public function exitState():void {
                        super.exitState();
                        elastic.removeSprites();
                        elastic = null;
+                       Globals.vars.root.addDebug("**** <- "+this);
                }
                override public function toString():String {
                        return "DrawWay";
index 8cbfd2e..b10e492 100644 (file)
@@ -45,6 +45,12 @@ package net.systemeD.potlatch2.controller {
                        }
                }
 
+        override public function enterState():void {
+                       Globals.vars.root.addDebug("**** -> "+this);
+        }
+        override public function exitState():void {
+                       Globals.vars.root.addDebug("**** <- "+this);
+        }
                override public function toString():String {
                        return "NoSelection";
                }
index 301cf89..0b3cc22 100644 (file)
@@ -75,9 +75,11 @@ package net.systemeD.potlatch2.controller {
 */      
         override public function enterState():void {
             selectNode(initNode);
+                       Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState():void {
             clearSelection();
+                       Globals.vars.root.addDebug("**** <- "+this);
         }
 
         override public function toString():String {
index 9fdf71c..aeb0fb0 100644 (file)
@@ -38,12 +38,10 @@ package net.systemeD.potlatch2.controller {
             if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
-                                       Globals.vars.root.addDebug("- start new way");
                     var way:Way = controller.connection.createWay({}, [entity, entity]);
                     return new DrawWay(way, true);
                                } else if ( entity is Way ) {
                                        // select way
-                                       Globals.vars.root.addDebug("- selected way");
                     selectWay(entity as Way);
                 } else if ( entity is Node ) {
                                        // *** select node
@@ -55,11 +53,11 @@ package net.systemeD.potlatch2.controller {
             } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
                                if ( entity is Way && focus==selectedWay && event.shiftKey) {
                                        // insert node within way (shift-click)
-                    var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event);
+                    var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event, true);
                                        d.forceDragStart();
                                        return d;
                                } else if ( entity is Node && entity.hasParent(selectedWay) ) {
-                    return new DragWayNode(selectedWay, Node(entity), event);
+                    return new DragWayNode(selectedWay, Node(entity), event, false);
                                }
             }
 
@@ -77,9 +75,11 @@ package net.systemeD.potlatch2.controller {
         
         override public function enterState():void {
             selectWay(initWay);
+                       Globals.vars.root.addDebug("**** -> "+this);
         }
         override public function exitState():void {
             clearSelection();
+                       Globals.vars.root.addDebug("**** <- "+this);
         }
 
         override public function toString():String {
index 3525bea..17be1e8 100644 (file)
@@ -9,28 +9,24 @@ package net.systemeD.potlatch2.controller {
         protected var initNode:Node;
         
         public function SelectedWayNode(way:Way,node:Node) {
-                       Globals.vars.root.addDebug("- SelectedWayNode: constructor");
                        super (way);
             initNode = node;
         }
  
         protected function selectNode(way:Way,node:Node):void {
-                       Globals.vars.root.addDebug("- SelectedWayNode: selectNode");
             if ( way == selectedWay && node == selectedNode )
                 return;
 
             clearSelection();
             controller.setTagViewer(node);
-            controller.map.setHighlight(node, { selected: true });
-            controller.map.setHighlight(way, { showNodes: true });
+            controller.map.setHighlight(way, { showNodes: true, nodeSelected: node.id });
             selectedWay = way;   initWay  = way;
             selectedNode = node; initNode = node;
         }
                 
         override protected function clearSelection():void {
             if ( selectedNode != null ) {
-                controller.map.setHighlight(selectedNode, { selected: false });
-               controller.map.setHighlight(selectedWay, { selected: false, showNodes: false });
+               controller.map.setHighlight(selectedWay, { selected: false, showNodes: false, nodeSelected: null });
                 controller.setTagViewer(null);
                 selectedNode = null;
                                selectedWay = null;
@@ -44,30 +40,25 @@ package net.systemeD.potlatch2.controller {
             if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
-                                       Globals.vars.root.addDebug("- SelectedWayNode: start new way");
                     var way:Way = controller.connection.createWay({}, [entity, entity]);
                     return new DrawWay(way, true);
                                } else if ( entity is Node ) {
                                        // select node within way
-                                       Globals.vars.root.addDebug("- SelectedWayNode: select other node");
                                        return new SelectedWayNode(selectedWay,Node(entity));
                 } else if ( entity is Way ) {
                                        // select way
-                                       Globals.vars.root.addDebug("- SelectedWayNode: select way");
                                        return new SelectedWay(selectedWay);
                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
-                                       Globals.vars.root.addDebug("- SelectedWayNode: deselect");
                     return new NoSelection();
                                }
             } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
                                if ( entity is Way && focus==selectedWay && event.shiftKey) {
                                        // insert node within way (shift-click)
-                       var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event);
+                       var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event, true);
                                        d.forceDragStart();
                                        return d;
                                } else if ( entity is Node && entity.hasParent(selectedWay) ) {
-                                       Globals.vars.root.addDebug("- SelectedWayNode: dragwaynode");
-                    return new DragWayNode(selectedWay, Node(entity), event);
+                    return new DragWayNode(selectedWay, Node(entity), event, false);
                                }
             }
 
@@ -76,6 +67,11 @@ package net.systemeD.potlatch2.controller {
 
                override public function enterState():void {
             selectNode(initWay,initNode);
+                       Globals.vars.root.addDebug("**** -> "+this);
+        }
+               override public function exitState():void {
+            clearSelection();
+                       Globals.vars.root.addDebug("**** <- "+this);
         }
 
         override public function toString():String {