author | mawalch |
Mon, 22 May 2017 12:19:24 +0200 | |
changeset 3955 | 23fc9de7f301 |
parent 3853 | 5a78ffcf69de |
child 3973 | 440d7bd84437 |
permissions | -rw-r--r-- |
1355 | 1 |
" |
2 |
COPYRIGHT (c) 1997 eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1406
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
13 |
|
3486 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
442 | 16 |
PluggableAdaptor subclass:#TypeConverter |
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
17 |
instanceVariableNames:'' |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
18 |
classVariableNames:'' |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
19 |
poolDictionaries:'' |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
20 |
category:'Interface-Support-Models' |
442 | 21 |
! |
22 |
||
23 |
!TypeConverter class methodsFor:'documentation'! |
|
24 |
||
1355 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1997 eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
||
39 |
! |
|
40 |
||
442 | 41 |
documentation |
42 |
" |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
43 |
a typeConverter can be used as an editFields model |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
44 |
(remember, that an editField expects a string in its model), |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
45 |
to convert the fields string value to some object and vice versa. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
46 |
Its main use is when building interfaces with inputFields, |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
47 |
where the datum to be entered is a non-string and you |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
48 |
want to have the entered value be converted automatically. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
49 |
(and vice versa, to convert the datum to a string). |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
50 |
|
442 | 51 |
No real new functionality is added here - all is inherited |
52 |
from PluggableAdapter; however, some specialized instance creation |
|
947 | 53 |
methods are added here. |
442 | 54 |
|
55 |
Notice: |
|
56 |
this class was implemented using protocol information |
|
57 |
from alpha testers - it may not be complete or compatible to |
|
58 |
the corresponding ST-80 class. |
|
59 |
If you encounter any incompatibilities, please forward a note |
|
60 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
61 |
||
62 |
[author:] |
|
63 |
Claus Gittinger |
|
64 |
" |
|
65 |
||
66 |
||
67 |
! |
|
68 |
||
69 |
examples |
|
70 |
" |
|
71 |
convert a number to a string: |
|
72 |
[exBegin] |
|
73 |
|v t i| |
|
74 |
||
75 |
v := 1 asValue. |
|
76 |
||
77 |
t := HorizontalPanelView new. |
|
78 |
t extent:200@50. |
|
79 |
t horizontalLayout:#fitSpace. |
|
80 |
||
81 |
i := EditField in:t. |
|
82 |
i model:(TypeConverter onNumberValue:v). |
|
83 |
t open. |
|
84 |
||
85 |
(Delay forSeconds:3) wait. |
|
86 |
v value:2. |
|
87 |
[exEnd] |
|
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
88 |
convert a number to a string with range: |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
89 |
[exBegin] |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
90 |
|v t i| |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
91 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
92 |
v := 1 asValue. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
93 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
94 |
t := HorizontalPanelView new. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
95 |
t extent:200@50. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
96 |
t horizontalLayout:#fitSpace. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
97 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
98 |
i := EditField in:t. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
99 |
i model:(TypeConverter onNumberValue:v minValue:0 maxValue:100). |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
100 |
t open. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
101 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
102 |
(Delay forSeconds:3) wait. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
103 |
v value:2. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
104 |
[exEnd] |
487 | 105 |
convert a date to a string: |
106 |
[exBegin] |
|
107 |
|d v| |
|
108 |
||
109 |
v := nil asValue. |
|
110 |
||
111 |
d := DialogBox new. |
|
112 |
d addInputFieldOn:(TypeConverter onDateValue:v). |
|
113 |
d addOkButton. |
|
114 |
d open. |
|
115 |
d accepted ifTrue:[ |
|
116 |
Transcript showCR:v value |
|
117 |
] |
|
118 |
[exEnd] |
|
2379 | 119 |
convert with thousands: |
120 |
[exBegin] |
|
121 |
|d v| |
|
122 |
||
123 |
v := 1234567 asValue. |
|
124 |
||
125 |
d := DialogBox new. |
|
126 |
d addInputFieldOn:((TypeConverter on:v) integerWithThousandsSeparator:$'). |
|
127 |
d addOkButton. |
|
128 |
d open. |
|
129 |
d accepted ifTrue:[ |
|
130 |
Transcript showCR:v value |
|
131 |
] |
|
132 |
[exEnd] |
|
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
133 |
convert with scale character: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
134 |
[exBegin] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
135 |
|d v| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
136 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
137 |
v := 1234567 asValue. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
138 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
139 |
d := DialogBox new. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
140 |
d addInputFieldOn:((TypeConverter on:v) numberWithOptionalScale). |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
141 |
d addOkButton. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
142 |
d open. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
143 |
d accepted ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
144 |
Transcript showCR:v value |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
145 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
146 |
[exEnd] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
147 |
convert with scale character and thousands separator: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
148 |
[exBegin] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
149 |
|d v scaleDict| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
150 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
151 |
scaleDict := Dictionary new. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
152 |
scaleDict at:$t put:1000. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
153 |
scaleDict at:$k put:1000. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
154 |
scaleDict at:$m put:1000000. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
155 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
156 |
v := 1234567 asValue. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
157 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
158 |
d := DialogBox new. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
159 |
d addInputFieldOn:((TypeConverter on:v) |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
160 |
numberWithOptionalScales:scaleDict |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
161 |
andThousandsSeparator:$'). |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
162 |
d addOkButton. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
163 |
d open. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
164 |
d accepted ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
165 |
Transcript showCR:v value |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
166 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
167 |
[exEnd] |
442 | 168 |
" |
169 |
! ! |
|
170 |
||
171 |
!TypeConverter class methodsFor:'instance creation'! |
|
172 |
||
486 | 173 |
onDateValue:aValueHolder |
174 |
"create and return a typeConverter, which retrieves |
|
175 |
a date via #value, and converts |
|
176 |
a date-string to a date via #value:. |
|
177 |
Useful as an editFields model, which operates on some |
|
178 |
date value (or aspectAdaptor, which adapts to a numeric slot)" |
|
179 |
||
180 |
^ (self on:aValueHolder) dateToText |
|
181 |
||
182 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
183 |
"Created: 4.3.1997 / 12:30:49 / cg" |
|
184 |
! |
|
185 |
||
442 | 186 |
onNumberValue:aValueHolder |
187 |
"create and return a typeConverter, which retrieves |
|
188 |
a values string representation via #value, and converts |
|
189 |
a number-string to a value via #value:. |
|
190 |
Useful as an editFields model, which operates on some |
|
191 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
|
192 |
||
193 |
^ (self on:aValueHolder) numberToText |
|
194 |
||
195 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
446 | 196 |
! |
197 |
||
487 | 198 |
onNumberValue:aValueHolder format:formatString |
199 |
"create and return a typeConverter, which retrieves |
|
200 |
a values string representation via #value, and converts |
|
201 |
a number-string to a value via #value:. |
|
202 |
Useful as an editFields model, which operates on some |
|
203 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
|
204 |
||
205 |
^ (self on:aValueHolder) numberToTextFormattedBy:formatString |
|
206 |
||
207 |
"Created: 4.3.1997 / 11:51:25 / cg" |
|
208 |
"Modified: 4.3.1997 / 11:51:41 / cg" |
|
209 |
! |
|
210 |
||
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
211 |
onNumberValue:aValueHolder leftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
212 |
"create and return a typeConverter, which retrieves |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
213 |
a values string representation via #value, and converts |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
214 |
a number-string to a value via #value:. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
215 |
Useful as an editFields model, which operates on some |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
216 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
217 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
218 |
^ (self on:aValueHolder) numberToTextLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
219 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
220 |
" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
221 |
|m| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
222 |
m := 5 asValue. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
223 |
((EditField model:(TypeConverter onNumberValue:m leftPaddedTo:2 with:$-)) width:100) openAt:(200@200). |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
224 |
m inspect. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
225 |
" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
226 |
! |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
227 |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
228 |
onNumberValue:aValueHolder minValue:min maxValue:max |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
229 |
"create and return a typeConverter, which retrieves |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
230 |
a values string representation via #value, and converts |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
231 |
a number-string to a value via #value:. |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
232 |
Useful as an editFields model, which operates on some |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
233 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
234 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
235 |
^ (self on:aValueHolder) numberToTextMinValue:min maxValue:max |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
236 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
237 |
"Created: 4.3.1997 / 11:51:25 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
238 |
"Modified: 4.3.1997 / 11:51:41 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
239 |
! |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
240 |
|
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
241 |
onNumberValue:aValueHolder postDecimalDigits:numPostDecimalDigits |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
242 |
"create and return a typeConverter, which retrieves |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
243 |
a values string representation via #value, and converts |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
244 |
a number-string to a value via #value:. |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
245 |
Useful as an editFields model, which operates on some |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
246 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
247 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
248 |
^ (self on:aValueHolder) numberToText:numPostDecimalDigits |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
249 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
250 |
"Modified: / 21.2.1997 / 18:46:11 / cg" |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
251 |
"Created: / 5.12.1997 / 02:55:18 / cg" |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
252 |
! |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
253 |
|
446 | 254 |
onSymbolValue:aValueHolder |
255 |
"create and return a typeConverter, which retrieves |
|
256 |
a symbol-values string representation via #value, and converts |
|
257 |
a string to a symbol via #value:. |
|
258 |
Useful as an editFields model, which operates on some |
|
259 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
|
260 |
||
261 |
^ (self on:aValueHolder) symbolOrNil |
|
262 |
||
263 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
487 | 264 |
! |
265 |
||
266 |
onTimeValue:aValueHolder |
|
267 |
"create and return a typeConverter, which retrieves |
|
268 |
a time via #value, and converts |
|
269 |
a time-string to a time via #value:. |
|
270 |
Useful as an editFields model, which operates on some |
|
271 |
date value (or aspectAdaptor, which adapts to a numeric slot)" |
|
272 |
||
273 |
^ (self on:aValueHolder) timeToText |
|
274 |
||
275 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
276 |
"Created: 4.3.1997 / 11:52:10 / cg" |
|
442 | 277 |
! ! |
278 |
||
2868 | 279 |
!TypeConverter class methodsFor:'queries'! |
280 |
||
281 |
possiblePrintConverterTypes |
|
282 |
"presented in the typeConverter UI-builder menu" |
|
283 |
||
284 |
^ #( |
|
285 |
#string |
|
286 |
#password |
|
287 |
#number |
|
288 |
#numberInRange |
|
289 |
#numberOrNil |
|
290 |
#numberInRangeOrNil |
|
291 |
#numberOrPointOrNil |
|
3214 | 292 |
#numberOrStringOrSymbolOrNil |
293 |
#numberOrSymbolOrNil |
|
294 |
#numberWithOptionalScale |
|
295 |
#integer |
|
2868 | 296 |
#integerInRange |
297 |
#integerWithThousandsSeparator |
|
3510 | 298 |
#integerCStyle |
2868 | 299 |
#fileSize |
3252 | 300 |
#frequency |
2868 | 301 |
#hexadecimal |
302 |
#hexIntegerInRange |
|
303 |
#symbolOrNil |
|
3214 | 304 |
#symbolOrBooleanOrNil |
305 |
#symbolOrNumberOrNil |
|
2868 | 306 |
#smalltalkObject |
307 |
#smalltalkPoint |
|
3214 | 308 |
#literal |
309 |
#date |
|
310 |
#dateOrNil |
|
2868 | 311 |
#dateDDMMYYYY |
312 |
#dateMMDDYYYY |
|
313 |
#time12H |
|
314 |
#time24H |
|
315 |
#time |
|
316 |
#timeOrNil |
|
317 |
#timestamp |
|
318 |
#timestampOrNil |
|
319 |
#timeDuration |
|
320 |
#timeDurationOrNil |
|
321 |
). |
|
322 |
||
323 |
"Created: / 25-09-2010 / 11:27:58 / cg" |
|
324 |
! ! |
|
325 |
||
442 | 326 |
!TypeConverter methodsFor:'accessing'! |
327 |
||
328 |
subject |
|
2406
0f7d2545e089
#dateWithFormat: - allow string dates
Stefan Vogel <sv@exept.de>
parents:
2401
diff
changeset
|
329 |
"return the subject to be converted" |
442 | 330 |
|
331 |
^ model |
|
332 |
! |
|
333 |
||
334 |
value:newValue |
|
335 |
"convert and change" |
|
336 |
||
337 |
self setValue:newValue |
|
338 |
||
339 |
"Created: 21.2.1997 / 18:45:39 / cg" |
|
340 |
! ! |
|
341 |
||
1001 | 342 |
!TypeConverter methodsFor:'input testing'! |
343 |
||
344 |
setNumberValue: value inModel: model fromInput: string |
|
1463 | 345 |
"for invalid numbers, the model is set to nil. |
346 |
By this, the dependents are forced to update their contents |
|
347 |
(that is: a bad input string will lead to a cleared input field here)." |
|
1001 | 348 |
|
1463 | 349 |
|lastInputChar needChange| |
350 |
||
351 |
string notEmpty ifTrue:[ |
|
352 |
1 to: string size - 1 do: [:i| (string at: i) isLetter ifTrue: [needChange := true]]. |
|
1001 | 353 |
lastInputChar := string at: string size. |
354 |
(lastInputChar isDigit not and: [lastInputChar isPrintable and: [ |
|
355 |
(string size > 1 or: [lastInputChar ~~ $-]) and: [ |
|
1463 | 356 |
(string occurrencesOf: $.) > 1 or: [lastInputChar ~~ $.]]]]) ifTrue: [needChange := true]. |
1001 | 357 |
]. |
358 |
||
1463 | 359 |
needChange == true ifTrue:[ |
360 |
value notNil ifTrue:[ |
|
361 |
model setValue:nil |
|
362 |
] ifFalse:[ |
|
363 |
model value isNil ifTrue:[ |
|
364 |
model changed:#value. |
|
365 |
^ self |
|
366 |
] |
|
367 |
]. |
|
368 |
]. |
|
1001 | 369 |
model value:value |
370 |
! ! |
|
371 |
||
3001 | 372 |
!TypeConverter methodsFor:'standard converters-date & time'! |
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
373 |
|
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
374 |
convertOldVWDateFormatSpecifierToNewSTXFormat:oldFormatSpec |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
375 |
"private helper to convert an old (VW) format-Array |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
376 |
of the form: |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
377 |
'mm/dd/yyyy' (VW-backward compatibility) |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
378 |
into: |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
379 |
'%m %d %y' (new ST/X format) |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
380 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
381 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
382 |
|in out c nDigits| |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
383 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
384 |
oldFormatSpec isArray ifTrue:[^ oldFormatSpec]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
385 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
386 |
out := '' writeStream. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
387 |
in := oldFormatSpec readStream. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
388 |
[in atEnd] whileFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
389 |
c := in next. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
390 |
nDigits := 1. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
391 |
c == $m ifTrue:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
392 |
[in peek == $m] whileTrue:[ nDigits := nDigits + 1. in next ]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
393 |
nDigits == 1 ifTrue:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
394 |
out nextPutAll:'%M'. "/ unpadded |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
395 |
] ifFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
396 |
out nextPutAll:'%m'. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
397 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
398 |
] ifFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
399 |
c == $d ifTrue:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
400 |
[in peek == $d] whileTrue:[ nDigits := nDigits + 1. in next ]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
401 |
nDigits == 1 ifTrue:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
402 |
out nextPutAll:'%D'. "/ unpadded |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
403 |
] ifFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
404 |
out nextPutAll:'%d'. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
405 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
406 |
] ifFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
407 |
c == $y ifTrue:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
408 |
[in peek == $y] whileTrue:[ nDigits := nDigits + 1. in next ]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
409 |
nDigits == 2 ifTrue:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
410 |
out nextPutAll:'%Y'. "/ 2 digits only |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
411 |
] ifFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
412 |
out nextPutAll:'%y'. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
413 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
414 |
] ifFalse:[ |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
415 |
out nextPut:c. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
416 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
417 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
418 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
419 |
]. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
420 |
^ out contents. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
421 |
! |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
422 |
|
2401
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
423 |
date |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
424 |
"setup the converter to convert from a string to a date |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
425 |
and vice versa. Nil is converted to todays date-string, |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
426 |
likewise, an empty string is converted back to todays date." |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
427 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
428 |
^ self dateWithFormat:nil orDefault:Date today |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
429 |
! |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
430 |
|
1047 | 431 |
dateDDMMYYYY |
1026 | 432 |
"setup the converter to convert from a string to a date formatted by printFormat |
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
433 |
DD-MM-YYYY; see also Date>>printFormat: |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
434 |
This is a backward compatibility method for very old code to print european-style dates. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
435 |
Please use dateWithFormat: which is much more flexible." |
1026 | 436 |
|
1266
3420e3a98217
Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents:
1265
diff
changeset
|
437 |
self dateToTextFormattedBy: #(1 2 3 $- 1 1 true) |
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
438 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
439 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
440 |
|vh| |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
441 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
442 |
vh := Date today asValue. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
443 |
TypeConverter new |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
444 |
dateDDMMYYYY |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
445 |
model:vh; |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
446 |
value. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
447 |
vh value |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
448 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
449 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
450 |
|vh| |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
451 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
452 |
vh := Date today asValue. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
453 |
TypeConverter new |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
454 |
dateDDMMYYYY |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
455 |
model:vh; |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
456 |
value:'12-01-2008'. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
457 |
vh value |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
458 |
" |
1026 | 459 |
! |
460 |
||
1047 | 461 |
dateMMDDYYYY |
1026 | 462 |
"setup the converter to convert from a string to a date formatted by printFormat |
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
463 |
MM/DD/YYYY; see also Date>>printFormat: |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
464 |
This is a backward compatibility method for very old code to print us-style dates. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
465 |
Please use dateWithFormat: which is much more flexible." |
1026 | 466 |
|
1266
3420e3a98217
Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents:
1265
diff
changeset
|
467 |
self dateToTextFormattedBy: #(2 1 3 $/ 1 1 true) |
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
468 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
469 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
470 |
|vh| |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
471 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
472 |
vh := Date today asValue. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
473 |
TypeConverter new |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
474 |
dateMMDDYYYY |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
475 |
model:vh; |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
476 |
value. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
477 |
vh value |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
478 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
479 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
480 |
|vh| |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
481 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
482 |
vh := Date today asValue. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
483 |
TypeConverter new |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
484 |
dateMMDDYYYY |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
485 |
model:vh; |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
486 |
value:'01/12/2008'. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
487 |
vh value |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
488 |
" |
1026 | 489 |
! |
490 |
||
487 | 491 |
dateOrNil |
492 |
"setup the converter to convert from a string to a date |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
493 |
and vice versa. Invalid dates are converted to nil; likewise, |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
494 |
a nil date is converted to an empty string." |
487 | 495 |
|
1832 | 496 |
^ self dateWithFormat:nil orDefault:nil |
497 |
! |
|
487 | 498 |
|
1832 | 499 |
dateOrNilWithFormat:aFormatString |
500 |
"setup the converter to convert from a string to a date |
|
501 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
502 |
a nil date is converted to an empty string. |
|
503 |
The format string must have one of the forms: |
|
504 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
505 |
or: |
|
506 |
'%m %d %y' |
|
507 |
" |
|
487 | 508 |
|
1832 | 509 |
^ self dateWithFormat:aFormatString orDefault:nil |
487 | 510 |
! |
511 |
||
486 | 512 |
dateToText |
513 |
"setup the converter to convert from a string to a date |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
514 |
and vice versa. Nil is converted to todays date-string, |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
515 |
likewise, an empty string is converted back to todays date." |
486 | 516 |
|
1832 | 517 |
^ self dateWithFormat:nil orDefault:Date today |
486 | 518 |
! |
519 |
||
1026 | 520 |
dateToTextFormattedBy: printFormat |
521 |
"setup the converter to convert from a string to a date formatted by printFormat |
|
522 |
and vice versa. Nil is converted to todays date-string, |
|
1697 | 523 |
likewise, an empty string is converted back to todays date. |
524 |
Uses the old, obsolete ST80 printFormat (see Date printFormat:)" |
|
1026 | 525 |
|
1832 | 526 |
^ self dateWithFormat:printFormat orDefault:Date today |
527 |
! |
|
528 |
||
529 |
dateWithFormat:aFormatString |
|
530 |
"setup the converter to convert from a string to a date |
|
531 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
532 |
a nil date is converted to an empty string. |
|
533 |
The format string must have one of the forms: |
|
534 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
535 |
or: |
|
536 |
'%m %d %y' |
|
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
537 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
538 |
see Date addPrintBindingsTo:language: for a format description. |
1832 | 539 |
" |
540 |
||
2882 | 541 |
^ self dateWithFormat:aFormatString orDefault:Date today language:nil |
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
542 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
543 |
" |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
544 |
|vh| |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
545 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
546 |
vh := Date today asValue. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
547 |
(TypeConverter new |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
548 |
dateWithFormat:'%m%d%y') |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
549 |
model:vh; |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
550 |
value. |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
551 |
vh value |
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
552 |
" |
2882 | 553 |
|
554 |
"Modified: / 16-01-2011 / 11:20:20 / cg" |
|
1832 | 555 |
! |
556 |
||
557 |
dateWithFormat:aFormatString orDefault:defaultValue |
|
2882 | 558 |
"setup the converter to convert from a string to a date and vice versa. |
559 |
Invalid dates are converted to nil; |
|
560 |
likewise, a nil date is converted to an empty string. |
|
561 |
The format string must have one of the forms: |
|
562 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
563 |
or: |
|
564 |
'%m %d %y' |
|
565 |
||
566 |
see Date addPrintBindingsTo:language: for a format description. |
|
567 |
" |
|
568 |
||
569 |
^ self dateWithFormat:aFormatString orDefault:defaultValue language:nil |
|
570 |
||
571 |
"Modified: / 16-01-2011 / 11:19:47 / cg" |
|
572 |
! |
|
573 |
||
574 |
dateWithFormat:aFormatString orDefault:defaultValue language:lang |
|
575 |
"setup the converter to convert from a string to a date and vice versa. |
|
576 |
Invalid dates are converted to nil; |
|
577 |
likewise, a nil date is converted to an empty string. |
|
1832 | 578 |
The format string must have one of the forms: |
579 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
580 |
or: |
|
581 |
'%m %d %y' |
|
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
582 |
|
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
583 |
see Date addPrintBindingsTo:language: for a format description. |
1832 | 584 |
" |
585 |
||
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
586 |
|stxFormat| |
1832 | 587 |
|
588 |
aFormatString notNil ifTrue:[ |
|
589 |
(aFormatString includes:$%) ifTrue:[ |
|
590 |
"/ a new (ST/X) formatString |
|
591 |
stxFormat := aFormatString |
|
592 |
] ifFalse:[ |
|
593 |
"/ an old (VW) formatString |
|
2607
2f81fde8732a
comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
594 |
stxFormat := self convertOldVWDateFormatSpecifierToNewSTXFormat:aFormatString |
1832 | 595 |
]. |
596 |
]. |
|
597 |
||
1026 | 598 |
self |
599 |
getBlock:[:model | |
|
1832 | 600 |
|date| |
1696 | 601 |
|
1832 | 602 |
(date := model value) isNil ifTrue:[ |
603 |
date := defaultValue |
|
604 |
]. |
|
605 |
date isNil ifTrue:[ |
|
606 |
'' |
|
607 |
] ifFalse:[ |
|
2882 | 608 |
date isString ifTrue:[ |
609 |
date |
|
1832 | 610 |
] ifFalse:[ |
2882 | 611 |
stxFormat isNil ifTrue:[ |
612 |
date printStringFormat:(date class defaultFormatString) language:lang |
|
613 |
] ifFalse:[ |
|
614 |
date printStringFormat:stxFormat language:lang |
|
615 |
]. |
|
2406
0f7d2545e089
#dateWithFormat: - allow string dates
Stefan Vogel <sv@exept.de>
parents:
2401
diff
changeset
|
616 |
]. |
0f7d2545e089
#dateWithFormat: - allow string dates
Stefan Vogel <sv@exept.de>
parents:
2401
diff
changeset
|
617 |
]] |
1026 | 618 |
|
619 |
putBlock: |
|
620 |
[:model :string | |
|
621 |
||
622 |
|value| |
|
623 |
||
2560 | 624 |
string isEmptyOrNil ifTrue:[ |
1832 | 625 |
value := defaultValue |
626 |
] ifFalse:[ |
|
627 |
stxFormat isNil ifTrue:[ |
|
628 |
value := Date readFrom:string onError:defaultValue |
|
629 |
] ifFalse:[ |
|
630 |
value := Date readFrom:string printFormat:stxFormat onError:defaultValue |
|
631 |
] |
|
1026 | 632 |
]. |
633 |
model value:value] |
|
634 |
||
635 |
updateBlock: [:m :a :p | true] |
|
2882 | 636 |
|
637 |
"Created: / 16-01-2011 / 11:17:46 / cg" |
|
1026 | 638 |
! |
639 |
||
3734 | 640 |
monthAndYear |
641 |
"setup the converter to convert from a string to a date |
|
642 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
643 |
a nil date is converted to an empty string. |
|
644 |
see Date addPrintBindingsTo:language: for a format description. |
|
645 |
" |
|
646 |
||
3736 | 647 |
^ self dateWithFormat:'%y-%m' |
3734 | 648 |
|
649 |
" |
|
650 |
|vh| |
|
651 |
||
652 |
vh := Date today asValue. |
|
653 |
(TypeConverter new monthAndYear) |
|
654 |
model:vh; |
|
655 |
value. |
|
656 |
vh value |
|
657 |
" |
|
658 |
! |
|
659 |
||
3001 | 660 |
time |
661 |
^ self time24H |
|
662 |
! |
|
663 |
||
664 |
time12H |
|
665 |
"setup the converter to convert from a string to a time formatted by 12 hours |
|
666 |
and vice versa." |
|
667 |
||
668 |
self timeToTextFormattedBy: #printString12HourFormat |
|
669 |
||
670 |
||
671 |
! |
|
672 |
||
673 |
time24H |
|
674 |
"setup the converter to convert from a string to a time formatted by 24 hours |
|
675 |
and vice versa." |
|
676 |
||
677 |
self timeToTextFormattedBy: #printString24HourFormat |
|
678 |
||
679 |
||
680 |
! |
|
681 |
||
682 |
timeDuration |
|
683 |
"setup the converter to convert from a string to a timeduration and vice versa." |
|
684 |
||
685 |
^ self timeOfClass:TimeDuration withFormat:nil orDefault:(0 seconds) language:nil |
|
686 |
||
687 |
"Created: / 25-09-2010 / 11:24:57 / cg" |
|
688 |
"Modified: / 16-01-2011 / 11:21:54 / cg" |
|
689 |
! |
|
690 |
||
691 |
timeDurationOrNil |
|
692 |
"setup the converter to convert from a string to a timeDuration and vice versa." |
|
693 |
||
694 |
self objectOrNilOfType:TimeDuration |
|
695 |
||
696 |
"Created: / 25-09-2010 / 11:25:24 / cg" |
|
697 |
! |
|
698 |
||
699 |
timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue |
|
700 |
"setup the converter to convert from a string to a time and vice versa. |
|
701 |
TimeClass is the class that should be used (e.g. Time or Timestamp). |
|
702 |
Invalid times are converted to defaultValue; likewise, |
|
703 |
a nil time is converted to an empty string." |
|
704 |
||
705 |
^ self timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue language:nil |
|
706 |
||
707 |
"Modified: / 16-01-2011 / 11:21:34 / cg" |
|
708 |
! |
|
709 |
||
710 |
timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue language:langOrNil |
|
711 |
"setup the converter to convert from a string to a time |
|
712 |
and vice versa. TimeClass is the class that should be used (e.g. Time or Timestamp). |
|
713 |
Invalid times are converted to defaultValue; likewise, |
|
714 |
a nil time is converted to an empty string." |
|
715 |
||
716 |
self |
|
717 |
getBlock:[:model | |
|
718 |
|time fmt| |
|
719 |
||
720 |
(time := model value) isNil ifTrue:[ |
|
721 |
time := defaultValue |
|
722 |
]. |
|
723 |
time isNil ifTrue:[ |
|
724 |
'' |
|
725 |
] ifFalse:[ |
|
3853 | 726 |
time isString ifTrue:[ |
727 |
time "/ not strictly ok, bit we don't want to get a DNU... |
|
728 |
] ifFalse:[ |
|
729 |
(fmt := aFormatString) isNil ifTrue:[ |
|
730 |
timeClass = TimeDuration ifTrue:[ |
|
731 |
time isInteger ifTrue:[ |
|
732 |
"backward compatibility - show integer time as seconds" |
|
733 |
time := time seconds. |
|
734 |
]. |
|
735 |
fmt := time formatForPrinting. |
|
736 |
] ifFalse:[ |
|
737 |
fmt := timeClass defaultFormatString |
|
3765 | 738 |
]. |
3001 | 739 |
]. |
3853 | 740 |
time printStringFormat:fmt language:langOrNil |
741 |
] |
|
3001 | 742 |
]] |
743 |
||
744 |
putBlock: |
|
745 |
[:model :string | |
|
746 |
||
747 |
|value| |
|
748 |
||
749 |
string isEmptyOrNil ifTrue:[ |
|
750 |
value := defaultValue |
|
751 |
] ifFalse:[ |
|
752 |
"/ aFormatString isNil ifTrue:[ |
|
753 |
value := timeClass readFrom:string onError:defaultValue |
|
754 |
"/ ] ifFalse:[ |
|
755 |
"/ value := timeClass readFrom:string printFormat:aFormatString onError:defaultValue |
|
756 |
"/ ] |
|
757 |
]. |
|
758 |
model value:value] |
|
759 |
||
760 |
updateBlock: [:m :a :p | true] |
|
761 |
||
762 |
"Created: / 16-01-2011 / 11:21:07 / cg" |
|
763 |
! |
|
764 |
||
765 |
timeOrNil |
|
766 |
"setup the converter to convert from a string to a time and vice versa." |
|
767 |
||
768 |
self objectOrNilOfType:Time |
|
769 |
||
770 |
"Created: / 04-03-1997 / 11:52:47 / cg" |
|
771 |
"Modified: / 12-01-2008 / 19:06:21 / cg" |
|
772 |
! |
|
773 |
||
774 |
timeStampOrNil |
|
775 |
<resource: #obsolete> |
|
776 |
"setup the converter to convert from a string to a timeStamp and vice versa." |
|
777 |
||
778 |
self timestampOrNil |
|
779 |
! |
|
780 |
||
781 |
timeToText |
|
782 |
"setup the converter to convert from a string to a time |
|
783 |
and vice versa." |
|
784 |
||
785 |
self timeToTextFormattedBy: #printString |
|
786 |
! |
|
787 |
||
788 |
timeToTextFormattedBy: format |
|
789 |
"setup the converter to convert from a string to a time formatted by format |
|
790 |
and vice versa." |
|
791 |
||
792 |
self |
|
793 |
getBlock:[:model | |
|
794 |
|time| |
|
795 |
||
796 |
(time := model value) isNil ifTrue:[ |
|
797 |
Time now perform: format |
|
798 |
] ifFalse:[ |
|
799 |
time perform: format |
|
800 |
]] |
|
801 |
||
802 |
putBlock: |
|
803 |
[:model :string | |
|
804 |
||
805 |
|value| |
|
806 |
||
807 |
string isEmptyOrNil ifTrue:[ |
|
808 |
value := Time now |
|
809 |
] ifFalse:[ |
|
810 |
value := Time readFrom:string onError:[Time now] |
|
811 |
]. |
|
812 |
model value:value] |
|
813 |
||
814 |
updateBlock: [:m :a :p | true] |
|
815 |
||
816 |
"Modified: 21.2.1997 / 18:59:06 / cg" |
|
817 |
"Created: 4.3.1997 / 11:52:47 / cg" |
|
818 |
! |
|
819 |
||
820 |
timestamp |
|
821 |
"setup the converter to convert from a string to a timestamp and vice versa." |
|
822 |
||
823 |
^ self timeOfClass:Timestamp withFormat:nil orDefault:Timestamp now |
|
824 |
! |
|
825 |
||
826 |
timestampOrNil |
|
827 |
"setup the converter to convert from a string to a timestamp and vice versa." |
|
828 |
||
829 |
self objectOrNilOfType:Timestamp |
|
830 |
||
831 |
"Modified: / 12-01-2008 / 19:06:06 / cg" |
|
3734 | 832 |
! |
833 |
||
834 |
year |
|
835 |
"setup the converter to convert from a string to a date |
|
836 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
837 |
a nil date is converted to an empty string. |
|
838 |
see Date addPrintBindingsTo:language: for a format description. |
|
839 |
" |
|
840 |
||
841 |
^ self dateWithFormat:'%y' |
|
842 |
||
843 |
" |
|
844 |
|vh| |
|
845 |
||
846 |
vh := Date today asValue. |
|
847 |
(TypeConverter new year) |
|
848 |
model:vh; |
|
849 |
value. |
|
850 |
vh value |
|
851 |
" |
|
3001 | 852 |
! ! |
853 |
||
854 |
!TypeConverter methodsFor:'standard converters-misc'! |
|
855 |
||
856 |
arrayLiteralOrStringOrSymbolOrNil |
|
857 |
"setup the converter to convert from a string to either a literal |
|
858 |
Array, a String or a symbol and vice versa. |
|
859 |
Invalid strings (i.e. empty) are converted to nil; |
|
860 |
nil values are converted to an empty string. |
|
861 |
This is a very special converter (for the GUI builder) |
|
862 |
- probably not belonging to here" |
|
863 |
||
864 |
self |
|
865 |
getBlock:[:model | |
|
866 |
|symbolValue| |
|
867 |
||
868 |
(symbolValue := model value) isNil ifTrue:[ |
|
3486 | 869 |
'' |
3001 | 870 |
] ifFalse:[ |
871 |
symbolValue storeString |
|
872 |
]] |
|
873 |
||
874 |
putBlock: |
|
875 |
[:model :string | |
|
876 |
||
877 |
|value s| |
|
878 |
||
879 |
string isEmptyOrNil ifTrue:[ |
|
880 |
value := nil |
|
881 |
] ifFalse:[ |
|
882 |
s := string withoutSeparators. |
|
883 |
(s startsWith:'#(') ifTrue:[ |
|
884 |
value := Array readFrom:s onError:nil |
|
885 |
] ifFalse:[ |
|
886 |
(s startsWith:'''') ifTrue:[ |
|
887 |
value := String readFrom:s onError:nil |
|
888 |
] ifFalse:[ |
|
889 |
(s startsWith:'#') ifTrue:[ |
|
890 |
s := s copyFrom:2 |
|
891 |
]. |
|
892 |
value := s asSymbol |
|
893 |
] |
|
894 |
] |
|
895 |
]. |
|
896 |
model value:value] |
|
897 |
||
898 |
updateBlock: [:m :a :p | true] |
|
899 |
||
900 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
901 |
"Created: / 26.10.1997 / 14:01:02 / cg" |
|
902 |
! |
|
903 |
||
904 |
arrayLiteralOrSymbolOrNil |
|
905 |
"setup the converter to convert from a string to either a literal |
|
906 |
Array or a symbol and vice versa. |
|
907 |
Invalid strings (i.e. empty) are converted to nil; |
|
908 |
nil values are converted to an empty string. |
|
909 |
This is a very special converter (for the GUI builder) |
|
910 |
- probably not belonging to here" |
|
911 |
||
912 |
self |
|
913 |
getBlock:[:model | |
|
914 |
|symbolValue| |
|
915 |
||
916 |
(symbolValue := model value) isNil ifTrue:[ |
|
3486 | 917 |
'' |
3001 | 918 |
] ifFalse:[ |
919 |
symbolValue isArray ifTrue:[ |
|
920 |
symbolValue storeString |
|
921 |
] ifFalse:[ |
|
922 |
'#' , symbolValue asString |
|
923 |
] |
|
924 |
]] |
|
925 |
||
926 |
putBlock: |
|
927 |
[:model :string | |
|
928 |
||
929 |
|value s| |
|
930 |
||
931 |
string isEmptyOrNil ifTrue:[ |
|
932 |
value := nil |
|
933 |
] ifFalse:[ |
|
934 |
s := string withoutSeparators. |
|
935 |
(s startsWith:'#(') ifTrue:[ |
|
936 |
value := Array readFrom:s onError:nil |
|
937 |
] ifFalse:[ |
|
938 |
(s startsWith:'#') ifTrue:[ |
|
939 |
s := s copyFrom:2 |
|
940 |
]. |
|
941 |
value := s asSymbol |
|
942 |
] |
|
943 |
]. |
|
944 |
model value:value] |
|
945 |
||
946 |
updateBlock: [:m :a :p | true] |
|
947 |
||
948 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
949 |
"Created: / 26.10.1997 / 14:01:02 / cg" |
|
950 |
! |
|
951 |
||
1791 | 952 |
fileSize |
953 |
"setup the converter to convert from a fileSize string to a number |
|
954 |
and vice versa. |
|
3486 | 955 |
A fileSize can have a scale of 1000 (k or kB), 1024 (ki or kiB), |
956 |
1000*1000 (m or mB), 1024*1024 (mi or miB), 1000*1000*1000 (g or gB), 1024*1024*1024 (gi or giB)." |
|
1791 | 957 |
|
958 |
self |
|
959 |
getBlock:[:model | |
|
960 |
|numericValue| |
|
961 |
||
962 |
(numericValue := model value) isNumber ifFalse:[ |
|
3486 | 963 |
'' |
1791 | 964 |
] ifTrue:[ |
965 |
UnitConverter fileSizeStringFor:numericValue |
|
966 |
]] |
|
967 |
||
968 |
putBlock: |
|
969 |
[:model :string | |
|
3486 | 970 |
model value:(UnitConverter fileSizeFromString:string)] |
1791 | 971 |
|
972 |
updateBlock: [:m :a :p | true] |
|
973 |
! |
|
974 |
||
3252 | 975 |
frequency |
976 |
"setup the converter to convert from a frequency string to a number |
|
977 |
and vice versa. |
|
978 |
A frequency can have a scale of 1000 (k or kHz), |
|
979 |
1000*1000 (m or MHz), 1000*1000*1000 (g or GHz)." |
|
980 |
||
981 |
self |
|
982 |
getBlock:[:model | |
|
983 |
|numericValue| |
|
984 |
||
985 |
(numericValue := model value) isNumber ifFalse:[ |
|
3486 | 986 |
'' |
3252 | 987 |
] ifTrue:[ |
988 |
UnitConverter frequencyStringFor:numericValue |
|
989 |
]] |
|
990 |
||
991 |
putBlock: |
|
992 |
[:model :string | |
|
993 |
||
994 |
model value:(UnitConverter frequencyFromString:string)] |
|
995 |
||
996 |
updateBlock: [:m :a :p | true] |
|
997 |
! |
|
998 |
||
3001 | 999 |
literal |
1000 |
"setup the converter to convert from a string to a literal |
|
1001 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
|
1002 |
nil values are converted to an empty string. |
|
1003 |
true, false, Numbers are parsed" |
|
1004 |
||
1005 |
self |
|
1006 |
getBlock:[:model | |
|
1007 |
|val s| |
|
1008 |
||
1009 |
val := model value. |
|
1010 |
(val isLiteral and:[val notNil]) ifTrue:[ |
|
1011 |
val isSymbol ifTrue:[ |
|
1012 |
"print 'special' symbols as symbols i.e. as #'symbol'" |
|
1013 |
(s := val storeString) second == $' ifTrue:[ |
|
1014 |
s |
|
1015 |
] ifFalse:[ |
|
1016 |
val printString |
|
1017 |
] |
|
1018 |
] ifFalse:[ |
|
1019 |
val storeString |
|
1020 |
]. |
|
1021 |
] ifFalse:[ |
|
1022 |
''. |
|
1023 |
]] |
|
1024 |
||
1025 |
putBlock: |
|
1026 |
[:model :string | |
|
1027 |
||
1028 |
|value s| |
|
1029 |
||
1030 |
string size == 0 ifTrue:[ |
|
1031 |
value := nil |
|
1032 |
] ifFalse:[ |
|
1033 |
s := string withoutSeparators. |
|
1034 |
"be careful, #readFrom:onError: returns nil for an undefined identifier" |
|
1035 |
s = 'true' ifTrue:[ |
|
1036 |
value := true. |
|
1037 |
] ifFalse:[s = 'false' ifTrue:[ |
|
1038 |
value := false. |
|
1039 |
] ifFalse:[s = 'nil' ifTrue:[ |
|
1040 |
value := nil. |
|
1041 |
] ifFalse:[s first isLetter ifTrue:[ |
|
1042 |
value := s asSymbol. |
|
1043 |
] ifFalse:[ |
|
1044 |
value := Object readFrom:s onError:[ |
|
1045 |
s asSymbol |
|
1046 |
]. |
|
1047 |
]]]]. |
|
1048 |
]. |
|
1049 |
model value:value] |
|
1050 |
||
1051 |
updateBlock: [:m :a :p | true] |
|
1052 |
||
1053 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
|
1054 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
|
1055 |
! |
|
1056 |
||
1057 |
objectOrNilOfType:timeOrDateClass |
|
1058 |
"common code for timeOrNil, dateOrNil and timeStampOrNil" |
|
1059 |
||
1060 |
self |
|
1061 |
getBlock:[:model | |
|
1062 |
|timeOrDate| |
|
1063 |
||
1064 |
(timeOrDate := model value) isNil ifTrue:[ |
|
1065 |
'' |
|
1066 |
] ifFalse:[ |
|
1067 |
timeOrDate printString |
|
1068 |
]] |
|
1069 |
||
1070 |
putBlock: |
|
1071 |
[:model :string | |
|
1072 |
||
1073 |
|value| |
|
1074 |
||
1075 |
string isEmptyOrNil ifTrue:[ |
|
1076 |
value := nil |
|
1077 |
] ifFalse:[ |
|
1078 |
value := timeOrDateClass readFrom:string onError:nil |
|
1079 |
]. |
|
1080 |
model value:value] |
|
1081 |
||
1082 |
updateBlock: [:m :a :p | true] |
|
1083 |
||
1084 |
"Created: / 12-01-2008 / 19:05:18 / cg" |
|
1085 |
! |
|
1086 |
||
1087 |
smalltalkObject |
|
1088 |
"setup the converter to convert from a string to any smalltalk object |
|
1089 |
and vice versa. The string used is the objects storeString. |
|
1090 |
Invalid strings (i.e. empty) are converted to nil. |
|
1091 |
This is a very special converter (for the GUI builder) |
|
1092 |
- probably not belonging to here" |
|
1093 |
||
1094 |
^ self smalltalkObjectWithClass:Object |
|
1095 |
! |
|
1096 |
||
1097 |
smalltalkObjectOrNil |
|
1098 |
"setup the converter to convert from a string to any smalltalk object |
|
1099 |
and vice versa. The string used is the objects storeString. |
|
1100 |
Invalid strings (i.e. empty) are converted to nil. |
|
1101 |
This is a very special converter (for the GUI builder) |
|
1102 |
- probably not belonging to here" |
|
1103 |
||
1104 |
^ self smalltalkObjectOrNilWithClass:Object |
|
1105 |
! |
|
1106 |
||
1107 |
smalltalkObjectOrNilWithClass:classOfObject |
|
1108 |
"setup the converter to convert from a string to a smalltalk object |
|
1109 |
and vice versa. The string used is the objects storeString. |
|
1110 |
Invalid strings (i.e. empty) are converted to nil. |
|
1111 |
This is a very special converter (for the GUI builder) |
|
1112 |
- probably not belonging to here" |
|
1113 |
||
1114 |
self |
|
1115 |
getBlock:[:model | |v s| |
|
3103 | 1116 |
v := model value. |
1117 |
v isNil ifTrue:[ |
|
3001 | 1118 |
s := 'nil' |
3103 | 1119 |
] ifFalse:[ |
1120 |
s := v storeString. |
|
1121 |
(v isString or:[v isNumber]) ifFalse:[ |
|
1122 |
s := s , ' "' , v class name , '" ' |
|
1123 |
] |
|
1124 |
]. |
|
1125 |
s |
|
1126 |
] |
|
1127 |
||
3001 | 1128 |
putBlock: |
1129 |
[:model :string | |
|
1130 |
||
3103 | 1131 |
|value| |
3001 | 1132 |
|
1133 |
string size > 0 ifTrue:[ |
|
1134 |
value := classOfObject readFrom:string onError:nil. |
|
1135 |
value := value ? string. |
|
1136 |
]. |
|
1137 |
model value:value |
|
1138 |
] |
|
1139 |
||
1140 |
updateBlock: [:m :a :p | true] |
|
1141 |
||
1142 |
"Created: / 29-10-1997 / 15:50:16 / cg" |
|
1143 |
"Modified: / 05-09-2006 / 17:57:53 / cg" |
|
1144 |
! |
|
1145 |
||
1146 |
smalltalkObjectWithClass:classOfObject |
|
1147 |
"setup the converter to convert from a string to a smalltalk object |
|
1148 |
and vice versa. The string used is the objects storeString. |
|
1149 |
Invalid strings (i.e. empty) are converted to nil. |
|
1150 |
This is a very special converter (for the GUI builder) |
|
1151 |
- probably not belonging to here" |
|
1152 |
||
1153 |
self |
|
1154 |
getBlock:[:model | |v s| |
|
3103 | 1155 |
v := model value. |
1156 |
v isNil ifTrue:[ |
|
3001 | 1157 |
s := '' |
3103 | 1158 |
] ifFalse:[ |
1159 |
s := v storeString. |
|
1160 |
(v isString or:[v isNumber]) ifFalse:[ |
|
1161 |
s := s , ' "' , v class name , '" ' |
|
1162 |
] |
|
1163 |
]. |
|
1164 |
s |
|
3001 | 1165 |
] |
1166 |
||
1167 |
putBlock: |
|
1168 |
[:model :string | |
|
1169 |
||
1170 |
|value| |
|
1171 |
||
1172 |
string size > 0 ifTrue:[ |
|
1173 |
value := classOfObject readFrom:string onError:nil. |
|
1174 |
model value:value ? string |
|
3103 | 1175 |
] ifFalse:[ |
1176 |
model value:value |
|
1177 |
] |
|
3001 | 1178 |
] |
1179 |
||
1180 |
updateBlock: [:m :a :p | true] |
|
1181 |
||
1182 |
"Created: / 29-10-1997 / 15:50:16 / cg" |
|
1183 |
"Modified: / 05-09-2006 / 17:57:37 / cg" |
|
1184 |
! |
|
1185 |
||
1186 |
smalltalkPoint |
|
1187 |
"setup the converter to convert from a string to a point object |
|
1188 |
and vice versa. The string used is the points storeString. |
|
1189 |
Invalid strings (i.e. empty) are converted to nil. |
|
1190 |
This is a very special converter (for the GUI builder) |
|
1191 |
- probably not belonging to here" |
|
1192 |
||
1193 |
^ self smalltalkObjectWithClass:Point |
|
1194 |
! |
|
1195 |
||
1196 |
symbolOrBooleanOrNil |
|
1197 |
"setup the converter to convert from a string to a symbol or boolean |
|
1198 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
|
1199 |
nil values are converted to an empty string. |
|
1200 |
In addition, the strings true/false convert to/from booleans." |
|
1201 |
||
1202 |
self |
|
1203 |
getBlock:[:model | |
|
1204 |
|symbolValue| |
|
1205 |
||
1206 |
((symbolValue := model value) isSymbol |
|
1207 |
or:[symbolValue isBoolean]) |
|
1208 |
ifFalse:[ |
|
1209 |
'' |
|
1210 |
] ifTrue:[ |
|
1211 |
(symbolValue == #true or:[symbolValue == #false]) ifTrue:[ |
|
1212 |
symbolValue storeString "/ to show the symbolness |
|
1213 |
] ifFalse:[ |
|
1214 |
symbolValue printString. "/ storeString |
|
1215 |
] |
|
1216 |
]] |
|
1217 |
||
1218 |
putBlock: |
|
1219 |
[:model :string | |
|
1220 |
||
1221 |
|value s| |
|
1222 |
||
1223 |
string size == 0 ifTrue:[ |
|
1224 |
value := nil |
|
1225 |
] ifFalse:[ |
|
1226 |
s := string withoutSeparators. |
|
1227 |
(s startsWith:'#') ifTrue:[ |
|
1228 |
s := s copyFrom:2. |
|
1229 |
(s startsWith:$') ifTrue:[ |
|
1230 |
s := s copyFrom:2 to:(s size - 1) |
|
1231 |
]. |
|
1232 |
value := s asSymbol |
|
1233 |
] ifFalse:[ |
|
1234 |
(#('true' 'false') includes:s) ifTrue:[ |
|
1235 |
value := Object readFromString:s. |
|
1236 |
] ifFalse:[ |
|
1237 |
value := s asSymbol |
|
1238 |
] |
|
1239 |
]. |
|
1240 |
]. |
|
1241 |
model value:value] |
|
1242 |
||
1243 |
updateBlock: [:m :a :p | true] |
|
1244 |
||
1245 |
"Created: / 21-02-1997 / 18:58:38 / cg" |
|
1246 |
"Modified (comment): / 20-03-2012 / 21:25:48 / cg" |
|
1247 |
! |
|
1248 |
||
1249 |
symbolOrNil |
|
1250 |
"setup the converter to convert from a string to a symbol |
|
1251 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
|
1252 |
nil values are converted to an empty string." |
|
1253 |
||
1254 |
self |
|
1255 |
getBlock:[:model | |
|
1256 |
|symbolValue| |
|
1257 |
||
1258 |
(symbolValue := model value) isSymbol ifFalse:[ |
|
3486 | 1259 |
'' |
3001 | 1260 |
] ifTrue:[ |
1261 |
symbolValue printString. "/ storeString |
|
1262 |
]] |
|
1263 |
||
1264 |
putBlock: |
|
1265 |
[:model :string | |
|
1266 |
||
1267 |
|value s| |
|
1268 |
||
1269 |
string size == 0 ifTrue:[ |
|
1270 |
value := nil |
|
1271 |
] ifFalse:[ |
|
1272 |
s := string withoutSeparators. |
|
1273 |
(s startsWith:'#') ifTrue:[ |
|
1274 |
s := s copyFrom:2. |
|
1275 |
(s startsWith:$') ifTrue:[ |
|
1276 |
s := s copyFrom:2 to:(s size - 1) |
|
1277 |
] |
|
1278 |
]. |
|
1279 |
value := s asSymbol |
|
1280 |
]. |
|
1281 |
model value:value] |
|
1282 |
||
1283 |
updateBlock: [:m :a :p | true] |
|
1284 |
||
1285 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
|
1286 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
|
3214 | 1287 |
! |
1288 |
||
1289 |
symbolOrNumberOrNil |
|
1290 |
"setup the converter to convert from a string to a symbol or number |
|
1291 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
|
1292 |
nil values are converted to an empty string." |
|
1293 |
||
1294 |
self |
|
1295 |
getBlock:[:model | |
|
1296 |
|symbolValue| |
|
1297 |
||
1298 |
((symbolValue := model value) isSymbol |
|
1299 |
or:[symbolValue isNumber]) |
|
1300 |
ifFalse:[ |
|
1301 |
'' |
|
1302 |
] ifTrue:[ |
|
1303 |
symbolValue storeString. |
|
1304 |
]] |
|
1305 |
||
1306 |
putBlock: |
|
1307 |
[:model :string | |
|
1308 |
||
1309 |
|value s| |
|
1310 |
||
1311 |
string size == 0 ifTrue:[ |
|
1312 |
value := nil |
|
1313 |
] ifFalse:[ |
|
1314 |
s := string withoutSeparators. |
|
1315 |
(s startsWith:'#') ifTrue:[ |
|
1316 |
s := s copyFrom:2. |
|
1317 |
(s startsWith:$') ifTrue:[ |
|
1318 |
s := s copyFrom:2 to:(s size - 1) |
|
1319 |
]. |
|
1320 |
value := s asSymbol |
|
1321 |
] ifFalse:[ |
|
1322 |
value := Number readFromString:s onError:[s asSymbol]. |
|
1323 |
]. |
|
1324 |
]. |
|
1325 |
model value:value] |
|
1326 |
||
1327 |
updateBlock: [:m :a :p | true] |
|
3001 | 1328 |
! ! |
1329 |
||
1330 |
!TypeConverter methodsFor:'standard converters-numbers'! |
|
1331 |
||
1122 | 1332 |
hexadecimal |
1047 | 1333 |
"setup the converter to convert from a hexadecimal string to a number |
1334 |
and vice versa." |
|
1335 |
||
1336 |
self |
|
1337 |
getBlock:[:model | |
|
1338 |
|hexValue| |
|
1339 |
||
1340 |
(hexValue := model value) isNumber ifFalse:[ |
|
3486 | 1341 |
'' |
1047 | 1342 |
] ifTrue:[ |
1343 |
hexValue hexPrintString |
|
1344 |
]] |
|
1345 |
||
1346 |
putBlock: |
|
1347 |
[:model :string | |
|
1348 |
||
1349 |
|value| |
|
1350 |
||
2560 | 1351 |
string isEmptyOrNil ifTrue:[ |
1047 | 1352 |
value := 0 |
1353 |
] ifFalse:[ |
|
1354 |
value := Integer readFrom: string radix:16 onError:[0] |
|
1355 |
]. |
|
1356 |
model value:value] |
|
1357 |
||
1358 |
updateBlock: [:m :a :p | true] |
|
1359 |
! |
|
1360 |
||
2623 | 1361 |
integer |
1362 |
"setup the converter to convert from a string to an integer |
|
1363 |
and vice versa. Invalid integers are converted to nil." |
|
1364 |
||
1365 |
self integerToText |
|
1366 |
! |
|
1367 |
||
3510 | 1368 |
integerCStyle |
1369 |
"setup the converter to convert from a string to an integer |
|
1370 |
and vice versa. Supports CStyle 0x/0b and 0 prefixes |
|
1371 |
Invalid integers are converted to nil." |
|
1372 |
||
1373 |
self integerToTextCStyle |
|
1374 |
! |
|
1375 |
||
2982 | 1376 |
integerOrNil |
1377 |
"setup the converter to convert from a string to an integer |
|
1378 |
and vice versa. Invalid numbers are converted to nil." |
|
1379 |
||
1380 |
self objectOrNilOfType:Integer |
|
1381 |
||
1382 |
"Modified: / 12-01-2008 / 19:08:42 / cg" |
|
1383 |
"Created: / 22-01-2012 / 11:28:24 / cg" |
|
1384 |
! |
|
1385 |
||
2366 | 1386 |
integerToHexTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
1387 |
"setup the converter to convert from a string to a number |
|
1388 |
and vice versa, but clamping the number into the range." |
|
1389 |
||
1390 |
^ self integerToTextMinValue:minVal maxValue:maxVal radix:16 format:formatStringOrNil |
|
1391 |
! |
|
1392 |
||
2623 | 1393 |
integerToText |
1394 |
"setup the converter to convert from a string to a integer |
|
1395 |
and vice versa." |
|
1396 |
||
1397 |
self |
|
1398 |
getBlock:[:model | |
|
1399 |
|numericValue| |
|
1400 |
||
1401 |
(numericValue := model value) isInteger ifFalse:[ |
|
3486 | 1402 |
'' |
2623 | 1403 |
] ifTrue:[ |
1404 |
numericValue printString |
|
1405 |
]] |
|
1406 |
||
1407 |
putBlock: |
|
1408 |
[:model :string | |
|
1409 |
||
1410 |
|value| |
|
1411 |
||
1412 |
string isEmptyOrNil ifTrue:[ |
|
1413 |
value := 0 |
|
1414 |
] ifFalse:[ |
|
1415 |
value := Integer readFromString: string onError:[0] |
|
1416 |
]. |
|
1417 |
model value:value] |
|
1418 |
||
1419 |
updateBlock: [:m :a :p | true] |
|
1420 |
! |
|
1421 |
||
3510 | 1422 |
integerToTextCStyle |
1423 |
"setup the converter to convert from a string to a integer |
|
1424 |
and vice versa. SUpports C-style integers in the form 0x, 0b 0 |
|
1425 |
and also Smalltalk radix integers" |
|
1426 |
||
1427 |
self |
|
1428 |
getBlock:[:model | |
|
1429 |
|numericValue| |
|
1430 |
||
1431 |
(numericValue := model value) isInteger ifFalse:[ |
|
1432 |
'' |
|
1433 |
] ifTrue:[ |
|
1434 |
numericValue printString |
|
1435 |
]] |
|
1436 |
||
1437 |
putBlock: |
|
1438 |
[:model :string | |
|
1439 |
||
1440 |
|value| |
|
1441 |
||
1442 |
string isEmptyOrNil ifTrue:[ |
|
1443 |
value := 0 |
|
1444 |
] ifFalse:[ |
|
1445 |
(string startsWith:'0x') ifTrue:[ |
|
1446 |
value := Integer readFromString: (string copyFrom:3) radix:16 onError:[0] |
|
1447 |
] ifFalse:[ |
|
1448 |
(string startsWith:'0b') ifTrue:[ |
|
1449 |
value := Integer readFromString: (string copyFrom:3) radix:2 onError:[0] |
|
1450 |
] ifFalse:[ |
|
1451 |
(string startsWith:'0') ifTrue:[ |
|
1452 |
value := Integer readFromString: string radix:8 onError:[0] |
|
1453 |
] ifFalse:[ |
|
1454 |
value := Integer readFromString: string onError:[0] |
|
1455 |
] |
|
1456 |
] |
|
1457 |
] |
|
1458 |
]. |
|
1459 |
model value:value] |
|
1460 |
||
1461 |
updateBlock: [:m :a :p | true] |
|
1462 |
! |
|
1463 |
||
1974 | 1464 |
integerToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
1465 |
"setup the converter to convert from a string to a number |
|
1466 |
and vice versa, but clamping the number into the range." |
|
1467 |
||
2366 | 1468 |
^ self integerToTextMinValue:minVal maxValue:maxVal radix:10 format:formatStringOrNil |
1469 |
! |
|
1470 |
||
1471 |
integerToTextMinValue:minVal maxValue:maxVal radix:radix format:formatStringOrNil |
|
1472 |
"setup the converter to convert from a string to a number |
|
1473 |
and vice versa, but clamping the number into the range." |
|
1474 |
||
1974 | 1475 |
self |
1476 |
getBlock:[:model | |
|
1477 |
|numericValue| |
|
1478 |
||
1479 |
(numericValue := model value) isNil ifTrue:[ |
|
3486 | 1480 |
'' |
1974 | 1481 |
] ifFalse:[ |
2379 | 1482 |
numericValue isString ifTrue:[ |
1483 |
numericValue |
|
1974 | 1484 |
] ifFalse:[ |
2379 | 1485 |
formatStringOrNil isNil ifTrue:[ |
2737
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
1486 |
radix = 10 ifTrue:[ |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
1487 |
numericValue printString |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
1488 |
] ifFalse:[ |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
1489 |
numericValue printStringRadix:radix |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
1490 |
] |
2379 | 1491 |
] ifFalse:[ |
1492 |
numericValue printfPrintString:formatStringOrNil |
|
1493 |
] |
|
1974 | 1494 |
] |
1495 |
]] |
|
1496 |
||
1497 |
putBlock: |
|
1498 |
[:model :string | |
|
1499 |
||
1500 |
|value c| |
|
1501 |
||
2560 | 1502 |
string isEmptyOrNil ifTrue:[ |
1974 | 1503 |
value := 0 |
1504 |
] ifFalse:[ |
|
2366 | 1505 |
value := Integer readFromString:string radix:radix onError:[0]. |
1974 | 1506 |
]. |
1507 |
minVal notNil ifTrue:[ |
|
1508 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
1509 |
value := value max:minVal. |
|
1510 |
]. |
|
1511 |
maxVal notNil ifTrue:[ |
|
1512 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
1513 |
value := value min:maxVal. |
|
1514 |
]. |
|
1515 |
self setNumberValue: value inModel: model fromInput: string. |
|
1516 |
] |
|
1517 |
||
1518 |
updateBlock: [:m :a :p | true] |
|
1519 |
||
1520 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
1521 |
! |
|
1522 |
||
2379 | 1523 |
integerWithThousandsSeparator |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1524 |
^ self numberWithThousandsSeparator |
2379 | 1525 |
! |
1526 |
||
1527 |
integerWithThousandsSeparator:sep |
|
1528 |
"setup the converter to convert from a string to a number with thousands separator |
|
1529 |
and vice versa." |
|
1530 |
||
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1531 |
^ self numberWithThousandsSeparator:sep |
2379 | 1532 |
! |
1533 |
||
508 | 1534 |
number |
1535 |
"setup the converter to convert from a string to a number |
|
1536 |
and vice versa. Invalid numbers are converted to nil." |
|
1537 |
||
1538 |
self numberToText |
|
1539 |
||
1540 |
"Created: 4.4.1997 / 12:46:14 / cg" |
|
1541 |
! |
|
1542 |
||
442 | 1543 |
numberOrNil |
1544 |
"setup the converter to convert from a string to a number |
|
1545 |
and vice versa. Invalid numbers are converted to nil." |
|
1546 |
||
2372 | 1547 |
self objectOrNilOfType:Number |
442 | 1548 |
|
2372 | 1549 |
"Modified: / 12-01-2008 / 19:08:42 / cg" |
442 | 1550 |
! |
1551 |
||
1463 | 1552 |
numberOrNilToTextMinValue:minVal maxValue:maxVal |
1553 |
"setup the converter to convert from a string to a number or nil |
|
1554 |
and vice versa, but clamping the number into the range." |
|
1555 |
||
1974 | 1556 |
self numberOrNilToTextMinValue:minVal maxValue:maxVal format:nil |
1557 |
! |
|
1558 |
||
1559 |
numberOrNilToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
|
1560 |
"setup the converter to convert from a string to a number or nil |
|
1561 |
and vice versa, but clamping the number into the range." |
|
1562 |
||
1463 | 1563 |
self |
1564 |
getBlock:[:model | |
|
1565 |
|numericValue| |
|
1566 |
||
1567 |
(numericValue := model value) isNil ifTrue:[ |
|
3486 | 1568 |
'' |
1463 | 1569 |
] ifFalse:[ |
1974 | 1570 |
formatStringOrNil isNil ifTrue:[ |
1571 |
numericValue printString |
|
1572 |
] ifFalse:[ |
|
1573 |
numericValue printfPrintString:formatStringOrNil |
|
1574 |
] |
|
1463 | 1575 |
]] |
1576 |
||
1577 |
putBlock: |
|
1578 |
[:model :string | |
|
1579 |
||
1580 |
|value c| |
|
1581 |
||
2560 | 1582 |
(string isEmptyOrNil or:[string isBlank]) ifTrue:[ |
1463 | 1583 |
value := nil |
1584 |
] ifFalse:[ |
|
1585 |
value := Number readFromString:string onError:[nil]. |
|
1586 |
value isNil ifTrue:[ |
|
1587 |
||
1588 |
] ifFalse:[ |
|
1589 |
minVal notNil ifTrue:[ |
|
1590 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
1591 |
value := value max:minVal. |
|
1592 |
]. |
|
1593 |
maxVal notNil ifTrue:[ |
|
1594 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
1595 |
value := value min:maxVal. |
|
1596 |
]. |
|
1597 |
]. |
|
1598 |
]. |
|
1599 |
self setNumberValue: value inModel: model fromInput: string. |
|
1600 |
] |
|
1601 |
||
1602 |
updateBlock: [:m :a :p | true] |
|
1603 |
||
1604 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
1605 |
! |
|
1606 |
||
1335
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1607 |
numberOrPointOrNil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1608 |
"setup the converter to convert from a string to a number or point |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1609 |
and vice versa. Invalid numbers/points are converted to nil." |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1610 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1611 |
self |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1612 |
getBlock:[:model | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1613 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1614 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1615 |
(value := model value) isNil ifTrue:[ |
3486 | 1616 |
'' |
1335
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1617 |
] ifFalse:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1618 |
value printString |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1619 |
]] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1620 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1621 |
putBlock: |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1622 |
[:model :string | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1623 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1624 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1625 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1626 |
string size > 0 ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1627 |
value := Point readFrom:string onError:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1628 |
Number readFrom:string onError:nil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1629 |
] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1630 |
]. |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1631 |
model value:value] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1632 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1633 |
updateBlock: [:m :a :p | true] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1634 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1635 |
"Created: / 5.2.2000 / 01:26:48 / cg" |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1636 |
! |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1637 |
|
1149 | 1638 |
numberOrStringOrSymbolOrNil |
1639 |
"setup the converter to convert from a string to either a numeric literal |
|
1640 |
or a symbol and vice versa. |
|
1641 |
Invalid strings (i.e. empty) are converted to nil; |
|
1642 |
nil values are converted to an empty string. |
|
1643 |
This is a very special converter (for the GUI builder) |
|
1644 |
- probably not belonging to here" |
|
1645 |
||
1646 |
self |
|
1647 |
getBlock:[:model | |
|
1648 |
|litValue| |
|
1649 |
||
1650 |
(litValue := model value) isNil ifTrue:[ |
|
3486 | 1651 |
'' |
1149 | 1652 |
] ifFalse:[ |
1653 |
litValue storeString |
|
1654 |
]] |
|
1655 |
||
1656 |
putBlock: |
|
1657 |
[:model :string | |
|
1658 |
||
1659 |
|value s| |
|
1660 |
||
2560 | 1661 |
string isEmptyOrNil ifTrue:[ |
1149 | 1662 |
value := nil |
1663 |
] ifFalse:[ |
|
1664 |
value := Number readFrom:string onError:nil. |
|
1665 |
value isNil ifTrue:[ |
|
1666 |
s := string withoutSeparators. |
|
1667 |
(s startsWith:'''') ifTrue:[ |
|
1668 |
value := String readFrom:s readStream onError:nil |
|
1669 |
] ifFalse:[ |
|
1670 |
(s startsWith:'#') ifTrue:[ |
|
1671 |
s := s copyFrom:2. |
|
1672 |
(s startsWith:$') ifTrue:[ |
|
1673 |
s := s copyFrom:2 to:(s size - 1) |
|
1674 |
]. |
|
1675 |
]. |
|
1676 |
value := s asSymbol |
|
1677 |
] |
|
1678 |
] |
|
1679 |
]. |
|
1680 |
model value:value] |
|
1681 |
||
1682 |
updateBlock: [:m :a :p | true] |
|
1683 |
||
1684 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
1685 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
1686 |
! |
|
1687 |
||
726 | 1688 |
numberOrSymbolOrNil |
1689 |
"setup the converter to convert from a string to either a numeric literal |
|
1690 |
or a symbol and vice versa. |
|
1691 |
Invalid strings (i.e. empty) are converted to nil; |
|
1692 |
nil values are converted to an empty string. |
|
1693 |
This is a very special converter (for the GUI builder) |
|
1694 |
- probably not belonging to here" |
|
1695 |
||
1696 |
self |
|
1697 |
getBlock:[:model | |
|
1698 |
|litValue| |
|
1699 |
||
1700 |
(litValue := model value) isNil ifTrue:[ |
|
3486 | 1701 |
'' |
726 | 1702 |
] ifFalse:[ |
1703 |
litValue storeString |
|
1704 |
]] |
|
1705 |
||
1706 |
putBlock: |
|
1707 |
[:model :string | |
|
1708 |
||
1709 |
|value s| |
|
1710 |
||
2560 | 1711 |
string isEmptyOrNil ifTrue:[ |
726 | 1712 |
value := nil |
1713 |
] ifFalse:[ |
|
1714 |
value := Number readFrom:string onError:nil. |
|
1715 |
value isNil ifTrue:[ |
|
1716 |
s := string withoutSeparators. |
|
1717 |
(s startsWith:'#') ifTrue:[ |
|
1718 |
s := s copyFrom:2. |
|
1719 |
(s startsWith:$') ifTrue:[ |
|
1720 |
s := s copyFrom:2 to:(s size - 1) |
|
1721 |
]. |
|
1722 |
]. |
|
1723 |
value := s asSymbol |
|
1724 |
] |
|
1725 |
]. |
|
1726 |
model value:value] |
|
1727 |
||
1728 |
updateBlock: [:m :a :p | true] |
|
1729 |
||
1730 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
1731 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
1732 |
! |
|
1733 |
||
442 | 1734 |
numberToText |
1735 |
"setup the converter to convert from a string to a number |
|
487 | 1736 |
and vice versa." |
442 | 1737 |
|
1738 |
self |
|
1739 |
getBlock:[:model | |
|
1740 |
|numericValue| |
|
1741 |
||
726 | 1742 |
(numericValue := model value) isNumber ifFalse:[ |
3486 | 1743 |
'' |
726 | 1744 |
] ifTrue:[ |
442 | 1745 |
numericValue printString |
1746 |
]] |
|
1747 |
||
1748 |
putBlock: |
|
1749 |
[:model :string | |
|
1750 |
||
1751 |
|value| |
|
1752 |
||
2560 | 1753 |
string isEmptyOrNil ifTrue:[ |
442 | 1754 |
value := 0 |
1755 |
] ifFalse:[ |
|
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1756 |
value := Number readFromString: string onError:[0] |
442 | 1757 |
]. |
1758 |
model value:value] |
|
1759 |
||
1760 |
updateBlock: [:m :a :p | true] |
|
1761 |
||
726 | 1762 |
"Created: / 21.2.1997 / 18:57:05 / cg" |
1763 |
"Modified: / 29.10.1997 / 15:49:21 / cg" |
|
442 | 1764 |
! |
1765 |
||
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1766 |
numberToText:numberOfPostDecimals |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1767 |
"setup the converter to convert from a string to a number |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1768 |
and vice versa." |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1769 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1770 |
self |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1771 |
getBlock:[:model | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1772 |
|numericValue| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1773 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1774 |
(numericValue := model value) isNumber ifFalse:[ |
3486 | 1775 |
'' |
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1776 |
] ifTrue:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1777 |
(numericValue asFixedPoint:numberOfPostDecimals) printString |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1778 |
]] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1779 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1780 |
putBlock: |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1781 |
[:model :string | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1782 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1783 |
|value| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1784 |
|
2560 | 1785 |
string isEmptyOrNil ifTrue:[ |
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1786 |
value := 0 |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1787 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1788 |
value := Number readFromString:string onError:[0] |
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1789 |
]. |
1001 | 1790 |
self setNumberValue: value inModel: model fromInput: string. |
1791 |
] |
|
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1792 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1793 |
updateBlock: [:m :a :p | true] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1794 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1795 |
"Created: / 5.12.1997 / 02:54:13 / cg" |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1796 |
"Modified: / 5.12.1997 / 18:21:04 / cg" |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1797 |
! |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1798 |
|
442 | 1799 |
numberToTextFormattedBy:formatString |
1800 |
"setup the converter to convert from a string to a number |
|
1801 |
and vice versa, using formatString. |
|
1802 |
The formatString is currently ignored when numbers are converted |
|
1803 |
from a string." |
|
1804 |
||
1805 |
self |
|
1806 |
getBlock:[:model | |
|
1807 |
|numericValue| |
|
1808 |
||
1809 |
(numericValue := model value) isNil ifTrue:[ |
|
3486 | 1810 |
'' |
442 | 1811 |
] ifFalse:[ |
1812 |
PrintConverter print:numericValue formattedBy:formatString |
|
1813 |
]] |
|
1814 |
||
1815 |
putBlock: |
|
1816 |
[:model :string | |
|
1817 |
||
1818 |
|value| |
|
1819 |
||
2560 | 1820 |
string isEmptyOrNil ifTrue:[ |
442 | 1821 |
value := 0 |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1822 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1823 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
442 | 1824 |
]. |
1825 |
model value:value] |
|
1826 |
||
1827 |
updateBlock: [:m :a :p | true] |
|
1828 |
||
1829 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
446 | 1830 |
! |
1831 |
||
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1832 |
numberToTextLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1833 |
"setup the converter to convert from a string to a number |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1834 |
and vice versa, using formatString. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1835 |
The formatString is currently ignored when numbers are converted |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1836 |
from a string." |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1837 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1838 |
self |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1839 |
getBlock:[:model | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1840 |
|numericValue| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1841 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1842 |
(numericValue := model value) isNil ifTrue:[ |
3486 | 1843 |
'' |
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1844 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1845 |
numericValue printStringLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1846 |
]] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1847 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1848 |
putBlock: |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1849 |
[:model :string | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1850 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1851 |
|value| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1852 |
|
2560 | 1853 |
string isEmptyOrNil ifTrue:[ |
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1854 |
value := 0 |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1855 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1856 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1857 |
]. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1858 |
model value:value] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1859 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1860 |
updateBlock: [:m :a :p | true] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1861 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1862 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1863 |
! |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1864 |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1865 |
numberToTextMinValue:minVal maxValue:maxVal |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1866 |
"setup the converter to convert from a string to a number |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1867 |
and vice versa, but clamping the number into the range." |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1868 |
|
1974 | 1869 |
self numberToTextMinValue:minVal maxValue:maxVal format:nil |
1870 |
! |
|
1871 |
||
1872 |
numberToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
|
1873 |
"setup the converter to convert from a string to a number |
|
1874 |
and vice versa, but clamping the number into the range." |
|
1875 |
||
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1876 |
self |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1877 |
getBlock:[:model | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1878 |
|numericValue| |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1879 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1880 |
(numericValue := model value) isNil ifTrue:[ |
3486 | 1881 |
'' |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1882 |
] ifFalse:[ |
1974 | 1883 |
formatStringOrNil isNil ifTrue:[ |
1884 |
numericValue printString |
|
1885 |
] ifFalse:[ |
|
1886 |
numericValue printfPrintString:formatStringOrNil |
|
1887 |
] |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1888 |
]] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1889 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1890 |
putBlock: |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1891 |
[:model :string | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1892 |
|
1001 | 1893 |
|value c| |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1894 |
|
2560 | 1895 |
string isEmptyOrNil ifTrue:[ |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1896 |
value := 0 |
1001 | 1897 |
] ifFalse:[ |
997 | 1898 |
value := Number readFromString: string onError:[0]. |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1899 |
]. |
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1900 |
minVal notNil ifTrue:[ |
1001 | 1901 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1902 |
value := value max:minVal. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1903 |
]. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1904 |
maxVal notNil ifTrue:[ |
1001 | 1905 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
944 | 1906 |
value := value min:maxVal. |
1001 | 1907 |
]. |
1908 |
self setNumberValue: value inModel: model fromInput: string. |
|
1909 |
] |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1910 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1911 |
updateBlock: [:m :a :p | true] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1912 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1913 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1914 |
! |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1915 |
|
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1916 |
numberWithOptionalScale |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1917 |
"setup the converter to convert from a string to a number |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1918 |
and vice versa. Invalid numbers are converted to nil. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1919 |
The number may be followed by one of m (for million) or |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1920 |
k (for thousand). E.g.: '1m2k55' " |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1921 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1922 |
|scaleDict| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1923 |
|
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1924 |
scaleDict := Dictionary withKeysAndValues:#( |
3214 | 1925 |
$g 1000000000 |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1926 |
$m 1000000 |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1927 |
$k 1000 |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1928 |
$t 1000 |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1929 |
). |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1930 |
self numberWithOptionalScales:scaleDict |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1931 |
! |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1932 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1933 |
numberWithOptionalScales:scaleDict |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1934 |
"setup the converter to convert from a string to a number or nil |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1935 |
and vice versa; allow for scale characters (such as k for thousand). |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1936 |
|
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1937 |
E.g. '1m2k55' " |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1938 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1939 |
self |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1940 |
getBlock:[:model | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1941 |
|numericValue| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1942 |
|
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1943 |
numericValue := model value. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1944 |
numericValue isEmptyOrNil ifTrue:[ |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1945 |
'' |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1946 |
] ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1947 |
numericValue printString |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1948 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1949 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1950 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1951 |
putBlock: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1952 |
[:model :string | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1953 |
|
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1954 |
|value c stream scaleChar scale partValue| |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1955 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1956 |
(string isEmptyOrNil or:[string isBlank]) ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1957 |
value := nil |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1958 |
] ifFalse:[ |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1959 |
value := 0. |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1960 |
stream := string readStream. |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1961 |
[ |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1962 |
partValue := Number readFrom:stream onError:[nil]. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1963 |
partValue notNil ifTrue:[ |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1964 |
stream skipSeparators. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1965 |
scaleChar := stream nextOrNil. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1966 |
scale := scaleDict at:scaleChar ifAbsent:1. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1967 |
value := value + (partValue * scale). |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1968 |
]. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1969 |
] doWhile:[partValue notNil]. |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1970 |
]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1971 |
self setNumberValue: value inModel: model fromInput: string. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1972 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1973 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1974 |
updateBlock: [:m :a :p | true] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1975 |
! |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1976 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1977 |
numberWithOptionalScales:scaleDict andThousandsSeparator:sep |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1978 |
"setup the converter to convert from a string to a number with thousands separator |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1979 |
and vice versa. Allow for scale characters (such as k for thousand) " |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1980 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1981 |
self |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1982 |
getBlock:[:model | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1983 |
|numericValue| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1984 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1985 |
(numericValue := model value) isNumber ifFalse:[ |
3486 | 1986 |
'' |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1987 |
] ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1988 |
String streamContents:[:s | numericValue printOn:s thousandsSeparator:sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1989 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1990 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1991 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1992 |
putBlock: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1993 |
[:model :string | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1994 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1995 |
|value c stream scaleChar scale s2| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1996 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1997 |
string isEmptyOrNil ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1998 |
value := 0 |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1999 |
] ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2000 |
s2 := string reject:[:ch | ch = sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2001 |
stream := s2 readStream. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2002 |
value := Number readFrom:stream onError:[nil]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2003 |
value notNil ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2004 |
stream skipSeparators. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2005 |
scaleChar := stream peek. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2006 |
scale := scaleDict at:scaleChar ifAbsent:1. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2007 |
value := value * scale. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2008 |
]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2009 |
]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2010 |
"/ model value:value |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2011 |
self setNumberValue: value inModel: model fromInput: string. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2012 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2013 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2014 |
updateBlock: [:m :a :p | true] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2015 |
! |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2016 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2017 |
numberWithThousandsSeparator |
3779 | 2018 |
"/ ^ self numberWithThousandsSeparator:$' |
2019 |
^ self numberWithThousandsSeparator:(UserPreferences current thousandsSeparatorCharacter) |
|
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2020 |
! |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2021 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2022 |
numberWithThousandsSeparator:sep |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2023 |
"setup the converter to convert from a string to a number with thousands separator |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2024 |
and vice versa." |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2025 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2026 |
self |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2027 |
getBlock:[:model | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2028 |
|numericValue| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2029 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2030 |
(numericValue := model value) isNumber ifFalse:[ |
3486 | 2031 |
'' |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2032 |
] ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2033 |
String streamContents:[:s | numericValue printOn:s thousandsSeparator:sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2034 |
]] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2035 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2036 |
putBlock: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2037 |
[:model :string | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2038 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2039 |
|value s2| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2040 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2041 |
string isEmptyOrNil ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2042 |
value := 0 |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2043 |
] ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2044 |
s2 := string reject:[:ch | ch = sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2045 |
value := Number readFromString:s2 onError:[0] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2046 |
]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2047 |
model value:value] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2048 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
2049 |
updateBlock: [:m :a :p | true] |
442 | 2050 |
! ! |
2051 |
||
2052 |
!TypeConverter class methodsFor:'documentation'! |
|
2053 |
||
2054 |
version |
|
3486 | 2055 |
^ '$Header$' |
2868 | 2056 |
! |
2057 |
||
2058 |
version_CVS |
|
3486 | 2059 |
^ '$Header$' |
442 | 2060 |
! ! |
3103 | 2061 |