TypeConverter.st
changeset 3252 974b0b2d3001
parent 3214 d39b11efa0a6
child 3486 dafab67a9be4
--- a/TypeConverter.st	Thu Sep 19 18:29:22 2013 +0200
+++ b/TypeConverter.st	Tue Sep 24 23:35:10 2013 +0200
@@ -294,6 +294,7 @@
         #integerInRange
         #integerWithThousandsSeparator
         #fileSize
+        #frequency
         #hexadecimal
         #hexIntegerInRange
         #symbolOrNil
@@ -921,6 +922,30 @@
         updateBlock: [:m :a :p | true]
 !
 
+frequency
+    "setup the converter to convert from a frequency string to a number
+     and vice versa.
+     A frequency can have a scale of 1000 (k or kHz),
+     1000*1000 (m or MHz), 1000*1000*1000 (g or GHz)."
+
+    self
+        getBlock:[:model |
+                |numericValue|
+
+                (numericValue := model value) isNumber ifFalse:[
+                    String new
+                ] ifTrue:[  
+                    UnitConverter frequencyStringFor:numericValue
+                ]]
+
+        putBlock:
+                [:model :string |
+
+                model value:(UnitConverter frequencyFromString:string)]
+
+        updateBlock: [:m :a :p | true]
+!
+
 literal
     "setup the converter to convert from a string to a literal
      and vice versa. Invalid symbols (i.e. empty) are converted to nil;
@@ -1927,10 +1952,10 @@
 !TypeConverter class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.70 2013-08-23 10:28:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.71 2013-09-24 21:35:10 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.70 2013-08-23 10:28:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.71 2013-09-24 21:35:10 cg Exp $'
 ! !