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 |
|
|
13 |
Object subclass:#TabulatorSpecification
|
128
|
14 |
instanceVariableNames:'tabUnit unitReference tabPositions tabTypes'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Support'
|
19
|
18 |
!
|
|
19 |
|
25
|
20 |
!TabulatorSpecification class methodsFor:'documentation'!
|
|
21 |
|
28
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
25
|
36 |
documentation
|
|
37 |
"
|
|
38 |
This is a helper class for table widgets and tabular data in
|
|
39 |
lists.
|
|
40 |
A tabulatorSpecification keeps track of where the tabs are,
|
36
|
41 |
and how they align. They are to be used in conjunction with
|
|
42 |
MultiColumnListEntry or the upcoming TableWidget.
|
|
43 |
However, they may also be useful to represent tabs in a
|
|
44 |
paragraph of text.
|
158
|
45 |
|
|
46 |
|
|
47 |
[author:]
|
|
48 |
Claus Gittinger
|
|
49 |
|
|
50 |
[see also:]
|
|
51 |
Ruler
|
|
52 |
ListView
|
28
|
53 |
"
|
|
54 |
!
|
25
|
55 |
|
28
|
56 |
examples
|
|
57 |
"
|
25
|
58 |
Example use (in a ListView):
|
161
|
59 |
[exBegin]
|
|
60 |
|listView tabSpec entry|
|
25
|
61 |
|
161
|
62 |
listView := ListView new.
|
25
|
63 |
|
161
|
64 |
tabSpec := TabulatorSpecification new.
|
|
65 |
tabSpec unit:#inch.
|
|
66 |
tabSpec positions:#(0 1 2.5 3.5 4 5 ).
|
|
67 |
tabSpec align: #(#left #left #right #right #center #decimal ).
|
25
|
68 |
|
161
|
69 |
entry := MultiColListEntry new.
|
|
70 |
entry tabulatorSpecification:tabSpec.
|
|
71 |
entry colAt:1 put:'left';
|
|
72 |
colAt:2 put:'left';
|
|
73 |
colAt:3 put:'right';
|
|
74 |
colAt:4 put:'right';
|
|
75 |
colAt:5 put:'center';
|
|
76 |
colAt:6 put:'.decimal'.
|
25
|
77 |
|
161
|
78 |
listView at:1 put:entry.
|
25
|
79 |
|
161
|
80 |
entry := MultiColListEntry new.
|
|
81 |
entry tabulatorSpecification:tabSpec.
|
|
82 |
entry colAt:1 put:'col1';
|
|
83 |
colAt:2 put:'col2';
|
|
84 |
colAt:3 put:'col3';
|
|
85 |
colAt:4 put:'col4';
|
|
86 |
colAt:5 put:'col5';
|
|
87 |
colAt:6 put:'col6.decimal'.
|
25
|
88 |
|
161
|
89 |
listView at:2 put:entry.
|
25
|
90 |
|
161
|
91 |
entry := MultiColListEntry new.
|
|
92 |
entry tabulatorSpecification:tabSpec.
|
|
93 |
entry colAt:1 put:'foo';
|
|
94 |
colAt:2 put:'fooBar';
|
|
95 |
colAt:3 put:'bar';
|
|
96 |
colAt:4 put:'barFoo';
|
|
97 |
colAt:5 put:'baz';
|
|
98 |
colAt:6 put:'1234.56'.
|
25
|
99 |
|
161
|
100 |
listView at:3 put:entry.
|
|
101 |
listView open
|
|
102 |
[exEnd]
|
25
|
103 |
|
28
|
104 |
|
|
105 |
defining field positions in millimeter :
|
161
|
106 |
[exBegin]
|
|
107 |
|listView tabSpec entry|
|
28
|
108 |
|
161
|
109 |
listView := ListView new.
|
28
|
110 |
|
161
|
111 |
tabSpec := TabulatorSpecification new.
|
|
112 |
tabSpec unit:#mm.
|
|
113 |
tabSpec positions:#(0 10 20 40).
|
|
114 |
tabSpec align: #left.
|
28
|
115 |
|
161
|
116 |
entry := MultiColListEntry new.
|
|
117 |
entry tabulatorSpecification:tabSpec.
|
|
118 |
entry colAt:1 put:'1';
|
|
119 |
colAt:2 put:'2';
|
|
120 |
colAt:3 put:'3';
|
|
121 |
colAt:4 put:'4'.
|
28
|
122 |
|
161
|
123 |
listView at:1 put:entry.
|
28
|
124 |
|
161
|
125 |
entry := MultiColListEntry new.
|
|
126 |
entry tabulatorSpecification:tabSpec.
|
|
127 |
entry colAt:1 put:'aa';
|
|
128 |
colAt:2 put:'bb';
|
|
129 |
colAt:3 put:'cc';
|
|
130 |
colAt:4 put:'dd'.
|
28
|
131 |
|
161
|
132 |
listView at:2 put:entry.
|
28
|
133 |
|
161
|
134 |
listView open
|
|
135 |
[exEnd]
|
28
|
136 |
|
|
137 |
defining field widths in millimeter :
|
161
|
138 |
[exBegin]
|
|
139 |
|listView tabSpec entry|
|
28
|
140 |
|
161
|
141 |
listView := ListView new.
|
28
|
142 |
|
161
|
143 |
tabSpec := TabulatorSpecification new.
|
|
144 |
tabSpec unit:#mm.
|
|
145 |
tabSpec widths:#(10 10 20 10).
|
|
146 |
tabSpec align: #left.
|
28
|
147 |
|
161
|
148 |
entry := MultiColListEntry new.
|
|
149 |
entry tabulatorSpecification:tabSpec.
|
|
150 |
entry colAt:1 put:'1';
|
|
151 |
colAt:2 put:'2';
|
|
152 |
colAt:3 put:'3';
|
|
153 |
colAt:4 put:'4'.
|
28
|
154 |
|
161
|
155 |
listView at:1 put:entry.
|
28
|
156 |
|
161
|
157 |
entry := MultiColListEntry new.
|
|
158 |
entry tabulatorSpecification:tabSpec.
|
|
159 |
entry colAt:1 put:'aa';
|
|
160 |
colAt:2 put:'bb';
|
|
161 |
colAt:3 put:'cc';
|
|
162 |
colAt:4 put:'dd'.
|
28
|
163 |
|
161
|
164 |
listView at:2 put:entry.
|
28
|
165 |
|
161
|
166 |
listView open
|
|
167 |
[exEnd]
|
28
|
168 |
|
|
169 |
defining field widths in pixels :
|
161
|
170 |
[exBegin]
|
|
171 |
|listView tabSpec entry|
|
28
|
172 |
|
161
|
173 |
listView := ListView new.
|
28
|
174 |
|
161
|
175 |
tabSpec := TabulatorSpecification new.
|
|
176 |
tabSpec unit:#pixel.
|
|
177 |
tabSpec widths:#(50 30 30 50).
|
|
178 |
tabSpec align: #left.
|
28
|
179 |
|
161
|
180 |
entry := MultiColListEntry new.
|
|
181 |
entry tabulatorSpecification:tabSpec.
|
|
182 |
entry colAt:1 put:'1';
|
|
183 |
colAt:2 put:'2';
|
|
184 |
colAt:3 put:'3';
|
|
185 |
colAt:4 put:'4'.
|
28
|
186 |
|
161
|
187 |
listView at:1 put:entry.
|
28
|
188 |
|
161
|
189 |
entry := MultiColListEntry new.
|
|
190 |
entry tabulatorSpecification:tabSpec.
|
|
191 |
entry colAt:1 put:'aa';
|
|
192 |
colAt:2 put:'bb';
|
|
193 |
colAt:3 put:'cc';
|
|
194 |
colAt:4 put:'dd'.
|
28
|
195 |
|
161
|
196 |
listView at:2 put:entry.
|
28
|
197 |
|
161
|
198 |
listView open
|
|
199 |
[exEnd]
|
25
|
200 |
"
|
|
201 |
! !
|
|
202 |
|
70
|
203 |
!TabulatorSpecification class methodsFor:'instance creation'!
|
|
204 |
|
|
205 |
unit:unit positions:positions
|
|
206 |
^ (self new) unit:unit; positions:positions
|
|
207 |
|
|
208 |
"
|
|
209 |
TabulatorSpecification unit:#inch positions:#(0 3)
|
|
210 |
"
|
|
211 |
|
|
212 |
"Modified: 30.8.1995 / 16:37:50 / claus"
|
|
213 |
! !
|
|
214 |
|
97
|
215 |
!TabulatorSpecification methodsFor:'accessing'!
|
|
216 |
|
|
217 |
align
|
|
218 |
"return the align-vector"
|
|
219 |
|
|
220 |
^ tabTypes
|
|
221 |
!
|
|
222 |
|
|
223 |
align:types
|
|
224 |
"
|
|
225 |
an array of tab-types; each one is
|
|
226 |
#left
|
|
227 |
#right
|
|
228 |
#center
|
|
229 |
#decimal
|
|
230 |
or a symbol which gives align of all tabs
|
|
231 |
|
|
232 |
"
|
|
233 |
tabTypes := types
|
|
234 |
!
|
|
235 |
|
|
236 |
positions
|
|
237 |
"return the position-vector"
|
|
238 |
|
|
239 |
^ tabPositions
|
|
240 |
!
|
|
241 |
|
|
242 |
positions:tabs
|
|
243 |
"set the position-vector"
|
|
244 |
|
|
245 |
tabPositions := tabs
|
|
246 |
!
|
|
247 |
|
|
248 |
size
|
|
249 |
"return the number of tabs in this spec"
|
|
250 |
|
|
251 |
^ tabPositions size
|
|
252 |
!
|
|
253 |
|
|
254 |
unit
|
|
255 |
"return the unit"
|
|
256 |
|
|
257 |
^ tabUnit
|
|
258 |
!
|
|
259 |
|
|
260 |
unit:aSymbol
|
|
261 |
"set the unit.
|
|
262 |
allowed are: #inch, #mm, #cm, #pixel and #col"
|
|
263 |
|
|
264 |
tabUnit := aSymbol
|
|
265 |
!
|
|
266 |
|
|
267 |
unitRelativeTo:someObject
|
|
268 |
"set for a relative unit. someObject should return its width
|
|
269 |
and the tabs are set fraction-relative to this number (in pixel)."
|
|
270 |
|
|
271 |
tabUnit := #relative.
|
|
272 |
unitReference := someObject
|
|
273 |
!
|
|
274 |
|
|
275 |
widths
|
|
276 |
"return a width-vector"
|
|
277 |
|
|
278 |
|prev|
|
|
279 |
|
|
280 |
prev := 0.
|
|
281 |
^ tabPositions collect:[:p | |w| w := p - prev. prev := p. w].
|
|
282 |
|
|
283 |
"
|
|
284 |
|spec|
|
|
285 |
|
|
286 |
spec := TabulatorSpecification new.
|
|
287 |
spec unit:#inch.
|
|
288 |
spec positions:#(0 1 2.5 3.5 4 5 ).
|
|
289 |
spec align: #(#left #left #right #right #center #decimal ).
|
|
290 |
spec widths
|
|
291 |
"
|
|
292 |
!
|
|
293 |
|
|
294 |
widths:fieldWidths
|
|
295 |
"set the position-vector from a vector of field widths"
|
|
296 |
|
|
297 |
|pos|
|
|
298 |
|
|
299 |
pos := 0.
|
|
300 |
tabPositions := fieldWidths collect:[:w |
|
|
301 |
|p|
|
|
302 |
|
|
303 |
p := pos.
|
|
304 |
pos := pos + w.
|
|
305 |
p].
|
|
306 |
! !
|
|
307 |
|
19
|
308 |
!TabulatorSpecification methodsFor:'queries'!
|
|
309 |
|
|
310 |
pixelsPerUnitOn:aGC
|
128
|
311 |
|device mm|
|
|
312 |
|
19
|
313 |
"
|
|
314 |
return the number of device pixels one unit of my tabs
|
|
315 |
takes on aGC
|
|
316 |
"
|
|
317 |
tabUnit isNil ifTrue:[
|
128
|
318 |
tabUnit := #col
|
25
|
319 |
].
|
|
320 |
tabUnit == #relative ifTrue:[
|
128
|
321 |
^ unitReference width
|
19
|
322 |
].
|
|
323 |
tabUnit == #col ifTrue:[
|
128
|
324 |
^ aGC font width
|
19
|
325 |
].
|
128
|
326 |
device := aGC device.
|
19
|
327 |
tabUnit == #inch ifTrue:[
|
128
|
328 |
^ device horizontalPixelPerInch
|
19
|
329 |
].
|
128
|
330 |
mm := device horizontalPixelPerMillimeter.
|
19
|
331 |
tabUnit == #mm ifTrue:[
|
128
|
332 |
^ mm
|
19
|
333 |
].
|
|
334 |
tabUnit == #cm ifTrue:[
|
128
|
335 |
^ mm * 10
|
19
|
336 |
].
|
|
337 |
"
|
|
338 |
assume pixels
|
|
339 |
"
|
|
340 |
^ 1.
|
128
|
341 |
|
|
342 |
"Modified: 22.2.1996 / 16:48:44 / cg"
|
19
|
343 |
!
|
|
344 |
|
|
345 |
positionOfTab:index forString:aString on:aGC
|
25
|
346 |
"return the position (in device units) of the string to be drawn
|
|
347 |
at position index."
|
|
348 |
|
19
|
349 |
|pos type idx left|
|
|
350 |
|
|
351 |
pos := self positionOfTab:index on:aGC.
|
|
352 |
pos isNil ifTrue:[^ nil].
|
|
353 |
|
28
|
354 |
type := self typeOfTab:index.
|
19
|
355 |
|
|
356 |
type == #right ifTrue:[
|
25
|
357 |
^ pos - (aGC font widthOf:aString).
|
19
|
358 |
].
|
|
359 |
type == #center ifTrue:[
|
25
|
360 |
^ pos - ((aGC font widthOf:aString) // 2).
|
19
|
361 |
].
|
|
362 |
type == #decimal ifTrue:[
|
25
|
363 |
idx := aString indexOf:$..
|
|
364 |
idx == 0 ifTrue:[
|
|
365 |
^ pos - (aGC font widthOf:aString).
|
|
366 |
].
|
|
367 |
left := aString copyTo:(idx-1).
|
|
368 |
^ pos - (aGC font widthOf:left).
|
19
|
369 |
].
|
|
370 |
"default is left"
|
|
371 |
^ pos
|
|
372 |
!
|
|
373 |
|
97
|
374 |
positionOfTab:index on:aGC
|
|
375 |
"return the position (in device units) of the tab at index"
|
25
|
376 |
|
97
|
377 |
|unit pos|
|
25
|
378 |
|
97
|
379 |
tabPositions isNil ifTrue:[^ nil].
|
19
|
380 |
|
97
|
381 |
unit := self pixelsPerUnitOn:aGC.
|
|
382 |
pos := ((tabPositions at:index) * unit).
|
|
383 |
^ pos
|
19
|
384 |
!
|
|
385 |
|
97
|
386 |
typeOfTab:index
|
|
387 |
"return the type of the tab at position index."
|
28
|
388 |
|
97
|
389 |
tabPositions isNil ifTrue:[^ #left].
|
|
390 |
tabTypes notNil ifTrue:[
|
|
391 |
(tabTypes isMemberOf:Symbol) ifTrue:[
|
|
392 |
^ tabTypes
|
|
393 |
].
|
|
394 |
^ tabTypes at:index.
|
|
395 |
].
|
|
396 |
"default is left"
|
|
397 |
^ #left
|
19
|
398 |
! !
|
|
399 |
|
98
|
400 |
!TabulatorSpecification class methodsFor:'documentation'!
|
|
401 |
|
|
402 |
version
|
161
|
403 |
^ '$Header: /cvs/stx/stx/libwidg2/TabulatorSpecification.st,v 1.11 1996-04-27 18:22:36 cg Exp $'
|
98
|
404 |
! !
|