author | Claus Gittinger <cg@exept.de> |
Mon, 06 May 2002 08:06:12 +0200 | |
changeset 2098 | d59707230877 |
parent 1969 | e325d38ce469 |
child 2925 | 359505806538 |
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 |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
13 |
"{ Package: 'stx:libwidg2' }" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
14 |
|
58 | 15 |
ListEntry subclass:#MultiColListEntry |
158 | 16 |
instanceVariableNames:'strings tabSpec' |
17 |
classVariableNames:'DefaultTabSpec' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Support' |
|
19 | 20 |
! |
21 |
||
329 | 22 |
!MultiColListEntry class methodsFor:'documentation'! |
25 | 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 |
||
25 | 38 |
documentation |
39 |
" |
|
40 |
Instances of MultiColListEntry can be used in place of strings |
|
36 | 41 |
as entries of the list in a ListView or SelectionInListView. |
34 | 42 |
They allow data to be presented in table (or any other) form. |
36 | 43 |
See example here and in TabulatorSpecs documentation. |
44 |
Notice, that each entry can have its own tabulator specification; |
|
45 |
although, usually all share a single spec. |
|
46 |
Also, notice that each column may align different; making these |
|
47 |
perfect elements to present table data. |
|
25 | 48 |
|
36 | 49 |
MultiColListEntry and TabulatorSpec were originally created to |
329 | 50 |
support nice tabular display of file-lists in the FileBrowser |
51 |
(see its long list); you may find many other uses ... |
|
158 | 52 |
|
53 |
[author:] |
|
54 |
Claus Gittinger |
|
36 | 55 |
" |
19 | 56 |
! |
57 |
||
36 | 58 |
examples |
59 |
" |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
60 |
putting multiColListEntries into a ListView (instead of strings) |
161 | 61 |
[exBegin] |
62 |
|v e myList tabs| |
|
19 | 63 |
|
161 | 64 |
myList := OrderedCollection new. |
19 | 65 |
|
161 | 66 |
tabs := TabulatorSpecification new. |
67 |
tabs unit:#inch. |
|
68 |
tabs positions:#(0 3 4). |
|
69 |
tabs align:#(left #center #left). |
|
19 | 70 |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
71 |
e := MultiColListEntry fromString:'left centered left'. |
161 | 72 |
e tabulatorSpecification:tabs. |
73 |
myList add:e. |
|
58 | 74 |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
75 |
e := MultiColListEntry fromString:'| | |'. |
161 | 76 |
e tabulatorSpecification:tabs. |
77 |
myList add:e. |
|
78 |
myList add:''. |
|
19 | 79 |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
80 |
e := MultiColListEntry fromString:'hello hallo salut'. |
161 | 81 |
e tabulatorSpecification:tabs. |
82 |
myList add:e. |
|
58 | 83 |
|
161 | 84 |
e := MultiColListEntry |
85 |
fromString:'good morning,guten Morgen,bon jour' |
|
86 |
separatedBy:$,. |
|
87 |
e tabulatorSpecification:tabs. |
|
88 |
myList add:e. |
|
19 | 89 |
|
161 | 90 |
e := MultiColListEntry new. |
91 |
e colAt:1 put:'good bye'. |
|
92 |
e colAt:2 put:'auf Wiedersehen'. |
|
93 |
e colAt:3 put:'au revoir '. |
|
94 |
e tabulatorSpecification:tabs. |
|
95 |
myList add:e. |
|
19 | 96 |
|
161 | 97 |
v := ListView new. |
98 |
v setList:myList expandTabs:false. |
|
99 |
v extent:500@100. |
|
100 |
v open |
|
101 |
[exEnd] |
|
36 | 102 |
|
103 |
||
104 |
||
58 | 105 |
many multiColListEntries in a scrollable ListView |
161 | 106 |
[exBegin] |
107 |
|v l e myList tabs| |
|
36 | 108 |
|
161 | 109 |
myList := OrderedCollection new. |
19 | 110 |
|
161 | 111 |
tabs := TabulatorSpecification new. |
112 |
tabs unit:#cm. |
|
113 |
tabs positions:#(1 3 5). |
|
114 |
tabs align:#(#right #center #left). |
|
19 | 115 |
|
161 | 116 |
1 to:100 do:[:i| |
117 |
e := MultiColListEntry new. |
|
118 |
e colAt:1 put:i printString. |
|
119 |
e colAt:2 put:i squared printString. |
|
120 |
e colAt:3 put:i sqrt printString. |
|
121 |
e tabulatorSpecification:tabs. |
|
122 |
myList add:e. |
|
123 |
]. |
|
124 |
l := ListView new. |
|
125 |
l setList:myList expandTabs:false. |
|
126 |
v := ScrollableView forView:l. |
|
127 |
v extent:300@200. |
|
128 |
v open |
|
129 |
[exEnd] |
|
36 | 130 |
|
131 |
||
132 |
||
58 | 133 |
like above, but uses nicer decimal alignments |
161 | 134 |
[exBegin] |
135 |
|v l e myList tabs| |
|
36 | 136 |
|
161 | 137 |
myList := OrderedCollection new. |
58 | 138 |
|
161 | 139 |
tabs := TabulatorSpecification new. |
140 |
tabs unit:#cm. |
|
141 |
tabs positions:#(1 3 6 9 12). |
|
142 |
tabs align:#(#right #decimal #decimal #decimal #decimal). |
|
19 | 143 |
|
161 | 144 |
1 to:100 do:[:i| |
145 |
e := MultiColListEntry new. |
|
146 |
e colAt:1 put:i printString. |
|
147 |
e colAt:2 put:i log printString. |
|
148 |
e colAt:3 put:i sqrt printString. |
|
149 |
e colAt:4 put:i sin printString. |
|
150 |
e colAt:5 put:i cos printString. |
|
151 |
e tabulatorSpecification:tabs. |
|
152 |
myList add:e. |
|
153 |
]. |
|
154 |
l := ListView new. |
|
155 |
l setList:myList expandTabs:false. |
|
156 |
v := ScrollableView forView:l. |
|
157 |
v extent:600@200. |
|
158 |
v open |
|
159 |
[exEnd] |
|
36 | 160 |
|
161 |
||
162 |
||
58 | 163 |
specifying tabs in inches |
161 | 164 |
[exBegin] |
165 |
|v l e myList tabs| |
|
19 | 166 |
|
161 | 167 |
myList := OrderedCollection new. |
19 | 168 |
|
161 | 169 |
tabs := TabulatorSpecification new. |
170 |
tabs unit:#inch. |
|
171 |
tabs positions:#(0 2 3.5 4 6 8 10 12). |
|
36 | 172 |
|
161 | 173 |
e := MultiColListEntry new. |
174 |
e colAt:1 put:'2'. |
|
175 |
e colAt:2 put:'3.5'. |
|
176 |
e colAt:3 put:'4'. |
|
177 |
e colAt:4 put:'6'. |
|
178 |
e colAt:5 put:'8'. |
|
179 |
e colAt:6 put:'10'. |
|
180 |
e colAt:7 put:'12'. |
|
181 |
e tabulatorSpecification:tabs. |
|
182 |
myList add:e. |
|
36 | 183 |
|
161 | 184 |
myList add:((MultiColListEntry fromString:'| | | | | | |') |
185 |
tabulatorSpecification:tabs). |
|
186 |
myList add:((MultiColListEntry fromString:'xxx xxx xxx xxx xxx xxx xxx') |
|
187 |
tabulatorSpecification:tabs). |
|
58 | 188 |
|
161 | 189 |
l := ListView new. |
190 |
l setList:myList expandTabs:false. |
|
191 |
v := HVScrollableView forView:l. |
|
192 |
v extent:600@200. |
|
193 |
v open |
|
194 |
[exEnd] |
|
36 | 195 |
|
196 |
||
58 | 197 |
if you have the columns available as a collection, |
198 |
setup can be done easier |
|
161 | 199 |
[exBegin] |
200 |
|v l e myList tabs| |
|
58 | 201 |
|
161 | 202 |
myList := OrderedCollection new. |
58 | 203 |
|
161 | 204 |
tabs := TabulatorSpecification new. |
205 |
tabs unit:#inch. |
|
206 |
tabs positions:#(0 2 3.5 4 6 8 10 12). |
|
58 | 207 |
|
161 | 208 |
e := MultiColListEntry new. |
209 |
e strings:#('2' '3.5' '4' '6' '8' '10' '12'). |
|
210 |
e tabulatorSpecification:tabs. |
|
211 |
myList add:e. |
|
36 | 212 |
|
161 | 213 |
l := ListView new. |
214 |
l setList:myList expandTabs:false. |
|
215 |
v := HVScrollableView forView:l. |
|
216 |
v extent:600@200. |
|
217 |
v open |
|
218 |
[exEnd] |
|
58 | 219 |
|
36 | 220 |
|
357 | 221 |
using icons instead of strings: |
222 |
[exBegin] |
|
223 |
|v l e myList tabs i1 i2 i3| |
|
224 |
||
225 |
myList := OrderedCollection new. |
|
226 |
||
227 |
tabs := TabulatorSpecification new. |
|
228 |
tabs unit:#cm. |
|
229 |
tabs positions:#(1 3 5). |
|
230 |
tabs align:#(#left #left #left). |
|
231 |
||
232 |
i1 := Image fromFile:'bitmaps/xpmBitmaps/document_images/small_dir.xpm'. |
|
233 |
i2 := Image fromFile:'bitmaps/xpmBitmaps/document_images/small_file.xpm'. |
|
234 |
i3 := Image fromFile:'bitmaps/xpmBitmaps/document_images/small_file_binary.xpm'. |
|
235 |
||
236 |
1 to:100 do:[:i| |
|
237 |
e := MultiColListEntry new. |
|
238 |
i odd ifTrue:[ |
|
239 |
e colAt:1 put:i1. |
|
240 |
] ifFalse:[ |
|
241 |
e colAt:1 put:i2 |
|
242 |
]. |
|
243 |
e colAt:2 put:i printString. |
|
244 |
e colAt:3 put:i3. |
|
245 |
e tabulatorSpecification:tabs. |
|
246 |
myList add:e. |
|
247 |
]. |
|
248 |
l := SelectionInListView new. |
|
249 |
l setList:myList expandTabs:false. |
|
250 |
v := ScrollableView forView:l. |
|
251 |
v extent:300@200. |
|
252 |
v open |
|
253 |
[exEnd] |
|
254 |
||
255 |
||
256 |
||
58 | 257 |
concrete example, show /etc/passwd in a table: |
161 | 258 |
[exBegin] |
259 |
||
260 |
|v l s myList line e htabs tabs fingerEntry| |
|
58 | 261 |
|
161 | 262 |
tabs := TabulatorSpecification new. |
263 |
tabs unit:#inch. |
|
264 |
tabs positions:#(0 2 3.5 4.5 5 8 11). |
|
265 |
tabs align: #(left left right right left left left). |
|
36 | 266 |
|
161 | 267 |
htabs := TabulatorSpecification new. |
268 |
htabs unit:#inch. |
|
269 |
htabs positions:#(0 2 3.5 4.5 5 8 11). |
|
270 |
htabs align: #(left center center center left left left). |
|
58 | 271 |
|
161 | 272 |
myList := OrderedCollection new. |
58 | 273 |
|
161 | 274 |
e := MultiColListEntry |
275 |
fromString:'login-name:password:uid:gid:finger-entry:home-dir:shell' |
|
276 |
separatedBy:$:. |
|
277 |
e tabulatorSpecification:htabs. |
|
278 |
myList add:e. |
|
279 |
myList add:''. |
|
36 | 280 |
|
161 | 281 |
s := '/etc/passwd' asFilename readStream. |
282 |
[s atEnd] whileFalse:[ |
|
283 |
line := s nextLine. |
|
284 |
e := MultiColListEntry |
|
285 |
fromString:line |
|
286 |
separatedBy:$:. |
|
287 |
fingerEntry := e colAt:5. |
|
288 |
e colAt:5 put:(fingerEntry asCollectionOfSubstringsSeparatedBy:$,) first. |
|
289 |
e tabulatorSpecification:tabs. |
|
290 |
myList add:e. |
|
291 |
]. |
|
292 |
s close. |
|
58 | 293 |
|
161 | 294 |
l := ListView new. |
295 |
l setList:myList expandTabs:false. |
|
296 |
v := HVScrollableView forView:l. |
|
297 |
v extent:600@200. |
|
298 |
v open |
|
299 |
[exEnd] |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
300 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
301 |
a (dynamic) menu with aligned columns: |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
302 |
[exBegin] |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
303 |
|menu item l tabSpec n1 n2 n3 n4| |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
304 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
305 |
menu := Menu new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
306 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
307 |
tabSpec := TabulatorSpecification new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
308 |
tabSpec unit:#inch. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
309 |
tabSpec positions:#(0 1.5 ). |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
310 |
tabSpec align: #(#left #right). |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
311 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
312 |
n1 := 123456. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
313 |
n2 := 123. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
314 |
n3 := 11111. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
315 |
n4 := 9876. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
316 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
317 |
l := MultiColListEntry fromStrings:#('N1:' '') tabulatorSpecification:tabSpec. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
318 |
l colAt:2 put:n1 printString. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
319 |
item := MenuItem new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
320 |
item label:l. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
321 |
menu addItem:item. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
322 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
323 |
l := MultiColListEntry fromStrings:#('N2:' '') tabulatorSpecification:tabSpec. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
324 |
l colAt:2 put:n2 printString. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
325 |
item := MenuItem new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
326 |
item label:l. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
327 |
menu addItem:item. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
328 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
329 |
l := MultiColListEntry fromStrings:#('N3:' '') tabulatorSpecification:tabSpec. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
330 |
l colAt:2 put:n3 printString. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
331 |
item := MenuItem new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
332 |
item label:l. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
333 |
menu addItem:item. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
334 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
335 |
l := MultiColListEntry fromStrings:#('N4:' '') tabulatorSpecification:tabSpec. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
336 |
l colAt:2 put:n4 printString. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
337 |
item := MenuItem new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
338 |
item label:l. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
339 |
menu addItem:item. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
340 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
341 |
menu showAtPointer. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
342 |
[exEnd] |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
343 |
|
36 | 344 |
" |
345 |
! ! |
|
346 |
||
329 | 347 |
!MultiColListEntry class methodsFor:'instance creation'! |
36 | 348 |
|
97 | 349 |
fromString:aString |
1159 | 350 |
"create and return a new listEntry with columns taken |
351 |
from the words of aString. Assumes that columns are |
|
352 |
separated by spaces in the string" |
|
353 |
||
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
354 |
^ self fromString:aString separatedBy:(Character space) |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
355 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
356 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
357 |
self fromString:'hello world a b' |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
358 |
" |
97 | 359 |
! |
360 |
||
361 |
fromString:aString separatedBy:separatorCharacter |
|
1159 | 362 |
"create and return a new listEntry with columns taken |
363 |
from the words of aString. Assumes that columns are |
|
364 |
separated by separatorCharacter in the string" |
|
365 |
||
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
366 |
|subStrings| |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
367 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
368 |
subStrings := aString asCollectionOfSubstringsSeparatedBy:separatorCharacter. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
369 |
^ self fromStrings:subStrings |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
370 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
371 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
372 |
self fromString:'hello:world:a:b' separatedBy:$: |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
373 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
374 |
! |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
375 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
376 |
fromString:aString separatedBy:separatorCharacter tabulatorSpecification:aTabSpec |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
377 |
"create and return a new listEntry with columns taken |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
378 |
from the words of aString. Assumes that columns are |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
379 |
separated by separatorCharacter in the string" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
380 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
381 |
|e| |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
382 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
383 |
e := self fromString:aString separatedBy:separatorCharacter. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
384 |
e tabulatorSpecification:aTabSpec. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
385 |
^ e |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
386 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
387 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
388 |
|tabSpec| |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
389 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
390 |
tabSpec := TabulatorSpecification new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
391 |
tabSpec unit:#inch. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
392 |
tabSpec positions:#(0 1.5 ). |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
393 |
tabSpec align: #(#left #right). |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
394 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
395 |
self fromString:'hello world a b' separatedBy:(Character space) tabulatorSpecification:tabSpec |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
396 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
397 |
! |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
398 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
399 |
fromStrings:aCollectionOfStrings |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
400 |
"create and return a new listEntry with columns taken |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
401 |
from the given aStrings." |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
402 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
403 |
|idx e| |
97 | 404 |
|
405 |
e := self new. |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
406 |
idx := 1. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
407 |
aCollectionOfStrings do:[:sub | |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
408 |
e colAt:idx put:sub. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
409 |
idx := idx + 1. |
97 | 410 |
]. |
411 |
^ e |
|
1969
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
412 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
413 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
414 |
self fromStrings:#('hello' 'world') |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
415 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
416 |
! |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
417 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
418 |
fromStrings:aCollectionOfStrings tabulatorSpecification:aTabSpec |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
419 |
"create and return a new listEntry with columns taken |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
420 |
from the given aStrings." |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
421 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
422 |
^ (self fromStrings:aCollectionOfStrings) tabulatorSpecification:aTabSpec |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
423 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
424 |
" |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
425 |
|tabSpec| |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
426 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
427 |
tabSpec := TabulatorSpecification new. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
428 |
tabSpec unit:#inch. |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
429 |
tabSpec positions:#(0 1.5 ). |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
430 |
tabSpec align: #(#left #right). |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
431 |
|
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
432 |
self fromStrings:#('hello' 'world') tabulatorSpecification:tabSpec |
e325d38ce469
examples and additional inst-creation
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
433 |
" |
97 | 434 |
! |
435 |
||
70 | 436 |
new:numberOfColumns |
1159 | 437 |
"create and return a new listEntry with numberOfColumns empty columns" |
438 |
||
70 | 439 |
|e| |
440 |
||
441 |
e := self new. |
|
442 |
1 to:numberOfColumns do:[:i | |
|
1159 | 443 |
e colAt:i put:''. |
70 | 444 |
]. |
445 |
^ e |
|
446 |
||
447 |
"Modified: 30.8.1995 / 16:33:53 / claus" |
|
448 |
! |
|
449 |
||
450 |
new:numberOfColumns tabulatorSpecification:aTabSpec |
|
1159 | 451 |
"create and return a new listEntry with numberOfColumns empty columns |
452 |
and the given tab-specification" |
|
453 |
||
70 | 454 |
^ (self new:numberOfColumns) tabulatorSpecification:aTabSpec |
455 |
||
456 |
"Modified: 30.8.1995 / 16:34:23 / claus" |
|
97 | 457 |
! ! |
458 |
||
459 |
!MultiColListEntry methodsFor:'accessing'! |
|
460 |
||
461 |
colAt:index |
|
462 |
"return the substring at column index" |
|
463 |
||
464 |
index > strings size ifTrue:[^ nil]. |
|
465 |
^ strings at:index |
|
70 | 466 |
! |
467 |
||
97 | 468 |
colAt:index put:aString |
469 |
"replace the substring at column index" |
|
470 |
||
471 |
strings isNil ifTrue:[ |
|
472 |
strings := OrderedCollection new:index |
|
473 |
]. |
|
474 |
index > strings size ifTrue:[strings grow:index]. |
|
475 |
strings at:index put:aString |
|
476 |
! |
|
477 |
||
478 |
strings:aCollectionOfStrings |
|
479 |
"replace all substrings" |
|
480 |
||
481 |
strings := OrderedCollection withAll:aCollectionOfStrings. |
|
36 | 482 |
! |
483 |
||
97 | 484 |
tabulatorSpecification:aTabSpec |
485 |
"set the tabulator spec" |
|
486 |
||
487 |
tabSpec := aTabSpec |
|
488 |
! ! |
|
489 |
||
490 |
!MultiColListEntry methodsFor:'converting'! |
|
491 |
||
492 |
asString |
|
493 |
"return the receiver as a string with embedded tabs" |
|
494 |
||
495 |
|s sub tab |
|
496 |
nSub "{ Class: SmallInteger }"| |
|
36 | 497 |
|
97 | 498 |
s := ''. |
499 |
tab := Character tab asString. |
|
500 |
nSub := strings size. |
|
501 |
1 to:nSub do:[:subStringIndex | |
|
363
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
502 |
sub := strings at:subStringIndex. |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
503 |
sub notNil ifTrue:[ |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
504 |
sub isString ifTrue:[ |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
505 |
s := s , sub. |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
506 |
] |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
507 |
]. |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
508 |
subStringIndex == nSub ifFalse:[ |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
509 |
s := s , tab |
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
510 |
] |
36 | 511 |
]. |
97 | 512 |
|
513 |
^ s |
|
103 | 514 |
|
515 |
"Created: 24.11.1995 / 18:54:27 / cg" |
|
363
c025abf2d73c
care for non-string entries in #asString.
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
516 |
"Modified: 17.4.1997 / 03:21:13 / cg" |
36 | 517 |
! ! |
518 |
||
89 | 519 |
!MultiColListEntry methodsFor:'defaults'! |
520 |
||
521 |
defaultTabSpec |
|
522 |
"the default tabulators are 1 inch apart" |
|
523 |
||
524 |
|spec| |
|
525 |
||
526 |
spec := DefaultTabSpec. |
|
527 |
spec isNil ifTrue:[ |
|
528 |
spec := TabulatorSpecification new. |
|
529 |
spec unit:#inch. |
|
530 |
spec positions:(0 to:20). |
|
531 |
spec align: #left. |
|
532 |
DefaultTabSpec := spec. |
|
533 |
]. |
|
534 |
^ spec. |
|
535 |
||
536 |
"Created: 17.11.1995 / 12:23:29 / cg" |
|
537 |
"Modified: 17.11.1995 / 12:24:20 / cg" |
|
538 |
! ! |
|
539 |
||
36 | 540 |
!MultiColListEntry methodsFor:'drawing'! |
541 |
||
108 | 542 |
displayOn:aGC x:x y:y opaque:opaque |
36 | 543 |
"display the receiver on a GC" |
544 |
||
357 | 545 |
|xPos spec tabPos prevString y0| |
36 | 546 |
|
89 | 547 |
spec := tabSpec. |
548 |
spec isNil ifTrue:[ |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
549 |
spec := self defaultTabSpec |
89 | 550 |
]. |
36 | 551 |
xPos := x. |
552 |
prevString := ''. |
|
364 | 553 |
|
1478 | 554 |
aGC font:(aGC font onDevice:aGC device). |
366
34e1870524f1
fetch device font before querying
Claus Gittinger <cg@exept.de>
parents:
364
diff
changeset
|
555 |
|
34e1870524f1
fetch device font before querying
Claus Gittinger <cg@exept.de>
parents:
364
diff
changeset
|
556 |
y0 := y - aGC font ascent. |
357 | 557 |
|
36 | 558 |
strings keysAndValuesDo:[:index :subString | |
357 | 559 |
|item| |
560 |
||
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
561 |
subString notNil ifTrue:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
562 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
563 |
find next tab |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
564 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
565 |
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
|
566 |
tabPos isNil ifTrue:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
567 |
" |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
568 |
no tab - just continue where we are ... |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
569 |
" |
2098 | 570 |
xPos := xPos + (prevString widthOn:aGC). "/ not: (aGC font widthOf:prevString) -- could be text or image |
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
571 |
] ifFalse:[ |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
572 |
xPos := tabPos + x. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
573 |
]. |
357 | 574 |
subString isString ifFalse:[ |
575 |
item := subString. |
|
576 |
item isImage ifTrue:[ |
|
2098 | 577 |
strings at:index put:(item := item onDevice:aGC device) |
357 | 578 |
]. |
579 |
item displayOn:aGC x:xPos y:y0 |
|
580 |
] ifTrue:[ |
|
581 |
opaque ifTrue:[ |
|
582 |
aGC displayOpaqueString:subString x:xPos y:y. |
|
583 |
] ifFalse:[ |
|
584 |
aGC displayString:subString x:xPos y:y. |
|
585 |
]. |
|
586 |
]. |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
587 |
prevString := subString. |
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
588 |
] |
36 | 589 |
]. |
89 | 590 |
|
366
34e1870524f1
fetch device font before querying
Claus Gittinger <cg@exept.de>
parents:
364
diff
changeset
|
591 |
"Modified: 19.4.1997 / 09:54:56 / cg" |
58 | 592 |
! ! |
36 | 593 |
|
58 | 594 |
!MultiColListEntry methodsFor:'queries'! |
595 |
||
357 | 596 |
heightOn:aGC |
597 |
"return the height of the receiver when displayed in aGC" |
|
598 |
||
599 |
|hMax| |
|
600 |
||
601 |
hMax := 0. |
|
602 |
strings keysAndValuesDo:[:index :subString | |
|
603 |
|h| |
|
604 |
||
605 |
subString notNil ifTrue:[ |
|
606 |
h := subString heightOn:aGC. |
|
607 |
hMax := hMax max:h. |
|
608 |
] |
|
609 |
]. |
|
610 |
^ hMax |
|
611 |
||
612 |
"Created: 15.4.1997 / 09:39:07 / cg" |
|
613 |
! |
|
614 |
||
173 | 615 |
widthOn:aGC |
58 | 616 |
"return the width of the receiver when displayed in aGC" |
617 |
||
62 | 618 |
|xPos xMax tabPos prevLen| |
58 | 619 |
|
620 |
"just to make certain: |
|
621 |
do not assume, that the last col is the rightmost one ... |
|
622 |
" |
|
623 |
xPos := 0. |
|
624 |
xMax := 0. |
|
625 |
prevLen := 0. |
|
626 |
strings keysAndValuesDo:[:index :subString | |
|
173 | 627 |
|w| |
62 | 628 |
|
173 | 629 |
subString notNil ifTrue:[ |
630 |
" |
|
631 |
find next tab |
|
632 |
" |
|
633 |
tabPos := tabSpec positionOfTab:index forString:subString on:aGC. |
|
634 |
tabPos isNil ifTrue:[ |
|
635 |
" |
|
636 |
no tab - just continue where we are ... |
|
637 |
" |
|
638 |
xPos := xPos + prevLen. |
|
639 |
] ifFalse:[ |
|
640 |
xPos := tabPos. |
|
641 |
]. |
|
211
f6e9378de69f
allow columns to consist of Text instances
Claus Gittinger <cg@exept.de>
parents:
173
diff
changeset
|
642 |
w := prevLen := subString widthOn:aGC. "/ aGC font widthOf:subString. |
173 | 643 |
xMax := xMax max:(xPos + w). |
644 |
] |
|
58 | 645 |
]. |
364 | 646 |
xMax isInteger ifFalse:[ |
647 |
^ xMax truncated + 1 |
|
648 |
]. |
|
58 | 649 |
^ xMax |
173 | 650 |
|
651 |
"Created: 12.5.1996 / 20:38:38 / cg" |
|
364 | 652 |
"Modified: 17.4.1997 / 12:52:00 / cg" |
58 | 653 |
! ! |
654 |
||
329 | 655 |
!MultiColListEntry class methodsFor:'documentation'! |
98 | 656 |
|
657 |
version |
|
2098 | 658 |
^ '$Header: /cvs/stx/stx/libwidg2/MultiColListEntry.st,v 1.27 2002-05-06 06:06:12 cg Exp $' |
98 | 659 |
! ! |