add number spinner editor and remove excess boxes from other components
authorDave Stubbs <osm@randomjunk.co.uk>
Sun, 29 Aug 2010 16:06:21 +0000 (16:06 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sun, 29 Aug 2010 16:06:21 +0000 (16:06 +0000)
net/systemeD/potlatch2/mapfeatures/EditorFactory.as
net/systemeD/potlatch2/mapfeatures/editors/CheckboxEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/CheckboxEditorFactory.as
net/systemeD/potlatch2/mapfeatures/editors/ChoiceEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/FreeTextEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/NumberEditor.mxml [new file with mode: 0755]
net/systemeD/potlatch2/mapfeatures/editors/NumberEditorFactory.as [new file with mode: 0755]
net/systemeD/potlatch2/mapfeatures/editors/SingleTagEditor.as
net/systemeD/potlatch2/mapfeatures/editors/SliderEditor.mxml
net/systemeD/potlatch2/mapfeatures/editors/SpeedEditor.mxml
resources/map_features.xml

index e6b5855..bfa0ab0 100644 (file)
@@ -19,6 +19,7 @@ package net.systemeD.potlatch2.mapfeatures {
             case "checkbox": return new CheckboxEditorFactory(inputXML);
             case "choice": return new ChoiceEditorFactory(inputXML);
             case "slider": return new SliderEditorFactory(inputXML);
+            case "number": return new NumberEditorFactory(inputXML);
             case "speed": return new SpeedEditorFactory(inputXML);
             case "route": return new RouteEditorFactory(inputXML);
             case "turn": return new TurnRestrictionEditorFactory(inputXML);
index bef6075..007f634 100755 (executable)
@@ -5,14 +5,14 @@
        xmlns:flexlib="flexlib.controls.*"
        verticalGap="0"
        width="100%"
-       toolTip="{fieldDescription}">
+       toolTip="{fieldDescription}"
+    direction="horizontal">
 
-       <mx:HBox>
        <mx:Label text="{fieldName}:"/>
        <mx:CheckBox id="inputBox" creationComplete="initCheckbox()"
                                 labelPlacement="right" label=""
                                 change="value=toYesNo()" />
-       </mx:HBox>
+
   <mx:Script><![CDATA[
   
        protected function initCheckbox():void {
index 3e98470..48067d1 100755 (executable)
@@ -11,7 +11,7 @@ package net.systemeD.potlatch2.mapfeatures.editors {
         public function CheckboxEditorFactory(inputXML:XML) {
             super(inputXML);
             _notPresentText = inputXML.hasOwnProperty("@absenceText") ? String(inputXML.@absenceText) : "Unset";
-            _notBooleanText = inputXML.hasOwnProperty("@invalidText") ? String(inputXML.@absenceText) : "Not yes/no";
+            _notBooleanText = inputXML.hasOwnProperty("@invalidText") ? String(inputXML.@invalidText) : "Not yes/no";
         }
         
         override protected function createSingleTagEditor():SingleTagEditor {
index 63a4caf..deb1ded 100644 (file)
@@ -2,10 +2,9 @@
 <edit:SingleTagEditor
        xmlns:mx="http://www.adobe.com/2006/mxml" 
        xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
-       verticalGap="0"
-       toolTip="{fieldDescription}">
+       toolTip="{fieldDescription}"
+    direction="{fieldDirection}" styleName="titledEditor">
 
-<mx:Box direction="{fieldDirection}" styleName="titledEditor">
   <mx:Label text="{fieldName}:"/>
   <edit:ChoiceComboBox id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
       change="value = inputBox.selectedItem.value"
@@ -19,7 +18,6 @@
         </mx:Component>
       </edit:itemRenderer>
   </edit:ChoiceComboBox>
-</mx:Box>
 
   <mx:Script><![CDATA[
       import mx.collections.*;
index 913f19a..1215620 100644 (file)
@@ -4,12 +4,11 @@
        xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
        xmlns:flexlib="flexlib.controls.*"
        width="100%"
-       toolTip="{fieldDescription}">
+       toolTip="{fieldDescription}"
+    direction="{fieldDirection}" styleName="titledEditor">
 
-  <mx:Box direction="{fieldDirection}" styleName="titledEditor">
   <mx:Label text="{fieldName}:"/>
   <flexlib:PromptingTextInput id="inputBox" prompt="{prompt}" text="{value}" width="100%" change="value = inputBox.text"/>
-  </mx:Box>
 
   <mx:Script><![CDATA[
   
diff --git a/net/systemeD/potlatch2/mapfeatures/editors/NumberEditor.mxml b/net/systemeD/potlatch2/mapfeatures/editors/NumberEditor.mxml
new file mode 100755 (executable)
index 0000000..a80dd14
--- /dev/null
@@ -0,0 +1,68 @@
+<?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}"
+    direction="{fieldDirection}" styleName="titledEditor">
+
+       <mx:Label text="{fieldName}:"/>
+    <mx:HBox horizontalGap="3" verticalAlign="middle">
+           <mx:NumericStepper id="input"
+                 minimum="{minimum}" maximum="{maximum}"
+                 stepSize="{stepSize}"
+                 value="{translatedValue}"
+                 enabled="{isValueValid}"
+                                change="value = input.value.toString()" />
+        <mx:Label text="{prompt}" visible="{value == null || value == ''}"/>
+    </mx:HBox>
+
+  <mx:Script><![CDATA[
+    [Bindable(event="factory_set")]
+    protected function get prompt():String {
+        return _factory == null ? null : NumberEditorFactory(_factory).notPresentText;
+    }
+
+    [Bindable(event="factory_set")]
+    public function get minimum():Number {
+        return NumberEditorFactory(_factory) == null ? 0 : NumberEditorFactory(_factory).minimum;
+    }
+
+    [Bindable(event="factory_set")]
+    public function get maximum():Number {
+        return NumberEditorFactory(_factory) == null ? 100 : NumberEditorFactory(_factory).maximum;
+    }
+
+    [Bindable(event="factory_set")]
+    public function get stepSize():Number {
+        return NumberEditorFactory(_factory) == null ? 1 : NumberEditorFactory(_factory).stepSize;
+    }
+
+    [Bindable(event="tag_changed")]
+    private function get translatedValue():Number {
+        var validatedValue:Number = getValidatedValue();
+        return validatedValue;
+    }
+
+    [Bindable(event="tag_changed")]
+    private function get isValueValid():Boolean {
+        var validatedValue:Number = getValidatedValue();
+        return !(isNaN(validatedValue) && value != null && value != "");
+    }
+
+    private function getValidatedValue():Number {
+        var valueStr:String = value;
+        if ( valueStr == null || valueStr == "" )
+            return Number.NaN;
+
+        var parsed:Number = parseFloat(value);
+        if ( isNaN(parsed) || parsed < minimum || parsed > maximum )
+            return Number.NaN;
+        return parsed;
+    }
+       
+  ]]></mx:Script>
+</edit:SingleTagEditor>
+
diff --git a/net/systemeD/potlatch2/mapfeatures/editors/NumberEditorFactory.as b/net/systemeD/potlatch2/mapfeatures/editors/NumberEditorFactory.as
new file mode 100755 (executable)
index 0000000..f35b266
--- /dev/null
@@ -0,0 +1,33 @@
+package net.systemeD.potlatch2.mapfeatures.editors {
+
+    import net.systemeD.halcyon.connection.*;
+    import net.systemeD.potlatch2.mapfeatures.*;
+    import flash.display.*;
+
+       public class NumberEditorFactory extends SingleTagEditorFactory {
+        private var _minimum:Number;
+        private var _maximum:Number;
+        private var _stepSize:Number;
+           private var _notPresentText:String;
+
+        public function NumberEditorFactory(inputXML:XML) {
+            super(inputXML);
+            _minimum = parseFloat(inputXML.hasOwnProperty("@minimum") ? String(inputXML.@minimum) : "0");
+            _maximum = parseFloat(inputXML.hasOwnProperty("@maximum") ? String(inputXML.@maximum) : "100");
+            _stepSize = parseFloat(inputXML.hasOwnProperty("@stepSize") ? String(inputXML.@stepSize) : "1");
+            _notPresentText = inputXML.hasOwnProperty("@absenceText") ? String(inputXML.@absenceText) : "Unset";
+        }
+        
+        override protected function createSingleTagEditor():SingleTagEditor {
+            return new NumberEditor();
+        }
+        
+        public function get minimum():Number { return _minimum; }
+        public function get maximum():Number { return _maximum; }
+        public function get stepSize():Number { return _stepSize; }
+        public function get notPresentText():String { return _notPresentText; }
+    }
+
+}
+
+
index b99f0fb..d28e869 100644 (file)
@@ -2,10 +2,10 @@ package net.systemeD.potlatch2.mapfeatures.editors {
 
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.mapfeatures.*;
-    import mx.containers.VBox;
+    import mx.containers.Box;
     import flash.events.*;
 
-    public class SingleTagEditor extends VBox {
+    public class SingleTagEditor extends Box {
 
       protected var _factory:SingleTagEditorFactory;
       protected var _entity:Entity;
index 97d7864..7b06ea4 100755 (executable)
@@ -5,9 +5,9 @@
        xmlns:flexlib="flexlib.controls.*"
        verticalGap="0"
        width="100%"
-       toolTip="{fieldDescription}">
+       toolTip="{fieldDescription}"
+    direction="horizontal" styleName="titledEditor">
 
-       <mx:HBox styleName="titledEditor">
        <mx:Label text="{fieldName}:"/>
        <mx:HSlider id="inputSlider"
                  minimum="{sliderMinimum}" maximum="{sliderMaximum}"
@@ -17,7 +17,7 @@
                  enabled="{isValueValid}"
                  liveDragging="true"
                                 change="setTagValueFromSlider()" />
-       </mx:HBox>
+
   <mx:Script><![CDATA[
 
     private function setTagValueFromSlider():void {
index 9a74d39..44ff0ff 100644 (file)
@@ -3,7 +3,7 @@
        xmlns:mx="http://www.adobe.com/2006/mxml" 
        xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
        toolTip="{fieldDescription}"
-       verticalGap="0">
+       direction="horizontal" styleName="titledEditor">
 
   <mx:Label text="{fieldName}:"/>
   <edit:ChoiceComboBox id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
index 0f6da7e..11a7ac1 100644 (file)
@@ -203,10 +203,6 @@ Quick documentation:
   </inputSet>
   
   <inputSet id="roadPhysical">
-    <input type="slider" presence="onTagMatch"
-        name="Layer" category="Physical" description="Relative vertical positions (-5 lowest, +5 highest)"
-        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"/>
@@ -230,24 +226,8 @@ Quick documentation:
   </inputSet>
 
   <inputSet id="roadLanes">
-    <!-- slider not implemented...-->
-    <!--    <input presence="always" type="slider" name="Lanes" category="Physical" description="Total number of lanes, counting both directions"
-           key="lanes" min="1" max="10" default="2"/>-->
-
-    <input presence="onTagMatch" type="choice" name="Lanes" category="Physical" description="Total number of lanes, counting both directions"
-       key="lanes" default="2">
-      <choice value="1" text="1" />
-      <choice value="2" text="2" />
-      <choice value="3" text="3" />
-      <choice value="4" text="4" />
-      <choice value="5" text="5" />
-      <choice value="6" text="6" />
-      <choice value="7" text="7" />
-      <choice value="8" text="8" />
-      <choice value="9" text="9" />
-      <choice value="10" text="10" />
-    </input>
-
+    <input presence="onTagMatch" type="number" name="Lanes" category="Physical" description="Total number of lanes, counting both directions"
+           key="lanes" minimum="1" maximum="10" layout="horizontal"/>
   </inputSet>
   
   <inputSet id="bridge">
@@ -258,7 +238,11 @@ Quick documentation:
       <choice value="viaduct" text="Viaduct" description="Viaduct"/>
       <choice value="suspension" text="Suspension bridge"/>
     </input>
-  </inputSet>
+    <input type="slider" presence="onTagMatch"
+        name="Layer" category="Physical" description="Relative vertical positions (-5 lowest, +5 highest)"
+        key="layer" minimum="-5" maximum="5" default="0" snapInterval="1" labels="Lowest,Ground,Highest"
+        defaultName="Ground"/>
+    </inputSet>
   <inputSet id="tunnel">
     <input type="choice" presence="onTagMatch"
         name="Tunnel" category="Physical" description="Road goes into a tunnel"
@@ -2016,7 +2000,7 @@ Quick documentation:
     <tag k="amenity" v="parking"/>
     <inputSet ref="names"/>
     <input type="freetext" presence="onTagMatch" category="Naming" name="Operator" key="operator" description="The provider of the postal service" priority="low"/>
-    <input type="freetext" presence="always" category="Parking" name="Capacity" key="capacity" description="The number of bicycles that can be parked in the group of bicycle parking racks"/>
+    <input type="number" minimum="0" maximum="99999" stepSize="1" presence="always" category="Parking" name="Capacity" key="capacity" description="The number of cars that can be parked in the car park"/>
     <inputSet ref="fee"/>
   </feature>
   
@@ -2030,7 +2014,9 @@ Quick documentation:
     <tag k="amenity" v="bicycle_parking"/>
     <inputSet ref="names"/>
     <input type="freetext" presence="onTagMatch" category="Naming" name="Operator" key="operator" description="The provider of the postal service" priority="low"/>
-    <input type="freetext" presence="always" category="Cycle" name="Capacity" key="capacity" description="The number of bicycles that can be parked in the group of bicycle parking racks"/>
+    <input type="number" minimum="0" maximum="99999" stepSize="1" 
+        presence="always" category="Cycle" name="Capacity" key="capacity"
+        description="The number of bicycles that can be parked in the group of bicycle parking racks"/>
     <inputSet ref="fee"/>
     <input type="choice" presence="always" category="Cycle" name="Covered" key="covered" description="Is the cycle parking covered, so that the bikes are kept dry?">
       <choice value="yes" text="Yes"/>