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