Merge branch 'master' of github.com:systemed/potlatch2
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / SingleTagEditor.as
1 package net.systemeD.potlatch2.mapfeatures.editors {
2
3     import net.systemeD.halcyon.connection.*;
4     import net.systemeD.potlatch2.mapfeatures.*;
5     import spark.components.FormItem;
6     import flash.events.*;
7
8     public class SingleTagEditor extends FormItem {
9
10       protected var _factory:SingleTagEditorFactory;
11       protected var _entity:Entity;
12       
13       [Bindable(event="factory_set")]
14       public function get fieldName():String {
15           return _factory == null ? "" : _factory.name;
16       }
17       
18       [Bindable(event="factory_set")]
19       public function get fieldDescription():String {
20           return _factory == null ? "" : _factory.description;
21       }
22
23       [Bindable(event="factory_set")]
24       public function get fieldDirection():String {
25           return _factory == null ? "" : _factory.direction;
26       }
27       
28       [Bindable(event="tag_changed")]
29       public function get value():String {
30           return _entity == null ? null : _entity.getTag(_factory.key);
31       }
32       
33       public function set value(val:String):void {
34           if ( _entity != null )
35               _entity.setTag(_factory.key, val, MainUndoStack.getGlobalStack().addAction);
36       }
37
38       public function set factory(factory:SingleTagEditorFactory):void {
39           _factory = factory;
40           dispatchEvent(new Event("factory_set"));
41       }
42       
43       public function set entity(entity:Entity):void {
44           _entity = entity;
45           entity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
46           dispatchEvent(new Event("tag_changed"));
47       }
48       
49       private function tagChanged(event:TagEvent):void {
50           var tagVal:String = _entity.getTag(_factory.key);
51           dispatchEvent(new Event("tag_changed"));
52       }
53
54                 [Embed(source="../../../../../embedded/help.png")] private var infoIcon:Class;
55
56                 import spark.components.*;
57                 import mx.managers.ToolTipManager;
58                 import mx.controls.ToolTip;
59                 import mx.core.IUIComponent;
60                 import flash.geom.Point;
61                 private var _tip:ToolTip;
62
63                 [Bindable(event="factory_set")]
64                 protected function get help():Image {
65                         var image:Image = new Image();
66                         image.source = infoIcon;
67                         image.width = 16;
68                         image.height = 16;
69                         image.addEventListener("mouseOver",showHelpBalloon,false,0,true);
70                         image.addEventListener("mouseOut" ,hideHelpBalloon,false,0,true);
71                         return image;
72                 }
73
74                 private function showHelpBalloon(e:Event):void {
75                         var point:Point=e.target.contentToGlobal(new Point(-8,16));
76                         _tip=ToolTipManager.createToolTip(fieldDescription,point.x,point.y,"errorTipBelow",IUIComponent(e.target)) as ToolTip;
77                 }
78                 private function hideHelpBalloon(e:Event):void {
79                         ToolTipManager.destroyToolTip(_tip);
80                 }
81
82     }
83
84 }
85
86