author | Claus Gittinger <cg@exept.de> |
Tue, 10 Oct 2006 22:11:19 +0200 | |
changeset 2244 | 99a72edca7ee |
parent 2199 | 4ec7c01ed26a |
child 2366 | 9865c8d52068 |
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 |
" |
|
12 |
||
13 |
||
14 |
||
1406
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
15 |
"{ Package: 'stx:libview2' }" |
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
16 |
|
442 | 17 |
PluggableAdaptor subclass:#TypeConverter |
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
18 |
instanceVariableNames:'' |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
19 |
classVariableNames:'' |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
20 |
poolDictionaries:'' |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
21 |
category:'Interface-Support-Models' |
442 | 22 |
! |
23 |
||
24 |
!TypeConverter class methodsFor:'documentation'! |
|
25 |
||
1355 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1997 eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
442 | 42 |
documentation |
43 |
" |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
44 |
a typeConverter can be used as an editFields model |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
45 |
(remember, that an editField expects a string in its model), |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
46 |
to convert the fields string value to some object and vice versa. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
47 |
Its main use is when building interfaces with inputFields, |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
48 |
where the datum to be entered is a non-string and you |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
49 |
want to have the entered value be converted automatically. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
50 |
(and vice versa, to convert the datum to a string). |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
51 |
|
442 | 52 |
No real new functionality is added here - all is inherited |
53 |
from PluggableAdapter; however, some specialized instance creation |
|
947 | 54 |
methods are added here. |
442 | 55 |
|
56 |
Notice: |
|
57 |
this class was implemented using protocol information |
|
58 |
from alpha testers - it may not be complete or compatible to |
|
59 |
the corresponding ST-80 class. |
|
60 |
If you encounter any incompatibilities, please forward a note |
|
61 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
62 |
||
63 |
[author:] |
|
64 |
Claus Gittinger |
|
65 |
" |
|
66 |
||
67 |
||
68 |
! |
|
69 |
||
70 |
examples |
|
71 |
" |
|
72 |
convert a number to a string: |
|
73 |
[exBegin] |
|
74 |
|v t i| |
|
75 |
||
76 |
v := 1 asValue. |
|
77 |
||
78 |
t := HorizontalPanelView new. |
|
79 |
t extent:200@50. |
|
80 |
t horizontalLayout:#fitSpace. |
|
81 |
||
82 |
i := EditField in:t. |
|
83 |
i model:(TypeConverter onNumberValue:v). |
|
84 |
t open. |
|
85 |
||
86 |
(Delay forSeconds:3) wait. |
|
87 |
v value:2. |
|
88 |
[exEnd] |
|
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
89 |
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
|
90 |
[exBegin] |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
91 |
|v t i| |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
92 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
93 |
v := 1 asValue. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
94 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
95 |
t := HorizontalPanelView new. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
96 |
t extent:200@50. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
97 |
t horizontalLayout:#fitSpace. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
98 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
99 |
i := EditField in:t. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
100 |
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
|
101 |
t open. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
102 |
|
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
103 |
(Delay forSeconds:3) wait. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
104 |
v value:2. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
105 |
[exEnd] |
487 | 106 |
convert a date to a string: |
107 |
[exBegin] |
|
108 |
|d v| |
|
109 |
||
110 |
v := nil asValue. |
|
111 |
||
112 |
d := DialogBox new. |
|
113 |
d addInputFieldOn:(TypeConverter onDateValue:v). |
|
114 |
d addOkButton. |
|
115 |
d open. |
|
116 |
d accepted ifTrue:[ |
|
117 |
Transcript showCR:v value |
|
118 |
] |
|
119 |
[exEnd] |
|
442 | 120 |
" |
121 |
! ! |
|
122 |
||
123 |
!TypeConverter class methodsFor:'instance creation'! |
|
124 |
||
486 | 125 |
onDateValue:aValueHolder |
126 |
"create and return a typeConverter, which retrieves |
|
127 |
a date via #value, and converts |
|
128 |
a date-string to a date via #value:. |
|
129 |
Useful as an editFields model, which operates on some |
|
130 |
date value (or aspectAdaptor, which adapts to a numeric slot)" |
|
131 |
||
132 |
^ (self on:aValueHolder) dateToText |
|
133 |
||
134 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
135 |
"Created: 4.3.1997 / 12:30:49 / cg" |
|
136 |
! |
|
137 |
||
442 | 138 |
onNumberValue:aValueHolder |
139 |
"create and return a typeConverter, which retrieves |
|
140 |
a values string representation via #value, and converts |
|
141 |
a number-string to a value via #value:. |
|
142 |
Useful as an editFields model, which operates on some |
|
143 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
|
144 |
||
145 |
^ (self on:aValueHolder) numberToText |
|
146 |
||
147 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
446 | 148 |
! |
149 |
||
487 | 150 |
onNumberValue:aValueHolder format:formatString |
151 |
"create and return a typeConverter, which retrieves |
|
152 |
a values string representation via #value, and converts |
|
153 |
a number-string to a value via #value:. |
|
154 |
Useful as an editFields model, which operates on some |
|
155 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
|
156 |
||
157 |
^ (self on:aValueHolder) numberToTextFormattedBy:formatString |
|
158 |
||
159 |
"Created: 4.3.1997 / 11:51:25 / cg" |
|
160 |
"Modified: 4.3.1997 / 11:51:41 / cg" |
|
161 |
! |
|
162 |
||
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
163 |
onNumberValue:aValueHolder leftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
164 |
"create and return a typeConverter, which retrieves |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
165 |
a values string representation via #value, and converts |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
166 |
a number-string to a value via #value:. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
167 |
Useful as an editFields model, which operates on some |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
168 |
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
|
169 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
170 |
^ (self on:aValueHolder) numberToTextLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
171 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
172 |
" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
173 |
|m| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
174 |
m := 5 asValue. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
175 |
((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
|
176 |
m inspect. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
177 |
" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
178 |
! |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
179 |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
180 |
onNumberValue:aValueHolder minValue:min maxValue:max |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
181 |
"create and return a typeConverter, which retrieves |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
182 |
a values string representation via #value, and converts |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
183 |
a number-string to a value via #value:. |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
187 |
^ (self on:aValueHolder) numberToTextMinValue:min maxValue:max |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
188 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
189 |
"Created: 4.3.1997 / 11:51:25 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
190 |
"Modified: 4.3.1997 / 11:51:41 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
191 |
! |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
192 |
|
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
193 |
onNumberValue:aValueHolder postDecimalDigits:numPostDecimalDigits |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
194 |
"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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
200 |
^ (self on:aValueHolder) numberToText:numPostDecimalDigits |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
201 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
202 |
"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
|
203 |
"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
|
204 |
! |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
205 |
|
446 | 206 |
onSymbolValue:aValueHolder |
207 |
"create and return a typeConverter, which retrieves |
|
208 |
a symbol-values string representation via #value, and converts |
|
209 |
a string to a symbol via #value:. |
|
210 |
Useful as an editFields model, which operates on some |
|
211 |
numeric value (or aspectAdaptor, which adapts to a numeric slot)" |
|
212 |
||
213 |
^ (self on:aValueHolder) symbolOrNil |
|
214 |
||
215 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
487 | 216 |
! |
217 |
||
218 |
onTimeValue:aValueHolder |
|
219 |
"create and return a typeConverter, which retrieves |
|
220 |
a time via #value, and converts |
|
221 |
a time-string to a time via #value:. |
|
222 |
Useful as an editFields model, which operates on some |
|
223 |
date value (or aspectAdaptor, which adapts to a numeric slot)" |
|
224 |
||
225 |
^ (self on:aValueHolder) timeToText |
|
226 |
||
227 |
"Modified: 21.2.1997 / 18:46:11 / cg" |
|
228 |
"Created: 4.3.1997 / 11:52:10 / cg" |
|
442 | 229 |
! ! |
230 |
||
231 |
!TypeConverter methodsFor:'accessing'! |
|
232 |
||
233 |
subject |
|
234 |
"return the cobverted subject" |
|
235 |
||
236 |
^ model |
|
237 |
||
238 |
"Created: 21.2.1997 / 18:45:12 / cg" |
|
239 |
! |
|
240 |
||
241 |
value:newValue |
|
242 |
"convert and change" |
|
243 |
||
244 |
self setValue:newValue |
|
245 |
||
246 |
"Created: 21.2.1997 / 18:45:39 / cg" |
|
247 |
! ! |
|
248 |
||
1001 | 249 |
!TypeConverter methodsFor:'input testing'! |
250 |
||
251 |
setNumberValue: value inModel: model fromInput: string |
|
1463 | 252 |
"for invalid numbers, the model is set to nil. |
253 |
By this, the dependents are forced to update their contents |
|
254 |
(that is: a bad input string will lead to a cleared input field here)." |
|
1001 | 255 |
|
1463 | 256 |
|lastInputChar needChange| |
257 |
||
258 |
string notEmpty ifTrue:[ |
|
259 |
1 to: string size - 1 do: [:i| (string at: i) isLetter ifTrue: [needChange := true]]. |
|
1001 | 260 |
lastInputChar := string at: string size. |
261 |
(lastInputChar isDigit not and: [lastInputChar isPrintable and: [ |
|
262 |
(string size > 1 or: [lastInputChar ~~ $-]) and: [ |
|
1463 | 263 |
(string occurrencesOf: $.) > 1 or: [lastInputChar ~~ $.]]]]) ifTrue: [needChange := true]. |
1001 | 264 |
]. |
265 |
||
1463 | 266 |
needChange == true ifTrue:[ |
267 |
value notNil ifTrue:[ |
|
268 |
model setValue:nil |
|
269 |
] ifFalse:[ |
|
270 |
model value isNil ifTrue:[ |
|
271 |
model changed:#value. |
|
272 |
^ self |
|
273 |
] |
|
274 |
]. |
|
275 |
]. |
|
1001 | 276 |
model value:value |
277 |
! ! |
|
278 |
||
726 | 279 |
!TypeConverter methodsFor:'standard converters'! |
442 | 280 |
|
1149 | 281 |
arrayLiteralOrStringOrSymbolOrNil |
282 |
"setup the converter to convert from a string to either a literal |
|
283 |
Array, a String or a symbol and vice versa. |
|
284 |
Invalid strings (i.e. empty) are converted to nil; |
|
285 |
nil values are converted to an empty string. |
|
286 |
This is a very special converter (for the GUI builder) |
|
287 |
- probably not belonging to here" |
|
288 |
||
289 |
self |
|
290 |
getBlock:[:model | |
|
291 |
|symbolValue| |
|
292 |
||
293 |
(symbolValue := model value) isNil ifTrue:[ |
|
294 |
String new |
|
295 |
] ifFalse:[ |
|
296 |
symbolValue storeString |
|
297 |
]] |
|
298 |
||
299 |
putBlock: |
|
300 |
[:model :string | |
|
301 |
||
302 |
|value s| |
|
303 |
||
304 |
string isEmpty ifTrue:[ |
|
305 |
value := nil |
|
306 |
] ifFalse:[ |
|
307 |
s := string withoutSeparators. |
|
308 |
(s startsWith:'#(') ifTrue:[ |
|
309 |
value := Array readFrom:s onError:nil |
|
310 |
] ifFalse:[ |
|
311 |
(s startsWith:'''') ifTrue:[ |
|
312 |
value := String readFrom:s onError:nil |
|
313 |
] ifFalse:[ |
|
314 |
(s startsWith:'#') ifTrue:[ |
|
315 |
s := s copyFrom:2 |
|
316 |
]. |
|
317 |
value := s asSymbol |
|
318 |
] |
|
319 |
] |
|
320 |
]. |
|
321 |
model value:value] |
|
322 |
||
323 |
updateBlock: [:m :a :p | true] |
|
324 |
||
325 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
326 |
"Created: / 26.10.1997 / 14:01:02 / cg" |
|
327 |
! |
|
328 |
||
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
329 |
arrayLiteralOrSymbolOrNil |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
330 |
"setup the converter to convert from a string to either a literal |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
331 |
Array or a symbol and vice versa. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
332 |
Invalid strings (i.e. empty) are converted to nil; |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
333 |
nil values are converted to an empty string. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
334 |
This is a very special converter (for the GUI builder) |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
335 |
- probably not belonging to here" |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
336 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
337 |
self |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
338 |
getBlock:[:model | |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
339 |
|symbolValue| |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
340 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
341 |
(symbolValue := model value) isNil ifTrue:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
342 |
String new |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
343 |
] ifFalse:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
344 |
symbolValue isArray ifTrue:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
345 |
symbolValue storeString |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
346 |
] ifFalse:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
347 |
'#' , symbolValue asString |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
348 |
] |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
349 |
]] |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
350 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
351 |
putBlock: |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
352 |
[:model :string | |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
353 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
354 |
|value s| |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
355 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
356 |
string isEmpty ifTrue:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
357 |
value := nil |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
358 |
] ifFalse:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
359 |
s := string withoutSeparators. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
360 |
(s startsWith:'#(') ifTrue:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
361 |
value := Array readFrom:s onError:nil |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
362 |
] ifFalse:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
363 |
(s startsWith:'#') ifTrue:[ |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
364 |
s := s copyFrom:2 |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
365 |
]. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
366 |
value := s asSymbol |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
367 |
] |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
368 |
]. |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
369 |
model value:value] |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
370 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
371 |
updateBlock: [:m :a :p | true] |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
372 |
|
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
373 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
374 |
"Created: / 26.10.1997 / 14:01:02 / cg" |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
375 |
! |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
376 |
|
1047 | 377 |
dateDDMMYYYY |
1026 | 378 |
"setup the converter to convert from a string to a date formatted by printFormat |
1266
3420e3a98217
Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents:
1265
diff
changeset
|
379 |
DD-MM-YYYY; see also Date>>printFormat:" |
1026 | 380 |
|
1266
3420e3a98217
Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents:
1265
diff
changeset
|
381 |
self dateToTextFormattedBy: #(1 2 3 $- 1 1 true) |
1026 | 382 |
! |
383 |
||
1047 | 384 |
dateMMDDYYYY |
1026 | 385 |
"setup the converter to convert from a string to a date formatted by printFormat |
386 |
MM:DD:YYYY; see also Date>>printFormat:" |
|
387 |
||
1266
3420e3a98217
Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents:
1265
diff
changeset
|
388 |
self dateToTextFormattedBy: #(2 1 3 $/ 1 1 true) |
1026 | 389 |
! |
390 |
||
487 | 391 |
dateOrNil |
392 |
"setup the converter to convert from a string to a date |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
393 |
and vice versa. Invalid dates are converted to nil; likewise, |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
394 |
a nil date is converted to an empty string." |
487 | 395 |
|
1832 | 396 |
^ self dateWithFormat:nil orDefault:nil |
397 |
! |
|
487 | 398 |
|
1832 | 399 |
dateOrNilWithFormat:aFormatString |
400 |
"setup the converter to convert from a string to a date |
|
401 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
402 |
a nil date is converted to an empty string. |
|
403 |
The format string must have one of the forms: |
|
404 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
405 |
or: |
|
406 |
'%m %d %y' |
|
407 |
" |
|
487 | 408 |
|
1832 | 409 |
^ self dateWithFormat:aFormatString orDefault:nil |
487 | 410 |
! |
411 |
||
486 | 412 |
dateToText |
413 |
"setup the converter to convert from a string to a date |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
414 |
and vice versa. Nil is converted to todays date-string, |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
415 |
likewise, an empty string is converted back to todays date." |
486 | 416 |
|
1832 | 417 |
^ self dateWithFormat:nil orDefault:Date today |
486 | 418 |
! |
419 |
||
1026 | 420 |
dateToTextFormattedBy: printFormat |
421 |
"setup the converter to convert from a string to a date formatted by printFormat |
|
422 |
and vice versa. Nil is converted to todays date-string, |
|
1697 | 423 |
likewise, an empty string is converted back to todays date. |
424 |
Uses the old, obsolete ST80 printFormat (see Date printFormat:)" |
|
1026 | 425 |
|
1832 | 426 |
^ self dateWithFormat:printFormat orDefault:Date today |
427 |
! |
|
428 |
||
429 |
dateWithFormat:aFormatString |
|
430 |
"setup the converter to convert from a string to a date |
|
431 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
432 |
a nil date is converted to an empty string. |
|
433 |
The format string must have one of the forms: |
|
434 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
435 |
or: |
|
436 |
'%m %d %y' |
|
437 |
" |
|
438 |
||
439 |
^ self dateWithFormat:aFormatString orDefault:Date today |
|
440 |
! |
|
441 |
||
442 |
dateWithFormat:aFormatString orDefault:defaultValue |
|
443 |
"setup the converter to convert from a string to a date |
|
444 |
and vice versa. Invalid dates are converted to nil; likewise, |
|
445 |
a nil date is converted to an empty string. |
|
446 |
The format string must have one of the forms: |
|
447 |
'mm/dd/yyyy' (for VW-backward compatibility) |
|
448 |
or: |
|
449 |
'%m %d %y' |
|
450 |
" |
|
451 |
||
452 |
|in out stxFormat c nDigits| |
|
453 |
||
454 |
aFormatString notNil ifTrue:[ |
|
455 |
(aFormatString includes:$%) ifTrue:[ |
|
456 |
"/ a new (ST/X) formatString |
|
457 |
stxFormat := aFormatString |
|
458 |
] ifFalse:[ |
|
459 |
"/ an old (VW) formatString |
|
460 |
out := '' writeStream. |
|
461 |
in := aFormatString readStream. |
|
462 |
[in atEnd] whileFalse:[ |
|
463 |
c := in next. |
|
464 |
nDigits := 1. |
|
465 |
c == $m ifTrue:[ |
|
466 |
[in peek == $m] whileTrue:[ nDigits := nDigits + 1. in next ]. |
|
467 |
nDigits == 1 ifTrue:[ |
|
468 |
out nextPutAll:'%M'. "/ unpadded |
|
469 |
] ifFalse:[ |
|
470 |
out nextPutAll:'%m'. |
|
471 |
]. |
|
472 |
] ifFalse:[ |
|
473 |
c == $d ifTrue:[ |
|
474 |
[in peek == $d] whileTrue:[ nDigits := nDigits + 1. in next ]. |
|
475 |
nDigits == 1 ifTrue:[ |
|
476 |
out nextPutAll:'%D'. "/ unpadded |
|
477 |
] ifFalse:[ |
|
478 |
out nextPutAll:'%d'. |
|
479 |
]. |
|
480 |
] ifFalse:[ |
|
481 |
c == $y ifTrue:[ |
|
482 |
[in peek == $y] whileTrue:[ nDigits := nDigits + 1. in next ]. |
|
483 |
nDigits == 2 ifTrue:[ |
|
484 |
out nextPutAll:'%Y'. "/ 2 digits only |
|
485 |
] ifFalse:[ |
|
486 |
out nextPutAll:'%y'. |
|
487 |
]. |
|
488 |
] ifFalse:[ |
|
489 |
out nextPut:c. |
|
490 |
]. |
|
491 |
]. |
|
492 |
]. |
|
493 |
]. |
|
494 |
stxFormat := out contents. |
|
495 |
]. |
|
496 |
]. |
|
497 |
||
1026 | 498 |
self |
499 |
getBlock:[:model | |
|
1832 | 500 |
|date| |
1696 | 501 |
|
1832 | 502 |
(date := model value) isNil ifTrue:[ |
503 |
date := defaultValue |
|
504 |
]. |
|
505 |
date isNil ifTrue:[ |
|
506 |
'' |
|
507 |
] ifFalse:[ |
|
508 |
stxFormat isNil ifTrue:[ |
|
509 |
date printString |
|
510 |
] ifFalse:[ |
|
511 |
date printStringFormat:stxFormat |
|
512 |
]]] |
|
1026 | 513 |
|
514 |
putBlock: |
|
515 |
[:model :string | |
|
516 |
||
517 |
|value| |
|
518 |
||
1832 | 519 |
string isEmpty ifTrue:[ |
520 |
value := defaultValue |
|
521 |
] ifFalse:[ |
|
522 |
stxFormat isNil ifTrue:[ |
|
523 |
value := Date readFrom:string onError:defaultValue |
|
524 |
] ifFalse:[ |
|
525 |
value := Date readFrom:string printFormat:stxFormat onError:defaultValue |
|
526 |
] |
|
1026 | 527 |
]. |
528 |
model value:value] |
|
529 |
||
530 |
updateBlock: [:m :a :p | true] |
|
531 |
! |
|
532 |
||
1791 | 533 |
fileSize |
534 |
"setup the converter to convert from a fileSize string to a number |
|
535 |
and vice versa. |
|
536 |
A fileSize can have a scale of 1024 (k or kB), |
|
537 |
1024*1024 (m or mB), 1024*1024*1024 (g or gB)." |
|
538 |
||
539 |
self |
|
540 |
getBlock:[:model | |
|
541 |
|numericValue| |
|
542 |
||
543 |
(numericValue := model value) isNumber ifFalse:[ |
|
544 |
String new |
|
545 |
] ifTrue:[ |
|
546 |
UnitConverter fileSizeStringFor:numericValue |
|
547 |
]] |
|
548 |
||
549 |
putBlock: |
|
550 |
[:model :string | |
|
551 |
||
552 |
model value:(UnitConverter fileSizeFromString:string)] |
|
553 |
||
554 |
updateBlock: [:m :a :p | true] |
|
555 |
! |
|
556 |
||
1122 | 557 |
hexadecimal |
1047 | 558 |
"setup the converter to convert from a hexadecimal string to a number |
559 |
and vice versa." |
|
560 |
||
561 |
self |
|
562 |
getBlock:[:model | |
|
563 |
|hexValue| |
|
564 |
||
565 |
(hexValue := model value) isNumber ifFalse:[ |
|
566 |
String new |
|
567 |
] ifTrue:[ |
|
568 |
hexValue hexPrintString |
|
569 |
]] |
|
570 |
||
571 |
putBlock: |
|
572 |
[:model :string | |
|
573 |
||
574 |
|value| |
|
575 |
||
576 |
string isEmpty ifTrue:[ |
|
577 |
value := 0 |
|
578 |
] ifFalse:[ |
|
579 |
value := Integer readFrom: string radix:16 onError:[0] |
|
580 |
]. |
|
581 |
model value:value] |
|
582 |
||
583 |
updateBlock: [:m :a :p | true] |
|
584 |
||
585 |
||
586 |
! |
|
587 |
||
1974 | 588 |
integerToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
589 |
"setup the converter to convert from a string to a number |
|
590 |
and vice versa, but clamping the number into the range." |
|
591 |
||
592 |
self |
|
593 |
getBlock:[:model | |
|
594 |
|numericValue| |
|
595 |
||
596 |
(numericValue := model value) isNil ifTrue:[ |
|
597 |
String new |
|
598 |
] ifFalse:[ |
|
599 |
formatStringOrNil isNil ifTrue:[ |
|
600 |
numericValue printString |
|
601 |
] ifFalse:[ |
|
602 |
numericValue printfPrintString:formatStringOrNil |
|
603 |
] |
|
604 |
]] |
|
605 |
||
606 |
putBlock: |
|
607 |
[:model :string | |
|
608 |
||
609 |
|value c| |
|
610 |
||
611 |
string isEmpty ifTrue:[ |
|
612 |
value := 0 |
|
613 |
] ifFalse:[ |
|
614 |
value := Integer readFromString: string onError:[0]. |
|
615 |
]. |
|
616 |
minVal notNil ifTrue:[ |
|
617 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
618 |
value := value max:minVal. |
|
619 |
]. |
|
620 |
maxVal notNil ifTrue:[ |
|
621 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
622 |
value := value min:maxVal. |
|
623 |
]. |
|
624 |
self setNumberValue: value inModel: model fromInput: string. |
|
625 |
] |
|
626 |
||
627 |
updateBlock: [:m :a :p | true] |
|
628 |
||
629 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
630 |
! |
|
631 |
||
1464
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
632 |
literal |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
633 |
"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
|
634 |
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
|
635 |
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
|
636 |
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
|
637 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
638 |
self |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
639 |
getBlock:[:model | |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
640 |
|val s| |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
641 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
642 |
val := model value. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
643 |
(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
|
644 |
val isSymbol ifTrue:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
645 |
"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
|
646 |
(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
|
647 |
s |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
648 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
649 |
val printString |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
650 |
] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
651 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
652 |
val storeString |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
653 |
]. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
654 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
655 |
''. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
656 |
]] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
657 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
658 |
putBlock: |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
659 |
[:model :string | |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
660 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
661 |
|value s| |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
662 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
663 |
string size == 0 ifTrue:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
664 |
value := nil |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
665 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
666 |
s := string withoutSeparators. |
1465 | 667 |
"be careful, #readFrom:onError: returns nil for an undefined identifier" |
668 |
s = 'true' ifTrue:[ |
|
669 |
value := true. |
|
670 |
] ifFalse:[s = 'false' ifTrue:[ |
|
671 |
value := false. |
|
672 |
] ifFalse:[s = 'nil' ifTrue:[ |
|
673 |
value := nil. |
|
674 |
] ifFalse:[s first isLetter ifTrue:[ |
|
675 |
value := s asSymbol. |
|
676 |
] ifFalse:[ |
|
677 |
value := Object readFrom:s onError:[ |
|
678 |
s asSymbol |
|
679 |
]. |
|
680 |
]]]]. |
|
1464
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
681 |
]. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
682 |
model value:value] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
683 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
684 |
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
|
685 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
686 |
"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
|
687 |
"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
|
688 |
! |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
689 |
|
508 | 690 |
number |
691 |
"setup the converter to convert from a string to a number |
|
692 |
and vice versa. Invalid numbers are converted to nil." |
|
693 |
||
694 |
self numberToText |
|
695 |
||
696 |
"Created: 4.4.1997 / 12:46:14 / cg" |
|
697 |
! |
|
698 |
||
442 | 699 |
numberOrNil |
700 |
"setup the converter to convert from a string to a number |
|
701 |
and vice versa. Invalid numbers are converted to nil." |
|
702 |
||
703 |
self |
|
704 |
getBlock:[:model | |
|
705 |
|numericValue| |
|
706 |
||
707 |
(numericValue := model value) isNil ifTrue:[ |
|
708 |
String new |
|
709 |
] ifFalse:[ |
|
710 |
numericValue printString |
|
711 |
]] |
|
712 |
||
713 |
putBlock: |
|
714 |
[:model :string | |
|
715 |
||
716 |
|value| |
|
717 |
||
1197
8e88ffde4374
dont get confused with a nil string value.
Claus Gittinger <cg@exept.de>
parents:
1192
diff
changeset
|
718 |
string size > 0 ifTrue:[ |
447 | 719 |
value := Number readFrom:string onError:nil |
1002 | 720 |
]. |
442 | 721 |
model value:value] |
722 |
||
723 |
updateBlock: [:m :a :p | true] |
|
724 |
||
725 |
"Created: 21.2.1997 / 18:58:38 / cg" |
|
726 |
! |
|
727 |
||
1463 | 728 |
numberOrNilToTextMinValue:minVal maxValue:maxVal |
729 |
"setup the converter to convert from a string to a number or nil |
|
730 |
and vice versa, but clamping the number into the range." |
|
731 |
||
1974 | 732 |
self numberOrNilToTextMinValue:minVal maxValue:maxVal format:nil |
733 |
! |
|
734 |
||
735 |
numberOrNilToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
|
736 |
"setup the converter to convert from a string to a number or nil |
|
737 |
and vice versa, but clamping the number into the range." |
|
738 |
||
1463 | 739 |
self |
740 |
getBlock:[:model | |
|
741 |
|numericValue| |
|
742 |
||
743 |
(numericValue := model value) isNil ifTrue:[ |
|
744 |
String new |
|
745 |
] ifFalse:[ |
|
1974 | 746 |
formatStringOrNil isNil ifTrue:[ |
747 |
numericValue printString |
|
748 |
] ifFalse:[ |
|
749 |
numericValue printfPrintString:formatStringOrNil |
|
750 |
] |
|
1463 | 751 |
]] |
752 |
||
753 |
putBlock: |
|
754 |
[:model :string | |
|
755 |
||
756 |
|value c| |
|
757 |
||
758 |
(string isEmpty or:[string isBlank]) ifTrue:[ |
|
759 |
value := nil |
|
760 |
] ifFalse:[ |
|
761 |
value := Number readFromString:string onError:[nil]. |
|
762 |
value isNil ifTrue:[ |
|
763 |
||
764 |
] ifFalse:[ |
|
765 |
minVal notNil ifTrue:[ |
|
766 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
767 |
value := value max:minVal. |
|
768 |
]. |
|
769 |
maxVal notNil ifTrue:[ |
|
770 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
771 |
value := value min:maxVal. |
|
772 |
]. |
|
773 |
]. |
|
774 |
]. |
|
775 |
self setNumberValue: value inModel: model fromInput: string. |
|
776 |
] |
|
777 |
||
778 |
updateBlock: [:m :a :p | true] |
|
779 |
||
780 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
781 |
! |
|
782 |
||
1335
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
783 |
numberOrPointOrNil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
784 |
"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
|
785 |
and vice versa. Invalid numbers/points are converted to nil." |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
786 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
787 |
self |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
788 |
getBlock:[:model | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
789 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
790 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
791 |
(value := model value) isNil ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
792 |
String new |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
793 |
] ifFalse:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
794 |
value printString |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
795 |
]] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
796 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
797 |
putBlock: |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
798 |
[:model :string | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
799 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
800 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
801 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
802 |
string size > 0 ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
803 |
value := Point readFrom:string onError:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
804 |
Number readFrom:string onError:nil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
805 |
] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
806 |
]. |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
807 |
model value:value] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
808 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
809 |
updateBlock: [:m :a :p | true] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
810 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
811 |
"Created: / 5.2.2000 / 01:26:48 / cg" |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
812 |
! |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
813 |
|
1149 | 814 |
numberOrStringOrSymbolOrNil |
815 |
"setup the converter to convert from a string to either a numeric literal |
|
816 |
or a symbol and vice versa. |
|
817 |
Invalid strings (i.e. empty) are converted to nil; |
|
818 |
nil values are converted to an empty string. |
|
819 |
This is a very special converter (for the GUI builder) |
|
820 |
- probably not belonging to here" |
|
821 |
||
822 |
self |
|
823 |
getBlock:[:model | |
|
824 |
|litValue| |
|
825 |
||
826 |
(litValue := model value) isNil ifTrue:[ |
|
827 |
String new |
|
828 |
] ifFalse:[ |
|
829 |
litValue storeString |
|
830 |
]] |
|
831 |
||
832 |
putBlock: |
|
833 |
[:model :string | |
|
834 |
||
835 |
|value s| |
|
836 |
||
837 |
string isEmpty ifTrue:[ |
|
838 |
value := nil |
|
839 |
] ifFalse:[ |
|
840 |
value := Number readFrom:string onError:nil. |
|
841 |
value isNil ifTrue:[ |
|
842 |
s := string withoutSeparators. |
|
843 |
(s startsWith:'''') ifTrue:[ |
|
844 |
value := String readFrom:s readStream onError:nil |
|
845 |
] ifFalse:[ |
|
846 |
(s startsWith:'#') ifTrue:[ |
|
847 |
s := s copyFrom:2. |
|
848 |
(s startsWith:$') ifTrue:[ |
|
849 |
s := s copyFrom:2 to:(s size - 1) |
|
850 |
]. |
|
851 |
]. |
|
852 |
value := s asSymbol |
|
853 |
] |
|
854 |
] |
|
855 |
]. |
|
856 |
model value:value] |
|
857 |
||
858 |
updateBlock: [:m :a :p | true] |
|
859 |
||
860 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
861 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
862 |
! |
|
863 |
||
726 | 864 |
numberOrSymbolOrNil |
865 |
"setup the converter to convert from a string to either a numeric literal |
|
866 |
or a symbol and vice versa. |
|
867 |
Invalid strings (i.e. empty) are converted to nil; |
|
868 |
nil values are converted to an empty string. |
|
869 |
This is a very special converter (for the GUI builder) |
|
870 |
- probably not belonging to here" |
|
871 |
||
872 |
self |
|
873 |
getBlock:[:model | |
|
874 |
|litValue| |
|
875 |
||
876 |
(litValue := model value) isNil ifTrue:[ |
|
877 |
String new |
|
878 |
] ifFalse:[ |
|
879 |
litValue storeString |
|
880 |
]] |
|
881 |
||
882 |
putBlock: |
|
883 |
[:model :string | |
|
884 |
||
885 |
|value s| |
|
886 |
||
887 |
string isEmpty ifTrue:[ |
|
888 |
value := nil |
|
889 |
] ifFalse:[ |
|
890 |
value := Number readFrom:string onError:nil. |
|
891 |
value isNil ifTrue:[ |
|
892 |
s := string withoutSeparators. |
|
893 |
(s startsWith:'#') ifTrue:[ |
|
894 |
s := s copyFrom:2. |
|
895 |
(s startsWith:$') ifTrue:[ |
|
896 |
s := s copyFrom:2 to:(s size - 1) |
|
897 |
]. |
|
898 |
]. |
|
899 |
value := s asSymbol |
|
900 |
] |
|
901 |
]. |
|
902 |
model value:value] |
|
903 |
||
904 |
updateBlock: [:m :a :p | true] |
|
905 |
||
906 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
907 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
908 |
! |
|
909 |
||
442 | 910 |
numberToText |
911 |
"setup the converter to convert from a string to a number |
|
487 | 912 |
and vice versa." |
442 | 913 |
|
914 |
self |
|
915 |
getBlock:[:model | |
|
916 |
|numericValue| |
|
917 |
||
726 | 918 |
(numericValue := model value) isNumber ifFalse:[ |
442 | 919 |
String new |
726 | 920 |
] ifTrue:[ |
442 | 921 |
numericValue printString |
922 |
]] |
|
923 |
||
924 |
putBlock: |
|
925 |
[:model :string | |
|
926 |
||
927 |
|value| |
|
928 |
||
929 |
string isEmpty ifTrue:[ |
|
930 |
value := 0 |
|
931 |
] ifFalse:[ |
|
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
932 |
value := Number readFromString: string onError:[0] |
442 | 933 |
]. |
934 |
model value:value] |
|
935 |
||
936 |
updateBlock: [:m :a :p | true] |
|
937 |
||
726 | 938 |
"Created: / 21.2.1997 / 18:57:05 / cg" |
939 |
"Modified: / 29.10.1997 / 15:49:21 / cg" |
|
442 | 940 |
! |
941 |
||
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
942 |
numberToText:numberOfPostDecimals |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
943 |
"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
|
944 |
and vice versa." |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
945 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
946 |
self |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
947 |
getBlock:[:model | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
948 |
|numericValue| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
949 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
950 |
(numericValue := model value) isNumber ifFalse:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
951 |
String new |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
952 |
] ifTrue:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
953 |
(numericValue asFixedPoint:numberOfPostDecimals) printString |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
954 |
]] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
955 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
956 |
putBlock: |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
957 |
[:model :string | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
958 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
959 |
|value| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
960 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
961 |
string isEmpty ifTrue:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
962 |
value := 0 |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
963 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
964 |
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
|
965 |
]. |
1001 | 966 |
self setNumberValue: value inModel: model fromInput: string. |
967 |
] |
|
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
968 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
969 |
updateBlock: [:m :a :p | true] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
970 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
971 |
"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
|
972 |
"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
|
973 |
! |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
974 |
|
442 | 975 |
numberToTextFormattedBy:formatString |
976 |
"setup the converter to convert from a string to a number |
|
977 |
and vice versa, using formatString. |
|
978 |
The formatString is currently ignored when numbers are converted |
|
979 |
from a string." |
|
980 |
||
981 |
self |
|
982 |
getBlock:[:model | |
|
983 |
|numericValue| |
|
984 |
||
985 |
(numericValue := model value) isNil ifTrue:[ |
|
986 |
String new |
|
987 |
] ifFalse:[ |
|
988 |
PrintConverter print:numericValue formattedBy:formatString |
|
989 |
]] |
|
990 |
||
991 |
putBlock: |
|
992 |
[:model :string | |
|
993 |
||
994 |
|value| |
|
995 |
||
996 |
string isEmpty ifTrue:[ |
|
997 |
value := 0 |
|
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
998 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
999 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
442 | 1000 |
]. |
1001 |
model value:value] |
|
1002 |
||
1003 |
updateBlock: [:m :a :p | true] |
|
1004 |
||
1005 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
446 | 1006 |
! |
1007 |
||
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1008 |
numberToTextLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1009 |
"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
|
1010 |
and vice versa, using formatString. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1011 |
The formatString is currently ignored when numbers are converted |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1012 |
from a string." |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1013 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1014 |
self |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1015 |
getBlock:[:model | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1016 |
|numericValue| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1017 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1018 |
(numericValue := model value) isNil ifTrue:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1019 |
String new |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1020 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1021 |
numericValue printStringLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1022 |
]] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1023 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1024 |
putBlock: |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1025 |
[:model :string | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1026 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1027 |
|value| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1028 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1029 |
string isEmpty ifTrue:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1030 |
value := 0 |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1031 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1032 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1033 |
]. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1034 |
model value:value] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1035 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1036 |
updateBlock: [:m :a :p | true] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1037 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1038 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1039 |
! |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
1040 |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1041 |
numberToTextMinValue:minVal maxValue:maxVal |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1042 |
"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
|
1043 |
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
|
1044 |
|
1974 | 1045 |
self numberToTextMinValue:minVal maxValue:maxVal format:nil |
1046 |
! |
|
1047 |
||
1048 |
numberToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil |
|
1049 |
"setup the converter to convert from a string to a number |
|
1050 |
and vice versa, but clamping the number into the range." |
|
1051 |
||
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1052 |
self |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1053 |
getBlock:[:model | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1054 |
|numericValue| |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1055 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1056 |
(numericValue := model value) isNil ifTrue:[ |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1057 |
String new |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1058 |
] ifFalse:[ |
1974 | 1059 |
formatStringOrNil isNil ifTrue:[ |
1060 |
numericValue printString |
|
1061 |
] ifFalse:[ |
|
1062 |
numericValue printfPrintString:formatStringOrNil |
|
1063 |
] |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1064 |
]] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1065 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1066 |
putBlock: |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1067 |
[:model :string | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1068 |
|
1001 | 1069 |
|value c| |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1070 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1071 |
string isEmpty ifTrue:[ |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1072 |
value := 0 |
1001 | 1073 |
] ifFalse:[ |
997 | 1074 |
value := Number readFromString: string onError:[0]. |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1075 |
]. |
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1076 |
minVal notNil ifTrue:[ |
1001 | 1077 |
(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
|
1078 |
value := value max:minVal. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1079 |
]. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1080 |
maxVal notNil ifTrue:[ |
1001 | 1081 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
944 | 1082 |
value := value min:maxVal. |
1001 | 1083 |
]. |
1084 |
self setNumberValue: value inModel: model fromInput: string. |
|
1085 |
] |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1086 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1087 |
updateBlock: [:m :a :p | true] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1088 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1089 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1090 |
! |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1091 |
|
726 | 1092 |
smalltalkObject |
1093 |
"setup the converter to convert from a string to any smalltalk object |
|
1094 |
and vice versa. The string used is the objects storeString. |
|
1095 |
Invalid strings (i.e. empty) are converted to nil. |
|
1096 |
This is a very special converter (for the GUI builder) |
|
1097 |
- probably not belonging to here" |
|
1098 |
||
1786 | 1099 |
^ self smalltalkObjectWithClass:Object |
1407 | 1100 |
! |
1101 |
||
1102 |
smalltalkObjectOrNil |
|
1103 |
"setup the converter to convert from a string to any smalltalk object |
|
1104 |
and vice versa. The string used is the objects storeString. |
|
1105 |
Invalid strings (i.e. empty) are converted to nil. |
|
1106 |
This is a very special converter (for the GUI builder) |
|
1107 |
- probably not belonging to here" |
|
1108 |
||
1786 | 1109 |
^ self smalltalkObjectOrNilWithClass:Object |
1110 |
! |
|
1111 |
||
1112 |
smalltalkObjectOrNilWithClass:classOfObject |
|
1113 |
"setup the converter to convert from a string to a smalltalk object |
|
1114 |
and vice versa. The string used is the objects storeString. |
|
1115 |
Invalid strings (i.e. empty) are converted to nil. |
|
1116 |
This is a very special converter (for the GUI builder) |
|
1117 |
- probably not belonging to here" |
|
1118 |
||
1407 | 1119 |
self |
1120 |
getBlock:[:model | |v s| |
|
1121 |
v := model value. |
|
1122 |
v isNil ifTrue:[ |
|
1406
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1123 |
s := 'nil' |
1199
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1124 |
] ifFalse:[ |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1125 |
s := v storeString. |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1126 |
(v isString or:[v isNumber]) ifFalse:[ |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1127 |
s := s , ' "' , v class name , '" ' |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1128 |
] |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1129 |
]. |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1130 |
s |
726 | 1131 |
] |
1132 |
||
1133 |
putBlock: |
|
1134 |
[:model :string | |
|
1135 |
||
1136 |
|value| |
|
1137 |
||
1199
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1138 |
string size > 0 ifTrue:[ |
2199 | 1139 |
value := classOfObject readFrom:string onError:nil. |
1140 |
value := value ? string. |
|
1192
6db390e6463e
default: String in SmalltalkObject
Claus Gittinger <cg@exept.de>
parents:
1149
diff
changeset
|
1141 |
]. |
726 | 1142 |
model value:value |
1143 |
] |
|
1144 |
||
1145 |
updateBlock: [:m :a :p | true] |
|
1146 |
||
2199 | 1147 |
"Created: / 29-10-1997 / 15:50:16 / cg" |
1148 |
"Modified: / 05-09-2006 / 17:57:53 / cg" |
|
726 | 1149 |
! |
1150 |
||
1786 | 1151 |
smalltalkObjectWithClass:classOfObject |
1152 |
"setup the converter to convert from a string to a smalltalk object |
|
1153 |
and vice versa. The string used is the objects storeString. |
|
1154 |
Invalid strings (i.e. empty) are converted to nil. |
|
1155 |
This is a very special converter (for the GUI builder) |
|
1156 |
- probably not belonging to here" |
|
1157 |
||
1158 |
self |
|
1159 |
getBlock:[:model | |v s| |
|
1160 |
v := model value. |
|
1161 |
v isNil ifTrue:[ |
|
1162 |
s := '' |
|
1163 |
] ifFalse:[ |
|
1164 |
s := v storeString. |
|
1165 |
(v isString or:[v isNumber]) ifFalse:[ |
|
1166 |
s := s , ' "' , v class name , '" ' |
|
1167 |
] |
|
1168 |
]. |
|
1169 |
s |
|
1170 |
] |
|
1171 |
||
1172 |
putBlock: |
|
1173 |
[:model :string | |
|
1174 |
||
1175 |
|value| |
|
1176 |
||
1177 |
string size > 0 ifTrue:[ |
|
1178 |
value := classOfObject readFrom:string onError:nil. |
|
2199 | 1179 |
model value:value ? string |
1786 | 1180 |
]. |
1181 |
] |
|
1182 |
||
1183 |
updateBlock: [:m :a :p | true] |
|
1184 |
||
2199 | 1185 |
"Created: / 29-10-1997 / 15:50:16 / cg" |
1186 |
"Modified: / 05-09-2006 / 17:57:37 / cg" |
|
1786 | 1187 |
! |
1188 |
||
1189 |
smalltalkPoint |
|
1190 |
"setup the converter to convert from a string to a point object |
|
1191 |
and vice versa. The string used is the points storeString. |
|
1192 |
Invalid strings (i.e. empty) are converted to nil. |
|
1193 |
This is a very special converter (for the GUI builder) |
|
1194 |
- probably not belonging to here" |
|
1195 |
||
1196 |
^ self smalltalkObjectWithClass:Point |
|
1197 |
! |
|
1198 |
||
1653
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1199 |
symbolOrBooleanOrNil |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1200 |
"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
|
1201 |
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
|
1202 |
nil values are converted to an empty string. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1203 |
In addition, the strings true/false convert to/from booleans." |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1204 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1205 |
self |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1206 |
getBlock:[:model | |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1207 |
|symbolValue| |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1208 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1209 |
((symbolValue := model value) isSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1210 |
or:[symbolValue isBoolean]) |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1211 |
ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1212 |
'' |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1213 |
] ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1214 |
symbolValue printString. "/ storeString |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1215 |
]] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1216 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1217 |
putBlock: |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1218 |
[:model :string | |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1219 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1220 |
|value s| |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1221 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1222 |
string size == 0 ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1223 |
value := nil |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1224 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1225 |
s := string withoutSeparators. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1226 |
(s startsWith:'#') ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1227 |
s := s copyFrom:2. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1228 |
(s startsWith:$') ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1229 |
s := s copyFrom:2 to:(s size - 1) |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1230 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1231 |
value := s asSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1232 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1233 |
(#('true' 'false') includes:s) ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1234 |
value := Object readFromString:s. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1235 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1236 |
value := s asSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1237 |
] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1238 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1239 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1240 |
model value:value] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1241 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1242 |
updateBlock: [:m :a :p | true] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1243 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1244 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1245 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1246 |
! |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1247 |
|
446 | 1248 |
symbolOrNil |
1249 |
"setup the converter to convert from a string to a symbol |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1250 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1251 |
nil values are converted to an empty string." |
446 | 1252 |
|
1253 |
self |
|
1254 |
getBlock:[:model | |
|
1255 |
|symbolValue| |
|
1256 |
||
726 | 1257 |
(symbolValue := model value) isSymbol ifFalse:[ |
446 | 1258 |
String new |
726 | 1259 |
] ifTrue:[ |
946 | 1260 |
symbolValue printString. "/ storeString |
446 | 1261 |
]] |
1262 |
||
1263 |
putBlock: |
|
1264 |
[:model :string | |
|
1265 |
||
1266 |
|value s| |
|
1267 |
||
1314 | 1268 |
string size == 0 ifTrue:[ |
446 | 1269 |
value := nil |
1270 |
] ifFalse:[ |
|
1271 |
s := string withoutSeparators. |
|
1272 |
(s startsWith:'#') ifTrue:[ |
|
726 | 1273 |
s := s copyFrom:2. |
1274 |
(s startsWith:$') ifTrue:[ |
|
1275 |
s := s copyFrom:2 to:(s size - 1) |
|
1276 |
] |
|
446 | 1277 |
]. |
1278 |
value := s asSymbol |
|
1279 |
]. |
|
1280 |
model value:value] |
|
1281 |
||
1282 |
updateBlock: [:m :a :p | true] |
|
1283 |
||
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1284 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
946 | 1285 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
487 | 1286 |
! |
1287 |
||
1047 | 1288 |
time12H |
1026 | 1289 |
"setup the converter to convert from a string to a time formatted by 12 hours |
1290 |
and vice versa." |
|
1291 |
||
1027 | 1292 |
self timeToTextFormattedBy: #printString12HourFormat |
1026 | 1293 |
|
1294 |
||
1295 |
! |
|
1296 |
||
1047 | 1297 |
time24H |
1026 | 1298 |
"setup the converter to convert from a string to a time formatted by 24 hours |
1299 |
and vice versa." |
|
1300 |
||
1027 | 1301 |
self timeToTextFormattedBy: #printString24HourFormat |
1026 | 1302 |
|
1303 |
||
1304 |
! |
|
1305 |
||
487 | 1306 |
timeOrNil |
1307 |
"setup the converter to convert from a string to a time |
|
1308 |
and vice versa." |
|
1309 |
||
1310 |
self |
|
1311 |
getBlock:[:model | |
|
1312 |
|time| |
|
1313 |
||
1314 |
(time := model value) isNil ifTrue:[ |
|
1315 |
'' |
|
1316 |
] ifFalse:[ |
|
1317 |
time printString |
|
1318 |
]] |
|
1319 |
||
1320 |
putBlock: |
|
1321 |
[:model :string | |
|
1322 |
||
1323 |
|value| |
|
1324 |
||
1325 |
string isEmpty ifTrue:[ |
|
1326 |
value := nil |
|
1327 |
] ifFalse:[ |
|
1328 |
value := Time readFrom:string onError:nil |
|
1329 |
]. |
|
1330 |
model value:value] |
|
1331 |
||
1332 |
updateBlock: [:m :a :p | true] |
|
1333 |
||
1334 |
"Created: 4.3.1997 / 11:52:47 / cg" |
|
1335 |
"Modified: 4.3.1997 / 12:05:48 / cg" |
|
1336 |
! |
|
1337 |
||
1338 |
timeToText |
|
1339 |
"setup the converter to convert from a string to a time |
|
1340 |
and vice versa." |
|
1341 |
||
1026 | 1342 |
self timeToTextFormattedBy: #printString |
1343 |
! |
|
1344 |
||
1345 |
timeToTextFormattedBy: format |
|
1346 |
"setup the converter to convert from a string to a time formatted by format |
|
1347 |
and vice versa." |
|
1348 |
||
487 | 1349 |
self |
1350 |
getBlock:[:model | |
|
1351 |
|time| |
|
1352 |
||
1353 |
(time := model value) isNil ifTrue:[ |
|
1026 | 1354 |
Time now perform: format |
487 | 1355 |
] ifFalse:[ |
1026 | 1356 |
time perform: format |
487 | 1357 |
]] |
1358 |
||
1359 |
putBlock: |
|
1360 |
[:model :string | |
|
1361 |
||
1362 |
|value| |
|
1363 |
||
1364 |
string isEmpty ifTrue:[ |
|
1365 |
value := Time now |
|
1026 | 1366 |
] ifFalse:[ |
1367 |
value := Time readFrom:string onError:[Time now] |
|
487 | 1368 |
]. |
1369 |
model value:value] |
|
1370 |
||
1371 |
updateBlock: [:m :a :p | true] |
|
1372 |
||
1373 |
"Modified: 21.2.1997 / 18:59:06 / cg" |
|
1374 |
"Created: 4.3.1997 / 11:52:47 / cg" |
|
442 | 1375 |
! ! |
1376 |
||
1377 |
!TypeConverter class methodsFor:'documentation'! |
|
1378 |
||
1379 |
version |
|
2199 | 1380 |
^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.48 2006-09-05 15:57:47 cg Exp $' |
442 | 1381 |
! ! |