add layer tag editing using a nice slider
authorDave Stubbs <osm@randomjunk.co.uk>
Sat, 28 Aug 2010 18:26:31 +0000 (18:26 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sat, 28 Aug 2010 18:26:31 +0000 (18:26 +0000)
net/systemeD/potlatch2/mapfeatures/EditorFactory.as
net/systemeD/potlatch2/mapfeatures/editors/ChoiceEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/SliderEditor.mxml [new file with mode: 0755]
net/systemeD/potlatch2/mapfeatures/editors/SliderEditorFactory.as [new file with mode: 0755]
resources/map_features.xml

index 017523ebd4e6546ae2c1425963bdeb99b72e1864..e6b58554227d1f61b84235497cb61a6fbdd66c95 100644 (file)
@@ -18,6 +18,7 @@ package net.systemeD.potlatch2.mapfeatures {
             case "freetext": return new FreeTextEditorFactory(inputXML);
             case "checkbox": return new CheckboxEditorFactory(inputXML);
             case "choice": return new ChoiceEditorFactory(inputXML);
+            case "slider": return new SliderEditorFactory(inputXML);
             case "speed": return new SpeedEditorFactory(inputXML);
             case "route": return new RouteEditorFactory(inputXML);
             case "turn": return new TurnRestrictionEditorFactory(inputXML);
index 97be62ceb046d03785cbd9ae211b3ac849db96a8..63a4caf6375d795fe2a35f785134e18161159a60 100644 (file)
@@ -65,7 +65,7 @@
           var choice:Choice = new Choice();
           choice.icon = null;
           choice.description = "Field not set";
-          choice.label = "<i>Unset</i>";
+          choice.label = "<font color='#a0a0a0'><i>Unset</i></font>";
           choice.value = null;
           return choice;
       }
diff --git a/net/systemeD/potlatch2/mapfeatures/editors/SliderEditor.mxml b/net/systemeD/potlatch2/mapfeatures/editors/SliderEditor.mxml
new file mode 100755 (executable)
index 0000000..97d7864
--- /dev/null
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<edit:SingleTagEditor
+       xmlns:mx="http://www.adobe.com/2006/mxml" 
+       xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
+       xmlns:flexlib="flexlib.controls.*"
+       verticalGap="0"
+       width="100%"
+       toolTip="{fieldDescription}">
+
+       <mx:HBox styleName="titledEditor">
+       <mx:Label text="{fieldName}:"/>
+       <mx:HSlider id="inputSlider"
+                 minimum="{sliderMinimum}" maximum="{sliderMaximum}"
+                 snapInterval="{sliderSnapInterval}" tickInterval="{sliderSnapInterval}"
+                 labels="{sliderLabels}" dataTipFormatFunction="formatDataTip"
+                 value="{translatedValue}"
+                 enabled="{isValueValid}"
+                 liveDragging="true"
+                                change="setTagValueFromSlider()" />
+       </mx:HBox>
+  <mx:Script><![CDATA[
+
+    private function setTagValueFromSlider():void {
+        // unset the tag if being set to the default
+        var newValue:Number = inputSlider.value;
+        value = newValue == SliderEditorFactory(_factory).defaultValue ? null : newValue.toString()
+    }
+
+    private function formatDataTip(value:Number):String {
+        if ( value == inputSlider.minimum )
+            return inputSlider.labels[0];
+        if ( value == inputSlider.maximum )
+            return inputSlider.labels[inputSlider.labels.length-1];
+        if ( value == SliderEditorFactory(_factory).defaultValue )
+            return SliderEditorFactory(_factory).defaultValueName
+        return value.toString();
+    }
+
+    [Bindable(event="factory_set")]
+    public function get sliderMinimum():Number {
+        return SliderEditorFactory(_factory) == null ? 0 : SliderEditorFactory(_factory).minimum;
+    }
+
+    [Bindable(event="factory_set")]
+    public function get sliderMaximum():Number {
+        return SliderEditorFactory(_factory) == null ? 100 : SliderEditorFactory(_factory).maximum;
+    }
+
+    [Bindable(event="factory_set")]
+    public function get sliderSnapInterval():Number {
+        return SliderEditorFactory(_factory) == null ? 1 : SliderEditorFactory(_factory).snapInterval;
+    }
+
+    [Bindable(event="factory_set")]
+    public function get sliderLabels():Array {
+        return SliderEditorFactory(_factory) == null ? ["0","100"] : SliderEditorFactory(_factory).labels;
+    }
+
+    [Bindable(event="tag_changed")]
+    private function get translatedValue():Number {
+        var validatedValue:Number = getValidatedValue();
+        return isNaN(validatedValue) ? SliderEditorFactory(_factory).defaultValue : validatedValue;
+    }
+
+    [Bindable(event="tag_changed")]
+    private function get isValueValid():Boolean {
+        var validatedValue:Number = getValidatedValue();
+        return !isNaN(validatedValue);
+    }
+
+    private function getValidatedValue():Number {
+        var valueStr:String = value;
+        if ( valueStr == null || valueStr == "" )
+            return SliderEditorFactory(_factory).defaultValue;
+
+        var parsed:Number = parseFloat(value);
+        if ( isNaN(parsed) || parsed < sliderMinimum || parsed > sliderMaximum )
+            return Number.NaN;
+        return parsed;
+    }
+       
+  ]]></mx:Script>
+</edit:SingleTagEditor>
+
diff --git a/net/systemeD/potlatch2/mapfeatures/editors/SliderEditorFactory.as b/net/systemeD/potlatch2/mapfeatures/editors/SliderEditorFactory.as
new file mode 100755 (executable)
index 0000000..ce83bb3
--- /dev/null
@@ -0,0 +1,42 @@
+package net.systemeD.potlatch2.mapfeatures.editors {
+
+    import net.systemeD.halcyon.connection.*;
+    import net.systemeD.potlatch2.mapfeatures.*;
+    import flash.display.*;
+
+       public class SliderEditorFactory extends SingleTagEditorFactory {
+        private var _minimum:Number;
+        private var _maximum:Number;
+        private var _default:Number;
+        private var _defaultName:String;
+        private var _snapInterval:Number;
+        private var _labels:Array;
+
+        public function SliderEditorFactory(inputXML:XML) {
+            super(inputXML);
+            _minimum = parseFloat(inputXML.hasOwnProperty("@minimum") ? String(inputXML.@minimum) : "0");
+            _maximum = parseFloat(inputXML.hasOwnProperty("@maximum") ? String(inputXML.@maximum) : "100");
+            _default = parseFloat(inputXML.hasOwnProperty("@default") ? String(inputXML.@default) : "0");
+            _snapInterval = parseFloat(inputXML.hasOwnProperty("@snapInterval") ? String(inputXML.@snapInterval) : "1");
+            _labels = inputXML.hasOwnProperty("@labels") ?
+                        String(inputXML.@labels).split(",") :
+                        [_minimum.toString(), _maximum.toString()];
+            _defaultName = inputXML.hasOwnProperty("@defaultName") ?
+                        String(inputXML.@defaultName) : _default.toString();
+        }
+        
+        override protected function createSingleTagEditor():SingleTagEditor {
+            return new SliderEditor();
+        }
+        
+        public function get minimum():Number { return _minimum; }
+        public function get maximum():Number { return _maximum; }
+        public function get defaultValue():Number { return _default; }
+        public function get defaultValueName():String { return _defaultName; }
+        public function get snapInterval():Number { return _snapInterval; }
+        public function get labels():Array { return _labels; }
+    }
+
+}
+
+
index 60f02fd64ae7c8be4e0a9028a68f60eb0ad2de53..0f6da7e792567759810ada37d5d0f622162c74be 100644 (file)
@@ -205,7 +205,8 @@ Quick documentation:
   <inputSet id="roadPhysical">
     <input type="slider" presence="onTagMatch"
         name="Layer" category="Physical" description="Relative vertical positions (-5 lowest, +5 highest)"
-        key="layer" min="-5" max="5" default="0"/>
+        key="layer" minimum="-5" maximum="5" default="0" snapInterval="1" labels="Lowest,Ground,Highest"
+        defaultName="Ground"/>
     <input type="freetext" presence="onTagMatch"
         name="Width" category="Physical"
         key="width" description="Width of the road" layout="horizontal"/>