author | Stefan Vogel <sv@exept.de> |
Fri, 23 Apr 2010 15:09:54 +0200 | |
changeset 2836 | 66a39bce5584 |
parent 2737 | 0c83579be3d3 |
child 2868 | 0eb805b3bf00 |
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:[ |
2737
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
780 |
radix = 10 ifTrue:[ |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
781 |
numericValue printString |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
782 |
] ifFalse:[ |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
783 |
numericValue printStringRadix:radix |
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
784 |
] |
2379 | 785 |
] ifFalse:[ |
786 |
numericValue printfPrintString:formatStringOrNil |
|
787 |
] |
|
1974 | 788 |
] |
789 |
]] |
|
790 |
||
791 |
putBlock: |
|
792 |
[:model :string | |
|
793 |
||
794 |
|value c| |
|
795 |
||
2560 | 796 |
string isEmptyOrNil ifTrue:[ |
1974 | 797 |
value := 0 |
798 |
] ifFalse:[ |
|
2366 | 799 |
value := Integer readFromString:string radix:radix onError:[0]. |
1974 | 800 |
]. |
801 |
minVal notNil ifTrue:[ |
|
802 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
803 |
value := value max:minVal. |
|
804 |
]. |
|
805 |
maxVal notNil ifTrue:[ |
|
806 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
807 |
value := value min:maxVal. |
|
808 |
]. |
|
809 |
self setNumberValue: value inModel: model fromInput: string. |
|
810 |
] |
|
811 |
||
812 |
updateBlock: [:m :a :p | true] |
|
813 |
||
814 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
815 |
! |
|
816 |
||
2379 | 817 |
integerWithThousandsSeparator |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
818 |
^ self numberWithThousandsSeparator |
2379 | 819 |
! |
820 |
||
821 |
integerWithThousandsSeparator:sep |
|
822 |
"setup the converter to convert from a string to a number with thousands separator |
|
823 |
and vice versa." |
|
824 |
||
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
825 |
^ self numberWithThousandsSeparator:sep |
2379 | 826 |
! |
827 |
||
1464
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
828 |
literal |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
829 |
"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
|
830 |
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
|
831 |
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
|
832 |
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
|
833 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
834 |
self |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
835 |
getBlock:[:model | |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
836 |
|val s| |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
837 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
838 |
val := model value. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
839 |
(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
|
840 |
val isSymbol ifTrue:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
841 |
"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
|
842 |
(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
|
843 |
s |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
844 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
845 |
val printString |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
846 |
] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
847 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
848 |
val storeString |
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 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
851 |
''. |
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 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
854 |
putBlock: |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
855 |
[:model :string | |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
856 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
857 |
|value s| |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
858 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
859 |
string size == 0 ifTrue:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
860 |
value := nil |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
861 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
862 |
s := string withoutSeparators. |
1465 | 863 |
"be careful, #readFrom:onError: returns nil for an undefined identifier" |
864 |
s = 'true' ifTrue:[ |
|
865 |
value := true. |
|
866 |
] ifFalse:[s = 'false' ifTrue:[ |
|
867 |
value := false. |
|
868 |
] ifFalse:[s = 'nil' ifTrue:[ |
|
869 |
value := nil. |
|
870 |
] ifFalse:[s first isLetter ifTrue:[ |
|
871 |
value := s asSymbol. |
|
872 |
] ifFalse:[ |
|
873 |
value := Object readFrom:s onError:[ |
|
874 |
s asSymbol |
|
875 |
]. |
|
876 |
]]]]. |
|
1464
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 |
model value:value] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
879 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
880 |
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
|
881 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
882 |
"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
|
883 |
"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
|
884 |
! |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
885 |
|
508 | 886 |
number |
887 |
"setup the converter to convert from a string to a number |
|
888 |
and vice versa. Invalid numbers are converted to nil." |
|
889 |
||
890 |
self numberToText |
|
891 |
||
892 |
"Created: 4.4.1997 / 12:46:14 / cg" |
|
893 |
! |
|
894 |
||
442 | 895 |
numberOrNil |
896 |
"setup the converter to convert from a string to a number |
|
897 |
and vice versa. Invalid numbers are converted to nil." |
|
898 |
||
2372 | 899 |
self objectOrNilOfType:Number |
442 | 900 |
|
2372 | 901 |
"Modified: / 12-01-2008 / 19:08:42 / cg" |
442 | 902 |
! |
903 |
||
1463 | 904 |
numberOrNilToTextMinValue:minVal maxValue:maxVal |
905 |
"setup the converter to convert from a string to a number or nil |
|
906 |
and vice versa, but clamping the number into the range." |
|
907 |
||
1974 | 908 |
self numberOrNilToTextMinValue:minVal maxValue:maxVal format:nil |
909 |
! |
|
910 |
||
911 |
numberOrNilToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
|
912 |
"setup the converter to convert from a string to a number or nil |
|
913 |
and vice versa, but clamping the number into the range." |
|
914 |
||
1463 | 915 |
self |
916 |
getBlock:[:model | |
|
917 |
|numericValue| |
|
918 |
||
919 |
(numericValue := model value) isNil ifTrue:[ |
|
920 |
String new |
|
921 |
] ifFalse:[ |
|
1974 | 922 |
formatStringOrNil isNil ifTrue:[ |
923 |
numericValue printString |
|
924 |
] ifFalse:[ |
|
925 |
numericValue printfPrintString:formatStringOrNil |
|
926 |
] |
|
1463 | 927 |
]] |
928 |
||
929 |
putBlock: |
|
930 |
[:model :string | |
|
931 |
||
932 |
|value c| |
|
933 |
||
2560 | 934 |
(string isEmptyOrNil or:[string isBlank]) ifTrue:[ |
1463 | 935 |
value := nil |
936 |
] ifFalse:[ |
|
937 |
value := Number readFromString:string onError:[nil]. |
|
938 |
value isNil ifTrue:[ |
|
939 |
||
940 |
] ifFalse:[ |
|
941 |
minVal notNil ifTrue:[ |
|
942 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
943 |
value := value max:minVal. |
|
944 |
]. |
|
945 |
maxVal notNil ifTrue:[ |
|
946 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
947 |
value := value min:maxVal. |
|
948 |
]. |
|
949 |
]. |
|
950 |
]. |
|
951 |
self setNumberValue: value inModel: model fromInput: string. |
|
952 |
] |
|
953 |
||
954 |
updateBlock: [:m :a :p | true] |
|
955 |
||
956 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
957 |
! |
|
958 |
||
1335
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
959 |
numberOrPointOrNil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
960 |
"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
|
961 |
and vice versa. Invalid numbers/points are converted to nil." |
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 |
self |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
964 |
getBlock:[:model | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
965 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
966 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
967 |
(value := model value) isNil ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
968 |
String new |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
969 |
] ifFalse:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
970 |
value printString |
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 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
973 |
putBlock: |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
974 |
[:model :string | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
975 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
976 |
|value| |
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 |
string size > 0 ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
979 |
value := Point readFrom:string onError:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
980 |
Number readFrom:string onError:nil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
981 |
] |
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 |
model value:value] |
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 |
updateBlock: [:m :a :p | true] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
986 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
987 |
"Created: / 5.2.2000 / 01:26:48 / cg" |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
988 |
! |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
989 |
|
1149 | 990 |
numberOrStringOrSymbolOrNil |
991 |
"setup the converter to convert from a string to either a numeric literal |
|
992 |
or a symbol and vice versa. |
|
993 |
Invalid strings (i.e. empty) are converted to nil; |
|
994 |
nil values are converted to an empty string. |
|
995 |
This is a very special converter (for the GUI builder) |
|
996 |
- probably not belonging to here" |
|
997 |
||
998 |
self |
|
999 |
getBlock:[:model | |
|
1000 |
|litValue| |
|
1001 |
||
1002 |
(litValue := model value) isNil ifTrue:[ |
|
1003 |
String new |
|
1004 |
] ifFalse:[ |
|
1005 |
litValue storeString |
|
1006 |
]] |
|
1007 |
||
1008 |
putBlock: |
|
1009 |
[:model :string | |
|
1010 |
||
1011 |
|value s| |
|
1012 |
||
2560 | 1013 |
string isEmptyOrNil ifTrue:[ |
1149 | 1014 |
value := nil |
1015 |
] ifFalse:[ |
|
1016 |
value := Number readFrom:string onError:nil. |
|
1017 |
value isNil ifTrue:[ |
|
1018 |
s := string withoutSeparators. |
|
1019 |
(s startsWith:'''') ifTrue:[ |
|
1020 |
value := String readFrom:s readStream onError:nil |
|
1021 |
] ifFalse:[ |
|
1022 |
(s startsWith:'#') ifTrue:[ |
|
1023 |
s := s copyFrom:2. |
|
1024 |
(s startsWith:$') ifTrue:[ |
|
1025 |
s := s copyFrom:2 to:(s size - 1) |
|
1026 |
]. |
|
1027 |
]. |
|
1028 |
value := s asSymbol |
|
1029 |
] |
|
1030 |
] |
|
1031 |
]. |
|
1032 |
model value:value] |
|
1033 |
||
1034 |
updateBlock: [:m :a :p | true] |
|
1035 |
||
1036 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
1037 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
1038 |
! |
|
1039 |
||
726 | 1040 |
numberOrSymbolOrNil |
1041 |
"setup the converter to convert from a string to either a numeric literal |
|
1042 |
or a symbol and vice versa. |
|
1043 |
Invalid strings (i.e. empty) are converted to nil; |
|
1044 |
nil values are converted to an empty string. |
|
1045 |
This is a very special converter (for the GUI builder) |
|
1046 |
- probably not belonging to here" |
|
1047 |
||
1048 |
self |
|
1049 |
getBlock:[:model | |
|
1050 |
|litValue| |
|
1051 |
||
1052 |
(litValue := model value) isNil ifTrue:[ |
|
1053 |
String new |
|
1054 |
] ifFalse:[ |
|
1055 |
litValue storeString |
|
1056 |
]] |
|
1057 |
||
1058 |
putBlock: |
|
1059 |
[:model :string | |
|
1060 |
||
1061 |
|value s| |
|
1062 |
||
2560 | 1063 |
string isEmptyOrNil ifTrue:[ |
726 | 1064 |
value := nil |
1065 |
] ifFalse:[ |
|
1066 |
value := Number readFrom:string onError:nil. |
|
1067 |
value isNil ifTrue:[ |
|
1068 |
s := string withoutSeparators. |
|
1069 |
(s startsWith:'#') ifTrue:[ |
|
1070 |
s := s copyFrom:2. |
|
1071 |
(s startsWith:$') ifTrue:[ |
|
1072 |
s := s copyFrom:2 to:(s size - 1) |
|
1073 |
]. |
|
1074 |
]. |
|
1075 |
value := s asSymbol |
|
1076 |
] |
|
1077 |
]. |
|
1078 |
model value:value] |
|
1079 |
||
1080 |
updateBlock: [:m :a :p | true] |
|
1081 |
||
1082 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
1083 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
1084 |
! |
|
1085 |
||
442 | 1086 |
numberToText |
1087 |
"setup the converter to convert from a string to a number |
|
487 | 1088 |
and vice versa." |
442 | 1089 |
|
1090 |
self |
|
1091 |
getBlock:[:model | |
|
1092 |
|numericValue| |
|
1093 |
||
726 | 1094 |
(numericValue := model value) isNumber ifFalse:[ |
442 | 1095 |
String new |
726 | 1096 |
] ifTrue:[ |
442 | 1097 |
numericValue printString |
1098 |
]] |
|
1099 |
||
1100 |
putBlock: |
|
1101 |
[:model :string | |
|
1102 |
||
1103 |
|value| |
|
1104 |
||
2560 | 1105 |
string isEmptyOrNil ifTrue:[ |
442 | 1106 |
value := 0 |
1107 |
] ifFalse:[ |
|
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1108 |
value := Number readFromString: string onError:[0] |
442 | 1109 |
]. |
1110 |
model value:value] |
|
1111 |
||
1112 |
updateBlock: [:m :a :p | true] |
|
1113 |
||
726 | 1114 |
"Created: / 21.2.1997 / 18:57:05 / cg" |
1115 |
"Modified: / 29.10.1997 / 15:49:21 / cg" |
|
442 | 1116 |
! |
1117 |
||
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1118 |
numberToText:numberOfPostDecimals |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1119 |
"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
|
1120 |
and vice versa." |
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 |
self |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1123 |
getBlock:[:model | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1124 |
|numericValue| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1125 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1126 |
(numericValue := model value) isNumber ifFalse:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1127 |
String new |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1128 |
] ifTrue:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1129 |
(numericValue asFixedPoint:numberOfPostDecimals) printString |
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 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1132 |
putBlock: |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1133 |
[:model :string | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1134 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1135 |
|value| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1136 |
|
2560 | 1137 |
string isEmptyOrNil ifTrue:[ |
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1138 |
value := 0 |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1139 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1140 |
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
|
1141 |
]. |
1001 | 1142 |
self setNumberValue: value inModel: model fromInput: string. |
1143 |
] |
|
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1144 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1145 |
updateBlock: [:m :a :p | true] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1146 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1147 |
"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
|
1148 |
"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
|
1149 |
! |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
1150 |
|
442 | 1151 |
numberToTextFormattedBy:formatString |
1152 |
"setup the converter to convert from a string to a number |
|
1153 |
and vice versa, using formatString. |
|
1154 |
The formatString is currently ignored when numbers are converted |
|
1155 |
from a string." |
|
1156 |
||
1157 |
self |
|
1158 |
getBlock:[:model | |
|
1159 |
|numericValue| |
|
1160 |
||
1161 |
(numericValue := model value) isNil ifTrue:[ |
|
1162 |
String new |
|
1163 |
] ifFalse:[ |
|
1164 |
PrintConverter print:numericValue formattedBy:formatString |
|
1165 |
]] |
|
1166 |
||
1167 |
putBlock: |
|
1168 |
[:model :string | |
|
1169 |
||
1170 |
|value| |
|
1171 |
||
2560 | 1172 |
string isEmptyOrNil ifTrue:[ |
442 | 1173 |
value := 0 |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1174 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1175 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
442 | 1176 |
]. |
1177 |
model value:value] |
|
1178 |
||
1179 |
updateBlock: [:m :a :p | true] |
|
1180 |
||
1181 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
446 | 1182 |
! |
1183 |
||
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1184 |
numberToTextLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1185 |
"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
|
1186 |
and vice versa, using formatString. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1187 |
The formatString is currently ignored when numbers are converted |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1188 |
from a string." |
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 |
self |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1191 |
getBlock:[:model | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1192 |
|numericValue| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1193 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1194 |
(numericValue := model value) isNil ifTrue:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1195 |
String new |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1196 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1197 |
numericValue printStringLeftPaddedTo:aSize with:aCharacter |
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 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1200 |
putBlock: |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1201 |
[:model :string | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1202 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1203 |
|value| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1204 |
|
2560 | 1205 |
string isEmptyOrNil ifTrue:[ |
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1206 |
value := 0 |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1207 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1208 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
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 |
model value:value] |
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 |
updateBlock: [:m :a :p | true] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1213 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1214 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1215 |
! |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1216 |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1217 |
numberToTextMinValue:minVal maxValue:maxVal |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1218 |
"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
|
1219 |
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
|
1220 |
|
1974 | 1221 |
self numberToTextMinValue:minVal maxValue:maxVal format:nil |
1222 |
! |
|
1223 |
||
1224 |
numberToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
|
1225 |
"setup the converter to convert from a string to a number |
|
1226 |
and vice versa, but clamping the number into the range." |
|
1227 |
||
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1228 |
self |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1229 |
getBlock:[:model | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1230 |
|numericValue| |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1231 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1232 |
(numericValue := model value) isNil ifTrue:[ |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1233 |
String new |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1234 |
] ifFalse:[ |
1974 | 1235 |
formatStringOrNil isNil ifTrue:[ |
1236 |
numericValue printString |
|
1237 |
] ifFalse:[ |
|
1238 |
numericValue printfPrintString:formatStringOrNil |
|
1239 |
] |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1240 |
]] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1241 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1242 |
putBlock: |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1243 |
[:model :string | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1244 |
|
1001 | 1245 |
|value c| |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1246 |
|
2560 | 1247 |
string isEmptyOrNil ifTrue:[ |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1248 |
value := 0 |
1001 | 1249 |
] ifFalse:[ |
997 | 1250 |
value := Number readFromString: string onError:[0]. |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1251 |
]. |
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1252 |
minVal notNil ifTrue:[ |
1001 | 1253 |
(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
|
1254 |
value := value max:minVal. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1255 |
]. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1256 |
maxVal notNil ifTrue:[ |
1001 | 1257 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
944 | 1258 |
value := value min:maxVal. |
1001 | 1259 |
]. |
1260 |
self setNumberValue: value inModel: model fromInput: string. |
|
1261 |
] |
|
941
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 |
updateBlock: [:m :a :p | true] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1264 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1265 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1266 |
! |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1267 |
|
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1268 |
numberWithOptionalScale |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1269 |
"setup the converter to convert from a string to a number |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1270 |
and vice versa. Invalid numbers are converted to nil. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1271 |
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
|
1272 |
k (for thousand). E.g.: '1m2k55' " |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1273 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1274 |
|scaleDict| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1275 |
|
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1276 |
scaleDict := Dictionary withKeysAndValues:#( |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1277 |
$m 1000000 |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1278 |
$k 1000 |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1279 |
$t 1000 |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1280 |
). |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1281 |
self numberWithOptionalScales:scaleDict |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1282 |
! |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1283 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1284 |
numberWithOptionalScales:scaleDict |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1285 |
"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
|
1286 |
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
|
1287 |
|
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1288 |
E.g. '1m2k55' " |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1289 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1290 |
self |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1291 |
getBlock:[:model | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1292 |
|numericValue| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1293 |
|
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1294 |
numericValue := model value. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1295 |
numericValue isEmptyOrNil ifTrue:[ |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1296 |
'' |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1297 |
] ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1298 |
numericValue printString |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1299 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1300 |
] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1301 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1302 |
putBlock: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1303 |
[:model :string | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1304 |
|
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1305 |
|value c stream scaleChar scale partValue| |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1306 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1307 |
(string isEmptyOrNil or:[string isBlank]) ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1308 |
value := nil |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1309 |
] ifFalse:[ |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1310 |
value := 0. |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1311 |
stream := string readStream. |
2620
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1312 |
[ |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1313 |
partValue := Number readFrom:stream onError:[nil]. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1314 |
partValue notNil ifTrue:[ |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1315 |
stream skipSeparators. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1316 |
scaleChar := stream nextOrNil. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1317 |
scale := scaleDict at:scaleChar ifAbsent:1. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1318 |
value := value + (partValue * scale). |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1319 |
]. |
7bd45a3ea825
Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents:
2613
diff
changeset
|
1320 |
] doWhile:[partValue notNil]. |
2613
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1321 |
]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1322 |
self setNumberValue: value inModel: model fromInput: string. |
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 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1325 |
updateBlock: [:m :a :p | true] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1326 |
! |
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 |
numberWithOptionalScales:scaleDict andThousandsSeparator:sep |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1329 |
"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
|
1330 |
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
|
1331 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1332 |
self |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1333 |
getBlock:[:model | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1334 |
|numericValue| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1335 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1336 |
(numericValue := model value) isNumber ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1337 |
String new |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1338 |
] ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1339 |
String streamContents:[:s | numericValue printOn:s thousandsSeparator:sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1340 |
] |
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 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1343 |
putBlock: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1344 |
[:model :string | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1345 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1346 |
|value c stream scaleChar scale s2| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1347 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1348 |
string isEmptyOrNil ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1349 |
value := 0 |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1350 |
] ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1351 |
s2 := string reject:[:ch | ch = sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1352 |
stream := s2 readStream. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1353 |
value := Number readFrom:stream onError:[nil]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1354 |
value notNil ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1355 |
stream skipSeparators. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1356 |
scaleChar := stream peek. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1357 |
scale := scaleDict at:scaleChar ifAbsent:1. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1358 |
value := value * scale. |
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 |
"/ model value:value |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1362 |
self setNumberValue: value inModel: model fromInput: string. |
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 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1365 |
updateBlock: [:m :a :p | true] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1366 |
! |
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 |
numberWithThousandsSeparator |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1369 |
^ self numberWithThousandsSeparator:$' |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1370 |
"/ ^ self numberWithThousandsSeparator:(UserPreferences current thousandsSeparatorCharacter) |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1371 |
! |
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 |
numberWithThousandsSeparator:sep |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1374 |
"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
|
1375 |
and vice versa." |
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 |
self |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1378 |
getBlock:[:model | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1379 |
|numericValue| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1380 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1381 |
(numericValue := model value) isNumber ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1382 |
String new |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1383 |
] ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1384 |
String streamContents:[:s | numericValue printOn:s thousandsSeparator:sep]. |
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 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1387 |
putBlock: |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1388 |
[:model :string | |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1389 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1390 |
|value s2| |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1391 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1392 |
string isEmptyOrNil ifTrue:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1393 |
value := 0 |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1394 |
] ifFalse:[ |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1395 |
s2 := string reject:[:ch | ch = sep]. |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1396 |
value := Number readFromString:s2 onError:[0] |
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 |
model value:value] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1399 |
|
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1400 |
updateBlock: [:m :a :p | true] |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1401 |
! |
4c6bedf19f55
new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents:
2607
diff
changeset
|
1402 |
|
2372 | 1403 |
objectOrNilOfType:timeOrDateClass |
1404 |
"common code for timeOrNil, dateOrNil and timeStampOrNil" |
|
1405 |
||
1406 |
self |
|
1407 |
getBlock:[:model | |
|
1408 |
|timeOrDate| |
|
1409 |
||
1410 |
(timeOrDate := model value) isNil ifTrue:[ |
|
1411 |
'' |
|
1412 |
] ifFalse:[ |
|
1413 |
timeOrDate printString |
|
1414 |
]] |
|
1415 |
||
1416 |
putBlock: |
|
1417 |
[:model :string | |
|
1418 |
||
1419 |
|value| |
|
1420 |
||
2560 | 1421 |
string isEmptyOrNil ifTrue:[ |
2372 | 1422 |
value := nil |
1423 |
] ifFalse:[ |
|
1424 |
value := timeOrDateClass readFrom:string onError:nil |
|
1425 |
]. |
|
1426 |
model value:value] |
|
1427 |
||
1428 |
updateBlock: [:m :a :p | true] |
|
1429 |
||
1430 |
"Created: / 12-01-2008 / 19:05:18 / cg" |
|
1431 |
! |
|
1432 |
||
726 | 1433 |
smalltalkObject |
1434 |
"setup the converter to convert from a string to any smalltalk object |
|
1435 |
and vice versa. The string used is the objects storeString. |
|
1436 |
Invalid strings (i.e. empty) are converted to nil. |
|
1437 |
This is a very special converter (for the GUI builder) |
|
1438 |
- probably not belonging to here" |
|
1439 |
||
1786 | 1440 |
^ self smalltalkObjectWithClass:Object |
1407 | 1441 |
! |
1442 |
||
1443 |
smalltalkObjectOrNil |
|
1444 |
"setup the converter to convert from a string to any smalltalk object |
|
1445 |
and vice versa. The string used is the objects storeString. |
|
1446 |
Invalid strings (i.e. empty) are converted to nil. |
|
1447 |
This is a very special converter (for the GUI builder) |
|
1448 |
- probably not belonging to here" |
|
1449 |
||
1786 | 1450 |
^ self smalltalkObjectOrNilWithClass:Object |
1451 |
! |
|
1452 |
||
1453 |
smalltalkObjectOrNilWithClass:classOfObject |
|
1454 |
"setup the converter to convert from a string to a smalltalk object |
|
1455 |
and vice versa. The string used is the objects storeString. |
|
1456 |
Invalid strings (i.e. empty) are converted to nil. |
|
1457 |
This is a very special converter (for the GUI builder) |
|
1458 |
- probably not belonging to here" |
|
1459 |
||
1407 | 1460 |
self |
1461 |
getBlock:[:model | |v s| |
|
1462 |
v := model value. |
|
1463 |
v isNil ifTrue:[ |
|
1406
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1464 |
s := 'nil' |
1199
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1465 |
] ifFalse:[ |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1466 |
s := v storeString. |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1467 |
(v isString or:[v isNumber]) ifFalse:[ |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1468 |
s := s , ' "' , v class name , '" ' |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1469 |
] |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1470 |
]. |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1471 |
s |
726 | 1472 |
] |
1473 |
||
1474 |
putBlock: |
|
1475 |
[:model :string | |
|
1476 |
||
1477 |
|value| |
|
1478 |
||
1199
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1479 |
string size > 0 ifTrue:[ |
2199 | 1480 |
value := classOfObject readFrom:string onError:nil. |
1481 |
value := value ? string. |
|
1192
6db390e6463e
default: String in SmalltalkObject
Claus Gittinger <cg@exept.de>
parents:
1149
diff
changeset
|
1482 |
]. |
726 | 1483 |
model value:value |
1484 |
] |
|
1485 |
||
1486 |
updateBlock: [:m :a :p | true] |
|
1487 |
||
2199 | 1488 |
"Created: / 29-10-1997 / 15:50:16 / cg" |
1489 |
"Modified: / 05-09-2006 / 17:57:53 / cg" |
|
726 | 1490 |
! |
1491 |
||
1786 | 1492 |
smalltalkObjectWithClass:classOfObject |
1493 |
"setup the converter to convert from a string to a smalltalk object |
|
1494 |
and vice versa. The string used is the objects storeString. |
|
1495 |
Invalid strings (i.e. empty) are converted to nil. |
|
1496 |
This is a very special converter (for the GUI builder) |
|
1497 |
- probably not belonging to here" |
|
1498 |
||
1499 |
self |
|
1500 |
getBlock:[:model | |v s| |
|
1501 |
v := model value. |
|
1502 |
v isNil ifTrue:[ |
|
1503 |
s := '' |
|
1504 |
] ifFalse:[ |
|
1505 |
s := v storeString. |
|
1506 |
(v isString or:[v isNumber]) ifFalse:[ |
|
1507 |
s := s , ' "' , v class name , '" ' |
|
1508 |
] |
|
1509 |
]. |
|
1510 |
s |
|
1511 |
] |
|
1512 |
||
1513 |
putBlock: |
|
1514 |
[:model :string | |
|
1515 |
||
1516 |
|value| |
|
1517 |
||
1518 |
string size > 0 ifTrue:[ |
|
1519 |
value := classOfObject readFrom:string onError:nil. |
|
2199 | 1520 |
model value:value ? string |
1786 | 1521 |
]. |
1522 |
] |
|
1523 |
||
1524 |
updateBlock: [:m :a :p | true] |
|
1525 |
||
2199 | 1526 |
"Created: / 29-10-1997 / 15:50:16 / cg" |
1527 |
"Modified: / 05-09-2006 / 17:57:37 / cg" |
|
1786 | 1528 |
! |
1529 |
||
1530 |
smalltalkPoint |
|
1531 |
"setup the converter to convert from a string to a point object |
|
1532 |
and vice versa. The string used is the points storeString. |
|
1533 |
Invalid strings (i.e. empty) are converted to nil. |
|
1534 |
This is a very special converter (for the GUI builder) |
|
1535 |
- probably not belonging to here" |
|
1536 |
||
1537 |
^ self smalltalkObjectWithClass:Point |
|
1538 |
! |
|
1539 |
||
1653
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1540 |
symbolOrBooleanOrNil |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1541 |
"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
|
1542 |
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
|
1543 |
nil values are converted to an empty string. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1544 |
In addition, the strings true/false convert to/from booleans." |
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 |
self |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1547 |
getBlock:[:model | |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1548 |
|symbolValue| |
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 |
((symbolValue := model value) isSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1551 |
or:[symbolValue isBoolean]) |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1552 |
ifFalse:[ |
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 |
] ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1555 |
symbolValue printString. "/ storeString |
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 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1558 |
putBlock: |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1559 |
[:model :string | |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1560 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1561 |
|value s| |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1562 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1563 |
string size == 0 ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1564 |
value := nil |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1565 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1566 |
s := string withoutSeparators. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1567 |
(s startsWith:'#') ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1568 |
s := s copyFrom:2. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1569 |
(s startsWith:$') ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1570 |
s := s copyFrom:2 to:(s size - 1) |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1571 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1572 |
value := s asSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1573 |
] ifFalse:[ |
2440 | 1574 |
(#('true' 'false') includes:s) ifTrue:[ |
1653
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1575 |
value := Object readFromString:s. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1576 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1577 |
value := s asSymbol |
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 |
]. |
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 |
model value:value] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1582 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1583 |
updateBlock: [:m :a :p | true] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1584 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1585 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1586 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1587 |
! |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1588 |
|
446 | 1589 |
symbolOrNil |
1590 |
"setup the converter to convert from a string to a symbol |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1591 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1592 |
nil values are converted to an empty string." |
446 | 1593 |
|
1594 |
self |
|
1595 |
getBlock:[:model | |
|
1596 |
|symbolValue| |
|
1597 |
||
726 | 1598 |
(symbolValue := model value) isSymbol ifFalse:[ |
446 | 1599 |
String new |
726 | 1600 |
] ifTrue:[ |
946 | 1601 |
symbolValue printString. "/ storeString |
446 | 1602 |
]] |
1603 |
||
1604 |
putBlock: |
|
1605 |
[:model :string | |
|
1606 |
||
1607 |
|value s| |
|
1608 |
||
1314 | 1609 |
string size == 0 ifTrue:[ |
446 | 1610 |
value := nil |
1611 |
] ifFalse:[ |
|
1612 |
s := string withoutSeparators. |
|
1613 |
(s startsWith:'#') ifTrue:[ |
|
726 | 1614 |
s := s copyFrom:2. |
1615 |
(s startsWith:$') ifTrue:[ |
|
1616 |
s := s copyFrom:2 to:(s size - 1) |
|
1617 |
] |
|
446 | 1618 |
]. |
1619 |
value := s asSymbol |
|
1620 |
]. |
|
1621 |
model value:value] |
|
1622 |
||
1623 |
updateBlock: [:m :a :p | true] |
|
1624 |
||
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1625 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
946 | 1626 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
487 | 1627 |
! |
1628 |
||
2401
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1629 |
time |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1630 |
^ self time24H |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1631 |
! |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1632 |
|
1047 | 1633 |
time12H |
1026 | 1634 |
"setup the converter to convert from a string to a time formatted by 12 hours |
1635 |
and vice versa." |
|
1636 |
||
1027 | 1637 |
self timeToTextFormattedBy: #printString12HourFormat |
1026 | 1638 |
|
1639 |
||
1640 |
! |
|
1641 |
||
1047 | 1642 |
time24H |
1026 | 1643 |
"setup the converter to convert from a string to a time formatted by 24 hours |
1644 |
and vice versa." |
|
1645 |
||
1027 | 1646 |
self timeToTextFormattedBy: #printString24HourFormat |
1026 | 1647 |
|
1648 |
||
1649 |
! |
|
1650 |
||
2401
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1651 |
timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1652 |
"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
|
1653 |
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
|
1654 |
Invalid times are converted to defaultValue; likewise, |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1655 |
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
|
1656 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1657 |
self |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1658 |
getBlock:[:model | |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1659 |
|time| |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1660 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1661 |
(time := model value) isNil ifTrue:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1662 |
time := defaultValue |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1663 |
]. |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1664 |
time isNil ifTrue:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1665 |
'' |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1666 |
] ifFalse:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1667 |
aFormatString isNil ifTrue:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1668 |
time printString |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1669 |
] ifFalse:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1670 |
time printStringFormat:aFormatString |
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 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1673 |
putBlock: |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1674 |
[:model :string | |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1675 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1676 |
|value| |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1677 |
|
2560 | 1678 |
string isEmptyOrNil ifTrue:[ |
2401
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1679 |
value := defaultValue |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1680 |
] ifFalse:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1681 |
"/ aFormatString isNil ifTrue:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1682 |
value := timeClass readFrom:string onError:defaultValue |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1683 |
"/ ] ifFalse:[ |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1684 |
"/ value := timeClass readFrom:string printFormat:aFormatString onError:defaultValue |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1685 |
"/ ] |
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 |
model value:value] |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1688 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1689 |
updateBlock: [:m :a :p | true] |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1690 |
! |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1691 |
|
487 | 1692 |
timeOrNil |
2372 | 1693 |
"setup the converter to convert from a string to a time and vice versa." |
487 | 1694 |
|
2372 | 1695 |
self objectOrNilOfType:Time |
487 | 1696 |
|
2372 | 1697 |
"Created: / 04-03-1997 / 11:52:47 / cg" |
1698 |
"Modified: / 12-01-2008 / 19:06:21 / cg" |
|
1699 |
! |
|
487 | 1700 |
|
2372 | 1701 |
timeStampOrNil |
2401
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1702 |
<resource: #obsolete> |
2372 | 1703 |
"setup the converter to convert from a string to a timeStamp and vice versa." |
487 | 1704 |
|
2401
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1705 |
self timestampOrNil |
487 | 1706 |
! |
1707 |
||
1708 |
timeToText |
|
1709 |
"setup the converter to convert from a string to a time |
|
1710 |
and vice versa." |
|
1711 |
||
1026 | 1712 |
self timeToTextFormattedBy: #printString |
1713 |
! |
|
1714 |
||
1715 |
timeToTextFormattedBy: format |
|
1716 |
"setup the converter to convert from a string to a time formatted by format |
|
1717 |
and vice versa." |
|
1718 |
||
487 | 1719 |
self |
1720 |
getBlock:[:model | |
|
1721 |
|time| |
|
1722 |
||
1723 |
(time := model value) isNil ifTrue:[ |
|
1026 | 1724 |
Time now perform: format |
487 | 1725 |
] ifFalse:[ |
1026 | 1726 |
time perform: format |
487 | 1727 |
]] |
1728 |
||
1729 |
putBlock: |
|
1730 |
[:model :string | |
|
1731 |
||
1732 |
|value| |
|
1733 |
||
2560 | 1734 |
string isEmptyOrNil ifTrue:[ |
487 | 1735 |
value := Time now |
1026 | 1736 |
] ifFalse:[ |
1737 |
value := Time readFrom:string onError:[Time now] |
|
487 | 1738 |
]. |
1739 |
model value:value] |
|
1740 |
||
1741 |
updateBlock: [:m :a :p | true] |
|
1742 |
||
1743 |
"Modified: 21.2.1997 / 18:59:06 / cg" |
|
1744 |
"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
|
1745 |
! |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1746 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1747 |
timestamp |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1748 |
"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
|
1749 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1750 |
^ self timeOfClass:Timestamp withFormat:nil orDefault:Timestamp now |
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 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1753 |
timestampOrNil |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1754 |
"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
|
1755 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1756 |
self objectOrNilOfType:Timestamp |
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1757 |
|
6ce0d64635e0
Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents:
2379
diff
changeset
|
1758 |
"Modified: / 12-01-2008 / 19:06:06 / cg" |
442 | 1759 |
! ! |
1760 |
||
1761 |
!TypeConverter class methodsFor:'documentation'! |
|
1762 |
||
1763 |
version |
|
2737
0c83579be3d3
changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents:
2623
diff
changeset
|
1764 |
^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.62 2009-09-08 21:13:20 cg Exp $' |
442 | 1765 |
! ! |