author | Claus Gittinger <cg@exept.de> |
Tue, 19 Apr 2016 15:27:44 +0200 | |
changeset 3654 | ef4d3adadd1e |
parent 3015 | 9fb23acffeb9 |
child 3706 | 957d8c1bbd16 |
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 |
|
125 | 14 |
ValueModel subclass:#ValueHolder |
223 | 15 |
instanceVariableNames:'value' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Support-Models' |
|
62 | 19 |
! |
20 |
||
68 | 21 |
!ValueHolder class methodsFor:'documentation'! |
22 |
||
69 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
71 | 26 |
All Rights Reserved |
69 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
68 | 37 |
documentation |
38 |
" |
|
69 | 39 |
a valueHolder can be used as a model for editFields, buttons etc. |
68 | 40 |
It stores some value internally, and sends update messages to its |
41 |
dependents when changed. |
|
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 |
|
50 |
[author:] |
|
51 |
Claus Gittinger |
|
68 | 52 |
" |
71 | 53 |
! |
54 |
||
55 |
examples |
|
56 |
" |
|
231 | 57 |
See many examples in DialogBox & EditField |
71 | 58 |
|
231 | 59 |
edit strings: |
60 |
[exBegin] |
|
61 |
|firstName lastName dialog| |
|
71 | 62 |
|
231 | 63 |
firstName := ValueHolder newString. |
64 |
lastName := ValueHolder newString. |
|
71 | 65 |
|
231 | 66 |
dialog := Dialog new. |
67 |
(dialog addTextLabel:'Name:') adjust:#left. |
|
68 |
dialog addInputFieldOn:firstName. |
|
69 |
dialog addVerticalSpace. |
|
70 |
(dialog addTextLabel:'Address:') adjust:#left. |
|
71 |
dialog addInputFieldOn:lastName. |
|
71 | 72 |
|
231 | 73 |
dialog addAbortButton; addOkButton. |
71 | 74 |
|
231 | 75 |
dialog open. |
76 |
dialog accepted ifTrue:[ |
|
268 | 77 |
Transcript show:firstName value; show:' '; showCR:lastName value |
231 | 78 |
] |
79 |
[exEnd] |
|
71 | 80 |
" |
68 | 81 |
! ! |
82 |
||
62 | 83 |
!ValueHolder class methodsFor:'instance creation'! |
84 |
||
125 | 85 |
newBoolean |
86 |
"return a new ValueHolder holding false as initial value" |
|
87 |
||
88 |
^ self with:false |
|
89 |
! |
|
68 | 90 |
|
125 | 91 |
newFraction |
92 |
"return a new ValueHolder holding 0.0 as initial value. |
|
93 |
The name is somewhat missleading - actually it should be called newFloat." |
|
94 |
||
95 |
^ self with:0.0 |
|
96 |
! |
|
97 |
||
98 |
newNumber |
|
99 |
"return a new ValueHolder holding 0 as initial value" |
|
100 |
||
101 |
^ self with:0 |
|
62 | 102 |
! |
103 |
||
104 |
newString |
|
68 | 105 |
"return a new ValueHolder holding an empty string as initial value" |
106 |
||
62 | 107 |
^ self with:'' |
108 |
! |
|
109 |
||
125 | 110 |
with:anObject |
111 |
"return a new ValueHolder holding anObject as initial value" |
|
68 | 112 |
|
125 | 113 |
^ (super new) setValue:anObject |
62 | 114 |
! ! |
115 |
||
116 |
!ValueHolder methodsFor:'accessing'! |
|
117 |
||
69 | 118 |
setValue:anObject |
119 |
"set my value without notification." |
|
62 | 120 |
|
121 |
value := anObject. |
|
122 |
! |
|
123 |
||
124 |
value |
|
68 | 125 |
"return my value" |
126 |
||
62 | 127 |
^ value |
128 |
! ! |
|
125 | 129 |
|
156 | 130 |
!ValueHolder methodsFor:'printing & storing'! |
131 |
||
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
132 |
displayOn:aGCOrStream |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
133 |
"Compatibility |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
134 |
append a printed desription on some stream (Dolphin, Squeak) |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
135 |
OR: |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
(although the fallBack is to display its printString ...)" |
700 | 139 |
|
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
140 |
"/ 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
|
141 |
"/ 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
|
142 |
aGCOrStream isStream ifFalse:[ |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
143 |
^ super displayOn:aGCOrStream. |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
144 |
]. |
700 | 145 |
|
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
146 |
aGCOrStream |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
147 |
nextPutAll:self class name; |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
148 |
nextPut:$(. |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
149 |
value displayOn:aGCOrStream. |
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
150 |
aGCOrStream nextPut:$) |
2770 | 151 |
! |
152 |
||
153 |
printOn:aStream |
|
154 |
"return a string for display in inspectors etc." |
|
155 |
||
156 |
self class name printOn:aStream. |
|
157 |
aStream nextPutAll:'('. |
|
158 |
value printOn:aStream. |
|
159 |
aStream nextPutAll:')' |
|
156 | 160 |
! ! |
161 |
||
129 | 162 |
!ValueHolder class methodsFor:'documentation'! |
163 |
||
164 |
version |
|
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
165 |
^ '$Header: /cvs/stx/stx/libview2/ValueHolder.st,v 1.20 2012-08-03 15:53:12 stefan Exp $' |
2770 | 166 |
! |
167 |
||
168 |
version_CVS |
|
3015
9fb23acffeb9
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2770
diff
changeset
|
169 |
^ '$Header: /cvs/stx/stx/libview2/ValueHolder.st,v 1.20 2012-08-03 15:53:12 stefan Exp $' |
129 | 170 |
! ! |