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