author | Claus Gittinger <cg@exept.de> |
Wed, 08 Feb 2017 00:50:25 +0100 | |
changeset 3864 | 37f4e48a35e7 |
parent 3707 | baba86518fd9 |
child 3926 | 518e74c68d80 |
child 4468 | ddc891549ca7 |
permissions | -rw-r--r-- |
75 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
" |
|
2770 | 12 |
"{ Package: 'stx:libview2' }" |
75 | 13 |
|
3706 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
125 | 16 |
ValueModel subclass:#ValueHolder |
223 | 17 |
instanceVariableNames:'value' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Support-Models' |
|
62 | 21 |
! |
22 |
||
68 | 23 |
!ValueHolder class methodsFor:'documentation'! |
24 |
||
69 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
71 | 28 |
All Rights Reserved |
69 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
68 | 39 |
documentation |
40 |
" |
|
3706 | 41 |
A valueHolder can be used as a model for editFields, buttons etc. |
68 | 42 |
It stores some value internally, and sends update messages to its |
43 |
dependents when changed. |
|
44 |
||
3706 | 45 |
Notice: |
231 | 46 |
this class was implemented using protocol information |
47 |
from alpha testers - it may not be complete or compatible to |
|
3706 | 48 |
the corresponding ST-80 class. |
49 |
If you encounter any incompatibilities, please forward a note |
|
231 | 50 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
223 | 51 |
|
52 |
[author:] |
|
53 |
Claus Gittinger |
|
68 | 54 |
" |
71 | 55 |
! |
56 |
||
57 |
examples |
|
58 |
" |
|
231 | 59 |
See many examples in DialogBox & EditField |
71 | 60 |
|
231 | 61 |
edit strings: |
62 |
[exBegin] |
|
63 |
|firstName lastName dialog| |
|
71 | 64 |
|
231 | 65 |
firstName := ValueHolder newString. |
66 |
lastName := ValueHolder newString. |
|
71 | 67 |
|
231 | 68 |
dialog := Dialog new. |
69 |
(dialog addTextLabel:'Name:') adjust:#left. |
|
70 |
dialog addInputFieldOn:firstName. |
|
71 |
dialog addVerticalSpace. |
|
72 |
(dialog addTextLabel:'Address:') adjust:#left. |
|
73 |
dialog addInputFieldOn:lastName. |
|
71 | 74 |
|
231 | 75 |
dialog addAbortButton; addOkButton. |
71 | 76 |
|
231 | 77 |
dialog open. |
78 |
dialog accepted ifTrue:[ |
|
268 | 79 |
Transcript show:firstName value; show:' '; showCR:lastName value |
231 | 80 |
] |
81 |
[exEnd] |
|
71 | 82 |
" |
68 | 83 |
! ! |
84 |
||
62 | 85 |
!ValueHolder class methodsFor:'instance creation'! |
86 |
||
125 | 87 |
newBoolean |
88 |
"return a new ValueHolder holding false as initial value" |
|
89 |
||
90 |
^ self with:false |
|
91 |
! |
|
68 | 92 |
|
125 | 93 |
newFraction |
94 |
"return a new ValueHolder holding 0.0 as initial value. |
|
95 |
The name is somewhat missleading - actually it should be called newFloat." |
|
96 |
||
3707 | 97 |
^ self with:0.0 |
125 | 98 |
! |
99 |
||
100 |
newNumber |
|
101 |
"return a new ValueHolder holding 0 as initial value" |
|
102 |
||
103 |
^ self with:0 |
|
62 | 104 |
! |
105 |
||
106 |
newString |
|
68 | 107 |
"return a new ValueHolder holding an empty string as initial value" |
108 |
||
62 | 109 |
^ self with:'' |
110 |
! |
|
111 |
||
125 | 112 |
with:anObject |
113 |
"return a new ValueHolder holding anObject as initial value" |
|
68 | 114 |
|
125 | 115 |
^ (super new) setValue:anObject |
62 | 116 |
! ! |
117 |
||
118 |
!ValueHolder methodsFor:'accessing'! |
|
119 |
||
69 | 120 |
setValue:anObject |
121 |
"set my value without notification." |
|
62 | 122 |
|
123 |
value := anObject. |
|
124 |
! |
|
125 |
||
126 |
value |
|
68 | 127 |
"return my value" |
128 |
||
62 | 129 |
^ value |
130 |
! ! |
|
125 | 131 |
|
156 | 132 |
!ValueHolder methodsFor:'printing & storing'! |
133 |
||
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
134 |
displayOn:aGCOrStream |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
135 |
"Compatibility |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
136 |
append a printed desription on some stream (Dolphin, Squeak) |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
137 |
OR: |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
138 |
display the receiver in a graphicsContext at 0@0 (ST80). |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
139 |
This method allows for any object to be displayed in some view |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
140 |
(although the fallBack is to display its printString ...)" |
700 | 141 |
|
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
142 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
143 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
144 |
aGCOrStream isStream ifFalse:[ |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
145 |
^ super displayOn:aGCOrStream. |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
146 |
]. |
700 | 147 |
|
3707 | 148 |
aGCOrStream |
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
149 |
nextPutAll:self class name; |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
150 |
nextPut:$(. |
3707 | 151 |
value displayOn:aGCOrStream. |
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
152 |
aGCOrStream nextPut:$) |
2770 | 153 |
! |
154 |
||
155 |
printOn:aStream |
|
156 |
"return a string for display in inspectors etc." |
|
157 |
||
158 |
self class name printOn:aStream. |
|
159 |
aStream nextPutAll:'('. |
|
160 |
value printOn:aStream. |
|
161 |
aStream nextPutAll:')' |
|
156 | 162 |
! ! |
163 |
||
129 | 164 |
!ValueHolder class methodsFor:'documentation'! |
165 |
||
166 |
version |
|
3706 | 167 |
^ '$Header$' |
2770 | 168 |
! |
169 |
||
170 |
version_CVS |
|
3706 | 171 |
^ '$Header$' |
129 | 172 |
! ! |
3706 | 173 |