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