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