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 |
"
|
1881
|
12 |
"{ Package: 'stx:libwidg2' }"
|
|
13 |
|
327
|
14 |
Model subclass:#TabulatorSpecification
|
128
|
15 |
instanceVariableNames:'tabUnit unitReference tabPositions tabTypes'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Support'
|
19
|
19 |
!
|
|
20 |
|
25
|
21 |
!TabulatorSpecification class methodsFor:'documentation'!
|
|
22 |
|
28
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
25
|
37 |
documentation
|
|
38 |
"
|
|
39 |
This is a helper class for table widgets and tabular data in
|
|
40 |
lists.
|
|
41 |
A tabulatorSpecification keeps track of where the tabs are,
|
36
|
42 |
and how they align. They are to be used in conjunction with
|
|
43 |
MultiColumnListEntry or the upcoming TableWidget.
|
|
44 |
However, they may also be useful to represent tabs in a
|
|
45 |
paragraph of text.
|
158
|
46 |
|
|
47 |
|
|
48 |
[author:]
|
|
49 |
Claus Gittinger
|
|
50 |
|
|
51 |
[see also:]
|
199
|
52 |
Ruler TabSpecRuler
|
158
|
53 |
ListView
|
28
|
54 |
"
|
|
55 |
!
|
25
|
56 |
|
28
|
57 |
examples
|
|
58 |
"
|
25
|
59 |
Example use (in a ListView):
|
161
|
60 |
[exBegin]
|
|
61 |
|listView tabSpec entry|
|
25
|
62 |
|
161
|
63 |
listView := ListView new.
|
25
|
64 |
|
161
|
65 |
tabSpec := TabulatorSpecification new.
|
|
66 |
tabSpec unit:#inch.
|
|
67 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
68 |
tabSpec align: #(#left #left #right #right #center #decimal ).
|
25
|
69 |
|
161
|
70 |
entry := MultiColListEntry new.
|
|
71 |
entry tabulatorSpecification:tabSpec.
|
|
72 |
entry colAt:1 put:'left';
|
|
73 |
colAt:2 put:'left';
|
|
74 |
colAt:3 put:'right';
|
|
75 |
colAt:4 put:'right';
|
|
76 |
colAt:5 put:'center';
|
|
77 |
colAt:6 put:'.decimal'.
|
25
|
78 |
|
161
|
79 |
listView at:1 put:entry.
|
25
|
80 |
|
161
|
81 |
entry := MultiColListEntry new.
|
|
82 |
entry tabulatorSpecification:tabSpec.
|
|
83 |
entry colAt:1 put:'col1';
|
|
84 |
colAt:2 put:'col2';
|
|
85 |
colAt:3 put:'col3';
|
|
86 |
colAt:4 put:'col4';
|
|
87 |
colAt:5 put:'col5';
|
|
88 |
colAt:6 put:'col6.decimal'.
|
25
|
89 |
|
161
|
90 |
listView at:2 put:entry.
|
25
|
91 |
|
161
|
92 |
entry := MultiColListEntry new.
|
|
93 |
entry tabulatorSpecification:tabSpec.
|
|
94 |
entry colAt:1 put:'foo';
|
|
95 |
colAt:2 put:'fooBar';
|
|
96 |
colAt:3 put:'bar';
|
|
97 |
colAt:4 put:'barFoo';
|
|
98 |
colAt:5 put:'baz';
|
|
99 |
colAt:6 put:'1234.56'.
|
25
|
100 |
|
161
|
101 |
listView at:3 put:entry.
|
1881
|
102 |
(ScrollableView forView:listView) open
|
161
|
103 |
[exEnd]
|
25
|
104 |
|
28
|
105 |
|
|
106 |
defining field positions in millimeter :
|
161
|
107 |
[exBegin]
|
|
108 |
|listView tabSpec entry|
|
28
|
109 |
|
161
|
110 |
listView := ListView new.
|
28
|
111 |
|
161
|
112 |
tabSpec := TabulatorSpecification new.
|
|
113 |
tabSpec unit:#mm.
|
|
114 |
tabSpec positions:#(0 10 20 40).
|
|
115 |
tabSpec align: #left.
|
28
|
116 |
|
161
|
117 |
entry := MultiColListEntry new.
|
|
118 |
entry tabulatorSpecification:tabSpec.
|
|
119 |
entry colAt:1 put:'1';
|
|
120 |
colAt:2 put:'2';
|
|
121 |
colAt:3 put:'3';
|
|
122 |
colAt:4 put:'4'.
|
28
|
123 |
|
161
|
124 |
listView at:1 put:entry.
|
28
|
125 |
|
161
|
126 |
entry := MultiColListEntry new.
|
|
127 |
entry tabulatorSpecification:tabSpec.
|
|
128 |
entry colAt:1 put:'aa';
|
|
129 |
colAt:2 put:'bb';
|
|
130 |
colAt:3 put:'cc';
|
|
131 |
colAt:4 put:'dd'.
|
28
|
132 |
|
161
|
133 |
listView at:2 put:entry.
|
28
|
134 |
|
161
|
135 |
listView open
|
|
136 |
[exEnd]
|
28
|
137 |
|
|
138 |
defining field widths in millimeter :
|
161
|
139 |
[exBegin]
|
|
140 |
|listView tabSpec entry|
|
28
|
141 |
|
161
|
142 |
listView := ListView new.
|
28
|
143 |
|
161
|
144 |
tabSpec := TabulatorSpecification new.
|
|
145 |
tabSpec unit:#mm.
|
|
146 |
tabSpec widths:#(10 10 20 10).
|
|
147 |
tabSpec align: #left.
|
28
|
148 |
|
161
|
149 |
entry := MultiColListEntry new.
|
|
150 |
entry tabulatorSpecification:tabSpec.
|
|
151 |
entry colAt:1 put:'1';
|
|
152 |
colAt:2 put:'2';
|
|
153 |
colAt:3 put:'3';
|
|
154 |
colAt:4 put:'4'.
|
28
|
155 |
|
161
|
156 |
listView at:1 put:entry.
|
28
|
157 |
|
161
|
158 |
entry := MultiColListEntry new.
|
|
159 |
entry tabulatorSpecification:tabSpec.
|
|
160 |
entry colAt:1 put:'aa';
|
|
161 |
colAt:2 put:'bb';
|
|
162 |
colAt:3 put:'cc';
|
|
163 |
colAt:4 put:'dd'.
|
28
|
164 |
|
161
|
165 |
listView at:2 put:entry.
|
28
|
166 |
|
161
|
167 |
listView open
|
|
168 |
[exEnd]
|
28
|
169 |
|
|
170 |
defining field widths in pixels :
|
161
|
171 |
[exBegin]
|
|
172 |
|listView tabSpec entry|
|
28
|
173 |
|
161
|
174 |
listView := ListView new.
|
28
|
175 |
|
161
|
176 |
tabSpec := TabulatorSpecification new.
|
|
177 |
tabSpec unit:#pixel.
|
|
178 |
tabSpec widths:#(50 30 30 50).
|
|
179 |
tabSpec align: #left.
|
28
|
180 |
|
161
|
181 |
entry := MultiColListEntry new.
|
|
182 |
entry tabulatorSpecification:tabSpec.
|
|
183 |
entry colAt:1 put:'1';
|
|
184 |
colAt:2 put:'2';
|
|
185 |
colAt:3 put:'3';
|
|
186 |
colAt:4 put:'4'.
|
28
|
187 |
|
161
|
188 |
listView at:1 put:entry.
|
28
|
189 |
|
161
|
190 |
entry := MultiColListEntry new.
|
|
191 |
entry tabulatorSpecification:tabSpec.
|
|
192 |
entry colAt:1 put:'aa';
|
|
193 |
colAt:2 put:'bb';
|
|
194 |
colAt:3 put:'cc';
|
|
195 |
colAt:4 put:'dd'.
|
28
|
196 |
|
161
|
197 |
listView at:2 put:entry.
|
28
|
198 |
|
161
|
199 |
listView open
|
|
200 |
[exEnd]
|
199
|
201 |
|
|
202 |
same as first example, but adding a TabSpecRuler to show where
|
|
203 |
the tabs are:
|
|
204 |
[exBegin]
|
|
205 |
|top ruler listView tabSpec entry|
|
|
206 |
|
|
207 |
top := StandardSystemView extent:300@300.
|
|
208 |
|
|
209 |
ruler := TabSpecRuler origin:0.0@0.0 corner:1.0@20 in:top.
|
|
210 |
ruler level:0.
|
327
|
211 |
ruler tabsAreVariable:false.
|
|
212 |
|
199
|
213 |
listView := ListView in:top.
|
|
214 |
listView origin:0.0@0.0 corner:1.0@1.0.
|
|
215 |
listView topInset:20.
|
|
216 |
|
|
217 |
tabSpec := TabulatorSpecification new.
|
|
218 |
tabSpec unit:#inch.
|
|
219 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
220 |
tabSpec align: #(#left #left #right #right #center #decimal ).
|
|
221 |
|
|
222 |
ruler tabulatorSpecification:tabSpec.
|
|
223 |
|
|
224 |
entry := MultiColListEntry new.
|
|
225 |
entry tabulatorSpecification:tabSpec.
|
|
226 |
entry colAt:1 put:'left';
|
|
227 |
colAt:2 put:'left';
|
|
228 |
colAt:3 put:'right';
|
|
229 |
colAt:4 put:'right';
|
|
230 |
colAt:5 put:'center';
|
|
231 |
colAt:6 put:'.decimal'.
|
|
232 |
|
|
233 |
listView at:1 put:entry.
|
|
234 |
|
|
235 |
entry := MultiColListEntry new.
|
|
236 |
entry tabulatorSpecification:tabSpec.
|
|
237 |
entry colAt:1 put:'col1';
|
|
238 |
colAt:2 put:'col2';
|
|
239 |
colAt:3 put:'col3';
|
|
240 |
colAt:4 put:'col4';
|
|
241 |
colAt:5 put:'col5';
|
|
242 |
colAt:6 put:'col6.decimal'.
|
|
243 |
|
|
244 |
listView at:2 put:entry.
|
|
245 |
|
|
246 |
entry := MultiColListEntry new.
|
|
247 |
entry tabulatorSpecification:tabSpec.
|
|
248 |
entry colAt:1 put:'foo';
|
|
249 |
colAt:2 put:'fooBar';
|
|
250 |
colAt:3 put:'bar';
|
|
251 |
colAt:4 put:'barFoo';
|
|
252 |
colAt:5 put:'baz';
|
|
253 |
colAt:6 put:'1234.56'.
|
|
254 |
|
|
255 |
listView at:3 put:entry.
|
|
256 |
top open
|
|
257 |
[exEnd]
|
327
|
258 |
|
|
259 |
much like previous example, but allow some tab positions to be
|
|
260 |
changed (with synchronousOperation):
|
|
261 |
[exBegin]
|
|
262 |
|top ruler listView tabSpec entry|
|
|
263 |
|
|
264 |
top := StandardSystemView extent:300@300.
|
|
265 |
|
|
266 |
ruler := TabSpecRuler origin:0.0@0.0 corner:1.0@20 in:top.
|
|
267 |
ruler level:0.
|
|
268 |
ruler fixedTabs:#(1).
|
|
269 |
ruler synchronousOperation:true.
|
|
270 |
|
|
271 |
listView := ListView in:top.
|
|
272 |
listView origin:0.0@0.0 corner:1.0@1.0.
|
|
273 |
listView topInset:20.
|
|
274 |
|
|
275 |
tabSpec := TabulatorSpecification new.
|
|
276 |
tabSpec unit:#inch.
|
|
277 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
278 |
tabSpec align: #(#left #left #left #left #left #decimal ).
|
|
279 |
|
|
280 |
ruler tabulatorSpecification:tabSpec.
|
|
281 |
|
|
282 |
entry := MultiColListEntry new.
|
|
283 |
entry tabulatorSpecification:tabSpec.
|
|
284 |
entry colAt:1 put:'left';
|
|
285 |
colAt:2 put:'left';
|
|
286 |
colAt:3 put:'left';
|
|
287 |
colAt:4 put:'left';
|
|
288 |
colAt:5 put:'left';
|
|
289 |
colAt:6 put:'.decimal'.
|
|
290 |
|
|
291 |
listView at:1 put:entry.
|
|
292 |
|
|
293 |
entry := MultiColListEntry new.
|
|
294 |
entry tabulatorSpecification:tabSpec.
|
|
295 |
entry colAt:1 put:'col1';
|
|
296 |
colAt:2 put:'col2';
|
|
297 |
colAt:3 put:'col3';
|
|
298 |
colAt:4 put:'col4';
|
|
299 |
colAt:5 put:'col5';
|
|
300 |
colAt:6 put:'col6'.
|
|
301 |
|
|
302 |
listView at:2 put:entry.
|
|
303 |
|
|
304 |
entry := MultiColListEntry new.
|
|
305 |
entry tabulatorSpecification:tabSpec.
|
|
306 |
entry colAt:1 put:'foo';
|
|
307 |
colAt:2 put:'fooBar';
|
|
308 |
colAt:3 put:'bar';
|
|
309 |
colAt:4 put:'barFoo';
|
|
310 |
colAt:5 put:'baz';
|
|
311 |
colAt:6 put:'1234.56'.
|
|
312 |
|
|
313 |
listView at:3 put:entry.
|
|
314 |
|
|
315 |
entry := MultiColListEntry new.
|
|
316 |
entry tabulatorSpecification:tabSpec.
|
|
317 |
entry colAt:1 put:'hello';
|
|
318 |
colAt:2 put:'world';
|
|
319 |
colAt:3 put:'how';
|
|
320 |
colAt:4 put:'about';
|
|
321 |
colAt:5 put:'this';
|
|
322 |
colAt:6 put:'0.2345'.
|
|
323 |
listView at:4 put:entry.
|
|
324 |
|
|
325 |
tabSpec onChangeSend:#redraw to:listView.
|
|
326 |
top open
|
|
327 |
[exEnd]
|
25
|
328 |
"
|
|
329 |
! !
|
|
330 |
|
70
|
331 |
!TabulatorSpecification class methodsFor:'instance creation'!
|
|
332 |
|
|
333 |
unit:unit positions:positions
|
|
334 |
^ (self new) unit:unit; positions:positions
|
|
335 |
|
|
336 |
"
|
|
337 |
TabulatorSpecification unit:#inch positions:#(0 3)
|
|
338 |
"
|
|
339 |
|
|
340 |
"Modified: 30.8.1995 / 16:37:50 / claus"
|
|
341 |
! !
|
|
342 |
|
97
|
343 |
!TabulatorSpecification methodsFor:'accessing'!
|
|
344 |
|
|
345 |
align
|
|
346 |
"return the align-vector"
|
|
347 |
|
|
348 |
^ tabTypes
|
|
349 |
!
|
|
350 |
|
|
351 |
align:types
|
|
352 |
"
|
|
353 |
an array of tab-types; each one is
|
|
354 |
#left
|
|
355 |
#right
|
|
356 |
#center
|
|
357 |
#decimal
|
|
358 |
or a symbol which gives align of all tabs
|
|
359 |
|
|
360 |
"
|
|
361 |
tabTypes := types
|
|
362 |
!
|
|
363 |
|
327
|
364 |
moveTabAtIndex:index to:unitPosition
|
|
365 |
"set an individual position"
|
|
366 |
|
|
367 |
tabPositions at:index put:unitPosition.
|
|
368 |
self changed:#tabPosition with:index
|
|
369 |
|
|
370 |
"Modified: 28.3.1997 / 14:55:27 / cg"
|
|
371 |
!
|
|
372 |
|
97
|
373 |
positions
|
|
374 |
"return the position-vector"
|
|
375 |
|
|
376 |
^ tabPositions
|
|
377 |
!
|
|
378 |
|
|
379 |
positions:tabs
|
|
380 |
"set the position-vector"
|
|
381 |
|
|
382 |
tabPositions := tabs
|
|
383 |
!
|
|
384 |
|
|
385 |
size
|
|
386 |
"return the number of tabs in this spec"
|
|
387 |
|
|
388 |
^ tabPositions size
|
|
389 |
!
|
|
390 |
|
|
391 |
unit
|
|
392 |
"return the unit"
|
|
393 |
|
|
394 |
^ tabUnit
|
|
395 |
!
|
|
396 |
|
|
397 |
unit:aSymbol
|
|
398 |
"set the unit.
|
|
399 |
allowed are: #inch, #mm, #cm, #pixel and #col"
|
|
400 |
|
|
401 |
tabUnit := aSymbol
|
|
402 |
!
|
|
403 |
|
|
404 |
unitRelativeTo:someObject
|
|
405 |
"set for a relative unit. someObject should return its width
|
|
406 |
and the tabs are set fraction-relative to this number (in pixel)."
|
|
407 |
|
|
408 |
tabUnit := #relative.
|
|
409 |
unitReference := someObject
|
|
410 |
!
|
|
411 |
|
|
412 |
widths
|
|
413 |
"return a width-vector"
|
|
414 |
|
|
415 |
|prev|
|
|
416 |
|
|
417 |
prev := 0.
|
|
418 |
^ tabPositions collect:[:p | |w| w := p - prev. prev := p. w].
|
|
419 |
|
|
420 |
"
|
|
421 |
|spec|
|
|
422 |
|
|
423 |
spec := TabulatorSpecification new.
|
|
424 |
spec unit:#inch.
|
|
425 |
spec positions:#(0 1 2.5 3.5 4 5 ).
|
|
426 |
spec align: #(#left #left #right #right #center #decimal ).
|
|
427 |
spec widths
|
|
428 |
"
|
|
429 |
!
|
|
430 |
|
|
431 |
widths:fieldWidths
|
|
432 |
"set the position-vector from a vector of field widths"
|
|
433 |
|
|
434 |
|pos|
|
|
435 |
|
|
436 |
pos := 0.
|
|
437 |
tabPositions := fieldWidths collect:[:w |
|
|
438 |
|p|
|
|
439 |
|
|
440 |
p := pos.
|
|
441 |
pos := pos + w.
|
|
442 |
p].
|
|
443 |
! !
|
|
444 |
|
19
|
445 |
!TabulatorSpecification methodsFor:'queries'!
|
|
446 |
|
|
447 |
pixelsPerUnitOn:aGC
|
327
|
448 |
"return the number of device pixels one unit of my tabs
|
|
449 |
takes on aGC"
|
|
450 |
|
128
|
451 |
|device mm|
|
|
452 |
|
19
|
453 |
tabUnit isNil ifTrue:[
|
128
|
454 |
tabUnit := #col
|
25
|
455 |
].
|
|
456 |
tabUnit == #relative ifTrue:[
|
128
|
457 |
^ unitReference width
|
19
|
458 |
].
|
|
459 |
tabUnit == #col ifTrue:[
|
128
|
460 |
^ aGC font width
|
19
|
461 |
].
|
189
|
462 |
device := aGC graphicsDevice.
|
19
|
463 |
tabUnit == #inch ifTrue:[
|
128
|
464 |
^ device horizontalPixelPerInch
|
19
|
465 |
].
|
128
|
466 |
mm := device horizontalPixelPerMillimeter.
|
19
|
467 |
tabUnit == #mm ifTrue:[
|
128
|
468 |
^ mm
|
19
|
469 |
].
|
|
470 |
tabUnit == #cm ifTrue:[
|
128
|
471 |
^ mm * 10
|
19
|
472 |
].
|
|
473 |
"
|
|
474 |
assume pixels
|
|
475 |
"
|
|
476 |
^ 1.
|
128
|
477 |
|
327
|
478 |
"Modified: 28.3.1997 / 14:52:12 / cg"
|
19
|
479 |
!
|
|
480 |
|
|
481 |
positionOfTab:index forString:aString on:aGC
|
25
|
482 |
"return the position (in device units) of the string to be drawn
|
|
483 |
at position index."
|
|
484 |
|
19
|
485 |
|pos type idx left|
|
|
486 |
|
|
487 |
pos := self positionOfTab:index on:aGC.
|
|
488 |
pos isNil ifTrue:[^ nil].
|
|
489 |
|
28
|
490 |
type := self typeOfTab:index.
|
19
|
491 |
|
|
492 |
type == #right ifTrue:[
|
25
|
493 |
^ pos - (aGC font widthOf:aString).
|
19
|
494 |
].
|
|
495 |
type == #center ifTrue:[
|
25
|
496 |
^ pos - ((aGC font widthOf:aString) // 2).
|
19
|
497 |
].
|
|
498 |
type == #decimal ifTrue:[
|
25
|
499 |
idx := aString indexOf:$..
|
|
500 |
idx == 0 ifTrue:[
|
|
501 |
^ pos - (aGC font widthOf:aString).
|
|
502 |
].
|
|
503 |
left := aString copyTo:(idx-1).
|
|
504 |
^ pos - (aGC font widthOf:left).
|
19
|
505 |
].
|
|
506 |
"default is left"
|
|
507 |
^ pos
|
|
508 |
!
|
|
509 |
|
97
|
510 |
positionOfTab:index on:aGC
|
|
511 |
"return the position (in device units) of the tab at index"
|
25
|
512 |
|
97
|
513 |
|unit pos|
|
25
|
514 |
|
97
|
515 |
tabPositions isNil ifTrue:[^ nil].
|
19
|
516 |
|
97
|
517 |
unit := self pixelsPerUnitOn:aGC.
|
4477
|
518 |
pos := ((tabPositions at:index) * unit) asInteger.
|
97
|
519 |
^ pos
|
19
|
520 |
!
|
|
521 |
|
97
|
522 |
typeOfTab:index
|
|
523 |
"return the type of the tab at position index."
|
28
|
524 |
|
97
|
525 |
tabPositions isNil ifTrue:[^ #left].
|
|
526 |
tabTypes notNil ifTrue:[
|
|
527 |
(tabTypes isMemberOf:Symbol) ifTrue:[
|
|
528 |
^ tabTypes
|
|
529 |
].
|
|
530 |
^ tabTypes at:index.
|
|
531 |
].
|
|
532 |
"default is left"
|
|
533 |
^ #left
|
327
|
534 |
!
|
|
535 |
|
|
536 |
unitsPerPixelOn:aGC
|
|
537 |
"return the number of units that one device pixels
|
|
538 |
takes on aGC"
|
|
539 |
|
|
540 |
^ 1 / (self pixelsPerUnitOn:aGC)
|
|
541 |
|
|
542 |
"Modified: 28.3.1997 / 14:52:01 / cg"
|
19
|
543 |
! !
|
|
544 |
|
98
|
545 |
!TabulatorSpecification class methodsFor:'documentation'!
|
|
546 |
|
|
547 |
version
|
4477
|
548 |
^ '$Header: /cvs/stx/stx/libwidg2/TabulatorSpecification.st,v 1.16 2014-01-27 16:06:18 stefan Exp $'
|
98
|
549 |
! !
|
4477
|
550 |
|