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