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