initial work on tag editor
[potlatch2.git] / net / systemeD / halcyon / TagViewer.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:VBox
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:halcyon="net.systemeD.halcyon.*"
5     backgroundColor="white"
6     creationComplete="loadFeatures()">
7
8   <mx:ViewStack id="stack" width="100%" height="100%">
9
10   <mx:VBox width="100%" height="100%" label="Simple">
11     <mx:HBox borderStyle="solid" verticalAlign="middle" width="100%" paddingLeft="3">
12         <mx:Image id="iconImage"/>
13         <mx:Text condenseWhite="true" width="100%" id="iconText"/>
14         <mx:LinkButton label="?" click="openDescription()" id="helpLabel"/>
15     </mx:HBox>
16   </mx:VBox>
17
18   <mx:VBox width="100%" height="100%" label="Advanced" initialize="checkAdvanced()">
19     <mx:Label id="advancedID">
20       <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
21     </mx:Label>
22
23     <mx:DataGrid width="100%" height="100%" id="advancedTagGrid">
24             <mx:columns>
25                 <mx:DataGridColumn dataField="key" headerText="Key"/>
26                 <mx:DataGridColumn dataField="value" headerText="Value"/>
27             </mx:columns>
28     </mx:DataGrid>
29
30     <mx:Label text="Key: {advancedTagGrid.selectedItem.key}"/>
31     <mx:Label text="Value: {advancedTagGrid.selectedItem.value}"/>
32   </mx:VBox>
33
34   </mx:ViewStack>
35
36   <mx:LinkBar dataProvider="{stack}"/>
37
38   <mx:Script><![CDATA[
39       import net.systemeD.halcyon.connection.*;
40       import net.systemeD.halcyon.mapfeatures.*;
41
42       private var mapFeatures:MapFeatures;
43       private var selectedEntity:Entity;
44       private var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
45
46       public function setEntity(entity:Entity):void {
47           this.selectedEntity = entity;
48
49           if ( advancedID != null )
50               setupAdvanced(entity);
51
52           var feature:XML = mapFeatures.findMatchingFeature(entity);
53           if ( feature != null )
54               setFeatureIcon(entity, feature);
55           else
56               blankFeatureIcon(entity);
57       }
58
59       private function setFeatureIcon(entity:Entity, feature:XML):void {
60           blankFeatureIcon(entity);
61
62           var icon:XMLList = feature.icon;
63           if ( icon.length == 0 )
64               return;
65
66           if ( icon[0].hasOwnProperty("@image") ) {
67               iconImage.source = icon.@image;
68           }
69
70           var txt:String = icon.children().toXMLString();
71           var replaceTag:Function = function():String {
72               var value:String = entity.getTag(arguments[1]);
73               return value == null ? "" : value;
74           };
75           txt = txt.replace(variablesPattern, replaceTag);
76           iconText.htmlText = "<i>"+feature.@name+"</i><br/>" + txt;
77       }
78
79       private function blankFeatureIcon(entity:Entity):void {
80           iconImage.source = null;
81           iconText.htmlText = entity == null ? "<i>Nothing selected</i>" : "<b>Not recognised</b><br/>Try looking at advanced";
82       }
83
84       private function checkAdvanced():void {
85           if ( selectedEntity != null )
86              setupAdvanced(selectedEntity);
87       }
88
89       private function setupAdvanced(entity:Entity):void {
90           var entityText:String = "xx";
91           if ( entity is Node ) entityText = "Node";
92           else if ( entity is Way ) entityText = "Way";
93           else if ( entity is Relation ) entityText = "Relation";
94           advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
95           advancedTagGrid.dataProvider = entity.getTagArray();
96       }
97
98       public function loadFeatures():void {
99           mapFeatures = MapFeatures.getInstance();
100       }
101
102       public function openDescription():void {
103           trace("open description here");
104       }
105   ]]></mx:Script>
106 </mx:VBox>
107