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