818
|
1 |
Object subclass:#Insets
|
|
2 |
instanceVariableNames:'left right top bottom'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Graphics-Geometry'
|
|
6 |
!
|
|
7 |
|
|
8 |
!Insets class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
documentation
|
|
11 |
|
|
12 |
"
|
|
13 |
The Insets class was added as an all purpose class holding the insets of a geometric
|
|
14 |
element like a view. A inset object just contains four dimensions specifying the top, left
|
|
15 |
right and bottom distance between the object and an outer border. Beside the simple methods
|
|
16 |
for setting and querying the instance variables, there also exists the methods for encoding
|
|
17 |
and decoding the inset as a literal array.
|
|
18 |
The insets class is used i.e. by the GridBagConstraints class.
|
|
19 |
|
|
20 |
[see also:]
|
|
21 |
GridBagConstraints GridBagLayout
|
|
22 |
|
|
23 |
[author:]
|
|
24 |
Andreas Vogel
|
|
25 |
|
|
26 |
"
|
|
27 |
!
|
|
28 |
|
|
29 |
examples
|
|
30 |
"
|
|
31 |
|
|
32 |
"
|
|
33 |
!
|
|
34 |
|
|
35 |
history
|
|
36 |
"Created: / 20.1.1998 / 18:34:00 / av"
|
|
37 |
! !
|
|
38 |
|
|
39 |
!Insets class methodsFor:'instance creation'!
|
|
40 |
|
|
41 |
new
|
|
42 |
" create a new instance of my class and do an explicit initialization call"
|
|
43 |
|
|
44 |
^ super new initialize
|
|
45 |
|
|
46 |
"Created: / 20.1.1998 / 18:34:36 / av"
|
|
47 |
"Modified: / 1.2.1998 / 12:39:24 / av"
|
|
48 |
! !
|
|
49 |
|
|
50 |
!Insets methodsFor:'accessing'!
|
|
51 |
|
|
52 |
bottom
|
|
53 |
"return the value of the instance variable 'bottom'"
|
|
54 |
|
|
55 |
^ bottom
|
|
56 |
|
|
57 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
58 |
"Modified: / 1.2.1998 / 12:39:50 / av"
|
|
59 |
!
|
|
60 |
|
|
61 |
bottom:something
|
|
62 |
"set the value of the instance variable 'bottom'"
|
|
63 |
|
|
64 |
bottom := something.
|
|
65 |
|
|
66 |
"Created: / 20.1.1998 / 18:33:51 / av"
|
|
67 |
"Modified: / 1.2.1998 / 12:39:56 / av"
|
|
68 |
!
|
|
69 |
|
|
70 |
left
|
|
71 |
"return the value of the instance variable 'left'"
|
|
72 |
|
|
73 |
^ left
|
|
74 |
|
|
75 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
76 |
"Modified: / 1.2.1998 / 12:40:01 / av"
|
|
77 |
!
|
|
78 |
|
|
79 |
left:something
|
|
80 |
"set the value of the instance variable 'left'"
|
|
81 |
|
|
82 |
left := something.
|
|
83 |
|
|
84 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
85 |
"Modified: / 1.2.1998 / 12:40:06 / av"
|
|
86 |
!
|
|
87 |
|
|
88 |
right
|
|
89 |
"return the value of the instance variable 'right'"
|
|
90 |
|
|
91 |
^ right
|
|
92 |
|
|
93 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
94 |
"Modified: / 1.2.1998 / 12:40:11 / av"
|
|
95 |
!
|
|
96 |
|
|
97 |
right:something
|
|
98 |
"set the value of the instance variable 'right'"
|
|
99 |
|
|
100 |
right := something.
|
|
101 |
|
|
102 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
103 |
"Modified: / 1.2.1998 / 12:40:16 / av"
|
|
104 |
!
|
|
105 |
|
|
106 |
top
|
|
107 |
"return the value of the instance variable 'top'"
|
|
108 |
|
|
109 |
^ top
|
|
110 |
|
|
111 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
112 |
"Modified: / 1.2.1998 / 12:40:26 / av"
|
|
113 |
!
|
|
114 |
|
|
115 |
top:something
|
|
116 |
"set the value of the instance variable 'top'"
|
|
117 |
|
|
118 |
top := something.
|
|
119 |
|
|
120 |
"Created: / 20.1.1998 / 18:33:50 / av"
|
|
121 |
"Modified: / 1.2.1998 / 12:40:31 / av"
|
|
122 |
! !
|
|
123 |
|
|
124 |
!Insets methodsFor:'converting'!
|
|
125 |
|
|
126 |
fromLiteralArrayEncoding:encoding
|
|
127 |
"Read my values from an encoding. The encoding is supposed to be of the form:
|
|
128 |
(Insets left right top bottom)
|
|
129 |
This is the reverse to literalArrayEncoding."
|
|
130 |
|
|
131 |
left := (encoding at:2).
|
|
132 |
right := (encoding at:3).
|
|
133 |
top := (encoding at:4).
|
|
134 |
bottom := (encoding at:5).
|
|
135 |
|
|
136 |
"
|
|
137 |
Insets new fromLiteralArrayEncoding:#(#Insets 96 97 98 99)
|
|
138 |
#(#Insets 96 97 98 99) decodeAsLiteralArray
|
|
139 |
"
|
|
140 |
|
|
141 |
"Created: / 21.1.1998 / 13:57:55 / av"
|
|
142 |
"Modified: / 1.2.1998 / 12:41:27 / av"
|
|
143 |
!
|
|
144 |
|
|
145 |
fromLiteralArrayEncodingAlt:encoding
|
|
146 |
"Read my values from an literal encoding. The encoding is supposed to be of the form:
|
|
147 |
(Insets #left: left #right: right #top: top #bottom: bottom)
|
|
148 |
In difference to fromLiteralArrayEncoding the instance variables aren't initialized with
|
|
149 |
fix positioned values. You have to name each field explicitly.
|
|
150 |
This is the reverse to literalArrayEncoding."
|
|
151 |
|
|
152 |
| stop sel |
|
|
153 |
|
|
154 |
stop := encoding size.
|
|
155 |
|
|
156 |
2 to:stop by:2 do:[ :i |
|
|
157 |
sel := encoding at:i.
|
|
158 |
(self respondsTo:sel) ifTrue:[
|
|
159 |
self perform:sel with:(encoding at:i+1)
|
|
160 |
]
|
|
161 |
].
|
|
162 |
|
|
163 |
"
|
|
164 |
Insets new fromLiteralArrayEncodingAlt:#(#Insets #'left:' 96 #'right:' 97 #'top:' 98 #'bottom:' 99)
|
|
165 |
#(#Insets #'left:' 96 #'right:' 97 #'top:' 98 #'bottom:' 99) decodeAsLiteralArray
|
|
166 |
"
|
|
167 |
|
|
168 |
"Created: / 21.1.1998 / 13:57:55 / av"
|
|
169 |
"Modified: / 1.2.1998 / 12:44:40 / av"
|
|
170 |
!
|
|
171 |
|
|
172 |
literalArrayEncoding
|
|
173 |
"Encode myself as a literal array, from which a copy of the receiver
|
|
174 |
can be reconstructed with #decodeAsLiteralArray. The encoding is:
|
|
175 |
#(#Insets left right top bottom)
|
|
176 |
"
|
|
177 |
|
|
178 |
^ (Array with:#Insets with:left with:right with:top with:bottom)
|
|
179 |
|
|
180 |
"
|
|
181 |
Insets new literalArrayEncoding
|
|
182 |
"
|
|
183 |
|
|
184 |
"Created: / 21.1.1998 / 19:28:17 / av"
|
|
185 |
"Modified: / 1.2.1998 / 12:45:26 / av"
|
|
186 |
!
|
|
187 |
|
|
188 |
literalArrayEncodingAlt
|
|
189 |
"Encode myself as a literal array, from which a copy of the receiver
|
|
190 |
can be reconstructed with #decodeAsLiteralArrayAlt. The encoding is:
|
|
191 |
#(#Insets #left: left #right: right #top: top #bottom: bottom)
|
|
192 |
"
|
|
193 |
|
|
194 |
| coll |
|
|
195 |
|
|
196 |
coll := OrderedCollection new.
|
|
197 |
|
|
198 |
coll add:#Insets.
|
|
199 |
coll add:#'left:' ; add:left.
|
|
200 |
coll add:#'right:' ; add:right.
|
|
201 |
coll add:#'top:' ; add:top.
|
|
202 |
coll add:#'bottom:' ; add:bottom.
|
|
203 |
|
|
204 |
^ coll asArray.
|
|
205 |
|
|
206 |
"
|
|
207 |
Insets new literalArrayEncodingAlt
|
|
208 |
"
|
|
209 |
|
|
210 |
"Created: / 21.1.1998 / 19:31:25 / av"
|
|
211 |
"Modified: / 1.2.1998 / 12:50:11 / av"
|
|
212 |
! !
|
|
213 |
|
|
214 |
!Insets methodsFor:'initialization'!
|
|
215 |
|
|
216 |
initialize
|
|
217 |
"Initialize a insets instance."
|
|
218 |
|
|
219 |
left := right := top := bottom := 0.
|
|
220 |
|
|
221 |
"Created: / 20.1.1998 / 18:35:07 / av"
|
|
222 |
"Modified: / 1.2.1998 / 12:50:47 / av"
|
|
223 |
! !
|
|
224 |
|
|
225 |
!Insets class methodsFor:'documentation'!
|
|
226 |
|
|
227 |
version
|
|
228 |
^ '$Header: /cvs/stx/stx/libview2/Insets.st,v 1.1 1998-02-03 18:11:10 cg Exp $'
|
|
229 |
! !
|