author | Claus Gittinger <cg@exept.de> |
Fri, 28 Mar 1997 15:22:14 +0100 | |
changeset 329 | 098318898b01 |
parent 211 | f6e9378de69f |
child 357 | 658764fa1f0f |
permissions | -rw-r--r-- |
36 | 1 |
" |
2 |
COPYRIGHT (c) 1994 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 |
" |
|
19 | 12 |
|
58 | 13 |
ListEntry subclass:#MultiColListEntry |
158 | 14 |
instanceVariableNames:'strings tabSpec' |
15 |
classVariableNames:'DefaultTabSpec' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Support' |
|
19 | 18 |
! |
19 |
||
329 | 20 |
!MultiColListEntry class methodsFor:'documentation'! |
25 | 21 |
|
36 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1994 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 |
||
25 | 36 |
documentation |
37 |
" |
|
38 |
Instances of MultiColListEntry can be used in place of strings |
|
36 | 39 |
as entries of the list in a ListView or SelectionInListView. |
34 | 40 |
They allow data to be presented in table (or any other) form. |
36 | 41 |
See example here and in TabulatorSpecs documentation. |
42 |
Notice, that each entry can have its own tabulator specification; |
|
43 |
although, usually all share a single spec. |
|
44 |
Also, notice that each column may align different; making these |
|
45 |
perfect elements to present table data. |
|
25 | 46 |
|
36 | 47 |
MultiColListEntry and TabulatorSpec were originally created to |
329 | 48 |
support nice tabular display of file-lists in the FileBrowser |
49 |
(see its long list); you may find many other uses ... |
|
158 | 50 |
|
51 |
[author:] |
|
52 |
Claus Gittinger |
|
36 | 53 |
" |
19 | 54 |
! |
55 |
||
36 | 56 |
examples |
57 |
" |
|
58 | 58 |
putting multiColListEntries into a ListView |
59 |
(instead of strings)' |
|
161 | 60 |
[exBegin] |
61 |
|v e myList tabs| |
|
19 | 62 |
|
161 | 63 |
myList := OrderedCollection new. |
19 | 64 |
|
161 | 65 |
tabs := TabulatorSpecification new. |
66 |
tabs unit:#inch. |
|
67 |
tabs positions:#(0 3 4). |
|
68 |
tabs align:#(left #center #left). |
|
19 | 69 |
|
161 | 70 |
e := MultiColListEntry |
71 |
fromString:'left centered left'. |
|
72 |
e tabulatorSpecification:tabs. |
|
73 |
myList add:e. |
|
58 | 74 |
|
161 | 75 |
e := MultiColListEntry |
76 |
fromString:'| | |'. |
|
77 |
e tabulatorSpecification:tabs. |
|
78 |
myList add:e. |
|
79 |
myList add:''. |
|
19 | 80 |
|
161 | 81 |
e := MultiColListEntry |
82 |
fromString:'hello hallo salut'. |
|
83 |
e tabulatorSpecification:tabs. |
|
84 |
myList add:e. |
|
58 | 85 |
|
161 | 86 |
e := MultiColListEntry |
87 |
fromString:'good morning,guten Morgen,bon jour' |
|
88 |
separatedBy:$,. |
|
89 |
e tabulatorSpecification:tabs. |
|
90 |
myList add:e. |
|
19 | 91 |
|
161 | 92 |
e := MultiColListEntry new. |
93 |
e colAt:1 put:'good bye'. |
|
94 |
e colAt:2 put:'auf Wiedersehen'. |
|
95 |
e colAt:3 put:'au revoir '. |
|
96 |
e tabulatorSpecification:tabs. |
|
97 |
myList add:e. |
|
19 | 98 |
|
161 | 99 |
v := ListView new. |
100 |
v setList:myList expandTabs:false. |
|
101 |
v extent:500@100. |
|
102 |
v open |
|
103 |
[exEnd] |
|
36 | 104 |
|
105 |
||
106 |
||
58 | 107 |
many multiColListEntries in a scrollable ListView |
161 | 108 |
[exBegin] |
109 |
|v l e myList tabs| |
|
36 | 110 |
|
161 | 111 |
myList := OrderedCollection new. |
19 | 112 |
|
161 | 113 |
tabs := TabulatorSpecification new. |
114 |
tabs unit:#cm. |
|
115 |
tabs positions:#(1 3 5). |
|
116 |
tabs align:#(#right #center #left). |
|
19 | 117 |
|
161 | 118 |
1 to:100 do:[:i| |
119 |
e := MultiColListEntry new. |
|
120 |
e colAt:1 put:i printString. |
|
121 |
e colAt:2 put:i squared printString. |
|
122 |
e colAt:3 put:i sqrt printString. |
|
123 |
e tabulatorSpecification:tabs. |
|
124 |
myList add:e. |
|
125 |
]. |
|
126 |
l := ListView new. |
|
127 |
l setList:myList expandTabs:false. |
|
128 |
v := ScrollableView forView:l. |
|
129 |
v extent:300@200. |
|
130 |
v open |
|
131 |
[exEnd] |
|
36 | 132 |
|
133 |
||
134 |
||
58 | 135 |
like above, but uses nicer decimal alignments |
161 | 136 |
[exBegin] |
137 |
|v l e myList tabs| |
|
36 | 138 |
|
161 | 139 |
myList := OrderedCollection new. |
58 | 140 |
|
161 | 141 |
tabs := TabulatorSpecification new. |
142 |
tabs unit:#cm. |
|
143 |
tabs positions:#(1 3 6 9 12). |
|
144 |
tabs align:#(#right #decimal #decimal #decimal #decimal). |
|
19 | 145 |
|
161 | 146 |
1 to:100 do:[:i| |
147 |
e := MultiColListEntry new. |
|
148 |
e colAt:1 put:i printString. |
|
149 |
e colAt:2 put:i log printString. |
|
150 |
e colAt:3 put:i sqrt printString. |
|
151 |
e colAt:4 put:i sin printString. |
|
152 |
e colAt:5 put:i cos printString. |
|
153 |
e tabulatorSpecification:tabs. |
|
154 |
myList add:e. |
|
155 |
]. |
|
156 |
l := ListView new. |
|
157 |
l setList:myList expandTabs:false. |
|
158 |
v := ScrollableView forView:l. |
|
159 |
v extent:600@200. |
|
160 |
v open |
|
161 |
[exEnd] |
|
36 | 162 |
|
163 |
||
164 |
||
58 | 165 |
specifying tabs in inches |
161 | 166 |
[exBegin] |
167 |
|v l e myList tabs| |
|
19 | 168 |
|
161 | 169 |
myList := OrderedCollection new. |
19 | 170 |
|
161 | 171 |
tabs := TabulatorSpecification new. |
172 |
tabs unit:#inch. |
|
173 |
tabs positions:#(0 2 3.5 4 6 8 10 12). |
|
36 | 174 |
|
161 | 175 |
e := MultiColListEntry new. |
176 |
e colAt:1 put:'2'. |
|
177 |
e colAt:2 put:'3.5'. |
|
178 |
e colAt:3 put:'4'. |
|
179 |
e colAt:4 put:'6'. |
|
180 |
e colAt:5 put:'8'. |
|
181 |
e colAt:6 put:'10'. |
|
182 |
e colAt:7 put:'12'. |
|
183 |
e tabulatorSpecification:tabs. |
|
184 |
myList add:e. |
|
36 | 185 |
|
161 | 186 |
myList add:((MultiColListEntry fromString:'| | | | | | |') |
187 |
tabulatorSpecification:tabs). |
|
188 |
myList add:((MultiColListEntry fromString:'xxx xxx xxx xxx xxx xxx xxx') |
|
189 |
tabulatorSpecification:tabs). |
|
58 | 190 |
|
161 | 191 |
l := ListView new. |
192 |
l setList:myList expandTabs:false. |
|
193 |
v := HVScrollableView forView:l. |
|
194 |
v extent:600@200. |
|
195 |
v open |
|
196 |
[exEnd] |
|
36 | 197 |
|
198 |
||
58 | 199 |
if you have the columns available as a collection, |
200 |
setup can be done easier |
|
161 | 201 |
[exBegin] |
202 |
|v l e myList tabs| |
|
58 | 203 |
|
161 | 204 |
myList := OrderedCollection new. |
58 | 205 |
|
161 | 206 |
tabs := TabulatorSpecification new. |
207 |
tabs unit:#inch. |
|
208 |
tabs positions:#(0 2 3.5 4 6 8 10 12). |
|
58 | 209 |
|
161 | 210 |
e := MultiColListEntry new. |
211 |
e strings:#('2' '3.5' '4' '6' '8' '10' '12'). |
|
212 |
e tabulatorSpecification:tabs. |
|
213 |
myList add:e. |
|
36 | 214 |
|
161 | 215 |
l := ListView new. |
216 |
l setList:myList expandTabs:false. |
|
217 |
v := HVScrollableView forView:l. |
|
218 |
v extent:600@200. |
|
219 |
v open |
|
220 |
[exEnd] |
|
58 | 221 |
|
36 | 222 |
|
58 | 223 |
concrete example, show /etc/passwd in a table: |
161 | 224 |
[exBegin] |
225 |
||
226 |
|v l s myList line e htabs tabs fingerEntry| |
|
58 | 227 |
|
161 | 228 |
tabs := TabulatorSpecification new. |
229 |
tabs unit:#inch. |
|
230 |
tabs positions:#(0 2 3.5 4.5 5 8 11). |
|
231 |
tabs align: #(left left right right left left left). |
|
36 | 232 |
|
161 | 233 |
htabs := TabulatorSpecification new. |
234 |
htabs unit:#inch. |
|
235 |
htabs positions:#(0 2 3.5 4.5 5 8 11). |
|
236 |
htabs align: #(left center center center left left left). |
|
58 | 237 |
|
161 | 238 |
myList := OrderedCollection new. |
58 | 239 |
|
161 | 240 |
e := MultiColListEntry |
241 |
fromString:'login-name:password:uid:gid:finger-entry:home-dir:shell' |
|
242 |
separatedBy:$:. |
|
243 |
e tabulatorSpecification:htabs. |
|
244 |
myList add:e. |
|
245 |
myList add:''. |
|
36 | 246 |
|
161 | 247 |
s := '/etc/passwd' asFilename readStream. |
248 |
[s atEnd] whileFalse:[ |
|
249 |
line := s nextLine. |
|
250 |
e := MultiColListEntry |
|
251 |
fromString:line |
|
252 |
separatedBy:$:. |
|
253 |
fingerEntry := e colAt:5. |
|
254 |
e colAt:5 put:(fingerEntry asCollectionOfSubstringsSeparatedBy:$,) first. |
|
255 |
e tabulatorSpecification:tabs. |
|
256 |
myList add:e. |
|
257 |
]. |
|
258 |
s close. |
|
58 | 259 |
|
161 | 260 |
l := ListView new. |
261 |
l setList:myList expandTabs:false. |
|
262 |
v := HVScrollableView forView:l. |
|
263 |
v extent:600@200. |
|
264 |
v open |
|
265 |
[exEnd] |
|
36 | 266 |
" |
267 |
! ! |
|
268 |
||
329 | 269 |
!MultiColListEntry class methodsFor:'instance creation'! |
36 | 270 |
|
97 | 271 |
fromString:aString |
272 |
^ self fromString:aString separatedBy:Character space |
|
273 |
! |
|
274 |
||
275 |
fromString:aString separatedBy:separatorCharacter |
|
276 |
|subStrings e| |
|
277 |
||
278 |
e := self new. |
|
279 |
subStrings := aString asCollectionOfSubstringsSeparatedBy:separatorCharacter. |
|
280 |
subStrings keysAndValuesDo:[:i :sub | |
|
281 |
e colAt:i put:sub. |
|
282 |
]. |
|
283 |
^ e |
|
284 |
! |
|
285 |
||
70 | 286 |
new:numberOfColumns |
287 |
|e| |
|
288 |
||
289 |
e := self new. |
|
290 |
1 to:numberOfColumns do:[:i | |
|
291 |
e colAt:i put:''. |
|
292 |
]. |
|
293 |
^ e |
|
294 |
||
295 |
"Modified: 30.8.1995 / 16:33:53 / claus" |
|
296 |
! |
|
297 |
||
298 |
new:numberOfColumns tabulatorSpecification:aTabSpec |
|
299 |
^ (self new:numberOfColumns) tabulatorSpecification:aTabSpec |
|
300 |
||
301 |
"Modified: 30.8.1995 / 16:34:23 / claus" |
|
97 | 302 |
! ! |
303 |
||
304 |
!MultiColListEntry methodsFor:'accessing'! |
|
305 |
||
306 |
colAt:index |
|
307 |
"return the substring at column index" |
|
308 |
||
309 |
index > strings size ifTrue:[^ nil]. |
|
310 |
^ strings at:index |
|
70 | 311 |
! |
312 |
||
97 | 313 |
colAt:index put:aString |
314 |
"replace the substring at column index" |
|
315 |
||
316 |
strings isNil ifTrue:[ |
|
317 |
strings := OrderedCollection new:index |
|
318 |
]. |
|
319 |
index > strings size ifTrue:[strings grow:index]. |
|
320 |
strings at:index put:aString |
|
321 |
! |
|
322 |
||
323 |
strings:aCollectionOfStrings |
|
324 |
"replace all substrings" |
|
325 |
||
326 |
strings := OrderedCollection withAll:aCollectionOfStrings. |
|
36 | 327 |
! |
328 |
||
97 | 329 |
tabulatorSpecification:aTabSpec |
330 |
"set the tabulator spec" |
|
331 |
||
332 |
tabSpec := aTabSpec |
|
333 |
! ! |
|
334 |
||
335 |
!MultiColListEntry methodsFor:'converting'! |
|
336 |
||
337 |
asString |
|
338 |
"return the receiver as a string with embedded tabs" |
|
339 |
||
340 |
|s sub tab |
|
341 |
nSub "{ Class: SmallInteger }"| |
|
36 | 342 |
|
97 | 343 |
s := ''. |
344 |
tab := Character tab asString. |
|
345 |
nSub := strings size. |
|
346 |
1 to:nSub do:[:subStringIndex | |
|
347 |
sub := strings at:subStringIndex. |
|
348 |
sub notNil ifTrue:[ |
|
349 |
s := s , sub. |
|
350 |
]. |
|
103 | 351 |
subStringIndex == nSub ifFalse:[ |
97 | 352 |
s := s , tab |
353 |
] |
|
36 | 354 |
]. |
97 | 355 |
|
356 |
^ s |
|
103 | 357 |
|
358 |
"Created: 24.11.1995 / 18:54:27 / cg" |
|
36 | 359 |
! ! |
360 |
||
89 | 361 |
!MultiColListEntry methodsFor:'defaults'! |
362 |
||
363 |
defaultTabSpec |
|
364 |
"the default tabulators are 1 inch apart" |
|
365 |
||
366 |
|spec| |
|
367 |
||
368 |
spec := DefaultTabSpec. |
|
369 |
spec isNil ifTrue:[ |
|
370 |
spec := TabulatorSpecification new. |
|
371 |
spec unit:#inch. |
|
372 |
spec positions:(0 to:20). |
|
373 |
spec align: #left. |
|
374 |
DefaultTabSpec := spec. |
|
375 |
]. |
|
376 |
^ spec. |
|
377 |
||
378 |
"Created: 17.11.1995 / 12:23:29 / cg" |
|
379 |
"Modified: 17.11.1995 / 12:24:20 / cg" |
|
380 |
! ! |
|
381 |
||
36 | 382 |
!MultiColListEntry methodsFor:'drawing'! |
383 |
||
108 | 384 |
displayOn:aGC x:x y:y opaque:opaque |
36 | 385 |
"display the receiver on a GC" |
386 |
||
89 | 387 |
|xPos spec tabPos prevString| |
36 | 388 |
|
89 | 389 |
spec := tabSpec. |
390 |
spec isNil ifTrue:[ |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
391 |
spec := self defaultTabSpec |
89 | 392 |
]. |
36 | 393 |
xPos := x. |
394 |
prevString := ''. |
|
395 |
strings keysAndValuesDo:[:index :subString | |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
396 |
subString notNil ifTrue:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
397 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
398 |
find next tab |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
399 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
400 |
tabPos := spec positionOfTab:index forString:subString on:aGC. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
401 |
tabPos isNil ifTrue:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
402 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
403 |
no tab - just continue where we are ... |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
404 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
405 |
xPos := xPos + (prevString widthOn:aGC). "/ (aGC font widthOf:prevString). |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
406 |
] ifFalse:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
407 |
xPos := tabPos + x. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
408 |
]. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
409 |
opaque ifTrue:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
410 |
aGC displayOpaqueString:subString x:xPos y:y. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
411 |
] ifFalse:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
412 |
aGC displayString:subString x:xPos y:y. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
413 |
]. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
414 |
prevString := subString. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
415 |
] |
36 | 416 |
]. |
89 | 417 |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
418 |
"Modified: 12.7.1996 / 23:03:19 / cg" |
58 | 419 |
! ! |
36 | 420 |
|
58 | 421 |
!MultiColListEntry methodsFor:'queries'! |
422 |
||
173 | 423 |
widthOn:aGC |
58 | 424 |
"return the width of the receiver when displayed in aGC" |
425 |
||
62 | 426 |
|xPos xMax tabPos prevLen| |
58 | 427 |
|
428 |
"just to make certain: |
|
429 |
do not assume, that the last col is the rightmost one ... |
|
430 |
" |
|
431 |
xPos := 0. |
|
432 |
xMax := 0. |
|
433 |
prevLen := 0. |
|
434 |
strings keysAndValuesDo:[:index :subString | |
|
173 | 435 |
|w| |
62 | 436 |
|
173 | 437 |
subString notNil ifTrue:[ |
438 |
" |
|
439 |
find next tab |
|
440 |
" |
|
441 |
tabPos := tabSpec positionOfTab:index forString:subString on:aGC. |
|
442 |
tabPos isNil ifTrue:[ |
|
443 |
" |
|
444 |
no tab - just continue where we are ... |
|
445 |
" |
|
446 |
xPos := xPos + prevLen. |
|
447 |
] ifFalse:[ |
|
448 |
xPos := tabPos. |
|
449 |
]. |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
450 |
w := prevLen := subString widthOn:aGC. "/ aGC font widthOf:subString. |
173 | 451 |
xMax := xMax max:(xPos + w). |
452 |
] |
|
58 | 453 |
]. |
454 |
^ xMax |
|
173 | 455 |
|
456 |
"Created: 12.5.1996 / 20:38:38 / cg" |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
457 |
"Modified: 12.7.1996 / 23:01:51 / cg" |
58 | 458 |
! ! |
459 |
||
329 | 460 |
!MultiColListEntry class methodsFor:'documentation'! |
98 | 461 |
|
462 |
version |
|
329 | 463 |
^ '$Header: /cvs/stx/stx/libwidg2/MultiColListEntry.st,v 1.19 1997-03-28 14:22:14 cg Exp $' |
98 | 464 |
! ! |