kill stupid tab bug
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / SliderEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:SingleTagEditor
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
5         xmlns:flexlib="flexlib.controls.*"
6         verticalGap="0"
7         width="100%"
8         toolTip="{fieldDescription}"
9     direction="horizontal" styleName="titledEditor">
10
11         <mx:Label text="{fieldName}:"/>
12         <mx:HSlider id="inputSlider"
13                  minimum="{sliderMinimum}" maximum="{sliderMaximum}"
14                  snapInterval="{sliderSnapInterval}" tickInterval="{sliderSnapInterval}"
15                  labels="{sliderLabels}" dataTipFormatFunction="formatDataTip"
16                  value="{translatedValue}"
17                  enabled="{isValueValid}"
18                  liveDragging="true"
19                                  change="setTagValueFromSlider()" />
20
21   <mx:Script><![CDATA[
22
23     private function setTagValueFromSlider():void {
24         // unset the tag if being set to the default
25         var newValue:Number = inputSlider.value;
26         value = newValue == SliderEditorFactory(_factory).defaultValue ? null : newValue.toString()
27     }
28
29     private function formatDataTip(value:Number):String {
30         if ( value == inputSlider.minimum )
31             return inputSlider.labels[0];
32         if ( value == inputSlider.maximum )
33             return inputSlider.labels[inputSlider.labels.length-1];
34         if ( value == SliderEditorFactory(_factory).defaultValue )
35             return SliderEditorFactory(_factory).defaultValueName
36         return value.toString();
37     }
38
39     [Bindable(event="factory_set")]
40     public function get sliderMinimum():Number {
41         return SliderEditorFactory(_factory) == null ? 0 : SliderEditorFactory(_factory).minimum;
42     }
43
44     [Bindable(event="factory_set")]
45     public function get sliderMaximum():Number {
46         return SliderEditorFactory(_factory) == null ? 100 : SliderEditorFactory(_factory).maximum;
47     }
48
49     [Bindable(event="factory_set")]
50     public function get sliderSnapInterval():Number {
51         return SliderEditorFactory(_factory) == null ? 1 : SliderEditorFactory(_factory).snapInterval;
52     }
53
54     [Bindable(event="factory_set")]
55     public function get sliderLabels():Array {
56         return SliderEditorFactory(_factory) == null ? ["0","100"] : SliderEditorFactory(_factory).labels;
57     }
58
59     [Bindable(event="tag_changed")]
60     private function get translatedValue():Number {
61         var validatedValue:Number = getValidatedValue();
62         return isNaN(validatedValue) ? SliderEditorFactory(_factory).defaultValue : validatedValue;
63     }
64
65     [Bindable(event="tag_changed")]
66     private function get isValueValid():Boolean {
67         var validatedValue:Number = getValidatedValue();
68         return !isNaN(validatedValue);
69     }
70
71     private function getValidatedValue():Number {
72         var valueStr:String = value;
73         if ( valueStr == null || valueStr == "" )
74             return SliderEditorFactory(_factory).defaultValue;
75
76         var parsed:Number = parseFloat(value);
77         if ( isNaN(parsed) || parsed < sliderMinimum || parsed > sliderMaximum )
78             return Number.NaN;
79         return parsed;
80     }
81         
82   ]]></mx:Script>
83 </edit:SingleTagEditor>
84