From 114ce034f2762c9ecc6b9c7b3597e9da66abcec5 Mon Sep 17 00:00:00 2001 From: Dave Stubbs Date: Sun, 26 Jul 2009 15:59:00 +0000 Subject: [PATCH] add a feature selector to the simple view --- net/systemeD/halcyon/CategorySelector.mxml | 50 +++++++++++++ net/systemeD/halcyon/TagViewer.mxml | 69 +++++++++++------ net/systemeD/halcyon/connection/Entity.as | 22 +++++- net/systemeD/halcyon/mapfeatures/Category.as | 40 ++++++++++ net/systemeD/halcyon/mapfeatures/Feature.as | 75 +++++++++++++++++++ .../halcyon/mapfeatures/MapFeatures.as | 41 ++++++++-- resources/map_features.xml | 53 ++++++++++--- 7 files changed, 310 insertions(+), 40 deletions(-) create mode 100644 net/systemeD/halcyon/CategorySelector.mxml create mode 100644 net/systemeD/halcyon/mapfeatures/Category.as create mode 100644 net/systemeD/halcyon/mapfeatures/Feature.as diff --git a/net/systemeD/halcyon/CategorySelector.mxml b/net/systemeD/halcyon/CategorySelector.mxml new file mode 100644 index 00000000..4957b351 --- /dev/null +++ b/net/systemeD/halcyon/CategorySelector.mxml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net/systemeD/halcyon/TagViewer.mxml b/net/systemeD/halcyon/TagViewer.mxml index da789ed5..e185ae32 100644 --- a/net/systemeD/halcyon/TagViewer.mxml +++ b/net/systemeD/halcyon/TagViewer.mxml @@ -6,11 +6,13 @@ creationComplete="loadFeatures()"> - - + + + + @@ -41,12 +43,18 @@ import net.systemeD.halcyon.connection.*; import net.systemeD.halcyon.mapfeatures.*; - import mx.collections.* - + import mx.collections.*; + import mx.containers.*; + import mx.events.*; + import mx.core.*; + import mx.managers.PopUpManager; + import flash.geom.Point; + private var mapFeatures:MapFeatures; private var selectedEntity:Entity; - private var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g; private var collection:ArrayCollection; + private var tw:CategorySelector = null; + private var feature:Feature = null; public function setEntity(entity:Entity):void { if ( selectedEntity != entity ) { @@ -63,31 +71,21 @@ } private function refreshFeatureIcon():void { - var feature:XML = mapFeatures.findMatchingFeature(selectedEntity); + feature = mapFeatures.findMatchingFeature(selectedEntity); if ( feature != null ) setFeatureIcon(selectedEntity, feature); else blankFeatureIcon(selectedEntity); } - private function setFeatureIcon(entity:Entity, feature:XML):void { + private function setFeatureIcon(entity:Entity, feature:Feature):void { blankFeatureIcon(entity); + + iconImage.source = feature.image; - var icon:XMLList = feature.icon; - if ( icon.length == 0 ) - return; - - if ( icon[0].hasOwnProperty("@image") ) { - iconImage.source = icon.@image; - } - - var txt:String = icon.children().toXMLString(); - var replaceTag:Function = function():String { - var value:String = entity.getTag(arguments[1]); - return value == null ? "" : value; - }; - txt = txt.replace(variablesPattern, replaceTag); - iconText.htmlText = ""+feature.@name+"
" + txt; + var txt:String = feature.htmlDetails(entity); + iconText.htmlText = txt; + popupChange.label = feature.name; } private function blankFeatureIcon(entity:Entity):void { @@ -95,6 +93,7 @@ iconText.htmlText = entity == null ? "Nothing selected" : "Not recognised
Try looking at the tags under the advanced properties"; + popupChange.label = "unknown"; } private function checkAdvanced():void { @@ -169,6 +168,32 @@ var k:String = advancedTagGrid.selectedItem.key; selectedEntity.setTag(k, null); } + + public function initFeatureBox():void { + tw = new CategorySelector(); + tw.addEventListener("selectedType", changeFeatureType); + popupChange.popUp = tw; + } + + public function changeFeatureType(event:Event):void { + if ( selectedEntity == null ) + return; + + // remove tags from the current feature + if ( feature != null ) { + for each( var tag:Object in feature.tags ) { + selectedEntity.setTag(tag["k"], null); + } + } + + // set tags for new feature + for each( var tag:Object in tw.selectedType.tags ) { + selectedEntity.setTag(tag["k"], tag["v"]); + } + + trace("w000t "+tw.selectedType); + popupChange.close(); + } ]]> diff --git a/net/systemeD/halcyon/connection/Entity.as b/net/systemeD/halcyon/connection/Entity.as index cb6b7428..b8204b1c 100644 --- a/net/systemeD/halcyon/connection/Entity.as +++ b/net/systemeD/halcyon/connection/Entity.as @@ -6,11 +6,13 @@ package net.systemeD.halcyon.connection { private var _id:Number; private var _version:uint; private var tags:Object = {}; + private var modified:Boolean = false; public function Entity(id:Number, version:uint, tags:Object) { this._id = id; this._version = version; this.tags = tags; + modified = id < 0; } public function get id():Number { @@ -38,6 +40,7 @@ package net.systemeD.halcyon.connection { delete tags[key]; else tags[key] = value; + modified = true; dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, key, key, old, value)); } } @@ -47,6 +50,7 @@ package net.systemeD.halcyon.connection { if ( oldKey != newKey ) { delete tags[oldKey]; tags[newKey] = value; + modified = true; dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, oldKey, newKey, value, value)); } } @@ -69,9 +73,21 @@ package net.systemeD.halcyon.connection { return copy; } - public function getType():String { - return ''; - } + public function get isDirty():Boolean { + return modified; + } + + public function markClean():void { + modified = false; + } + + protected function markDirty():void { + modified = true; + } + + public function getType():String { + return ''; + } } diff --git a/net/systemeD/halcyon/mapfeatures/Category.as b/net/systemeD/halcyon/mapfeatures/Category.as new file mode 100644 index 00000000..14d0d28c --- /dev/null +++ b/net/systemeD/halcyon/mapfeatures/Category.as @@ -0,0 +1,40 @@ +package net.systemeD.halcyon.mapfeatures { + + import flash.events.EventDispatcher; + import flash.events.Event; + + public class Category extends EventDispatcher { + private var mapFeatures:MapFeatures; + private var _name:String; + private var _id:String; + private var _features:Array; + + public function Category(mapFeatures:MapFeatures, name:String, id:String) { + this.mapFeatures = mapFeatures; + this._name = name; + this._id = id; + + _features = new Array(); + for each( var feature:Feature in mapFeatures.features ) { + if ( feature.isInCategory(id) ) + _features.push(feature); + } + } + + public function get id():String { + return _id; + } + + [Bindable(event="categoryChange")] + public function get name():String { + return _name; + } + + [Bindable(event="featuresChanged")] + public function get features():Array { + return _features; + } + } +} + + diff --git a/net/systemeD/halcyon/mapfeatures/Feature.as b/net/systemeD/halcyon/mapfeatures/Feature.as new file mode 100644 index 00000000..abc3bde3 --- /dev/null +++ b/net/systemeD/halcyon/mapfeatures/Feature.as @@ -0,0 +1,75 @@ +package net.systemeD.halcyon.mapfeatures { + + import flash.events.EventDispatcher; + import flash.events.Event; + import net.systemeD.halcyon.connection.Entity; + + public class Feature extends EventDispatcher { + private var mapFeatures:MapFeatures; + private var _xml:XML; + private static var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g; + private var _tags:Array; + + public function Feature(_xml:XML) { + this._xml = _xml; + _tags = new Array(); + + for each(var tag:XML in definition.tag) { + var tagObj:Object = new Object(); + tagObj["k"] = tag.@k; + tagObj["v"] = tag.@v; + _tags.push(tagObj); + } + + } + + public function get definition():XML { + return _xml; + } + + [Bindable(event="nameChanged")] + public function get name():String { + return _xml.@name; + } + + [Bindable(event="imageChanged")] + public function get image():String { + var icon:XMLList = _xml.icon; + + if ( icon.length() > 0 && icon[0].hasOwnProperty("@image") ) + return icon[0].@image; + else + return null; + } + + public function htmlDetails(entity:Entity):String { + var icon:XMLList = _xml.icon; + if ( icon == null ) + return ""; + + var txt:String = icon.children().toXMLString(); + var replaceTag:Function = function():String { + var value:String = entity.getTag(arguments[1]); + return value == null ? "" : value; + }; + txt = txt.replace(variablesPattern, replaceTag); + return txt; + } + + public function isInCategory(category:String):Boolean { + var cats:XMLList = _xml.category; + if ( cats.length() == 0 ) + return false; + + for each( var cat:XML in cats ) + if ( cat.text()[0] == category ) + return true; + return false; + } + + public function get tags():Array { + return _tags; + } + } +} + diff --git a/net/systemeD/halcyon/mapfeatures/MapFeatures.as b/net/systemeD/halcyon/mapfeatures/MapFeatures.as index 82b114cb..42859ccd 100644 --- a/net/systemeD/halcyon/mapfeatures/MapFeatures.as +++ b/net/systemeD/halcyon/mapfeatures/MapFeatures.as @@ -1,5 +1,6 @@ package net.systemeD.halcyon.mapfeatures { + import flash.events.EventDispatcher; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; @@ -10,7 +11,7 @@ package net.systemeD.halcyon.mapfeatures { import net.systemeD.halcyon.connection.*; - public class MapFeatures { + public class MapFeatures extends EventDispatcher { private static var instance:MapFeatures; public static function getInstance():MapFeatures { @@ -24,6 +25,8 @@ package net.systemeD.halcyon.mapfeatures { private var xml:XML = null; + private var _features:Array = null; + private var _categories:Array = null; protected function loadFeatures():void { var request:URLRequest = new URLRequest("map_features.xml"); @@ -34,22 +37,33 @@ package net.systemeD.halcyon.mapfeatures { private function onFeatureLoad(event:Event):void { xml = new XML(URLLoader(event.target).data); + + _features = new Array(); + for each(var feature:XML in xml.feature) { + _features.push(new Feature(feature)); + } + _categories = new Array(); + for each(var catXML:XML in xml.category) { + if ( catXML.child("category").length() == 0 ) + _categories.push(new Category(this, catXML.@name, catXML.@id)); + } + dispatchEvent(new Event("featuresLoaded")); } public function hasLoaded():Boolean { return xml != null; } - public function findMatchingFeature(entity:Entity):XML { + public function findMatchingFeature(entity:Entity):Feature { if ( xml == null ) return null; - for each(var feature:XML in xml.feature) { + for each(var feature:Feature in features) { // check for matching tags var match:Boolean = true; - for each(var tag:XML in feature.tag) { - var entityTag:String = entity.getTag(tag.@k); - match = entityTag == tag.@v || (entityTag != null && tag.@v == "*"); + for each(var tag:Object in feature.tags) { + var entityTag:String = entity.getTag(tag.k); + match = entityTag == tag.v || (entityTag != null && tag.v == "*"); if ( !match ) break; } if ( match ) @@ -57,6 +71,21 @@ package net.systemeD.halcyon.mapfeatures { } return null; } + + [Bindable(event="featuresLoaded")] + public function get categories():Array { + if ( xml == null ) + return null; + return _categories; + } + + [Bindable(event="featuresLoaded")] + public function get features():Array { + if ( xml == null ) + return null; + return _features; + } + } } diff --git a/resources/map_features.xml b/resources/map_features.xml index 099d104d..55dee80b 100644 --- a/resources/map_features.xml +++ b/resources/map_features.xml @@ -2,9 +2,30 @@ + + + + + + + + + + + + + + + + + + + + + roads ${ref}
@@ -14,11 +35,13 @@
+ roads + roads ${ref}
${name} @@ -29,6 +52,7 @@
+ roads ${ref}
${name} @@ -39,6 +63,7 @@
+ roads ${ref}
${name} @@ -49,6 +74,7 @@
+ roads ${name}
${ref} @@ -59,6 +85,7 @@
+ roads ${name}
${postal_code} @@ -69,6 +96,7 @@
+ roads ${name} @@ -78,6 +106,7 @@ + roads ${name} @@ -90,6 +119,7 @@ + roads This road has not been given a specific type. It's a road, and that's all that's known. @@ -99,6 +129,7 @@ + roads ${name} @@ -108,6 +139,7 @@ + roads ${name} @@ -117,6 +149,7 @@ + roads ${name} @@ -130,6 +163,7 @@ + paths ${name} ${ncn_ref} ${rcn_ref} ${lcn_ref} ${ref} @@ -139,6 +173,7 @@ + paths ${name} ${ref} @@ -148,6 +183,7 @@ + paths @@ -156,6 +192,7 @@ + paths @@ -194,6 +231,7 @@ + water ${name} @@ -203,6 +241,7 @@ + water ${name} @@ -212,6 +251,7 @@ + water ${name} @@ -221,6 +261,7 @@ + water ${name} @@ -233,6 +274,7 @@ + transport ${name} @@ -242,6 +284,7 @@ + transport ${name} @@ -251,6 +294,7 @@ + transport ${name} @@ -259,15 +303,6 @@ - - - ${name} - - - - - - -- 2.36.1