More refactoring work-in-progress
authorRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 17:18:05 +0000 (18:18 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 17:18:05 +0000 (18:18 +0100)
18 files changed:
REFACTOR.txt
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/RelationLoaderPanel.mxml
net/systemeD/potlatch2/RelationSelectPanel.mxml
net/systemeD/potlatch2/Toolbox.mxml
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/DrawQuadrilateral.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
net/systemeD/potlatch2/mapfeatures/editors/TurnRestrictionEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/TurnRestrictionIcon.mxml
net/systemeD/potlatch2/save/OAuthPanel.mxml
net/systemeD/potlatch2/save/SaveManager.as
net/systemeD/potlatch2/tools/Circularise.as

index a0747982f9cb365620b6cdd44cd4cc04fac72242..632e6aeb131bb3468a8e2ef1ab1e7179e618df09 100644 (file)
@@ -24,7 +24,6 @@ Global changes:
 - move lots of connection.map to connection.map.editableLayer
 - remove all references to getConnection etc. - there can now be more than one Connection
 - remove all back-references to Map except where necessary for lat/long/scale
-- Controllers are full of references to controller.map and to controller.connection
 - getParam is broken - there needs to be a global equivalent (not in Connection) for stuff sent via flashvars - i.e. loaderInfo.parameters (but that's Flex-only)
 - Look for Connection. - lots of static stuff which shouldn't be that any more
 
index 88361dd4b16a2f21e89a7634d1941ad9408befba..48a4771616bd77645ae6b3a5c8b2b63c830296c1 100644 (file)
@@ -23,7 +23,6 @@ package net.systemeD.potlatch2 {
                private var toolbox:Toolbox;
         
         public var state:ControllerState;
-        private var _connection:Connection;
         
                private var keys:Object={};
                public var clipboards:Object={};
@@ -65,7 +64,6 @@ package net.systemeD.potlatch2 {
 
         public function setActive():void {
             map.setController(this);
-            _connection = map.connection;
         }
 
         /** Accesses map object. */
@@ -73,11 +71,6 @@ package net.systemeD.potlatch2 {
             return _map;
         }
         
-        /** Accesss connection object. */
-        public function get connection():Connection {
-            return _connection;
-        }
-
         /**
         * Updates the various user interfaces that change when the selection changes.
         * Currently this is the TagViewer and the Toolbox
index 39fb79fa94b3fe21e7fd2af7762136ca19f9cab1..2a617a146f7bb3daf9123aaa6a8531c190cb0eb0 100644 (file)
                import mx.managers.PopUpManager;
 
                private var entity:Entity;
+               private var connection:Connection;
                private var relid:Number;
                
                public function setEntity(e:Entity):void {
                        entity=e;
+                       connection=e.connection;
                }
 
                private function loadRelation():void {
                        relid = Number(requestedID.text);
                        PopUpManager.removePopUp(this);
 
-                       var conn:Connection = Connection.getConnection();
                        if (!relid) return;
-                       if (conn.getRelation(relid)) {
+                       if (connection.getRelation(relid)) {
                                relationLoaded(null);
                        } else {
-                               conn.loadEntityByID("relation",relid);
-                               conn.addEventListener(Connection.LOAD_COMPLETED, relationLoaded);
+                               connection.loadEntityByID("relation",relid);
+                               connection.addEventListener(Connection.LOAD_COMPLETED, relationLoaded);
                        }
                }
                
                private function relationLoaded(event:Event):void {
-                       var conn:Connection = Connection.getConnection();
-                       var relation:Relation = conn.getRelation(relid);
-                       conn.removeEventListener(Connection.LOAD_COMPLETED, relationLoaded);
+                       var relation:Relation = connection.getRelation(relid);
+                       connection.removeEventListener(Connection.LOAD_COMPLETED, relationLoaded);
                        if (!relation) return;
 
                        var undo:CompositeUndoableAction = new CompositeUndoableAction("Add to relation");
index 3c17eaff647b3952a5535003a1295f9a88b944aa..f10440d25a23f74c19ebd8669401421910009412 100644 (file)
@@ -23,6 +23,7 @@
         */
         public function init(e:Entity, t:Object):void {
           entity = e;
+          conn = e.connection;
           defaulttags = {};
           for (var k:String in t) {  
             //tagmatches[k]=t[k];// deep copy match pattern tags
@@ -32,7 +33,6 @@
           PopUpManager.centerPopUp(this);
     
           var titles:Array = [];
-          conn = Connection.getConnection();
           relationList = conn.getMatchingRelationIDs(t);
           if (relationList.length == 0) {
             warning.text = "No relations available";
index a553ab6a26ee6b7be38e1db1e0e386dbac23adcf..dcb05c35dbf89d7c9e53035edcc8953c1a841eb1 100644 (file)
                public function doDelete():void {
                        var undo:CompositeUndoableAction = new CompositeUndoableAction("Delete objects");
                        for each (var entity:Entity in controller.state.selection) {
-                               if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
+                               if (entity is Node) { entity.connection.unregisterPOI(Node(entity)); }
                                entity.remove(undo.push);
                        }
                        MainUndoStack.getGlobalStack().addAction(undo);
index 94c62f7902d933901981c6b777de1fd88207ce85..e442dba6e2bce196e15a4204d310c3cbc730c367 100644 (file)
@@ -65,9 +65,9 @@ package net.systemeD.potlatch2.controller {
                protected function sharedKeyboardEvents(event:KeyboardEvent):ControllerState {
                        switch (event.keyCode) {
                                case 66:        setSourceTag(); break;                                                                                                  // B - set source tag for current object
-                               case 67:        controller.connection.closeChangeset(); break;                                                  // C - close changeset
+                               case 67:        editableLayer.connection.closeChangeset(); break;                                               // C - close changeset
                                case 68:        editableLayer.alpha=1.3-editableLayer.alpha; return null;                               // D - dim
-                               case 83:        SaveManager.saveChanges(controller.connection); break;                                  // S - save
+                               case 83:        SaveManager.saveChanges(editableLayer.connection); break;                               // S - save
                                case 84:        controller.tagViewer.togglePanel(); return null;                                                // T - toggle tags panel
                                case 90:        if (!event.shiftKey) { MainUndoStack.getGlobalStack().undo(); return null;}// Z - undo
                                            else { MainUndoStack.getGlobalStack().redo(); return null;  }           // Shift-Z - redo                                           
@@ -87,7 +87,7 @@ package net.systemeD.potlatch2.controller {
                        if ( paint && paint.isBackground ) {
                                if ( event.type == MouseEvent.MOUSE_DOWN && ((event.shiftKey && event.ctrlKey) || event.altKey) ) {
                                        // alt-click to pull data out of vector background layer
-                                       var newEntity:Entity=paint.findSource().pullThrough(entity,controller.connection);
+                                       var newEntity:Entity=paint.findSource().pullThrough(entity,editableLayer.connection);
                                        if (entity is Way) { return new SelectedWay(newEntity as Way); }
                                        else if (entity is Node) { return new SelectedPOINode(newEntity as Node); }
                 } else if (event.type == MouseEvent.MOUSE_DOWN && entity is Marker) {
@@ -206,7 +206,7 @@ package net.systemeD.potlatch2.controller {
                protected function revertHandler(event:CloseEvent):void {
                        if (event.detail==Alert.CANCEL) return;
                        for each (var item:Entity in _selection) {
-                               controller.connection.loadEntity(item);
+                               item.connection.loadEntity(item);
                        }
                }
 
index f53a7172ccd05c9b33489991996e62744b4af9ef..1b618fd95004daed25b20fc291bffd9317227718 100644 (file)
@@ -43,7 +43,7 @@ package net.systemeD.potlatch2.controller {
             var lat:Number = controller.map.coord2lat(event.localY);
             var lon:Number = controller.map.coord2lon(event.localX);
             var undo:CompositeUndoableAction = new CompositeUndoableAction("Insert node");
-            var node:Node = controller.connection.createNode({}, lat, lon, undo.push);
+            var node:Node = selectedWay.connection.createNode({}, lat, lon, undo.push);
             var index:int = selectedWay.insertNodeAtClosestPosition(node, true, undo.push);
                        for each (w in ways) { w.insertNodeAtClosestPosition(node, true, undo.push); }
             MainUndoStack.getGlobalStack().addAction(undo);
@@ -59,7 +59,7 @@ package net.systemeD.potlatch2.controller {
                        return new SelectedWayNode(parentWay,draggingIndex);
                                } else if (event.shiftKey && !isNew) {
                                        // start new way
-                                       var way:Way = controller.connection.createWay({}, [entity],
+                                       var way:Way = entity.connection.createWay({}, [entity],
                                            MainUndoStack.getGlobalStack().addAction);
                                        return new DrawWay(way, true, false);
                                } else if (event.shiftKey && isNew) {
index 4fc5589001e25c61dca573095f08b6d4731c0384..a7dc400553bccc7622df2cd8118906a05a459624 100644 (file)
@@ -54,7 +54,7 @@ package net.systemeD.potlatch2.controller {
 
                override public function enterState():void {
                        controller.map.draggable=false;
-                       var conn:Connection=controller.connection;
+                       var conn:Connection=sourceNode.connection;
                        var undo:CompositeUndoableAction = new CompositeUndoableAction("Draw quadrilateral");
                        var cornerlon:Number =controller.map.coord2lon(controller.map.mouseX);
                        var cornerlat:Number =controller.map.coord2lat(controller.map.mouseY);
index d66f5e0a79dd6a151ba2174745cc6eb48c7dbf37..84a95497ddf3279a0e2873787da626587b709eee 100644 (file)
@@ -92,7 +92,7 @@ package net.systemeD.potlatch2.controller {
                                    var lat:Number = controller.map.coord2lat(event.localY);
                                    var lon:Number = controller.map.coord2lon(event.localX);
                                    var undo:CompositeUndoableAction = new CompositeUndoableAction("Insert node");
-                                   node = controller.connection.createNode({}, lat, lon, undo.push);
+                                   node = firstSelected.connection.createNode({}, lat, lon, undo.push);
                                    Way(firstSelected).insertNodeAtClosestPosition(node, true, undo.push);
                                                appendNode(node,undo.push);
                                    MainUndoStack.getGlobalStack().addAction(undo);
@@ -211,7 +211,7 @@ package net.systemeD.potlatch2.controller {
                    
                        var lat:Number = controller.map.coord2lat(event.localY);
                        var lon:Number = controller.map.coord2lon(event.localX);
-                       var node:Node = controller.connection.createNode({}, lat, lon, undo.push);
+                       var node:Node = firstSelected.connection.createNode({}, lat, lon, undo.push);
                        appendNode(node, undo.push);
                        
                        performAction(undo);
@@ -245,7 +245,7 @@ package net.systemeD.potlatch2.controller {
                        // Only actually delete the node if it has no other tags, and is not part of other ways (or part of this way twice)
                        if (node.numParentWays==1 && Way(firstSelected).hasOnceOnly(node) && !node.hasInterestingTags()) {
                                editableLayer.setPurgable([node], true);
-                               controller.connection.unregisterPOI(node);
+                               node.connection.unregisterPOI(node);
                                node.remove(undo.push);
                        }
 
index c65c6f2b1ade893351e0b2569bccc5c46434649b..5c5f8800b1ff42e4b513cb9509ce1e9c5fb20f5d 100644 (file)
@@ -26,11 +26,12 @@ package net.systemeD.potlatch2.controller {
                        if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING) {
                                map.dragstate=map.NOT_DRAGGING;
                                var undo:CompositeUndoableAction = new BeginWayAction();
-                               var startNode:Node = controller.connection.createNode(
+                               var conn:Connection = editableLayer.connection;
+                               var startNode:Node = conn.createNode(
                                        {}, 
                                        controller.map.coord2lat(event.localY),
                                        controller.map.coord2lon(event.localX), undo.push);
-                               var way:Way = controller.connection.createWay({}, [startNode], undo.push);
+                               var way:Way = conn.createWay({}, [startNode], undo.push);
                                MainUndoStack.getGlobalStack().addAction(undo);
                                return new DrawWay(way, true, false);
                        }
index 278759db6f1a5837014bf01e55d65fbd47a16001..2710dc9949814a07c904a2f844535ccd58fe80dd 100644 (file)
@@ -53,7 +53,7 @@ package net.systemeD.potlatch2.controller {
                }
 
                public function deletePOI():ControllerState {
-                       controller.connection.unregisterPOI(firstSelected as Node);
+                       firstSelected.connection.unregisterPOI(firstSelected as Node);
                        firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
                        return new NoSelection();
                }
index 50f02edeb522419370d55f86bf4d6c633510586e..a24ce7b90d421150139a111aa495d5f5e88cbfbd 100644 (file)
@@ -48,7 +48,7 @@ package net.systemeD.potlatch2.controller {
 
             if ( event.type == MouseEvent.MOUSE_UP && entity is Node && event.shiftKey ) {
                                // start new way
-                               var way:Way = controller.connection.createWay({}, [entity], MainUndoStack.getGlobalStack().addAction);
+                               var way:Way = entity.connection.createWay({}, [entity], MainUndoStack.getGlobalStack().addAction);
                                return new DrawWay(way, true, false);
                        } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==firstSelected && event.shiftKey) {
                                // insert node within way (shift-click)
index 77a050a6d272c957ddf2ae42b029d3290f357ed9..22e48029b7df830590ca7d268c1824507223d071 100644 (file)
@@ -49,7 +49,7 @@ package net.systemeD.potlatch2.controller {
 
             if ( event.type == MouseEvent.MOUSE_UP && entity is Node && event.shiftKey ) {
                                // start new way
-                var way:Way = controller.connection.createWay({}, [entity],
+                var way:Way = entity.connection.createWay({}, [entity],
                     MainUndoStack.getGlobalStack().addAction);
                 return new DrawWay(way, true, false);
                        } else if ( event.type == MouseEvent.MOUSE_UP && entity is Node && focus == parentWay ) {
@@ -180,7 +180,7 @@ package net.systemeD.potlatch2.controller {
             var q:Point = map.localToGlobal(p);
 
             // First, look for POI nodes in 20x20 pixel box around the current node
-            var hitnodes:Array = controller.connection.getObjectsByBbox(
+            var hitnodes:Array = editableLayer.connection.getObjectsByBbox(
                 map.coord2lon(p.x-10),
                 map.coord2lon(p.x+10),
                 map.coord2lat(p.y-10),
index 852c4b9488eee6e2eb12e9cd76902a1e3c4fb1e8..69b97026c700dec6e6b09345eb2476f3bd72b5d6 100644 (file)
@@ -30,8 +30,7 @@
        }
 
        public function addNewTurnRestriction():void {
-               var conn:Connection = Connection.getConnection();
-               var relation:Relation = conn.createRelation(
+               var relation:Relation = _entity.connection.createRelation(
                        { type: 'restriction' }, 
                        [ new RelationMember(_entity, 'via') ],
             MainUndoStack.getGlobalStack().addAction);
index 943a41c9c6080738697a9f9bf2e44e4c586c5ad1..f7cebe687d4e854192ae37ebc836847c98e3bdde 100644 (file)
@@ -63,6 +63,7 @@
     import net.systemeD.potlatch2.RelationEditorPanel;
     import net.systemeD.potlatch2.mapfeatures.*;
        import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.Globals;
     import flash.events.*;
     import mx.collections.ArrayCollection;
        }
        
        private function setHighlights(bool:Boolean):void {
-               var map:Map = Globals.vars.root;
-               var from:Object=findSelected('from'); if (from) { map.setHighlight(from.data, { restrictfrom: bool } ); }
-               var to:Object  =findSelected('to'  ); if (to  ) { map.setHighlight(to.data  , { restrictto: bool   } ); }
+               var paint:MapPaint = Map(Globals.vars.root).editableLayer;      // ** FIXME: should really be the mapPaint layer where the objects are located
+               var from:Object=findSelected('from'); if (from) { paint.setHighlight(from.data, { restrictfrom: bool } ); }
+               var to:Object  =findSelected('to'  ); if (to  ) { paint.setHighlight(to.data  , { restrictto: bool   } ); }
        }
     
     ]]></mx:Script>
index 350df9be9337b254c5657f1cfa0c056d8b0ce235..c01a542febb431b406d9c4e39e98af22e45ee5c7 100644 (file)
         
         private function getAuthText():String {
             return "To save data you must authorise this application to edit "+
-                    Connection.serverName + " on your behalf.";
+                    connection.serverName + " on your behalf.";
         }
         
+               public function setConnection(connection:Connection):void {
+                       this.connection=connection;
+               }
+
         private function openURL(url:String):void {
                        if (ExternalInterface.available) {
                                var winH:int = 560;
                }
         
         private function getRequestToken():void {
-            connection = Connection.getConnection();
-            
             var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
             var consumer:OAuthConsumer = getConsumer();
             var url:String = Connection.getParam("oauth_request_url", "http://127.0.0.1:3000/oauth/request_token");
             PopUpManager.removePopUp(this);
             
             _accessToken = getResponseToken(URLLoader(event.target));
-            Connection.getConnection().setAuthToken(_accessToken);
+            connection.setAuthToken(_accessToken);
             dispatchEvent(new Event(ACCESS_TOKEN_EVENT));
         }
         
index bc9ab3d56beed65c667d1602d06254e9fc791539..c2b95685b8d5fed04913726cfcd59932944941b4 100644 (file)
@@ -33,6 +33,7 @@ package net.systemeD.potlatch2.save {
             var oauthPanel:OAuthPanel = OAuthPanel(
                 PopUpManager.createPopUp(Application(Application.application), OAuthPanel, true));
             PopUpManager.centerPopUp(oauthPanel);
+                       oauthPanel.setConnection(_connection);
             
             var listener:Function = function(event:Event):void {
                 var accessToken:OAuthToken = oauthPanel.accessToken;
index 6a0cf9f479e72f2dcbb000f14b7f036267dccab5..88bf1e846c4655c50e9a85816059aed4ff577fe7 100644 (file)
@@ -163,7 +163,7 @@ package net.systemeD.potlatch2.tools {
                        var lon:Number = cx+Math.sin(ang*Math.PI/180)*d;
                        lats.splice(index, 0, lat);
                        lons.splice(index, 0, lon);
-                       var newNode:Node = map.connection.createNode({}, map.latp2lat(lat), lon, action.push);
+                       var newNode:Node = way.connection.createNode({}, map.latp2lat(lat), lon, action.push);
                        way.insertNode(index, newNode, action.push);
                }
        }