author | Claus Gittinger <cg@exept.de> |
Tue, 16 Jan 2018 16:20:36 +0100 | |
changeset 4044 | 9400ab00cbfc |
parent 4028 | 3408e9d75b99 |
child 4090 | 8e3704b9d8f7 |
permissions | -rw-r--r-- |
74 | 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 |
" |
|
4028 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
14 |
"{ NameSpace: Smalltalk }" |
|
74 | 15 |
|
125 | 16 |
ValueHolder subclass:#BufferedValueHolder |
223 | 17 |
instanceVariableNames:'subject triggerChannel bufferedValue' |
18 |
classVariableNames:'NotYetAssigned' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Support-Models' |
|
71 | 21 |
! |
22 |
||
23 |
!BufferedValueHolder class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
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 |
||
39 |
documentation |
|
40 |
" |
|
90 | 41 |
a bufferedValueHolder keeps a temporary copy of the realHolders value, |
71 | 42 |
and only does a real store of the value when triggered. |
43 |
Triggering is done by depending on a trigger objects value, which is |
|
44 |
typically a ValueHolder for a boolean, which is set by an ok-button. |
|
45 |
||
231 | 46 |
Notice: |
47 |
this class was implemented using protocol information |
|
48 |
from alpha testers - it may not be complete or compatible to |
|
49 |
the corresponding ST-80 class. |
|
50 |
If you encounter any incompatibilities, please forward a note |
|
51 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
223 | 52 |
|
731 | 53 |
[see also:] |
54 |
CodingExamples_GUI::BufferedValueHolderDemo |
|
55 |
||
223 | 56 |
[author:] |
57 |
Claus Gittinger |
|
71 | 58 |
" |
59 |
! |
|
60 |
||
61 |
examples |
|
62 |
" |
|
72 | 63 |
unbuffered (values are changed, even if not accepted, |
64 |
iff a field is left with Return or accept is done in a field): |
|
231 | 65 |
[exBegin] |
66 |
|firstName lastName dialog| |
|
71 | 67 |
|
231 | 68 |
firstName := 'foo' asValue. |
69 |
lastName := 'bar' asValue. |
|
71 | 70 |
|
231 | 71 |
dialog := Dialog new. |
72 |
(dialog addTextLabel:'Name:') layout:#left. |
|
73 |
dialog addInputFieldOn:firstName. |
|
74 |
dialog addVerticalSpace. |
|
75 |
(dialog addTextLabel:'Address:') layout:#left. |
|
76 |
dialog addInputFieldOn:lastName. |
|
71 | 77 |
|
231 | 78 |
dialog addAbortButton; addOkButton. |
71 | 79 |
|
231 | 80 |
dialog open. |
71 | 81 |
|
268 | 82 |
Transcript show:firstName value; show:' '; showCR:lastName value |
231 | 83 |
[exEnd] |
71 | 84 |
|
72 | 85 |
|
86 |
buffered (values are only stored when accepted; undo reloads old values) |
|
87 |
(use an instance of TriggerValue. If a ValueHolder was used, we had |
|
88 |
to temporarily set its value back to nil, to have the change really be |
|
89 |
forwarded to its dependends) |
|
231 | 90 |
[exBegin] |
91 |
|firstName lastName trigger dialog| |
|
71 | 92 |
|
231 | 93 |
firstName := 'foo' asValue. |
94 |
lastName := 'bar' asValue. |
|
95 |
trigger := TriggerValue new. |
|
71 | 96 |
|
231 | 97 |
dialog := Dialog new. |
98 |
(dialog addTextLabel:'Name:') layout:#left. |
|
99 |
dialog addInputFieldOn:(BufferedValueHolder |
|
100 |
subject:firstName |
|
101 |
triggerChannel:trigger). |
|
102 |
dialog addVerticalSpace. |
|
103 |
(dialog addTextLabel:'Address:') layout:#left. |
|
104 |
dialog addInputFieldOn:(BufferedValueHolder |
|
105 |
subject:lastName |
|
106 |
triggerChannel:trigger). |
|
71 | 107 |
|
231 | 108 |
dialog addAbortButton; |
109 |
addButton:(Button new |
|
110 |
label:'undo'; |
|
111 |
action:[trigger value:false]); |
|
112 |
addOkButton. |
|
71 | 113 |
|
231 | 114 |
dialog open. |
115 |
dialog accepted ifTrue:[ |
|
116 |
trigger value:true |
|
117 |
]. |
|
71 | 118 |
|
268 | 119 |
Transcript show:firstName value; show:' '; showCR:lastName value |
231 | 120 |
[exEnd] |
71 | 121 |
" |
122 |
! ! |
|
123 |
||
124 |
!BufferedValueHolder class methodsFor:'initialization'! |
|
125 |
||
126 |
intialize |
|
127 |
NotYetAssigned := Object new |
|
128 |
! ! |
|
129 |
||
130 |
!BufferedValueHolder class methodsFor:'instance creation'! |
|
131 |
||
132 |
subject:someModel triggerChannel:aTrigger |
|
133 |
"return a new BufferedValueHolder offering a buffered copy of someModels |
|
134 |
value - only updating this value, when aTrigger changes to true." |
|
135 |
||
136 |
^ self new subject:someModel; triggerChannel:aTrigger |
|
137 |
! ! |
|
138 |
||
125 | 139 |
!BufferedValueHolder methodsFor:'accessing'! |
140 |
||
141 |
setValue:anObject |
|
142 |
"set my value without notification." |
|
143 |
||
144 |
bufferedValue := anObject. |
|
145 |
! |
|
146 |
||
147 |
subject:someModel |
|
148 |
subject notNil ifTrue:[ |
|
149 |
subject removeDependent:self |
|
150 |
]. |
|
151 |
subject := someModel. |
|
152 |
subject notNil ifTrue:[ |
|
153 |
subject addDependent:self |
|
154 |
] |
|
155 |
! |
|
71 | 156 |
|
4028 | 157 |
value |
158 |
"return my value" |
|
159 |
||
160 |
bufferedValue == NotYetAssigned ifTrue:[ |
|
161 |
bufferedValue := subject value |
|
162 |
]. |
|
163 |
^ bufferedValue |
|
164 |
! ! |
|
165 |
||
166 |
!BufferedValueHolder methodsFor:'accessing-channels'! |
|
167 |
||
125 | 168 |
triggerChannel:aTrigger |
169 |
triggerChannel notNil ifTrue:[ |
|
170 |
triggerChannel removeDependent:self |
|
171 |
]. |
|
172 |
triggerChannel := aTrigger. |
|
173 |
triggerChannel notNil ifTrue:[ |
|
174 |
triggerChannel addDependent:self |
|
175 |
] |
|
71 | 176 |
! ! |
125 | 177 |
|
71 | 178 |
!BufferedValueHolder methodsFor:'change & update'! |
179 |
||
180 |
update:something with:aParameter from:changedObject |
|
1009 | 181 |
|triggerVal| |
182 |
||
71 | 183 |
changedObject == triggerChannel ifTrue:[ |
1009 | 184 |
triggerVal := triggerChannel value. |
185 |
||
186 |
triggerVal == true ifTrue:[ |
|
731 | 187 |
" |
188 |
now, store the buffered value into the subject |
|
189 |
" |
|
190 |
subject value:bufferedValue. |
|
191 |
^ self |
|
192 |
]. |
|
1009 | 193 |
triggerVal == false ifTrue:[ |
731 | 194 |
" |
195 |
cancel: flush my buffered value |
|
196 |
" |
|
197 |
bufferedValue := NotYetAssigned. |
|
1009 | 198 |
self changed:#value. |
731 | 199 |
]. |
1009 | 200 |
"/ self changed:#value. |
731 | 201 |
^ self |
71 | 202 |
]. |
203 |
changedObject == subject ifTrue:[ |
|
731 | 204 |
bufferedValue := NotYetAssigned. |
205 |
self changed:#value. |
|
206 |
^ self |
|
71 | 207 |
]. |
731 | 208 |
|
1009 | 209 |
"Modified: / 28.7.1998 / 11:54:39 / cg" |
71 | 210 |
! ! |
211 |
||
125 | 212 |
!BufferedValueHolder methodsFor:'initialization'! |
71 | 213 |
|
125 | 214 |
initialize |
215 |
super initialize. |
|
216 |
bufferedValue := NotYetAssigned |
|
217 |
! ! |
|
71 | 218 |
|
773
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
219 |
!BufferedValueHolder methodsFor:'queries'! |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
220 |
|
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
221 |
isBuffering |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
222 |
"return true, if the receiver is currently buffering something |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
223 |
(i.e. its value has been assigned)" |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
224 |
|
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
225 |
^ bufferedValue ~~ NotYetAssigned |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
226 |
|
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
227 |
"Modified: / 27.1.1998 / 12:09:46 / cg" |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
228 |
! ! |
b6337f784d05
added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents:
731
diff
changeset
|
229 |
|
129 | 230 |
!BufferedValueHolder class methodsFor:'documentation'! |
231 |
||
232 |
version |
|
4028 | 233 |
^ '$Header$' |
129 | 234 |
! ! |
4028 | 235 |