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 5334bde..a074798 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 3b01b9e..cbf3c91 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 d400117..c0fdd69 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 e3a90bc..5afeae1 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 644b39f..4631b0e 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 3a21b00..d015232 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 fc297f8..8751249 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 cd3d526..f3bc8d9 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 794e96d..79774aa 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 17bb572..4c7597e 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 c8f5f32..d6b784f 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 19e0032..65b9f25 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 12c6c4a..4f72b73 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 99d0b58..42a35fb 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 b5bebfa..beda1c7 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 3ed4e85..331826a 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 b79efbd..d88ddae 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 a9e14e8..f6abba5 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 cc6db63..f10d079 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 4788e7f..94c62f7 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 21aef75..d66f5e0 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 2601577..3feb114 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 5bb16b0..77a050a 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 ae3e60f..4d87dd1 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 e5cd233..bc9ab3d 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 ed49b96..6f23129 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 b050fc4..9f11e07 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 94f364c..133c5f4 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(); }