author | Claus Gittinger <cg@exept.de> |
Wed, 03 Dec 2003 12:48:56 +0100 | |
changeset 1869 | c6800c75b7d0 |
parent 1832 | fb54a0eabe13 |
child 1974 | 025c3119062b |
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 |
||
1464
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
588 |
literal |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
589 |
"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
|
590 |
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
|
591 |
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
|
592 |
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
|
593 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
594 |
self |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
595 |
getBlock:[:model | |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
596 |
|val s| |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
597 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
598 |
val := model value. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
599 |
(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
|
600 |
val isSymbol ifTrue:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
601 |
"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
|
602 |
(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
|
603 |
s |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
604 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
605 |
val printString |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
606 |
] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
607 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
608 |
val storeString |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
609 |
]. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
610 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
611 |
''. |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
612 |
]] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
613 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
614 |
putBlock: |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
615 |
[:model :string | |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
616 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
617 |
|value s| |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
618 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
619 |
string size == 0 ifTrue:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
620 |
value := nil |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
621 |
] ifFalse:[ |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
622 |
s := string withoutSeparators. |
1465 | 623 |
"be careful, #readFrom:onError: returns nil for an undefined identifier" |
624 |
s = 'true' ifTrue:[ |
|
625 |
value := true. |
|
626 |
] ifFalse:[s = 'false' ifTrue:[ |
|
627 |
value := false. |
|
628 |
] ifFalse:[s = 'nil' ifTrue:[ |
|
629 |
value := nil. |
|
630 |
] ifFalse:[s first isLetter ifTrue:[ |
|
631 |
value := s asSymbol. |
|
632 |
] ifFalse:[ |
|
633 |
value := Object readFrom:s onError:[ |
|
634 |
s asSymbol |
|
635 |
]. |
|
636 |
]]]]. |
|
1464
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 |
model value:value] |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
639 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
640 |
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
|
641 |
|
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
642 |
"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
|
643 |
"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
|
644 |
! |
883cfaa89ffa
Add #literal conversion to convert strings to literals or symbols.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
645 |
|
508 | 646 |
number |
647 |
"setup the converter to convert from a string to a number |
|
648 |
and vice versa. Invalid numbers are converted to nil." |
|
649 |
||
650 |
self numberToText |
|
651 |
||
652 |
"Created: 4.4.1997 / 12:46:14 / cg" |
|
653 |
! |
|
654 |
||
442 | 655 |
numberOrNil |
656 |
"setup the converter to convert from a string to a number |
|
657 |
and vice versa. Invalid numbers are converted to nil." |
|
658 |
||
659 |
self |
|
660 |
getBlock:[:model | |
|
661 |
|numericValue| |
|
662 |
||
663 |
(numericValue := model value) isNil ifTrue:[ |
|
664 |
String new |
|
665 |
] ifFalse:[ |
|
666 |
numericValue printString |
|
667 |
]] |
|
668 |
||
669 |
putBlock: |
|
670 |
[:model :string | |
|
671 |
||
672 |
|value| |
|
673 |
||
1197
8e88ffde4374
dont get confused with a nil string value.
Claus Gittinger <cg@exept.de>
parents:
1192
diff
changeset
|
674 |
string size > 0 ifTrue:[ |
447 | 675 |
value := Number readFrom:string onError:nil |
1002 | 676 |
]. |
442 | 677 |
model value:value] |
678 |
||
679 |
updateBlock: [:m :a :p | true] |
|
680 |
||
681 |
"Created: 21.2.1997 / 18:58:38 / cg" |
|
682 |
! |
|
683 |
||
1463 | 684 |
numberOrNilToTextMinValue:minVal maxValue:maxVal |
685 |
"setup the converter to convert from a string to a number or nil |
|
686 |
and vice versa, but clamping the number into the range." |
|
687 |
||
688 |
self |
|
689 |
getBlock:[:model | |
|
690 |
|numericValue| |
|
691 |
||
692 |
(numericValue := model value) isNil ifTrue:[ |
|
693 |
String new |
|
694 |
] ifFalse:[ |
|
695 |
numericValue printString |
|
696 |
]] |
|
697 |
||
698 |
putBlock: |
|
699 |
[:model :string | |
|
700 |
||
701 |
|value c| |
|
702 |
||
703 |
(string isEmpty or:[string isBlank]) ifTrue:[ |
|
704 |
value := nil |
|
705 |
] ifFalse:[ |
|
706 |
value := Number readFromString:string onError:[nil]. |
|
707 |
value isNil ifTrue:[ |
|
708 |
||
709 |
] ifFalse:[ |
|
710 |
minVal notNil ifTrue:[ |
|
711 |
(value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
712 |
value := value max:minVal. |
|
713 |
]. |
|
714 |
maxVal notNil ifTrue:[ |
|
715 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
|
716 |
value := value min:maxVal. |
|
717 |
]. |
|
718 |
]. |
|
719 |
]. |
|
720 |
self setNumberValue: value inModel: model fromInput: string. |
|
721 |
] |
|
722 |
||
723 |
updateBlock: [:m :a :p | true] |
|
724 |
||
725 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
726 |
! |
|
727 |
||
1335
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
728 |
numberOrPointOrNil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
729 |
"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
|
730 |
and vice versa. Invalid numbers/points are converted to nil." |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
731 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
732 |
self |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
733 |
getBlock:[:model | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
734 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
735 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
736 |
(value := model value) isNil ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
737 |
String new |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
738 |
] ifFalse:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
739 |
value printString |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
740 |
]] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
741 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
742 |
putBlock: |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
743 |
[:model :string | |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
744 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
745 |
|value| |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
746 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
747 |
string size > 0 ifTrue:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
748 |
value := Point readFrom:string onError:[ |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
749 |
Number readFrom:string onError:nil |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
750 |
] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
751 |
]. |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
752 |
model value:value] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
753 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
754 |
updateBlock: [:m :a :p | true] |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
755 |
|
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
756 |
"Created: / 5.2.2000 / 01:26:48 / cg" |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
757 |
! |
275352274890
a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
758 |
|
1149 | 759 |
numberOrStringOrSymbolOrNil |
760 |
"setup the converter to convert from a string to either a numeric literal |
|
761 |
or a symbol and vice versa. |
|
762 |
Invalid strings (i.e. empty) are converted to nil; |
|
763 |
nil values are converted to an empty string. |
|
764 |
This is a very special converter (for the GUI builder) |
|
765 |
- probably not belonging to here" |
|
766 |
||
767 |
self |
|
768 |
getBlock:[:model | |
|
769 |
|litValue| |
|
770 |
||
771 |
(litValue := model value) isNil ifTrue:[ |
|
772 |
String new |
|
773 |
] ifFalse:[ |
|
774 |
litValue storeString |
|
775 |
]] |
|
776 |
||
777 |
putBlock: |
|
778 |
[:model :string | |
|
779 |
||
780 |
|value s| |
|
781 |
||
782 |
string isEmpty ifTrue:[ |
|
783 |
value := nil |
|
784 |
] ifFalse:[ |
|
785 |
value := Number readFrom:string onError:nil. |
|
786 |
value isNil ifTrue:[ |
|
787 |
s := string withoutSeparators. |
|
788 |
(s startsWith:'''') ifTrue:[ |
|
789 |
value := String readFrom:s readStream onError:nil |
|
790 |
] ifFalse:[ |
|
791 |
(s startsWith:'#') ifTrue:[ |
|
792 |
s := s copyFrom:2. |
|
793 |
(s startsWith:$') ifTrue:[ |
|
794 |
s := s copyFrom:2 to:(s size - 1) |
|
795 |
]. |
|
796 |
]. |
|
797 |
value := s asSymbol |
|
798 |
] |
|
799 |
] |
|
800 |
]. |
|
801 |
model value:value] |
|
802 |
||
803 |
updateBlock: [:m :a :p | true] |
|
804 |
||
805 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
806 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
807 |
! |
|
808 |
||
726 | 809 |
numberOrSymbolOrNil |
810 |
"setup the converter to convert from a string to either a numeric literal |
|
811 |
or a symbol and vice versa. |
|
812 |
Invalid strings (i.e. empty) are converted to nil; |
|
813 |
nil values are converted to an empty string. |
|
814 |
This is a very special converter (for the GUI builder) |
|
815 |
- probably not belonging to here" |
|
816 |
||
817 |
self |
|
818 |
getBlock:[:model | |
|
819 |
|litValue| |
|
820 |
||
821 |
(litValue := model value) isNil ifTrue:[ |
|
822 |
String new |
|
823 |
] ifFalse:[ |
|
824 |
litValue storeString |
|
825 |
]] |
|
826 |
||
827 |
putBlock: |
|
828 |
[:model :string | |
|
829 |
||
830 |
|value s| |
|
831 |
||
832 |
string isEmpty ifTrue:[ |
|
833 |
value := nil |
|
834 |
] ifFalse:[ |
|
835 |
value := Number readFrom:string onError:nil. |
|
836 |
value isNil ifTrue:[ |
|
837 |
s := string withoutSeparators. |
|
838 |
(s startsWith:'#') ifTrue:[ |
|
839 |
s := s copyFrom:2. |
|
840 |
(s startsWith:$') ifTrue:[ |
|
841 |
s := s copyFrom:2 to:(s size - 1) |
|
842 |
]. |
|
843 |
]. |
|
844 |
value := s asSymbol |
|
845 |
] |
|
846 |
]. |
|
847 |
model value:value] |
|
848 |
||
849 |
updateBlock: [:m :a :p | true] |
|
850 |
||
851 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
852 |
"Created: / 29.10.1997 / 15:49:26 / cg" |
|
853 |
! |
|
854 |
||
442 | 855 |
numberToText |
856 |
"setup the converter to convert from a string to a number |
|
487 | 857 |
and vice versa." |
442 | 858 |
|
859 |
self |
|
860 |
getBlock:[:model | |
|
861 |
|numericValue| |
|
862 |
||
726 | 863 |
(numericValue := model value) isNumber ifFalse:[ |
442 | 864 |
String new |
726 | 865 |
] ifTrue:[ |
442 | 866 |
numericValue printString |
867 |
]] |
|
868 |
||
869 |
putBlock: |
|
870 |
[:model :string | |
|
871 |
||
872 |
|value| |
|
873 |
||
874 |
string isEmpty ifTrue:[ |
|
875 |
value := 0 |
|
876 |
] ifFalse:[ |
|
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
877 |
value := Number readFromString: string onError:[0] |
442 | 878 |
]. |
879 |
model value:value] |
|
880 |
||
881 |
updateBlock: [:m :a :p | true] |
|
882 |
||
726 | 883 |
"Created: / 21.2.1997 / 18:57:05 / cg" |
884 |
"Modified: / 29.10.1997 / 15:49:21 / cg" |
|
442 | 885 |
! |
886 |
||
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
887 |
numberToText:numberOfPostDecimals |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
888 |
"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
|
889 |
and vice versa." |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
890 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
891 |
self |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
892 |
getBlock:[:model | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
893 |
|numericValue| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
894 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
895 |
(numericValue := model value) isNumber ifFalse:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
896 |
String new |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
897 |
] ifTrue:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
898 |
(numericValue asFixedPoint:numberOfPostDecimals) printString |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
899 |
]] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
900 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
901 |
putBlock: |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
902 |
[:model :string | |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
903 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
904 |
|value| |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
905 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
906 |
string isEmpty ifTrue:[ |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
907 |
value := 0 |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
908 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
909 |
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
|
910 |
]. |
1001 | 911 |
self setNumberValue: value inModel: model fromInput: string. |
912 |
] |
|
747
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
913 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
914 |
updateBlock: [:m :a :p | true] |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
915 |
|
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
916 |
"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
|
917 |
"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
|
918 |
! |
fe0360fb81ee
added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents:
726
diff
changeset
|
919 |
|
442 | 920 |
numberToTextFormattedBy:formatString |
921 |
"setup the converter to convert from a string to a number |
|
922 |
and vice versa, using formatString. |
|
923 |
The formatString is currently ignored when numbers are converted |
|
924 |
from a string." |
|
925 |
||
926 |
self |
|
927 |
getBlock:[:model | |
|
928 |
|numericValue| |
|
929 |
||
930 |
(numericValue := model value) isNil ifTrue:[ |
|
931 |
String new |
|
932 |
] ifFalse:[ |
|
933 |
PrintConverter print:numericValue formattedBy:formatString |
|
934 |
]] |
|
935 |
||
936 |
putBlock: |
|
937 |
[:model :string | |
|
938 |
||
939 |
|value| |
|
940 |
||
941 |
string isEmpty ifTrue:[ |
|
942 |
value := 0 |
|
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
943 |
] ifFalse:[ |
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
944 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
442 | 945 |
]. |
946 |
model value:value] |
|
947 |
||
948 |
updateBlock: [:m :a :p | true] |
|
949 |
||
950 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
|
446 | 951 |
! |
952 |
||
1426
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
953 |
numberToTextLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
954 |
"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
|
955 |
and vice versa, using formatString. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
956 |
The formatString is currently ignored when numbers are converted |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
957 |
from a string." |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
958 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
959 |
self |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
960 |
getBlock:[:model | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
961 |
|numericValue| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
962 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
963 |
(numericValue := model value) isNil ifTrue:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
964 |
String new |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
965 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
966 |
numericValue printStringLeftPaddedTo:aSize with:aCharacter |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
967 |
]] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
968 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
969 |
putBlock: |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
970 |
[:model :string | |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
971 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
972 |
|value| |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
973 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
974 |
string isEmpty ifTrue:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
975 |
value := 0 |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
976 |
] ifFalse:[ |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
977 |
value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
978 |
]. |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
979 |
model value:value] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
980 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
981 |
updateBlock: [:m :a :p | true] |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
982 |
|
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
983 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
984 |
! |
6a5f5372fcc4
added: a converter for number - string, string lwftpaddedTo: with:
tm
parents:
1407
diff
changeset
|
985 |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
986 |
numberToTextMinValue:minVal maxValue:maxVal |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
987 |
"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
|
988 |
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
|
989 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
990 |
self |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
991 |
getBlock:[:model | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
992 |
|numericValue| |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
993 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
994 |
(numericValue := model value) isNil ifTrue:[ |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
995 |
String new |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
996 |
] ifFalse:[ |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
997 |
numericValue printString |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
998 |
]] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
999 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1000 |
putBlock: |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1001 |
[:model :string | |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1002 |
|
1001 | 1003 |
|value c| |
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1004 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1005 |
string isEmpty ifTrue:[ |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1006 |
value := 0 |
1001 | 1007 |
] ifFalse:[ |
997 | 1008 |
value := Number readFromString: string onError:[0]. |
1000
70e95e4dca22
use #readFromString:onError: for string->number convertations
tz
parents:
997
diff
changeset
|
1009 |
]. |
942
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1010 |
minVal notNil ifTrue:[ |
1001 | 1011 |
(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
|
1012 |
value := value max:minVal. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1013 |
]. |
54949af3f3c1
number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents:
941
diff
changeset
|
1014 |
maxVal notNil ifTrue:[ |
1001 | 1015 |
(value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil]. |
944 | 1016 |
value := value min:maxVal. |
1001 | 1017 |
]. |
1018 |
self setNumberValue: value inModel: model fromInput: string. |
|
1019 |
] |
|
941
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1020 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1021 |
updateBlock: [:m :a :p | true] |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1022 |
|
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1023 |
"Modified: 21.2.1997 / 18:59:44 / cg" |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1024 |
! |
ba196649eaec
added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents:
747
diff
changeset
|
1025 |
|
726 | 1026 |
smalltalkObject |
1027 |
"setup the converter to convert from a string to any smalltalk object |
|
1028 |
and vice versa. The string used is the objects storeString. |
|
1029 |
Invalid strings (i.e. empty) are converted to nil. |
|
1030 |
This is a very special converter (for the GUI builder) |
|
1031 |
- probably not belonging to here" |
|
1032 |
||
1786 | 1033 |
^ self smalltalkObjectWithClass:Object |
1407 | 1034 |
! |
1035 |
||
1036 |
smalltalkObjectOrNil |
|
1037 |
"setup the converter to convert from a string to any smalltalk object |
|
1038 |
and vice versa. The string used is the objects storeString. |
|
1039 |
Invalid strings (i.e. empty) are converted to nil. |
|
1040 |
This is a very special converter (for the GUI builder) |
|
1041 |
- probably not belonging to here" |
|
1042 |
||
1786 | 1043 |
^ self smalltalkObjectOrNilWithClass:Object |
1044 |
! |
|
1045 |
||
1046 |
smalltalkObjectOrNilWithClass:classOfObject |
|
1047 |
"setup the converter to convert from a string to a smalltalk object |
|
1048 |
and vice versa. The string used is the objects storeString. |
|
1049 |
Invalid strings (i.e. empty) are converted to nil. |
|
1050 |
This is a very special converter (for the GUI builder) |
|
1051 |
- probably not belonging to here" |
|
1052 |
||
1407 | 1053 |
self |
1054 |
getBlock:[:model | |v s| |
|
1055 |
v := model value. |
|
1056 |
v isNil ifTrue:[ |
|
1406
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1057 |
s := 'nil' |
1199
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1058 |
] ifFalse:[ |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1059 |
s := v storeString. |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1060 |
(v isString or:[v isNumber]) ifFalse:[ |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1061 |
s := s , ' "' , v class name , '" ' |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1062 |
] |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1063 |
]. |
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1064 |
s |
726 | 1065 |
] |
1066 |
||
1067 |
putBlock: |
|
1068 |
[:model :string | |
|
1069 |
||
1070 |
|value| |
|
1071 |
||
1199
623c4cfe253d
better smalltalkObject typeConverter
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
1072 |
string size > 0 ifTrue:[ |
1786 | 1073 |
value := classOfObject readFrom:string onError:[ |
1406
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1074 |
string size > 0 ifTrue:[ |
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1075 |
value := string |
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1076 |
] |
7cd10ca1a425
smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents:
1355
diff
changeset
|
1077 |
]. |
1192
6db390e6463e
default: String in SmalltalkObject
Claus Gittinger <cg@exept.de>
parents:
1149
diff
changeset
|
1078 |
]. |
726 | 1079 |
model value:value |
1080 |
] |
|
1081 |
||
1082 |
updateBlock: [:m :a :p | true] |
|
1083 |
||
1084 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
1085 |
"Created: / 29.10.1997 / 15:50:16 / cg" |
|
1086 |
! |
|
1087 |
||
1786 | 1088 |
smalltalkObjectWithClass:classOfObject |
1089 |
"setup the converter to convert from a string to a smalltalk object |
|
1090 |
and vice versa. The string used is the objects storeString. |
|
1091 |
Invalid strings (i.e. empty) are converted to nil. |
|
1092 |
This is a very special converter (for the GUI builder) |
|
1093 |
- probably not belonging to here" |
|
1094 |
||
1095 |
self |
|
1096 |
getBlock:[:model | |v s| |
|
1097 |
v := model value. |
|
1098 |
v isNil ifTrue:[ |
|
1099 |
s := '' |
|
1100 |
] ifFalse:[ |
|
1101 |
s := v storeString. |
|
1102 |
(v isString or:[v isNumber]) ifFalse:[ |
|
1103 |
s := s , ' "' , v class name , '" ' |
|
1104 |
] |
|
1105 |
]. |
|
1106 |
s |
|
1107 |
] |
|
1108 |
||
1109 |
putBlock: |
|
1110 |
[:model :string | |
|
1111 |
||
1112 |
|value| |
|
1113 |
||
1114 |
string size > 0 ifTrue:[ |
|
1115 |
value := classOfObject readFrom:string onError:nil. |
|
1787 | 1116 |
value notNil ifTrue:[ |
1117 |
model value:value |
|
1786 | 1118 |
]. |
1119 |
]. |
|
1120 |
] |
|
1121 |
||
1122 |
updateBlock: [:m :a :p | true] |
|
1123 |
||
1124 |
"Modified: / 26.10.1997 / 13:50:32 / cg" |
|
1125 |
"Created: / 29.10.1997 / 15:50:16 / cg" |
|
1126 |
! |
|
1127 |
||
1128 |
smalltalkPoint |
|
1129 |
"setup the converter to convert from a string to a point object |
|
1130 |
and vice versa. The string used is the points storeString. |
|
1131 |
Invalid strings (i.e. empty) are converted to nil. |
|
1132 |
This is a very special converter (for the GUI builder) |
|
1133 |
- probably not belonging to here" |
|
1134 |
||
1135 |
^ self smalltalkObjectWithClass:Point |
|
1136 |
! |
|
1137 |
||
1653
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1138 |
symbolOrBooleanOrNil |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1139 |
"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
|
1140 |
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
|
1141 |
nil values are converted to an empty string. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1142 |
In addition, the strings true/false convert to/from booleans." |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1143 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1144 |
self |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1145 |
getBlock:[:model | |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1146 |
|symbolValue| |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1147 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1148 |
((symbolValue := model value) isSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1149 |
or:[symbolValue isBoolean]) |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1150 |
ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1151 |
'' |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1152 |
] ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1153 |
symbolValue printString. "/ storeString |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1154 |
]] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1155 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1156 |
putBlock: |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1157 |
[:model :string | |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1158 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1159 |
|value s| |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1160 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1161 |
string size == 0 ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1162 |
value := nil |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1163 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1164 |
s := string withoutSeparators. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1165 |
(s startsWith:'#') ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1166 |
s := s copyFrom:2. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1167 |
(s startsWith:$') ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1168 |
s := s copyFrom:2 to:(s size - 1) |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1169 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1170 |
value := s asSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1171 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1172 |
(#('true' 'false') includes:s) ifTrue:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1173 |
value := Object readFromString:s. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1174 |
] ifFalse:[ |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1175 |
value := s asSymbol |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1176 |
] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1177 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1178 |
]. |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1179 |
model value:value] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1180 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1181 |
updateBlock: [:m :a :p | true] |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1182 |
|
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1183 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1184 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1185 |
! |
f086f72cc8fa
new converter: symbolOrBooleanOrNil
Claus Gittinger <cg@exept.de>
parents:
1465
diff
changeset
|
1186 |
|
446 | 1187 |
symbolOrNil |
1188 |
"setup the converter to convert from a string to a symbol |
|
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1189 |
and vice versa. Invalid symbols (i.e. empty) are converted to nil; |
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1190 |
nil values are converted to an empty string." |
446 | 1191 |
|
1192 |
self |
|
1193 |
getBlock:[:model | |
|
1194 |
|symbolValue| |
|
1195 |
||
726 | 1196 |
(symbolValue := model value) isSymbol ifFalse:[ |
446 | 1197 |
String new |
726 | 1198 |
] ifTrue:[ |
946 | 1199 |
symbolValue printString. "/ storeString |
446 | 1200 |
]] |
1201 |
||
1202 |
putBlock: |
|
1203 |
[:model :string | |
|
1204 |
||
1205 |
|value s| |
|
1206 |
||
1314 | 1207 |
string size == 0 ifTrue:[ |
446 | 1208 |
value := nil |
1209 |
] ifFalse:[ |
|
1210 |
s := string withoutSeparators. |
|
1211 |
(s startsWith:'#') ifTrue:[ |
|
726 | 1212 |
s := s copyFrom:2. |
1213 |
(s startsWith:$') ifTrue:[ |
|
1214 |
s := s copyFrom:2 to:(s size - 1) |
|
1215 |
] |
|
446 | 1216 |
]. |
1217 |
value := s asSymbol |
|
1218 |
]. |
|
1219 |
model value:value] |
|
1220 |
||
1221 |
updateBlock: [:m :a :p | true] |
|
1222 |
||
722
ea6d08251333
added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents:
508
diff
changeset
|
1223 |
"Created: / 21.2.1997 / 18:58:38 / cg" |
946 | 1224 |
"Modified: / 26.5.1998 / 15:06:06 / cg" |
487 | 1225 |
! |
1226 |
||
1047 | 1227 |
time12H |
1026 | 1228 |
"setup the converter to convert from a string to a time formatted by 12 hours |
1229 |
and vice versa." |
|
1230 |
||
1027 | 1231 |
self timeToTextFormattedBy: #printString12HourFormat |
1026 | 1232 |
|
1233 |
||
1234 |
! |
|
1235 |
||
1047 | 1236 |
time24H |
1026 | 1237 |
"setup the converter to convert from a string to a time formatted by 24 hours |
1238 |
and vice versa." |
|
1239 |
||
1027 | 1240 |
self timeToTextFormattedBy: #printString24HourFormat |
1026 | 1241 |
|
1242 |
||
1243 |
! |
|
1244 |
||
487 | 1245 |
timeOrNil |
1246 |
"setup the converter to convert from a string to a time |
|
1247 |
and vice versa." |
|
1248 |
||
1249 |
self |
|
1250 |
getBlock:[:model | |
|
1251 |
|time| |
|
1252 |
||
1253 |
(time := model value) isNil ifTrue:[ |
|
1254 |
'' |
|
1255 |
] ifFalse:[ |
|
1256 |
time printString |
|
1257 |
]] |
|
1258 |
||
1259 |
putBlock: |
|
1260 |
[:model :string | |
|
1261 |
||
1262 |
|value| |
|
1263 |
||
1264 |
string isEmpty ifTrue:[ |
|
1265 |
value := nil |
|
1266 |
] ifFalse:[ |
|
1267 |
value := Time readFrom:string onError:nil |
|
1268 |
]. |
|
1269 |
model value:value] |
|
1270 |
||
1271 |
updateBlock: [:m :a :p | true] |
|
1272 |
||
1273 |
"Created: 4.3.1997 / 11:52:47 / cg" |
|
1274 |
"Modified: 4.3.1997 / 12:05:48 / cg" |
|
1275 |
! |
|
1276 |
||
1277 |
timeToText |
|
1278 |
"setup the converter to convert from a string to a time |
|
1279 |
and vice versa." |
|
1280 |
||
1026 | 1281 |
self timeToTextFormattedBy: #printString |
1282 |
! |
|
1283 |
||
1284 |
timeToTextFormattedBy: format |
|
1285 |
"setup the converter to convert from a string to a time formatted by format |
|
1286 |
and vice versa." |
|
1287 |
||
487 | 1288 |
self |
1289 |
getBlock:[:model | |
|
1290 |
|time| |
|
1291 |
||
1292 |
(time := model value) isNil ifTrue:[ |
|
1026 | 1293 |
Time now perform: format |
487 | 1294 |
] ifFalse:[ |
1026 | 1295 |
time perform: format |
487 | 1296 |
]] |
1297 |
||
1298 |
putBlock: |
|
1299 |
[:model :string | |
|
1300 |
||
1301 |
|value| |
|
1302 |
||
1303 |
string isEmpty ifTrue:[ |
|
1304 |
value := Time now |
|
1026 | 1305 |
] ifFalse:[ |
1306 |
value := Time readFrom:string onError:[Time now] |
|
487 | 1307 |
]. |
1308 |
model value:value] |
|
1309 |
||
1310 |
updateBlock: [:m :a :p | true] |
|
1311 |
||
1312 |
"Modified: 21.2.1997 / 18:59:06 / cg" |
|
1313 |
"Created: 4.3.1997 / 11:52:47 / cg" |
|
442 | 1314 |
! ! |
1315 |
||
1316 |
!TypeConverter class methodsFor:'documentation'! |
|
1317 |
||
1318 |
version |
|
1832 | 1319 |
^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.46 2003-10-09 19:52:59 cg Exp $' |
442 | 1320 |
! ! |