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