93 examples |
144 examples |
94 " |
145 " |
95 see more examples in EnterFieldGroup>>examples. |
146 see more examples in EnterFieldGroup>>examples. |
96 |
147 |
97 |
148 |
98 basic field in a view: |
149 Step-by-step introduction: |
99 |
150 |
100 |top field| |
151 |
101 |
152 basic field in some view: |
102 top := StandardSystemView new. |
153 |
103 top extent:200@100. |
154 |top field| |
104 |
155 |
105 field := EditField origin:0.0@0.0 in:top. |
156 top := StandardSystemView new. |
106 field width:1.0. 'let its height as-is'. |
157 top extent:200@100. |
107 |
158 |
108 top open |
159 field := EditField origin:0.0@0.0 in:top. |
|
160 field width:1.0. 'let its height as-is'. |
|
161 |
|
162 top open |
109 |
163 |
110 |
164 |
111 forward input in topView to the field: |
165 forward input in topView to the field: |
112 (currently, the field does not know this - therefore, |
166 (currently, the field does not know this - therefore, |
113 its been told here ... this may change) |
167 its been told here ... this may change) |
114 |
168 |
115 |top field| |
169 |top field| |
116 |
170 |
117 top := StandardSystemView new. |
171 top := StandardSystemView new. |
118 top extent:200@100. |
172 top extent:200@100. |
119 |
173 |
120 field := EditField origin:0.0@0.0 in:top. |
174 field := EditField origin:0.0@0.0 in:top. |
121 field width:1.0. 'let its height as-is'. |
175 field width:1.0. 'let its height as-is'. |
122 |
176 |
123 top delegate:(KeyboardForwarder toView:field). |
177 top delegate:(KeyboardForwarder toView:field). |
124 field hasKeyboardFocus:true. |
178 field hasKeyboardFocus:true. |
125 top open |
179 top open |
126 |
180 |
127 |
181 |
128 to make it look better: set some inset: |
182 to make it look better: set some inset: |
129 |
183 |
130 |top field| |
184 |top field spacing| |
131 |
185 |
132 top := StandardSystemView new. |
186 top := StandardSystemView new. |
133 top extent:200@100. |
187 top extent:200@100. |
134 |
188 |
135 field := EditField origin:0.0@ViewSpacing in:top. |
189 spacing := View viewSpacing. |
136 field width:1.0. 'let its height as-is'. |
190 field := EditField origin:(0.0 @ spacing) in:top. |
137 field leftInset:ViewSpacing; |
191 field width:1.0. 'let its height as-is'. |
138 rightInset:ViewSpacing. |
192 field leftInset:spacing; rightInset:spacing. |
139 |
193 |
140 top open |
194 top open |
141 |
195 |
142 |
196 |
143 give it an initial contents: |
197 give it an initial contents: |
144 |
198 |
145 |top field| |
199 |top field| |
146 |
200 |
147 top := StandardSystemView new. |
201 top := StandardSystemView new. |
148 top extent:200@100. |
202 top extent:200@100. |
149 |
203 |
150 field := EditField origin:0.0@ViewSpacing in:top. |
204 field := EditField origin:(0.0 @ 0@0) in:top. |
151 field width:1.0. |
205 field width:1.0. |
152 field leftInset:ViewSpacing; |
206 |
153 rightInset:ViewSpacing. |
207 field editValue:'hello world'. |
154 field editValue:'hello world'. |
208 |
155 |
209 top open |
156 top open |
|
157 |
210 |
158 |
211 |
159 have it preselected: |
212 have it preselected: |
160 |
213 |
161 |top field| |
214 |top field| |
162 |
215 |
163 top := StandardSystemView new. |
216 top := StandardSystemView new. |
164 top extent:200@100. |
217 top extent:200@100. |
165 |
218 |
166 field := EditField origin:0.0@ViewSpacing in:top. |
219 field := EditField origin:(0.0 @ 0.0) in:top. |
167 field width:1.0. |
220 field width:1.0. |
168 field leftInset:ViewSpacing; |
221 field editValue:'hello world' selected:true. |
169 rightInset:ViewSpacing. |
222 |
170 field editValue:'hello world' selected:true. |
223 top open |
171 |
|
172 top open |
|
173 |
224 |
174 |
225 |
175 have part of it preselected: |
226 have part of it preselected: |
176 |
227 |
177 |top field| |
228 |top field| |
178 |
229 |
179 top := StandardSystemView new. |
230 top := StandardSystemView new. |
180 top extent:200@100. |
231 top extent:200@100. |
181 |
232 |
182 field := EditField origin:0.0@ViewSpacing in:top. |
233 field := EditField origin:(0.0 @ 0.0) in:top. |
183 field width:1.0. |
234 field width:1.0. |
184 field leftInset:ViewSpacing; |
235 |
185 rightInset:ViewSpacing. |
236 field editValue:'hello world'. |
186 field editValue:'hello world'; |
237 field selectFromCharacterPosition:1 to:5. |
187 selectFromCharacterPosition:1 to:5. |
238 |
188 |
239 top open |
189 top open |
|
190 |
240 |
191 |
241 |
192 set a size limit: |
242 set a size limit: |
193 |
243 |
194 |top field| |
244 |top field| |
195 |
245 |
196 top := StandardSystemView new. |
246 top := StandardSystemView new. |
197 top extent:200@100. |
247 top extent:200@100. |
198 |
248 |
199 field := EditField origin:0.0@ViewSpacing in:top. |
249 field := EditField origin:(0.0 @ 0.0) in:top. |
200 field width:1.0. |
250 field width:1.0. |
201 field leftInset:ViewSpacing; |
251 field editValue:'hello'. |
202 rightInset:ViewSpacing. |
252 |
203 field editValue:'hello'; |
253 field maxChars:8. |
204 maxChars:8. |
254 |
205 |
255 top open |
206 top open |
256 |
|
257 |
|
258 set a size limit, initial width and stop it from scrolling |
|
259 notice: you may prefer a constant-pitch font (such as courier): |
|
260 |
|
261 |top field| |
|
262 |
|
263 top := StandardSystemView new. |
|
264 top extent:200@100. |
|
265 |
|
266 field := EditField origin:(0.0 @ 0.0) in:top. |
|
267 field innerWidth:(field font widthOf:'00000000'). |
|
268 field editValue:'12345678'. |
|
269 |
|
270 field maxChars:8. |
|
271 field autoScroll:false. |
|
272 |
|
273 top open |
207 |
274 |
208 |
275 |
209 enable / disable: |
276 enable / disable: |
210 |
277 |
211 |top panel check field ena| |
278 |top panel check field ena| |
212 |
279 |
213 top := StandardSystemView new. |
280 top := StandardSystemView new. |
214 top extent:200@100. |
281 top extent:200@100. |
215 |
282 |
216 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
283 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
217 panel horizontalLayout:#leftSpace. |
284 panel horizontalLayout:#leftSpace. |
218 |
285 |
219 check := CheckBox label:'enable' in:panel. |
286 check := CheckBox label:'enable' in:panel. |
220 check turnOn. |
287 check turnOn. |
221 check action:[:onOff | onOff ifTrue:[field enable] ifFalse:[field disable]]. |
288 check action:[:onOff | onOff ifTrue:[field enable] ifFalse:[field disable]]. |
222 |
289 |
223 panel add:(View new height:30). |
290 panel add:(View new height:30). |
224 |
291 |
225 field := EditField in:panel. |
292 field := EditField in:panel. |
226 field width:1.0. |
293 field width:1.0. |
227 field leftInset:ViewSpacing; |
294 field editValue:'hello'. |
228 rightInset:ViewSpacing. |
|
229 field editValue:'hello'. |
|
230 |
295 |
231 top open |
296 top open |
232 |
297 |
233 |
298 |
234 enable / disable using a channel: |
299 enable / disable using a channel: |
235 |
300 |
236 |top panel check field ena| |
301 |top panel check field ena| |
237 |
302 |
238 top := StandardSystemView new. |
303 top := StandardSystemView new. |
239 top extent:200@100. |
304 top extent:200@100. |
240 |
305 |
241 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
306 panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
242 panel horizontalLayout:#leftSpace. |
307 panel horizontalLayout:#leftSpace. |
243 |
308 |
244 ena := true asValue. |
309 ena := true asValue. |
245 |
310 |
246 check := CheckBox label:'enable' in:panel. |
311 check := CheckBox label:'enable' in:panel. |
247 check model:ena. |
312 check model:ena. |
248 |
313 |
249 panel add:(View new height:30). |
314 panel add:(View new height:30). |
250 |
315 |
251 field := EditField in:panel. |
316 field := EditField in:panel. |
252 field enableChannel:ena. |
317 field enableChannel:ena. |
253 field width:1.0. |
318 field width:1.0. |
254 field leftInset:ViewSpacing; |
319 field editValue:'hello'. |
255 rightInset:ViewSpacing. |
320 |
256 field editValue:'hello'. |
321 top open |
257 |
|
258 top open |
|
259 |
322 |
260 |
323 |
261 use a converter: |
324 use a converter: |
262 - numbers (default to 0): |
325 - numbers (default to 0): |
263 |
326 |
264 |top field| |
327 |top field| |
265 |
328 |
266 top := StandardSystemView new. |
329 top := StandardSystemView new. |
267 top extent:200@100. |
330 top extent:200@100. |
268 |
331 |
269 field := EditField origin:0.0@ViewSpacing in:top. |
332 field := EditField origin:0.0@ViewSpacing in:top. |
270 field width:1.0. |
333 field width:1.0. |
271 field leftInset:ViewSpacing; |
334 field leftInset:ViewSpacing; |
272 rightInset:ViewSpacing. |
335 rightInset:ViewSpacing. |
273 |
336 |
274 field converter:(PrintConverter new initForNumber). |
337 field converter:(PrintConverter new initForNumber). |
275 field editValue:1234. |
338 field editValue:1234. |
276 field acceptAction:[:value | Transcript showCr:value]. |
339 field acceptAction:[:value | Transcript showCr:value]. |
277 field crAction:[field accept. top destroy]. |
340 field crAction:[field accept. top destroy]. |
278 top open. |
341 top open. |
279 |
342 |
280 - dates: |
343 - dates: |
281 |
344 |
282 |top field| |
345 |top field| |
283 |
346 |
284 top := StandardSystemView new. |
347 top := StandardSystemView new. |
285 top extent:200@100. |
348 top extent:200@100. |
286 |
349 |
287 field := EditField origin:0.0@ViewSpacing in:top. |
350 field := EditField origin:0.0@ViewSpacing in:top. |
288 field width:1.0. |
351 field width:1.0. |
289 field leftInset:ViewSpacing; |
352 field leftInset:ViewSpacing; |
290 rightInset:ViewSpacing. |
353 rightInset:ViewSpacing. |
291 |
354 |
292 field converter:(PrintConverter new initForDate). |
355 field converter:(PrintConverter new initForDate). |
293 field editValue:Date today. |
356 field editValue:Date today. |
294 field acceptAction:[:value | Transcript showCr:value class name , ' ' , value printString]. |
357 field acceptAction:[:value | Transcript showCr:value class name , ' ' , value printString]. |
295 field crAction:[field accept. top destroy]. |
358 field crAction:[field accept. top destroy]. |
296 top open. |
359 top open. |
297 |
360 |
298 |
361 |
299 setting immediateAccept, makes the field update with every key: |
362 setting immediateAccept, makes the field update with every key: |
300 |
363 |
301 - immediate accept numbers, defaulting to nil: |
364 - immediate accept numbers, defaulting to nil: |
302 |
365 |
303 |top field| |
366 |top field| |
304 |
367 |
305 top := StandardSystemView new. |
368 top := StandardSystemView new. |
306 top extent:200@100. |
369 top extent:200@100. |
307 |
370 |
308 field := EditField origin:0.0@ViewSpacing in:top. |
371 field := EditField origin:0.0@ViewSpacing in:top. |
309 field width:1.0. |
372 field width:1.0. |
310 field leftInset:ViewSpacing; |
373 field leftInset:ViewSpacing; |
311 rightInset:ViewSpacing. |
374 rightInset:ViewSpacing. |
312 |
375 |
313 field converter:(PrintConverter new initForNumberOrNil). |
376 field converter:(PrintConverter new initForNumberOrNil). |
314 field immediateAccept:true. |
377 field immediateAccept:true. |
315 field editValue:1234. |
378 field editValue:1234. |
316 field acceptAction:[:value | Transcript showCr:value]. |
379 field acceptAction:[:value | Transcript showCr:value]. |
317 field crAction:[field accept. top destroy]. |
380 field crAction:[field accept. top destroy]. |
318 top open. |
381 top open. |
319 |
382 |
320 |
383 |
|
384 |
|
385 grouping multiple fields, and forward keyPres from the outer view to the active field |
|
386 (i.e. actually: to the group): |
|
387 |
|
388 |top field1 field2 field3 group| |
|
389 |
|
390 |
|
391 top := StandardSystemView new. |
|
392 top extent:200@100. |
|
393 |
|
394 field1 := EditField origin:(0.0 @ 0.0) in:top. |
|
395 field1 width:1.0. |
|
396 |
|
397 field2 := EditField origin:(0.0 @ 0.0) in:top. |
|
398 field2 width:0.5. |
|
399 field2 topInset:(field1 height); bottomInset:(field1 height negated). |
|
400 |
|
401 field3 := EditField origin:(0.5 @ 0.0) in:top. |
|
402 field3 width:0.5. |
|
403 field3 topInset:(field1 height); bottomInset:(field1 height negated). |
|
404 |
|
405 group := EnterFieldGroup new. |
|
406 group add:field1; add:field2; add:field3. |
|
407 |
|
408 top delegate:(KeyboardForwarder to:group). |
|
409 |
|
410 top open. |
|
411 |
|
412 |
|
413 in addition: tell the group to close when the last field is left: |
|
414 |
|
415 |top field1 field2 field3 group| |
|
416 |
|
417 |
|
418 top := StandardSystemView new. |
|
419 top extent:200@100. |
|
420 |
|
421 field1 := EditField origin:(0.0 @ 0.0) in:top. |
|
422 field1 width:1.0. |
|
423 |
|
424 field2 := EditField origin:(0.0 @ 0.0) in:top. |
|
425 field2 width:0.5. |
|
426 field2 topInset:(field1 height); bottomInset:(field1 height negated). |
|
427 |
|
428 field3 := EditField origin:(0.5 @ 0.0) in:top. |
|
429 field3 width:0.5. |
|
430 field3 topInset:(field1 height); bottomInset:(field1 height negated). |
|
431 |
|
432 group := EnterFieldGroup new. |
|
433 group add:field1; add:field2; add:field3. |
|
434 group leaveAction:[top destroy]. |
|
435 |
|
436 top delegate:(KeyboardForwarder to:group). |
|
437 |
|
438 top open. |
321 |
439 |
322 |
440 |
323 use a model: |
441 use a model: |
324 (see changing model value in inspector when return is pressed in the field) |
442 (see changing model value in inspector when return is pressed in the field) |
325 |
443 |
326 |top field model| |
444 |top field model| |
327 |
445 |
328 model := 'hello world' asValue. |
446 model := 'hello world' asValue. |
329 |
447 |
330 top := StandardSystemView new. |
448 top := StandardSystemView new. |
331 top extent:200@100. |
449 top extent:200@100. |
332 |
450 |
333 field := EditField origin:0.0@ViewSpacing in:top. |
451 field := EditField origin:(0.0 @ 0.0) in:top. |
334 field width:1.0. |
452 field width:1.0. |
335 field leftInset:ViewSpacing; |
453 field model:model. |
336 rightInset:ViewSpacing. |
454 field acceptOnReturn:true. |
337 field model:model. |
455 |
338 field acceptOnReturn:true. |
456 top open. |
339 |
457 model inspect. |
340 top open. |
|
341 model inspect. |
|
342 |
458 |
343 |
459 |
344 two views on the same model (each accepts on return): |
460 two views on the same model (each accepts on return): |
345 |
461 |
346 |top1 top2 field1 field2 model| |
462 |top1 top2 field1 field2 model| |
347 |
463 |
348 model := 'hello world' asValue. |
464 model := 'hello world' asValue. |
349 |
465 |
350 top1 := StandardSystemView new. |
466 top1 := StandardSystemView new. |
351 top1 extent:200@100. |
467 top1 extent:200@100. |
352 field1 := EditField origin:0.0@ViewSpacing in:top1. |
468 field1 := EditField origin:(0.0 @ 0.0) in:top1. |
353 field1 width:1.0. |
469 field1 width:1.0. |
354 field1 leftInset:ViewSpacing; |
470 field1 model:model. |
355 rightInset:ViewSpacing. |
471 field1 acceptOnReturn:true. |
356 field1 model:model. |
472 top1 open. |
357 field1 acceptOnReturn:true. |
473 |
358 top1 open. |
474 top2 := StandardSystemView new. |
359 |
475 top2 extent:200@100. |
360 top2 := StandardSystemView new. |
476 field2 := EditField origin:(0.0 @ 0.0) in:top2. |
361 top2 extent:200@100. |
477 field2 width:1.0. |
362 field2 := EditField origin:0.0@ViewSpacing in:top2. |
478 field2 model:model. |
363 field2 width:1.0. |
479 field2 acceptOnReturn:true. |
364 field2 leftInset:ViewSpacing; |
480 top2 open. |
365 rightInset:ViewSpacing. |
|
366 field2 model:model. |
|
367 field2 acceptOnReturn:true. |
|
368 top2 open. |
|
369 |
481 |
370 two views on the same model (no accept on return): |
482 two views on the same model (no accept on return): |
371 |
483 |
372 |top1 top2 field1 field2 model| |
484 |top1 top2 field1 field2 model| |
373 |
485 |
374 model := 'hello world' asValue. |
486 model := 'hello world' asValue. |
375 |
487 |
376 top1 := StandardSystemView new. |
488 top1 := StandardSystemView new. |
377 top1 extent:200@100. |
489 top1 extent:200@100. |
378 field1 := EditField origin:0.0@ViewSpacing in:top1. |
490 field1 := EditField origin:(0.0 @ 0.0) in:top1. |
379 field1 width:1.0. |
491 field1 width:1.0. |
380 field1 leftInset:ViewSpacing; |
492 field1 model:model; acceptOnReturn:false. |
381 rightInset:ViewSpacing. |
493 top1 open. |
382 field1 model:model; acceptOnReturn:false. |
494 |
383 top1 open. |
495 top2 := StandardSystemView new. |
384 |
496 top2 extent:200@100. |
385 top2 := StandardSystemView new. |
497 field2 := EditField origin:(0.0 @ 0.0) in:top2. |
386 top2 extent:200@100. |
498 field2 width:1.0. |
387 field2 := EditField origin:0.0@ViewSpacing in:top2. |
499 field2 model:model; acceptOnReturn:false. |
388 field2 width:1.0. |
500 top2 open. |
389 field2 leftInset:ViewSpacing; |
501 |
390 rightInset:ViewSpacing. |
502 with immediate accept (every key updates the model): |
391 field2 model:model; acceptOnReturn:false. |
503 |
392 top2 open. |
504 |top1 top2 field1 field2 model| |
393 |
505 |
394 with immediate accept: |
506 model := 'hello world' asValue. |
395 |
507 |
396 |top1 top2 field1 field2 model| |
508 top1 := StandardSystemView new. |
397 |
509 top1 extent:200@100. |
398 model := 'hello world' asValue. |
510 field1 := EditField origin:(0.0 @ 0.0) in:top1. |
399 |
511 field1 width:1.0. |
400 top1 := StandardSystemView new. |
512 field1 model:model; immediateAccept:true. |
401 top1 extent:200@100. |
513 top1 open. |
402 field1 := EditField origin:0.0@ViewSpacing in:top1. |
514 |
403 field1 width:1.0. |
515 top2 := StandardSystemView new. |
404 field1 leftInset:ViewSpacing; rightInset:ViewSpacing. |
516 top2 extent:200@100. |
405 field1 model:model; immediateAccept:true. |
517 field2 := EditField origin:(0.0 @ 0.0) in:top2. |
406 top1 open. |
518 field2 width:1.0. |
407 |
519 field2 model:model; immediateAccept:true. |
408 top2 := StandardSystemView new. |
520 top2 open. |
409 top2 extent:200@100. |
|
410 field2 := EditField origin:0.0@ViewSpacing in:top2. |
|
411 field2 width:1.0. |
|
412 field2 leftInset:ViewSpacing; rightInset:ViewSpacing. |
|
413 field2 model:model; immediateAccept:true. |
|
414 top2 open. |
|
415 |
521 |
416 just an example; a checkBox and an editField on the same model: |
522 just an example; a checkBox and an editField on the same model: |
417 |
523 |
418 |top1 top2 field1 box model| |
524 |top1 top2 field1 box model| |
419 |
525 |
420 model := false asValue. |
526 model := false asValue. |
421 |
527 |
422 top1 := StandardSystemView new. |
528 top1 := StandardSystemView new. |
423 top1 extent:200@100. |
529 top1 extent:200@100. |
424 field1 := EditField origin:0.0@ViewSpacing in:top1. |
530 field1 := EditField origin:(0.0 @ 0.0) in:top1. |
425 field1 width:1.0. |
531 field1 width:1.0. |
426 field1 leftInset:ViewSpacing; |
532 field1 converter:(PrintConverter new initForYesNo). |
427 rightInset:ViewSpacing. |
533 field1 model:model. |
428 field1 converter:(PrintConverter new initForYesNo). |
534 top1 open. |
429 field1 model:model. |
535 |
430 top1 open. |
536 top2 := StandardSystemView new. |
431 |
537 top2 extent:200@100. |
432 top2 := StandardSystemView new. |
538 box := CheckBox on:model. |
433 top2 extent:200@100. |
539 box label:'on/off'. |
434 box := CheckBox on:model. |
540 top2 add:box. |
435 box label:'on/off'. |
541 top2 open. |
436 top2 add:box. |
542 |
437 top2 open. |
543 model inspect. |
438 |
|
439 model inspect. |
|
440 |
544 |
441 |
545 |
442 connecting fields: |
546 connecting fields: |
443 update field2 wehenever field1 is changed. |
547 update field2 wehenever field1 is changed. |
444 (normally, the processing below (xChanged) is done in your application |
548 (normally, the processing below (xChanged) is done in your application |
445 class, or in a complex model. For the demonstration below, we use |
549 class, or in a complex model. For the demonstration below, we use |
446 a Plug to simulate the protocol.) |
550 a Plug to simulate the protocol.) |
447 |
551 |
448 |application top field1 field2 value1 value2| |
552 |application top field1 field2 value1 value2| |
449 |
553 |
450 application := Plug new. |
554 application := Plug new. |
451 application respondTo:#value1Changed |
555 application respondTo:#value1Changed |
452 with:[value2 value:(value1 value isNil ifTrue:[nil] |
556 with:[value2 value:(value1 value isNil ifTrue:[nil] |
453 ifFalse:[value1 value squared])]. |
557 ifFalse:[value1 value squared])]. |
454 |
558 |
455 value1 := 1 asValue. |
559 value1 := 1 asValue. |
456 value2 := 1 asValue. |
560 value2 := 1 asValue. |
457 |
561 |
458 top := Dialog new. |
562 top := Dialog new. |
459 top extent:200@200. |
563 top extent:200@200. |
460 |
564 |
461 (top addTextLabel:'some number:') layout:#left. |
565 (top addTextLabel:'some number:') layout:#left. |
462 top addVerticalSpace. |
566 top addVerticalSpace. |
463 |
567 |
464 (top addInputFieldOn:value1 tabable:false) |
568 (top addInputFieldOn:value1 tabable:false) |
465 converter:(PrintConverter new initForNumberOrNil); |
569 converter:(PrintConverter new initForNumberOrNil); |
466 immediateAccept:true. |
570 immediateAccept:true. |
467 top addVerticalSpace. |
571 top addVerticalSpace. |
468 |
572 |
469 (top addTextLabel:'squared:') layout:#left. |
573 (top addTextLabel:'squared:') layout:#left. |
470 top addVerticalSpace. |
574 top addVerticalSpace. |
471 (top addInputFieldOn:value2 tabable:false) |
575 (top addInputFieldOn:value2 tabable:false) |
472 converter:(PrintConverter new initForNumberOrNil). |
576 converter:(PrintConverter new initForNumberOrNil). |
473 |
577 |
474 value1 onChangeSend:#value1Changed to:application. |
578 value1 onChangeSend:#value1Changed to:application. |
475 |
579 |
476 top openModeless. |
580 top openModeless. |
477 |
581 |
478 |
582 |
479 two-way connect: |
583 two-way connect: |
480 each field updates the other (notice, that we have to turn off |
584 each field updates the other (notice, that we have to turn off |
481 onChange: notification, to avoid an endless notification cycle) |
585 onChange: notification, to avoid an endless notification cycle) |
482 |
586 |
483 |application top field1 field2 value1 value2| |
587 |application top field1 field2 value1 value2| |
484 |
588 |
485 application := Plug new. |
589 application := Plug new. |
486 application respondTo:#value1Changed |
590 application respondTo:#value1Changed |
487 with:[value2 retractInterestsFor:application. |
591 with:[value2 retractInterestsFor:application. |
488 value2 value:(value1 value isNil ifTrue:[nil] |
592 value2 value:(value1 value isNil ifTrue:[nil] |
489 ifFalse:[value1 value squared]). |
593 ifFalse:[value1 value squared]). |
490 value2 onChangeSend:#value2Changed to:application. |
594 value2 onChangeSend:#value2Changed to:application. |
491 ]. |
595 ]. |
492 application respondTo:#value2Changed |
596 application respondTo:#value2Changed |
493 with:[value1 retractInterestsFor:application. |
597 with:[value1 retractInterestsFor:application. |
494 value1 value:(value2 value isNil ifTrue:[nil] |
598 value1 value:(value2 value isNil ifTrue:[nil] |
495 ifFalse:[value2 value sqrt]). |
599 ifFalse:[value2 value sqrt]). |
496 value1 onChangeSend:#value1Changed to:application. |
600 value1 onChangeSend:#value1Changed to:application. |
497 ]. |
601 ]. |
498 |
602 |
499 value1 := 1 asValue. |
603 value1 := 1 asValue. |
500 value2 := 1 asValue. |
604 value2 := 1 asValue. |
501 |
605 |
502 top := Dialog new. |
606 top := Dialog new. |
503 top extent:200@200. |
607 top extent:200@200. |
504 |
608 |
505 (top addTextLabel:'some number:') layout:#left. |
609 (top addTextLabel:'some number:') layout:#left. |
506 top addVerticalSpace. |
610 top addVerticalSpace. |
507 |
611 |
508 (top addInputFieldOn:value1 tabable:false) |
612 (top addInputFieldOn:value1 tabable:false) |
509 converter:(PrintConverter new initForNumberOrNil); |
613 converter:(PrintConverter new initForNumberOrNil); |
510 immediateAccept:true. |
614 immediateAccept:true. |
511 top addVerticalSpace. |
615 top addVerticalSpace. |
512 |
616 |
513 (top addTextLabel:'squared:') layout:#left. |
617 (top addTextLabel:'squared:') layout:#left. |
514 top addVerticalSpace. |
618 top addVerticalSpace. |
515 (top addInputFieldOn:value2 tabable:false) |
619 (top addInputFieldOn:value2 tabable:false) |
516 converter:(PrintConverter new initForNumberOrNil); |
620 converter:(PrintConverter new initForNumberOrNil); |
517 immediateAccept:true. |
621 immediateAccept:true. |
518 |
622 |
519 value1 onChangeSend:#value1Changed to:application. |
623 value1 onChangeSend:#value1Changed to:application. |
520 value2 onChangeSend:#value2Changed to:application. |
624 value2 onChangeSend:#value2Changed to:application. |
521 |
625 |
522 top openModeless. |
626 top openModeless. |
523 " |
627 " |
524 ! ! |
628 ! ! |
525 |
629 |
526 !EditField class methodsFor:'defaults'! |
630 !EditField class methodsFor:'defaults'! |
527 |
631 |