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