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