1 package net.systemeD.potlatch2.mapfeatures.editors {
5 public class SpeedChoice extends EventDispatcher {
7 private static const speedRE:RegExp = /^([0-9.]+)\s*(.*)$/;
9 private var _scalar:Number = -1;
10 private var _unit:String = null;
11 private var _description:String = "";
12 private var _value:String = null;
13 private var _isEditable:Boolean = false;
15 public function SpeedChoice(speedStr:String) {
19 private function parseSpeedString(speedStr:String):Object {
20 var match:Object = speedRE.exec(speedStr);
25 var scalar:Number = Number(match[1]);
26 var unit:String = match[2].replace(/\s/g, "");
27 if ( unit == null || unit == "" || unit == "kph" || unit == "kmh" )
29 return {scalar: scalar, unit: unit};
30 } catch ( exception:Object ) {
37 [Bindable(event="valueChange")]
38 public function get scalar():String { return String(_scalar); }
40 [Bindable(event="valueChange")]
41 public function get description():String { return _description; }
43 [Bindable(event="valueChange")]
44 public function get value():String { return _value; }
46 [Bindable(event="valueChange")]
47 public function get unit():String { return _unit; }
49 [Bindable(event="editableChange")]
50 public function get isEditable():Boolean { return _isEditable; }
52 public function set isEditable(editable:Boolean):void {
53 _isEditable = editable;
54 dispatchEvent(new Event("editableChange"));
57 public function isTagMatch(tagValue:String):Boolean {
58 if ( _value == tagValue )
61 var tagSpeed:Object = parseSpeedString(tagValue);
62 return tagSpeed != null && tagSpeed.scalar == _scalar && tagSpeed.unit == _unit;
65 public function set value(speedStr:String):void {
66 var speed:Object = parseSpeedString(speedStr);
67 if ( speed != null ) {
68 _scalar = speed.scalar;
70 _description = String(_scalar) + " "+_unit;
71 _value = String(_scalar) + (_unit == "km/h" ? "":_unit);
75 dispatchEvent(new Event("valueChange"));