ADD keyboard shortcuts , and . (< and >) to step node by node along a way. Maintain...
authorSteve Bennett <stevagewp@gmail.com>
Sun, 13 Feb 2011 22:49:22 +0000 (22:49 +0000)
committerSteve Bennett <stevagewp@gmail.com>
Sun, 13 Feb 2011 22:49:22 +0000 (22:49 +0000)
REFACTOR scrollIfNeeded() to Map.as

net/systemeD/halcyon/Map.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 492b57e..79f9888 100644 (file)
@@ -1,25 +1,17 @@
 package net.systemeD.halcyon {
 
-       import flash.text.TextField;
-       import flash.geom.Rectangle;
-       import flash.display.DisplayObjectContainer;
        import flash.display.Loader;
        import flash.display.Sprite;
-       import flash.display.Shape;
-       import flash.display.Stage;
-       import flash.display.BitmapData;
-       import flash.display.LoaderInfo;
-       import flash.text.Font;
-       import flash.utils.ByteArray;
        import flash.events.*;
+       import flash.external.ExternalInterface;
+       import flash.geom.Rectangle;
        import flash.net.*;
-    import flash.external.ExternalInterface;
-
-    import net.systemeD.halcyon.connection.*;
-    import net.systemeD.halcyon.connection.EntityEvent;
-       import net.systemeD.halcyon.styleparser.*;
-       import net.systemeD.halcyon.Globals;
+       import flash.text.Font;
+       import flash.text.TextField;
        import flash.ui.Keyboard;
+       
+       import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.styleparser.*;
 
 //     for experimental export function:
 //     import flash.net.FileReference;
@@ -246,6 +238,14 @@ package net.systemeD.halcyon {
                        updateEntityUIs(false,false);
                        download();
                }
+               
+               /** Recentre map at given lat/lon, if that point is currently outside the visible area. */
+               public function scrollIfNeeded(lat:Number,lon:Number): void{
+            if (lat> edge_t || lat < edge_b || lon < edge_l || lon > edge_r) {
+                moveMapFromLatLon(lat, lon);
+            }
+
+               }
 
                // Co-ordinate conversion functions
 
index 61ba7b6..528c6a9 100644 (file)
@@ -310,12 +310,7 @@ package net.systemeD.potlatch2.controller {
                        controller.map.setHighlight(nextNode, { selectedway: true });
 
                        // recentre the map if the new lat/lon is offscreen
-                       if (nextNode.lat > controller.map.edge_t ||
-                               nextNode.lat < controller.map.edge_b ||  
-                               nextNode.lon < controller.map.edge_l ||
-                               nextNode.lon > controller.map.edge_r) {
-                               controller.map.moveMapFromLatLon(nextNode.lat, nextNode.lon);
-                       }
+                       controller.map.scrollIfNeeded(nextNode.lat,nextNode.lon);
                }
                
                override public function enterState():void {
index 0b2743d..bab211e 100644 (file)
@@ -1,16 +1,13 @@
 package net.systemeD.potlatch2.controller {
        import flash.events.*;
-       import flash.display.DisplayObject;
-       import flash.ui.Keyboard;
        import flash.geom.Point;
-    import net.systemeD.potlatch2.EditController;
-    import net.systemeD.potlatch2.tools.Parallelise;
-    import net.systemeD.potlatch2.tools.Quadrilateralise;
-    import net.systemeD.potlatch2.tools.Simplify;
-    import net.systemeD.halcyon.connection.*;
-       import net.systemeD.halcyon.MapPaint;
-       import net.systemeD.halcyon.WayUI;
+       import flash.ui.Keyboard;
+       
        import net.systemeD.halcyon.Globals;
+       import net.systemeD.halcyon.WayUI;
+       import net.systemeD.halcyon.connection.*;
+       import net.systemeD.potlatch2.tools.Quadrilateralise;
+       import net.systemeD.potlatch2.tools.Simplify;
 
     /** Behaviour that takes place while a way is selected includes: adding a node to the way, straightening/reshaping the way, dragging it. */
     public class SelectedWay extends ControllerState {
@@ -18,15 +15,17 @@ package net.systemeD.potlatch2.controller {
         protected var initWay:Way;
         private var clicked:Point;             // did the user enter this state by clicking at a particular point?
                private var wayList:Array;              // list of ways to cycle through with '/' keypress
+               private var initIndex: int;     // index of last selected node if entered from SelectedWayNode
         
         /** 
         * @param way The way that is now selected.
         * @param point The location that was clicked.
         * @param ways An ordered list of ways sharing a node, to make "way cycling" work. */
-        public function SelectedWay(way:Way, point:Point=null, ways:Array=null) {
+        public function SelectedWay(way:Way, point:Point=null, ways:Array=null, index:int=0) {
             initWay = way;
                        clicked = point;
                        wayList = ways;
+                       initIndex=index;
         }
 
         private function updateSelectionUI(e:Event):void {
@@ -76,6 +75,9 @@ package net.systemeD.potlatch2.controller {
                                case 191: /* / */           return cycleWays();
                                case Keyboard.BACKSPACE:        
                                case Keyboard.DELETE:           if (event.shiftKey) { return deleteWay(); } break;
+                case 188: /* , */           return new SelectedWayNode(initWay, initIndex); // allows navigating from one way to another by keyboard
+                case 190: /* . */           return new SelectedWayNode(initWay, initIndex); //  using <, > and /           
+
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
@@ -92,7 +94,9 @@ package net.systemeD.potlatch2.controller {
                                }
                        }
                        wayList=wayList.slice(1).concat(wayList[0]);
-                       return new SelectedWay(wayList[0], clicked, wayList);
+                       // Find the new way's index of the currently "selected" node, to facilitate keyboard navigation
+                       var newindex:int = Way(wayList[0]).indexOfNode(initWay.getNode(initIndex));
+                       return new SelectedWay(wayList[0], clicked, wayList, newindex);
                }
 
                /** Perform deletion of currently selected way. */
index 9d47c5a..04a91ce 100644 (file)
@@ -77,6 +77,8 @@ package net.systemeD.potlatch2.controller {
                 case 74:                    if (event.shiftKey) { return unjoin() }; return join();// 'J'
                                case Keyboard.BACKSPACE:        return deleteNode();
                                case Keyboard.DELETE:           return deleteNode();
+                               case 188: /* , */           return stepNode(-1);
+                               case 190: /* . */           return stepNode(+1);           
                        }
                        var cs:ControllerState = sharedKeyboardEvents(event);
                        return cs ? cs : this;
@@ -89,16 +91,18 @@ package net.systemeD.potlatch2.controller {
         public function get selectedNode():Node {
             return parentWay.getNode(selectedIndex);
         }
-
-
+        
                private function cycleWays():ControllerState {
                        var wayList:Array=firstSelected.parentWays;
                        if (wayList.length==1) { return this; }
                        wayList.splice(wayList.indexOf(parentWay),1);
+            // find index of this node in the newly selected way, to maintain state for keyboard navigation
+            var newindex:int = Way(wayList[0]).indexOfNode(parentWay.getNode(initIndex));
                        return new SelectedWay(wayList[0],
                                               new Point(controller.map.lon2coord(Node(firstSelected).lon),
                                                         controller.map.latp2coord(Node(firstSelected).latp)),
-                                              wayList.concat(parentWay));
+                                              wayList.concat(parentWay),
+                                              newindex);
                }
 
                override public function enterState():void {
@@ -223,6 +227,16 @@ package net.systemeD.potlatch2.controller {
             map.connection.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
             return new SelectedWayNode(n.parentWays[0], Way(n.parentWays[0]).indexOfNode(n));
         }
+        
+        /** Move the selection one node further up or down this way, looping if necessary. */
+        public function stepNode(delta:int):ControllerState {
+            var ni:int = (selectedIndex + delta + parentWay.length) %  parentWay.length
+            controller.map.scrollIfNeeded(parentWay.getNode(ni).lat,parentWay.getNode(ni).lon);
+            return new SelectedWayNode(parentWay, ni);
+        }
+
     }
+    
+    
 }