TypeConverter.st
changeset 747 fe0360fb81ee
parent 726 cdab756aebe4
child 941 ba196649eaec
equal deleted inserted replaced
746:8e84030fcec8 747:fe0360fb81ee
   108 
   108 
   109     ^ (self on:aValueHolder) numberToTextFormattedBy:formatString
   109     ^ (self on:aValueHolder) numberToTextFormattedBy:formatString
   110 
   110 
   111     "Created: 4.3.1997 / 11:51:25 / cg"
   111     "Created: 4.3.1997 / 11:51:25 / cg"
   112     "Modified: 4.3.1997 / 11:51:41 / cg"
   112     "Modified: 4.3.1997 / 11:51:41 / cg"
       
   113 !
       
   114 
       
   115 onNumberValue:aValueHolder postDecimalDigits:numPostDecimalDigits
       
   116     "create and return a typeConverter, which retrieves
       
   117      a values string representation via #value, and converts
       
   118      a number-string to a value via #value:.
       
   119      Useful as an editFields model, which operates on some
       
   120      numeric value (or aspectAdaptor, which adapts to a numeric slot)"
       
   121 
       
   122     ^ (self on:aValueHolder) numberToText:numPostDecimalDigits
       
   123 
       
   124     "Modified: / 21.2.1997 / 18:46:11 / cg"
       
   125     "Created: / 5.12.1997 / 02:55:18 / cg"
   113 !
   126 !
   114 
   127 
   115 onSymbolValue:aValueHolder
   128 onSymbolValue:aValueHolder
   116     "create and return a typeConverter, which retrieves
   129     "create and return a typeConverter, which retrieves
   117      a symbol-values string representation via #value, and converts
   130      a symbol-values string representation via #value, and converts
   387 
   400 
   388     "Created: / 21.2.1997 / 18:57:05 / cg"
   401     "Created: / 21.2.1997 / 18:57:05 / cg"
   389     "Modified: / 29.10.1997 / 15:49:21 / cg"
   402     "Modified: / 29.10.1997 / 15:49:21 / cg"
   390 !
   403 !
   391 
   404 
       
   405 numberToText:numberOfPostDecimals
       
   406     "setup the converter to convert from a string to a number
       
   407      and vice versa."
       
   408 
       
   409     self
       
   410         getBlock:[:model |
       
   411                 |numericValue|
       
   412 
       
   413                 (numericValue := model value) isNumber ifFalse:[
       
   414                     String new
       
   415                 ] ifTrue:[
       
   416                     (numericValue asFixedPoint:numberOfPostDecimals) printString
       
   417                 ]]
       
   418 
       
   419         putBlock:
       
   420                 [:model :string |
       
   421 
       
   422                 |value|
       
   423 
       
   424                 string isEmpty ifTrue:[
       
   425                     value := 0
       
   426                 ] ifFalse:[
       
   427                     value := Number readFromString:string onError:0
       
   428                 ].
       
   429                 model value:value]
       
   430 
       
   431         updateBlock: [:m :a :p | true]
       
   432 
       
   433     "Created: / 5.12.1997 / 02:54:13 / cg"
       
   434     "Modified: / 5.12.1997 / 18:21:04 / cg"
       
   435 !
       
   436 
   392 numberToTextFormattedBy:formatString
   437 numberToTextFormattedBy:formatString
   393     "setup the converter to convert from a string to a number
   438     "setup the converter to convert from a string to a number
   394      and vice versa, using formatString.
   439      and vice versa, using formatString.
   395      The formatString is currently ignored when numbers are converted
   440      The formatString is currently ignored when numbers are converted
   396      from a string."
   441      from a string."
   554 ! !
   599 ! !
   555 
   600 
   556 !TypeConverter class methodsFor:'documentation'!
   601 !TypeConverter class methodsFor:'documentation'!
   557 
   602 
   558 version
   603 version
   559     ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.8 1997-10-29 16:10:44 cg Exp $'
   604     ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.9 1997-12-08 17:37:47 cg Exp $'
   560 ! !
   605 ! !