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%">
9 <mx:VBox width="100%" height="100%" label="Simple">
10 <mx:HBox borderStyle="inset" verticalAlign="middle" width="100%" paddingLeft="3" id="iconContainer">
11 <mx:Image id="iconImage"/>
12 <mx:VBox width="100%" verticalGap="1">
13 <mx:PopUpButton id="popupChange" creationComplete="initFeatureBox()" openAlways="true" width="100%"/>
14 <mx:Text condenseWhite="true" width="100%" id="iconText"/>
16 <mx:LinkButton label="?" click="openDescription()" id="helpLabel"/>
18 <mx:VBox width="100%" id="editorBox" paddingLeft="2" paddingRight="2"/>
21 <mx:VBox width="100%" height="100%" label="Advanced" initialize="checkAdvanced()" verticalGap="1">
22 <mx:Label id="advancedID">
23 <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
26 <mx:DataGrid editable="true" width="100%" height="100%" id="advancedTagGrid">
28 <mx:DataGridColumn editable="true" dataField="key" headerText="Key"/>
29 <mx:DataGridColumn editable="true" dataField="value" headerText="Value"/>
33 <mx:HBox horizontalAlign="right" width="100%">
34 <mx:LinkButton label="Delete" click="removeTag()"/>
35 <mx:LinkButton label="Add" click="addNewTag()"/>
41 <mx:LinkBar dataProvider="{stack}"/>
44 import net.systemeD.halcyon.connection.*;
45 import net.systemeD.potlatch2.mapfeatures.*;
47 import mx.collections.*;
48 import mx.containers.*;
51 import mx.managers.PopUpManager;
52 import flash.geom.Point;
54 private var mapFeatures:MapFeatures;
55 private var selectedEntity:Entity;
56 private var collection:ArrayCollection;
57 private var tw:CategorySelector = null;
58 private var feature:Feature = null;
60 public function setEntity(entity:Entity):void {
61 if ( selectedEntity != entity ) {
62 if ( selectedEntity != null )
63 selectedEntity.removeEventListener(Connection.TAG_CHANGE, tagChanged);
64 selectedEntity = entity;
65 if ( selectedEntity != null )
66 selectedEntity.addEventListener(Connection.TAG_CHANGE, tagChanged);
69 if ( advancedID != null )
70 setupAdvanced(entity);
75 private function refreshFeatureIcon():void {
76 var oldFeature:Feature = feature;
77 feature = selectedEntity == null ? null : mapFeatures.findMatchingFeature(selectedEntity);
78 if ( feature != oldFeature )
81 if ( feature != null )
82 setFeatureIcon(selectedEntity, feature);
84 blankFeatureIcon(selectedEntity);
87 private function setFeatureIcon(entity:Entity, feature:Feature):void {
88 //blankFeatureIcon(entity);
90 iconImage.source = feature.image;
92 var txt:String = feature.htmlDetails(entity);
93 iconText.htmlText = txt;
94 popupChange.label = feature.name;
95 tw.setSelectedFeature(feature);
98 private function blankFeatureIcon(entity:Entity):void {
99 iconImage.source = null;
100 iconText.htmlText = entity == null ?
101 "<i>Nothing selected</i>" :
102 "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
103 popupChange.label = "unknown";
104 tw.setSelectedFeature(null);
107 private function initialiseEditors():void {
108 editorBox.removeAllChildren();
109 if ( selectedEntity == null || feature == null )
112 for each (var factory:EditorFactory in feature.editors) {
113 var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
114 if ( editor != null )
115 editorBox.addChild(editor);
119 private function checkAdvanced():void {
120 if ( selectedEntity != null )
121 setupAdvanced(selectedEntity);
124 private function setupAdvanced(entity:Entity):void {
125 if ( collection == null ) {
126 collection = new ArrayCollection();
127 advancedTagGrid.dataProvider = collection;
130 collection.removeAll();
132 if ( entity == null ) {
133 advancedID.htmlText = "";
135 var entityText:String = "xx";
136 if ( entity is Node ) entityText = "Node";
137 else if ( entity is Way ) entityText = "Way";
138 else if ( entity is Relation ) entityText = "Relation";
139 advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
141 var tags:Array = entity.getTagArray();
143 for each(var tag:Tag in tags)
144 collection.addItem(tag);
148 private function tagChanged(event:TagEvent):void {
149 refreshFeatureIcon();
151 if ( collection != null ) {
152 // check to see if the key is already in our list
153 var exists:Boolean = false;
156 for ( i = 0; i < collection.length && !exists; i++ ) {
157 tag = Tag(collection.getItemAt(i));
158 exists = tag.key == event.key;
161 tag = new Tag(selectedEntity, event.key, event.newValue);
162 collection.addItem(tag);
163 collection.refresh();
165 if ( event.newValue == null ) {
166 collection.removeItemAt(i-1);
167 collection.refresh();
173 public function loadFeatures():void {
174 mapFeatures = MapFeatures.getInstance();
177 public function openDescription():void {
178 trace("open description here");
181 public function addNewTag():void {
182 var newKey:String = "(new tag)";
183 var newTag:Tag = new Tag(selectedEntity, newKey, "(new value)");
184 collection.addItem(newTag);
185 advancedTagGrid.editedItemPosition = {rowIndex: collection.getItemIndex(newTag), columnIndex: 0};
188 public function removeTag():void {
189 var k:String = advancedTagGrid.selectedItem.key;
190 selectedEntity.setTag(k, null);
193 public function initFeatureBox():void {
194 tw = new CategorySelector();
195 tw.addEventListener("selectedType", changeFeatureType);
196 popupChange.popUp = tw;
199 public function changeFeatureType(event:Event):void {
200 if ( selectedEntity == null )
203 var newFeature:Feature = tw.selectedType;
205 // remove tags from the current feature
206 if ( feature != null ) {
207 for each( var oldtag:Object in feature.tags ) {
208 selectedEntity.setTag(oldtag["k"], null);
212 // set tags for new feature
213 if ( newFeature != null ) {
214 for each( var newtag:Object in newFeature.tags ) {
215 selectedEntity.setTag(newtag["k"], newtag["v"]);