55 |
55 |
56 examples |
56 examples |
57 " |
57 " |
58 stupid examples: |
58 stupid examples: |
59 convert date <-> string: |
59 convert date <-> string: |
60 |
60 [exBegin] |
61 |conv| |
61 |conv| |
62 |
62 |
63 conv := (PrintConverter new) |
63 conv := (PrintConverter new) |
64 toPrint:[:date | date printString] |
64 toPrint:[:date | date printString] |
65 toRead:[:string | Date readFromString:string]. |
65 toRead:[:string | Date readFromString:string]. |
66 (conv printStringFor:(Date today)) inspect. |
66 (conv printStringFor:(Date today)) inspect. |
67 (conv readValueFrom:(Date today printString)) inspect |
67 (conv readValueFrom:(Date today printString)) inspect |
|
68 [exEnd] |
68 |
69 |
69 |
70 |
70 convert number <-> string: |
71 convert number <-> string: |
71 |
72 [exBegin] |
72 |conv| |
73 |conv| |
73 |
74 |
74 conv := (PrintConverter new) initForNumber. |
75 conv := (PrintConverter new) initForNumber. |
75 (conv printStringFor:12345) inspect. |
76 (conv printStringFor:12345) inspect. |
76 (conv readValueFrom:'12345') inspect |
77 (conv readValueFrom:'12345') inspect |
|
78 [exEnd] |
77 |
79 |
78 |
80 |
79 convert boolean <-> string: |
81 convert boolean <-> string: |
80 |
82 [exBegin] |
81 |conv| |
83 |conv| |
82 |
84 |
83 conv := (PrintConverter new) initForYesNo. |
85 conv := (PrintConverter new) initForYesNo. |
84 (conv printStringFor:true). |
86 (conv printStringFor:true). |
85 (conv printStringFor:false). |
87 (conv printStringFor:false). |
86 (conv readValueFrom:'yes'). |
88 (conv readValueFrom:'yes'). |
87 (conv readValueFrom:'no'). |
89 (conv readValueFrom:'no'). |
88 'if language is german:'. |
90 'if language is german:'. |
89 (conv readValueFrom:'ja'). |
91 (conv readValueFrom:'ja'). |
90 (conv readValueFrom:'nein') |
92 (conv readValueFrom:'nein') |
|
93 [exEnd] |
91 |
94 |
92 concrete examples: |
95 concrete examples: |
93 convert in an inputField: |
96 convert in an inputField: |
94 |
97 [exBegin] |
95 |dialog field| |
98 |dialog field| |
96 |
99 |
97 dialog := Dialog new. |
100 dialog := Dialog new. |
98 dialog addTextLabel:'a number (and only numbers):'. |
101 dialog addTextLabel:'a number (and only numbers):'. |
99 dialog addVerticalSpace. |
102 dialog addVerticalSpace. |
101 field converter:(PrintConverter new initForNumber). |
104 field converter:(PrintConverter new initForNumber). |
102 field immediateAccept:true. |
105 field immediateAccept:true. |
103 dialog addOkButton. |
106 dialog addOkButton. |
104 dialog open. |
107 dialog open. |
105 dialog accepted ifTrue:[ |
108 dialog accepted ifTrue:[ |
106 Transcript showCr:field editValue |
109 Transcript showCr:field editValue |
107 ] |
110 ] |
|
111 [exEnd] |
108 |
112 |
109 convert a models value for a label: |
113 convert a models value for a label: |
110 |
114 [exBegin] |
111 |top v1 v2 l1 l2| |
115 |top v1 v2 l1 l2| |
112 |
116 |
113 v1 := 0 asValue. |
117 v1 := 0 asValue. |
114 v2 := Date today asValue. |
118 v2 := Date today asValue. |
115 |
119 |
128 |
132 |
129 top open. |
133 top open. |
130 |
134 |
131 'now, change the values ...'. |
135 'now, change the values ...'. |
132 [ |
136 [ |
133 1 to:50 do:[:i| |
137 1 to:50 do:[:i| |
134 v1 value:(v1 value + 1). |
138 v1 value:(v1 value + 1). |
135 v2 value:(v2 value addDays:1). |
139 v2 value:(v2 value addDays:1). |
136 (Delay forSeconds:0.5) wait |
140 (Delay forSeconds:0.5) wait |
137 ] |
141 ] |
138 ] fork |
142 ] fork |
|
143 [exEnd] |
139 |
144 |
140 convert a models value for a label with limited precision |
145 convert a models value for a label with limited precision |
141 float conversion: |
146 float conversion: |
142 |
147 [exBegin] |
143 |top v l1 l2| |
148 |top v l1 l2| |
144 |
149 |
145 v := 0.0 asValue. |
150 v := 0.0 asValue. |
146 |
151 |
147 top := StandardSystemView new. |
152 top := StandardSystemView new. |
159 |
164 |
160 top open. |
165 top open. |
161 |
166 |
162 'now, change the values ...'. |
167 'now, change the values ...'. |
163 [ |
168 [ |
164 1 to:100 do:[:i| |
169 1 to:100 do:[:i| |
165 v value:(v value + 0.005). |
170 v value:(v value + 0.005). |
166 (Delay forSeconds:0.5) wait |
171 (Delay forSeconds:0.5) wait |
167 ] |
172 ] |
168 ] fork |
173 ] fork |
|
174 [exEnd] |
169 |
175 |
170 a custom converter, converting a number to either 'odd' |
176 a custom converter, converting a number to either 'odd' |
171 or 'even' strings (we only need a one-way converter for labels): |
177 or 'even' strings (we only need a one-way converter for labels): |
172 |
178 [exBegin] |
173 |top v l1 l2| |
179 |top v l1 l2| |
174 |
180 |
175 v := 0 asValue. |
181 v := 0 asValue. |
176 |
182 |
177 top := StandardSystemView new. |
183 top := StandardSystemView new. |
182 l1 model:v; labelMessage:#value; aspect:#value. |
188 l1 model:v; labelMessage:#value; aspect:#value. |
183 l1 level:-1; inset:10. |
189 l1 level:-1; inset:10. |
184 |
190 |
185 l2 := Label origin:0.0@0.5 corner:1.0@1.0 in:top. |
191 l2 := Label origin:0.0@0.5 corner:1.0@1.0 in:top. |
186 l2 converter:(PrintConverter |
192 l2 converter:(PrintConverter |
187 new |
193 new |
188 toPrint:[:num | num even ifTrue:['even'] |
194 toPrint:[:num | num even ifTrue:['even'] |
189 ifFalse:['odd']] |
195 ifFalse:['odd']] |
190 toRead:[:string | ]). |
196 toRead:[:string | ]). |
191 l2 model:v; labelMessage:#value; aspect:#value. |
197 l2 model:v; labelMessage:#value; aspect:#value. |
192 l2 level:-1; inset:10. |
198 l2 level:-1; inset:10. |
193 |
199 |
194 top open. |
200 top open. |
195 |
201 |
196 'now, change the values ...'. |
202 'now, change the values ...'. |
197 [ |
203 [ |
198 1 to:100 do:[:i| |
204 1 to:100 do:[:i| |
199 v value:(v value + 1). |
205 v value:(v value + 1). |
200 (Delay forSeconds:0.5) wait |
206 (Delay forSeconds:0.5) wait |
201 ] |
207 ] |
202 ] fork |
208 ] fork |
|
209 [exEnd] |
203 |
210 |
204 see more examples in the EditField examples. |
211 see more examples in the EditField examples. |
205 " |
212 " |
206 ! ! |
213 ! ! |
207 |
214 |