1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:mx="http://www.adobe.com/2006/mxml"
4 xmlns:halcyon="net.systemeD.halcyon.*"
5 backgroundColor="white"
6 creationComplete="loadFeatures()">
8 <mx:ViewStack id="stack" width="100%" height="100%">
10 <mx:VBox width="100%" height="100%" label="Simple">
11 <mx:HBox borderStyle="inset" verticalAlign="middle" width="100%" paddingLeft="3" id="iconContainer">
12 <mx:Image id="iconImage"/>
13 <mx:Text condenseWhite="true" width="100%" id="iconText"/>
14 <mx:LinkButton label="?" click="openDescription()" id="helpLabel"/>
18 <mx:VBox width="100%" height="100%" label="Advanced" initialize="checkAdvanced()" verticalGap="1">
19 <mx:Label id="advancedID">
20 <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
23 <mx:DataGrid editable="true" width="100%" height="100%" id="advancedTagGrid">
25 <mx:DataGridColumn editable="true" dataField="key" headerText="Key"/>
26 <mx:DataGridColumn editable="true" dataField="value" headerText="Value"/>
30 <mx:HBox horizontalAlign="right" width="100%">
31 <mx:LinkButton label="Delete" click="removeTag()"/>
32 <mx:LinkButton label="Add" click="addNewTag()"/>
38 <mx:LinkBar dataProvider="{stack}"/>
41 import net.systemeD.halcyon.connection.*;
42 import net.systemeD.halcyon.mapfeatures.*;
44 import mx.collections.*
46 private var mapFeatures:MapFeatures;
47 private var selectedEntity:Entity;
48 private var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
49 private var collection:ArrayCollection;
51 public function setEntity(entity:Entity):void {
52 if ( selectedEntity != entity ) {
53 if ( selectedEntity != null )
54 selectedEntity.removeEventListener(Connection.TAG_CHANGE, tagChanged);
55 selectedEntity = entity;
56 selectedEntity.addEventListener(Connection.TAG_CHANGE, tagChanged);
59 if ( advancedID != null )
60 setupAdvanced(entity);
65 private function refreshFeatureIcon():void {
66 var feature:XML = mapFeatures.findMatchingFeature(selectedEntity);
67 if ( feature != null )
68 setFeatureIcon(selectedEntity, feature);
70 blankFeatureIcon(selectedEntity);
73 private function setFeatureIcon(entity:Entity, feature:XML):void {
74 blankFeatureIcon(entity);
76 var icon:XMLList = feature.icon;
77 if ( icon.length == 0 )
80 if ( icon[0].hasOwnProperty("@image") ) {
81 iconImage.source = icon.@image;
84 var txt:String = icon.children().toXMLString();
85 var replaceTag:Function = function():String {
86 var value:String = entity.getTag(arguments[1]);
87 return value == null ? "" : value;
89 txt = txt.replace(variablesPattern, replaceTag);
90 iconText.htmlText = "<i>"+feature.@name+"</i><br/>" + txt;
93 private function blankFeatureIcon(entity:Entity):void {
94 iconImage.source = null;
95 iconText.htmlText = entity == null ?
96 "<i>Nothing selected</i>" :
97 "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
100 private function checkAdvanced():void {
101 if ( selectedEntity != null )
102 setupAdvanced(selectedEntity);
105 private function setupAdvanced(entity:Entity):void {
106 var entityText:String = "xx";
107 if ( entity is Node ) entityText = "Node";
108 else if ( entity is Way ) entityText = "Way";
109 else if ( entity is Relation ) entityText = "Relation";
111 advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
113 if ( collection == null ) {
114 collection = new ArrayCollection();
115 //var sort:Sort = new Sort();
116 //sort.fields = [new SortField("key", true)];
117 //collection.sort = sort;
118 //collection.refresh();
119 advancedTagGrid.dataProvider = collection;
121 collection.removeAll();
122 var tags:Array = entity.getTagArray();
124 for each(var tag:Tag in tags)
125 collection.addItem(tag);
128 private function tagChanged(event:TagEvent):void {
129 refreshFeatureIcon();
131 if ( collection != null ) {
132 // check to see if the key is already in our list
133 var exists:Boolean = false;
136 for ( i = 0; i < collection.length && !exists; i++ ) {
137 tag = Tag(collection.getItemAt(i));
138 exists = tag.key == event.key;
141 tag = new Tag(selectedEntity, event.key, event.newValue);
142 collection.addItem(tag);
143 collection.refresh();
145 if ( event.newValue == null ) {
146 collection.removeItemAt(i-1);
147 collection.refresh();
153 public function loadFeatures():void {
154 mapFeatures = MapFeatures.getInstance();
157 public function openDescription():void {
158 trace("open description here");
161 public function addNewTag():void {
162 var newKey:String = "(new tag)";
163 var newTag:Tag = new Tag(selectedEntity, newKey, "(new value)");
164 collection.addItem(newTag);
165 advancedTagGrid.editedItemPosition = {rowIndex: collection.getItemIndex(newTag), columnIndex: 0};
168 public function removeTag():void {
169 var k:String = advancedTagGrid.selectedItem.key;
170 selectedEntity.setTag(k, null);