More refactoring in progress
authorRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 15:33:52 +0000 (16:33 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 15:33:52 +0000 (16:33 +0100)
28 files changed:
REFACTOR.txt
halcyon_viewer.as
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/VectorLayer.as
net/systemeD/halcyon/connection/AMFConnection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/OSMConnection.as
net/systemeD/halcyon/connection/Trace.as
net/systemeD/halcyon/connection/UndoableEntityAction.as
net/systemeD/halcyon/connection/XMLBaseConnection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/halcyon/connection/actions/CreatePOIAction.as
net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
net/systemeD/halcyon/connection/actions/DeleteWayAction.as
net/systemeD/halcyon/connection/actions/SplitWayAction.as
net/systemeD/halcyon/connection/actions/UnjoinNodeAction.as
net/systemeD/potlatch2/collections/Stylesheets.as
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/SelectedMultiple.as
net/systemeD/potlatch2/controller/SelectedWayNode.as
net/systemeD/potlatch2/save/SaveDialog.mxml
net/systemeD/potlatch2/save/SaveManager.as
net/systemeD/potlatch2/tools/Parallelise.as
net/systemeD/potlatch2/tools/Quadrilateralise.as
potlatch2.mxml

index 5334bde039437e16836156c83980cb60252e0138..a0747982f9cb365620b6cdd44cd4cc04fac72242 100644 (file)
@@ -4,14 +4,10 @@ Aims:
 - to enable multiple Maps to be shown on-screen (e.g. for junction editor)
 - to bring Connection and VectorLayer code together
 
-==== think what to do about controllers ====
-
-
 Map.as changes:
 becomes a collection of MapPaint objects, all with the same lat/long/scale
 (plus a backdrop sprite and a background imagery sprite)
 √ move listeners to Connection to MapPaint (e.g. new way created in the Connection - MapPaint should know about it, not Map)
-- refactor tileset/setbackground stuff?
 
 MapPaint.as changes:
 - gains a reference to a Connection - i.e. the source data for this layer
@@ -29,4 +25,10 @@ Global changes:
 - 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
-- move AttentionEvent stuff
+- 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
+
+Further refactoring probably needed:
+- move AttentionEvent stuff (some may be commented out)
+- Traces (e.g. in potlatch2.mxml) - seems a bit mixed up
+- refactor tileset/setbackground stuff?
index 3b01b9e919b8bcca8bb6c92743414c4a74ad5581..cbf3c914f9ac12dcc29ba1e70233568607b8187e 100644 (file)
@@ -69,7 +69,7 @@ package {
                }
 
                private function onRefreshCSS(str:String):void {
-                       theMap.setStyle(str);
+                       theMap.editableLayer.setStyle(str);
                }               
                private function onJumpTo(lat:Number,lon:Number):void {
                        theMap.init(lat,lon);
index d40011704a4e91260892bba90457725d9541e32f..c0fdd6997e88dc7b00f4b8bb7cda743fdb55dc4e 100644 (file)
@@ -76,8 +76,6 @@ package net.systemeD.halcyon {
                public var tileset:TileSet; 
                /** background tile URL, name and scheme */
                private var tileparams:Object={ url:'' }; 
-               /** internal style URL */
-               private var styleurl:String=''; 
                /** show all objects, even if unstyled? */
                public var showall:Boolean=true; 
                
@@ -228,7 +226,7 @@ package net.systemeD.halcyon {
                public function download():void {
                        this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
-                               paintContainer.getChildAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
+                               getLayerAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
                }
 
         // Handle mouse events on ways/nodes
@@ -248,19 +246,14 @@ package net.systemeD.halcyon {
                // Add layers
                
                public function addLayer(connection:Connection, styleurl:String, backgroundlayer:Boolean=true):void {
-                       var paint:MapPaint=new MapPaint(this,connection,-5,5);
+                       var paint:MapPaint=new MapPaint(this, connection, styleurl, -5, 5);
                        paintContainer.addChild(paint);
                        paint.isBackground=backgroundlayer;
-                       if (styleurl) {
-                               // if we've only just set up paint, then setStyle won't have created the RuleSet
-                               paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
-                               paint.ruleset.loadFromCSS(styleurl);
-                       }
                }
 
                public function removeLayerByName(name:String):void {
                        for (var i:uint=0; i<paintContainer.numChildren; i++) {
-                               if (paintContainer.getChildAt(i).connection.name==name)
+                               if (getLayerAt(i).connection.name==name)
                                        paintContainer.removeChildAt(i);
                                        // >>>> REFACTOR: needs to do the equivalent of VectorLayer.blank()
                        }
@@ -268,18 +261,21 @@ package net.systemeD.halcyon {
                
                public function findLayer(name:String):MapPaint {
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
-                               if (paintContainer.getChildAt(i).connection.name==name) return paintContainer.getChildAt(i);
+                               if (getLayerAt(i).connection.name==name) return getLayerAt(i);
                        return null;
                }
+
+               private function getLayerAt(i:uint):MapPaint {
+                       return MapPaint(paintContainer.getChildAt(i));
+               }
                
                /* Find which layer is editable */
                public function get editableLayer():MapPaint {
                        var editableLayer:MapPaint;
                        for (var i:uint=0; i<paintContainer.numChildren; i++) {
-                               layer=paintContainer.getChildAt(i);
-                               if (!layer.isBackground) {
+                               if (!getLayerAt(i).isBackground) {
                                        if (editableLayer) trace("Multiple editable layers found");
-                                       editableLayer=layer;
+                                       editableLayer=getLayerAt(i);
                                }
                        }
                        return editableLayer;
@@ -290,15 +286,15 @@ package net.systemeD.halcyon {
                
                private function updateAllEntityUIs(redraw:Boolean,remove:Boolean):void {
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
-                               paintContainer.getChildAt(i).updateEntityUIs(redraw, remove);
+                               getLayerAt(i).updateEntityUIs(redraw, remove);
                }
                public function redraw():void {
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
-                               paintContainer.getChildAt(i).redraw();
+                               getLayerAt(i).redraw();
                }
                public function redrawPOIs():void { 
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
-                               paintContainer.getChildAt(i).redrawPOIs();
+                               getLayerAt(i).redrawPOIs();
                }
                
                public function zoomIn():void {
@@ -319,15 +315,6 @@ package net.systemeD.halcyon {
                        download();
                }
 
-               /** Switch to new MapCSS. */
-               public function setStyle(url:String):void {
-                       styleurl=url;
-                       if (paint) { 
-                               paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
-                               paint.ruleset.loadFromCSS(url);
-                       }
-        }
-
                /** Select a new background imagery. */
                public function setBackground(bg:Object):void {
                        tileparams=bg;
index e3a90bc3a7fa9e746d0e78a133ccf4528aec0918..5afeae10942a0c25ab4782ff1c1705a0baa3d05d 100644 (file)
@@ -49,7 +49,7 @@ package net.systemeD.halcyon {
                 * @param minlayer The lowest OSM layer to display.
                 * @param maxlayer The highest OSM layer to display.
                 * */ 
-               public function MapPaint(map:Map,connection:Connection,minlayer:int,maxlayer:int) {
+               public function MapPaint(map:Map, connection:Connection, styleurl:String, minlayer:int, maxlayer:int) {
                        mouseEnabled=false;
 
                        this.map=map;
@@ -59,6 +59,10 @@ package net.systemeD.halcyon {
                        sublayerIndex[1]=0;
                        var s:Sprite, l:int;
 
+                       // Set up stylesheet
+                       ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
+                       ruleset.loadFromCSS(styleurl);
+
                        // Listen for changes on this Connection
             connection.addEventListener(Connection.NEW_WAY, newWayCreatedListener);
             connection.addEventListener(Connection.NEW_POI, newPOICreatedListener);
@@ -335,6 +339,12 @@ package net.systemeD.halcyon {
             for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
                }
                
+               /** Switch to new MapCSS. */
+               public function setStyle(url:String):void {
+                       ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
+                       ruleset.loadFromCSS(url);
+        }
+
                // >>>> REFACTOR: remove this
                public function findSource():VectorLayer {
                        var v:VectorLayer;
index 644b39f47c53f3c922ead6905e825bae7cfb6645..4631b0e4fe9119ff3883e04883fe161cd08b0c70 100644 (file)
@@ -170,7 +170,7 @@ package net.systemeD.halcyon {
                                oldNode=Node(entity);
                                unregisterPOI(oldNode);
                                var newPoiAction:CreatePOIAction = new CreatePOIAction(
-                                       oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
+                                       this, oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
                                MainUndoStack.getGlobalStack().addAction(newPoiAction);
                                paint.deleteNodeUI(oldNode);
                                delete nodes[oldNode.id];
index 3a21b00477a310a3f2f19ae49b5cedae9973ad66..d015232837eed373a61c2e29343ffc0c3074d0c1 100644 (file)
@@ -28,8 +28,7 @@ package net.systemeD.halcyon.connection {
                public function AMFConnection(name:String,api:String,policy:String,initparams:Object) {
 
                        super(name,api,policy,initparams);
-                       if (Connection.policyURL!='')
-                Security.loadPolicyFile(Connection.policyURL);
+                       if (policyURL!='') Security.loadPolicyFile(policyURL);
 
                        readConnection=new NetConnection();
                        readConnection.objectEncoding = flash.net.ObjectEncoding.AMF0;
index fc297f8a45e359faabeb9f279315168f86a5720a..87512499bfc3608592aeb66d9a2a76a0748f9ac8 100644 (file)
@@ -202,9 +202,9 @@ package net.systemeD.halcyon.connection {
             if (this is Node) {
                 var n:Node = Node(this);
                 if (isDeleted) {
-                    Connection.getConnection().removeDupe(n);
+                    connection.removeDupe(n);
                 } else {
-                    Connection.getConnection().addDupe(n);
+                    connection.addDupe(n);
                 }
             }
         }
index cd3d52696d1446f570038dcc014dff66b0590252..f3bc8d9971c70ea6939621e8d58a2d305cf4cfef 100644 (file)
@@ -31,7 +31,6 @@ package net.systemeD.halcyon.connection {
         }
 
         private function setLatLonImmediate(lat:Number, lon:Number):void {
-            var connection:Connection = Connection.getConnection();
             connection.removeDupe(this);
             this._lat = lat;
             this._latproj = lat2latp(lat);
@@ -89,7 +88,6 @@ package net.systemeD.halcyon.connection {
         */
         public function join(ways:Array, performAction:Function):void {
             if (this.isDupe() || ways.length > 0) {
-              var connection:Connection = Connection.getConnection();
               var nodes:Array = connection.getNodesAtPosition(lat,lon);
               // filter the nodes array to remove any occurances of this.
               // Pass "this" as thisObject to get "this" into the callback function
@@ -111,7 +109,6 @@ package net.systemeD.halcyon.connection {
         }
 
         public function isDupe():Boolean {
-            var connection:Connection = Connection.getConnection();
             if (connection.getNode(this.id) == this // node could be part of a vector layer
                 && connection.nodesAtPosition(lat, lon) > 1) {
               return true;
index 794e96dbf50348d6aba5de40108e53b5d575c21c..79774aa419af9330f396e22f97913466719ee38c 100644 (file)
@@ -47,13 +47,12 @@ package net.systemeD.halcyon.connection {
                public function OSMConnection(name:String,api:String,policy:String,initparams:Object) {
 
                        super(name,api,policy,initparams);
-                       if (Connection.policyURL!='')
-                Security.loadPolicyFile(Connection.policyURL);
+                       if (policyURL!='') Security.loadPolicyFile(policyURL);
 
-            tileResolution = Number(Connection.getParam("tile_resolution", "0.2"));
+            tileResolution = Number(getParam("tile_resolution", "0.2"));
 
                        var o:Object = new Object();
-                       var files:String = Connection.getParam("files","");
+                       var files:String = getParam("files","");
                        if (files=="") {
                                filemode=TILED;
                        } else {
index 17bb5725b8a2a121d222beda149b5013c4a704a2..4c7597e7ed58cd67147eeca406b8710e45b96a05 100644 (file)
@@ -23,12 +23,14 @@ package net.systemeD.halcyon.connection {
         private var _filename:String;
         private var _traceData:String;
         private var map:Map;
+        private var _connection:Connection;
         private var _layer:VectorLayer;
         private var simplify:Boolean = false;
 
         private static const STYLESHEET:String="stylesheets/gpx.css";
 
-        public function Trace() {
+        public function Trace(connection:Connection) {
+                       _connection = connection;
             map = Globals.vars.root;
         }
 
@@ -61,7 +63,7 @@ package net.systemeD.halcyon.connection {
 
         private function fetchFromServer():void {
             // todo - needs proper error handling
-            Connection.getConnection().fetchTrace(id, saveTraceData);
+            _connection.fetchTrace(id, saveTraceData);
             dispatchEvent(new Event("loading_data"));
         }
 
index c8f5f32a3cdb10b95d305ac509818777bcb78d56..d6b784f8f606292628763f0591569cf570029256 100644 (file)
@@ -36,7 +36,7 @@ package net.systemeD.halcyon.connection {
             }
 
             if ( !connectionWasDirty ) {
-              Connection.getConnection().markDirty();
+              entity.connection.markDirty();
             }
         }
 
@@ -52,7 +52,7 @@ package net.systemeD.halcyon.connection {
             }
 
             if ( !connectionWasDirty ) {
-              Connection.getConnection().markClean();
+              entity.connection.markClean();
             }
         }
 
@@ -62,7 +62,7 @@ package net.systemeD.halcyon.connection {
         */
         private function init():void {
             wasDirty = entity.isDirty;
-            connectionWasDirty = Connection.getConnection().isDirty;
+            connectionWasDirty = entity.connection.isDirty;
             initialised = true;
         }
             
index 19e0032d3a698383bf7e450bf7becedbcaf212f5..65b9f2586e3c77333618dc210a11aff83929185d 100644 (file)
@@ -13,7 +13,8 @@ package net.systemeD.halcyon.connection {
     */
        public class XMLBaseConnection extends Connection {
 
-               public function XMLBaseConnection() {
+               public function XMLBaseConnection(name:String,api:String,policy:String,initparams:Object) {
+                       super(name,api,policy,initparams);
                }
                
         protected function loadedMap(event:Event):void {
index 12c6c4a9bd18254f073d718ab3b30574069ee64c..4f72b73738861ef25f3061cf19e33ed870b3a7de 100644 (file)
@@ -19,12 +19,10 @@ package net.systemeD.halcyon.connection {
                public function XMLConnection(name:String,api:String,policy:String,initparams:Object) {
 
                        super(name,api,policy,initparams);
-                       if (Connection.policyURL!='')
-                Security.loadPolicyFile(Connection.policyURL);
-            var oauthPolicy:String = Connection.getParam("oauth_policy", "");
-            if ( oauthPolicy != "" ) {
-                Security.loadPolicyFile(oauthPolicy);
-            }
+                       if (policyURL != "") Security.loadPolicyFile(policyURL);
+
+            var oauthPolicy:String = getParam("oauth_policy", "");
+            if (oauthPolicy != "") Security.loadPolicyFile(oauthPolicy);
                }
                
                override public function loadBbox(left:Number,right:Number,
@@ -441,7 +439,7 @@ package net.systemeD.halcyon.connection {
             clearTraces();
             var files:XML = new XML(URLLoader(event.target).data);
             for each(var traceData:XML in files.gpx_file) {
-              var t:Trace = new Trace().fromXML(traceData);
+              var t:Trace = new Trace(this).fromXML(traceData);
               addTrace(t);
             }
             traces_loaded = true;
index 99d0b58da8d32ef764b96d5683aae41e55906c9f..42a35fbf54985e9cc208f26351bb1913005de516 100644 (file)
@@ -10,9 +10,11 @@ package net.systemeD.halcyon.connection.actions {
                private var tags:Object;
                private var lat:Number;
                private var lon:Number;
+               private var connection:Connection;
         
-        public function CreatePOIAction(tags:Object, lat:Number, lon:Number) {
+        public function CreatePOIAction(connection:Connection, tags:Object, lat:Number, lon:Number) {
           super("Create POI");
+          this.connection = connection;
           this.tags = tags;
           this.lat = lat;
           this.lon = lon;
@@ -20,17 +22,17 @@ package net.systemeD.halcyon.connection.actions {
         
         public override function doAction():uint {
           if (newNode == null) {
-            newNode = Connection.getConnection().createNode(tags,lat,lon,push);
+            newNode = connection.createNode(tags,lat,lon,push);
           }
           super.doAction();
-          Connection.getConnection().registerPOI(newNode);
+          connection.registerPOI(newNode);
           
           return SUCCESS;
         }
         
         public override function undoAction():uint {
           super.undoAction();
-          Connection.getConnection().unregisterPOI(newNode);
+          connection.unregisterPOI(newNode);
           
           return SUCCESS;
         }
index b5bebfa4e956629c2bf2510da501e8fe0f8c7640..beda1c7fc5b5a9b4169c1ee0cd99b5ad7c663f17 100644 (file)
@@ -49,7 +49,7 @@ package net.systemeD.halcyon.connection.actions {
             } else {
               markClean();
             }
-            Connection.getConnection().dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
+            node.connection.dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
             if ( effects != null )
                 effects.undoAction();
             return SUCCESS;
index 3ed4e856f332d3de1b6e875167bc8d73b0f551d9..331826a8472e9e7b2d98233f1cff687fd9ea0939 100644 (file)
@@ -56,7 +56,7 @@ package net.systemeD.halcyon.connection.actions {
             } else {
               markClean();
             }
-            Connection.getConnection().dispatchEvent(new EntityEvent(Connection.NEW_WAY, way));
+            entity.connection.dispatchEvent(new EntityEvent(Connection.NEW_WAY, way));
             effects.undoAction();
             for each(var node:Node in oldNodeList) {
                 nodeList.push(node);
index b79efbdf317ff385c30305c636d714aae1b993b0..d88ddaee16c738f8a543904482b97ef2df9ce7f1 100644 (file)
@@ -16,7 +16,7 @@ package net.systemeD.halcyon.connection.actions {
     
         public override function doAction():uint {
             if (newWay==null) {
-                               newWay = Connection.getConnection().createWay(
+                               newWay = selectedWay.connection.createWay(
                                        selectedWay.getTagsCopy(), 
                                        selectedWay.sliceNodes(nodeIndex,selectedWay.length),
                                        push);
index a9e14e84c44dfa54b78982c8b29f4bd2190a5d0b..f6abba57f45af4e62b4f1c2e788d764fb1b3804b 100644 (file)
@@ -25,7 +25,7 @@ package net.systemeD.halcyon.connection.actions {
                way.dispatchEvent(new EntityEvent(Connection.WAY_REORDERED, way));      // no longer a junction, so force redraw
                 continue;
               } else {
-                var newNode:Node = Connection.getConnection().createNode(node.getTagsCopy(), node.lat, node.lon, push);
+                var newNode:Node = way.connection.createNode(node.getTagsCopy(), node.lat, node.lon, push);
                 for (var i:int = 0; i < way.length; i++) {
                   if(way.getNode(i) == node) {
                     way.removeNodeByIndex(i, push);
index cc6db63de9bf92fe54c4117b61cd2c2ea879a285..f10d079f9fb0824478585de49a77021ab1fa1b29 100644 (file)
@@ -74,7 +74,8 @@ package net.systemeD.potlatch2.collections {
                }
 
                public function setStylesheet(name:String,url:String):void {
-                       _map.setStyle(url);
+                       _map.editableLayer.setStyle(url);
+                       // >>>> REFACTOR: not great to have a reference to editableLayer in here
                        var obj:SharedObject = SharedObject.getLocal("user_state");
                        obj.setProperty("stylesheet_url",url);
                        obj.setProperty("stylesheet_name",name);
index 4788e7f81fb0eba1a97807821037c0bbf3c684cc..94c62f7902d933901981c6b777de1fd88207ce85 100644 (file)
@@ -67,7 +67,7 @@ package net.systemeD.potlatch2.controller {
                                case 66:        setSourceTag(); break;                                                                                                  // B - set source tag for current object
                                case 67:        controller.connection.closeChangeset(); break;                                                  // C - close changeset
                                case 68:        editableLayer.alpha=1.3-editableLayer.alpha; return null;                               // D - dim
-                               case 83:        SaveManager.saveChanges(); break;                                                                               // S - save
+                               case 83:        SaveManager.saveChanges(controller.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                                           
index 21aef75fcecd4fe4b4fa7f497279aeaf4f917f84..d66f5e0a79dd6a151ba2174745cc6eb48c7dbf37 100644 (file)
@@ -56,6 +56,7 @@ package net.systemeD.potlatch2.controller {
                             MainUndoStack.getGlobalStack().undo(); // undo the BeginWayAction that (presumably?) just happened
                             
                             var newPoiAction:CreatePOIAction = new CreatePOIAction(
+                                                               editableLayer.connection,
                                                                {},
                                                                controller.map.coord2lat(event.localY),
                                                                controller.map.coord2lon(event.localX));
index 260157714f4b08365c4a8d9c4b2be5d866fbf4e0..3feb114beca8ca46843758e9f446bc245ddcb0bc 100644 (file)
@@ -64,7 +64,7 @@ package net.systemeD.potlatch2.controller {
                 for each (var conflict:String in conflictTags) conflictTags2.push(conflict);
                 if (conflictTags2.length>0)
                     msg += " *Warning* The following tags conflicted and need attention: " + conflictTags2;
-                map.connection.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
+                // >>>> somethingorother.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
             }
 
                        return controller.findStateForSelection(waylist);
index 5bb16b00b6097a49d7aecf2edc466467e28afa03..77a050a6d272c957ddf2ae42b029d3290f357ed9 100644 (file)
@@ -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 = map.connection.getObjectsByBbox(
+            var hitnodes:Array = controller.connection.getObjectsByBbox(
                 map.coord2lon(p.x-10),
                 map.coord2lon(p.x+10),
                 map.coord2lat(p.y-10),
@@ -221,7 +221,7 @@ package net.systemeD.potlatch2.controller {
             if (MergeNodesAction.lastProblemTags) {
                 msg += " *Warning* The following tags conflicted and need attention: " + MergeNodesAction.lastProblemTags;
             }
-            map.connection.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
+            // somethingorother.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, msg));
             return new SelectedWayNode(n.parentWays[0], Way(n.parentWays[0]).indexOfNode(n));
         }
         
index ae3e60f633c34be60d69d9a7c8e785f852e86855..4d87dd1395bc58177bbe817267d8d2f25f8031ca 100644 (file)
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.halcyon.AttentionEvent;
     
-    private var conn:Connection = Connection.getConnection();
+    private var _connection:Connection;
        private var doSkip:Boolean = false;
     
     [Bindable]
     private var failureText:String = "";
 
+       public function setConnection(connection:Connection):void {
+               _connection=connection;
+       }
+
        public function dontPrompt():void {
                if (processSequence.initialized) { skipInput(); } else { doSkip=true; }
        }
         }
         
         // add the listeners
-        conn.addEventListener(Connection.NEW_CHANGESET, changesetCreated);
-        conn.addEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
-        conn.createChangeset(tags);
+        _connection.addEventListener(Connection.NEW_CHANGESET, changesetCreated);
+        _connection.addEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
+        _connection.createChangeset(tags);
     }
 
     private function allowForEdit(event:DataGridEvent):void {
     }
 
     private function changesetCreated(event:EntityEvent=null):void {
-        var changeset:Changeset = conn.getActiveChangeset();
+        var changeset:Changeset = _connection.getActiveChangeset();
         addStatus("Saving to changeset "+changeset.id);
         
         saveProgress.label = "Uploading changes";
-        conn.addEventListener(Connection.SAVE_COMPLETED, saveCompleted);
-        conn.uploadChanges();
+        _connection.addEventListener(Connection.SAVE_COMPLETED, saveCompleted);
+        _connection.uploadChanges();
     }
     
     private function changesetError(event:Event):void {
     
     private function saveCompleted(event:SaveCompleteEvent):void {
         if ( event.saveOK ) {
-                       conn.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Changes successfully saved"));
+                       _connection.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Changes successfully saved"));
             close();
         } else {
             fail("Failure when uploading data");
     }
     
     private function close():void {
-        conn.removeEventListener(Connection.NEW_CHANGESET, changesetCreated);
-        conn.removeEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
-        conn.removeEventListener(Connection.SAVE_COMPLETED, saveCompleted);
+        _connection.removeEventListener(Connection.NEW_CHANGESET, changesetCreated);
+        _connection.removeEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
+        _connection.removeEventListener(Connection.SAVE_COMPLETED, saveCompleted);
         PopUpManager.removePopUp(this);
     }
   ]]></mx:Script>
index e5cd2339a116ff17017ac92990a9496bbcb3090f..bc9ab3d56beed65c667d1602d06254e9fc791539 100644 (file)
@@ -10,18 +10,19 @@ package net.systemeD.potlatch2.save {
     public class SaveManager {
     
         private static var instance:SaveManager = new SaveManager();
+               private var _connection:Connection;
 
-        public static function saveChanges():void {
-            instance.save(instance.saveData);
+        public static function saveChanges(connection:Connection):void {
+            instance.save(instance.saveData,connection);
         }
 
-        public static function ensureAccess(callback:Function):void {
-            instance.save(callback);
+        public static function ensureAccess(callback:Function, connection:Connection):void {
+            instance.save(callback,connection);
         }
 
-        private function save(callback:Function):void {
-            var conn:Connection = Connection.getConnection();
-            if (conn.hasAccessToken()) {
+        private function save(callback:Function, connection:Connection):void {
+                       _connection=connection;
+            if (connection.hasAccessToken()) {
                 callback();
             } else {
                 getNewToken(callback);
@@ -49,11 +50,10 @@ package net.systemeD.potlatch2.save {
         private function saveData():void {
             var saveDialog:SaveDialog = SaveDialog(
                 PopUpManager.createPopUp(Application(Application.application), SaveDialog, true));
+                       saveDialog.setConnection(_connection);
             PopUpManager.centerPopUp(saveDialog);
 
-                       if (Connection.getConnection().getActiveChangeset()) {
-                               saveDialog.dontPrompt();
-                       }
+                       if (_connection.getActiveChangeset()) saveDialog.dontPrompt();
         }
     }
     
index ed49b96871f91302f157ef9b529aaab42102bfd0..6f231294464383c741b150c6c45fe50e18f2d5e2 100644 (file)
@@ -20,7 +20,7 @@ package net.systemeD.potlatch2.tools {
                 * */
                public function Parallelise(way:Way) {
                        var a:Number, b:Number, h:Number, i:uint, j:uint, k:int;
-                       connection  = Connection.getConnection();
+                       connection  = way.connection;
                        originalWay = way;
                        parallelWay = connection.createWay({}, [], MainUndoStack.getGlobalStack().addAction);
 
index b050fc47d9a2e747bcfec1a33d34d842a64d46a0..9f11e07f3e109bf1a17bcf9224cf0c4925d9741b 100644 (file)
@@ -29,7 +29,7 @@ package net.systemeD.potlatch2.tools {
         functor.step();
         var newScore:Number = functor.goodness;
         if (newScore > score) {
-          Connection.getConnection().dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Corners too sharp to straighten"));
+          // somethingorother.dispatchEvent(new AttentionEvent(AttentionEvent.ALERT, null, "Corners too sharp to straighten"));
           return false;
            }
         score = newScore;
index 94f364ce19b74e5b449744f75bd79dc5ad3c066a..133c5f4011fb1769fa895b170a3d86512f0d8e47 100644 (file)
@@ -56,7 +56,7 @@
         <mx:Button id="helpButton" label="Help" click="new HelpDialog().init();" styleName="appBarButton" />
         <mx:Button id="optionsButton" label="Options" click="new OptionsDialog().init();" styleName="appBarButton" />
         <mx:Button label="Save" icon="@Embed('embedded/upload.svg')" disabledIcon="@Embed('embedded/upload_disabled.svg')" styleName="appBarButton"
-                       click="SaveManager.saveChanges();" id="saveButton" enabled="false"/>
+                       click="SaveManager.saveChanges(theMap.editableLayer.connection);" id="saveButton" enabled="false"/>
     </mx:ApplicationControlBar>
     
     <mx:HDividedBox width="100%" height="100%">
             
             var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI");
             
-            var node:Node = Connection.getConnection().createNode({}, lat, lon, createAction.push);
+                       var conn:Connection = theMap.editableLayer.connection;
+            var node:Node = conn.createNode({}, lat, lon, createAction.push);
             for each ( var tag:Object in tags ) {
                 node.setTag(tag.k, tag.v, createAction.push);
             }
-                       Connection.getConnection().registerPOI(node);
+                       conn.registerPOI(node);
                        MainUndoStack.getGlobalStack().addAction(createAction);
             theController.setState(new SelectedPOINode(node));
         }
         }
 
         private function loadTrace(id:Number):void {
-            var conn:Connection = Connection.getConnection();
+            var conn:Connection = theMap.editableLayer.connection;
             conn.addEventListener(Connection.TRACES_LOADED, function (e:Event):void {
                 for each (var trace:Trace in conn.getTraces()) {
                     if (trace.id == id) { trace.addToMap(); }