2467
|
1 |
"{ Package: 'stx:libwidg2' }"
|
|
2 |
|
4870
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
741
|
5 |
View subclass:#GraphColumnView
|
754
|
6 |
instanceVariableNames:'columns listHolder references referenceHolder referenceSelector
|
|
7 |
referenceColor showReferences zoomY zoomYHolder oldMenuMessage
|
|
8 |
windowSize windowSizeHolder gridColor showGrid fgColor bgColor
|
|
9 |
scrollUpdatesOriginX graphOriginX graphOriginXHolder'
|
741
|
10 |
classVariableNames:'DefaultBackgroundColor DefaultGridColor DefaultForegroundColor
|
754
|
11 |
DefaultReferenceColor'
|
741
|
12 |
poolDictionaries:''
|
|
13 |
category:'Views-Graphs'
|
|
14 |
!
|
|
15 |
|
749
|
16 |
!GraphColumnView class methodsFor:'documentation'!
|
|
17 |
|
|
18 |
documentation
|
|
19 |
"
|
|
20 |
The class describes the common interface supported by the 2D or 3D GraphColumnView.
|
|
21 |
This Viewclasses provide a lot of functionality for showing and manipulating graphs
|
|
22 |
described through to a GraphColumn description. Each change in a graph description
|
|
23 |
immediately take affect in the garph view.
|
|
24 |
|
|
25 |
|
|
26 |
[See also:]
|
|
27 |
GraphColumn
|
|
28 |
GraphColumnView2D
|
|
29 |
GraphColumnView3D
|
|
30 |
|
|
31 |
[Author:]
|
|
32 |
Claus Atzkern
|
|
33 |
"
|
|
34 |
|
|
35 |
! !
|
741
|
36 |
|
|
37 |
!GraphColumnView class methodsFor:'defaults'!
|
|
38 |
|
|
39 |
defaultMenu
|
|
40 |
"redefined by subclass: should return the default middle button menu
|
|
41 |
"
|
|
42 |
^ nil
|
|
43 |
!
|
|
44 |
|
|
45 |
updateStyleCache
|
|
46 |
"extract values from the styleSheet and cache them in class variables
|
|
47 |
"
|
|
48 |
DefaultForegroundColor := Color black.
|
754
|
49 |
DefaultReferenceColor := Color darkGray.
|
741
|
50 |
DefaultGridColor := Color lightGray.
|
754
|
51 |
DefaultBackgroundColor := Color veryLightGray.
|
741
|
52 |
"
|
|
53 |
self updateStyleCache
|
|
54 |
"
|
|
55 |
|
|
56 |
! !
|
|
57 |
|
|
58 |
!GraphColumnView methodsFor:'accessing'!
|
|
59 |
|
|
60 |
columns
|
749
|
61 |
"returns the list of column descriptions
|
741
|
62 |
"
|
|
63 |
^ columns
|
|
64 |
|
|
65 |
|
|
66 |
!
|
|
67 |
|
|
68 |
columns:aList
|
749
|
69 |
"set the list of columns descriptions
|
741
|
70 |
"
|
|
71 |
columns notNil ifTrue:[
|
|
72 |
columns do:[:aCol| aCol removeDependent:self ]
|
|
73 |
].
|
|
74 |
|
|
75 |
aList size ~~ 0 ifTrue:[
|
|
76 |
columns := OrderedCollection new.
|
|
77 |
|
|
78 |
aList do:[:aColumn|
|
|
79 |
aColumn addDependent:self.
|
|
80 |
columns add:aColumn
|
|
81 |
]
|
|
82 |
] ifFalse:[
|
|
83 |
columns := nil
|
|
84 |
].
|
754
|
85 |
self doRecomputeGraph
|
741
|
86 |
!
|
|
87 |
|
749
|
88 |
graphOriginX
|
|
89 |
"returns the logical index X of the first visible row; this number is used for
|
|
90 |
accessing Y values from the GraphColumn description. On default, the value
|
|
91 |
is set to 1.
|
|
92 |
"
|
|
93 |
^ graphOriginX
|
|
94 |
|
|
95 |
|
|
96 |
!
|
|
97 |
|
|
98 |
graphOriginX:aNumber
|
|
99 |
"set the logical index X of the first visible row; this number is used for
|
|
100 |
accessing Y values from the GraphColumn description. On default, the value
|
|
101 |
is set to 1.
|
|
102 |
Changing the number, a scroll left or right is triggered.
|
|
103 |
"
|
|
104 |
|newX state|
|
|
105 |
|
|
106 |
aNumber isNumber ifTrue:[
|
|
107 |
newX := aNumber isInteger ifTrue:[aNumber]
|
|
108 |
ifFalse:[(aNumber asFloat) rounded]. "/ no fractions
|
|
109 |
|
|
110 |
newX ~~ graphOriginX ifTrue:[
|
|
111 |
state := scrollUpdatesOriginX.
|
|
112 |
scrollUpdatesOriginX := true.
|
|
113 |
self scroll:(graphOriginX - newX).
|
|
114 |
scrollUpdatesOriginX := state.
|
|
115 |
]
|
|
116 |
]
|
|
117 |
!
|
|
118 |
|
754
|
119 |
referenceSelector
|
|
120 |
"returns the selector how to access the X value of an instance into
|
|
121 |
the reference list. If the selector is nil (default), the entry is
|
|
122 |
assumed to be the X value.
|
|
123 |
"
|
|
124 |
^ referenceSelector
|
|
125 |
!
|
|
126 |
|
|
127 |
referenceSelector:aSelector
|
|
128 |
"set the selector how to access the X value of an instance into the
|
|
129 |
reference list. If the selector is nil (default), the entry is
|
|
130 |
assumed to be the X value.
|
|
131 |
"
|
|
132 |
referenceSelector := (aSelector size == 0) ifTrue:[ #value ]
|
|
133 |
ifFalse:[ aSelector asSymbol ]
|
|
134 |
!
|
|
135 |
|
|
136 |
references
|
|
137 |
"returns list of references
|
|
138 |
"
|
|
139 |
^ references
|
|
140 |
|
|
141 |
|
|
142 |
!
|
|
143 |
|
|
144 |
references:aListOfReferences
|
|
145 |
"change the list of references
|
|
146 |
"
|
|
147 |
aListOfReferences size == 0 ifTrue:[
|
|
148 |
references isEmpty ifTrue:[
|
|
149 |
^ self "/ nothing changed
|
|
150 |
].
|
|
151 |
references := OrderedCollection new.
|
|
152 |
] ifFalse:[
|
|
153 |
references := OrderedCollection new.
|
|
154 |
aListOfReferences do:[:i| references add:i ]
|
|
155 |
].
|
|
156 |
self updateReferences:#size atRelX:nil
|
|
157 |
!
|
|
158 |
|
749
|
159 |
scrollUpdatesOriginX
|
|
160 |
"returns true, if the graphOriginX automatically is updated by
|
|
161 |
any scroll action. The default is set to false.
|
|
162 |
"
|
|
163 |
^ scrollUpdatesOriginX
|
|
164 |
!
|
|
165 |
|
|
166 |
scrollUpdatesOriginX:aBool
|
|
167 |
"set to true if the graphOriginX automatically should be updated by any
|
|
168 |
scroll action. Otherwise a scroll has no influnce to the current
|
|
169 |
graphOriginX.
|
|
170 |
The default is set to false.
|
|
171 |
"
|
|
172 |
scrollUpdatesOriginX := aBool
|
|
173 |
!
|
|
174 |
|
741
|
175 |
showDefaultMenu
|
749
|
176 |
"returns true, if the middleButton menu is set to the default menu
|
|
177 |
provided by the graph.
|
741
|
178 |
"
|
|
179 |
^ self menuMessage == #defaultMenu
|
|
180 |
!
|
|
181 |
|
|
182 |
showDefaultMenu:aBool
|
749
|
183 |
"enable or disable the default menu provided by the graph
|
741
|
184 |
"
|
|
185 |
|currMsg|
|
|
186 |
|
|
187 |
currMsg := self menuMessage.
|
|
188 |
|
|
189 |
aBool ifTrue:[
|
|
190 |
oldMenuMessage := currMsg.
|
|
191 |
self menuMessage:#defaultMenu
|
|
192 |
] ifFalse:[
|
|
193 |
currMsg == #defaultMenu ifTrue:[
|
|
194 |
self menuMessage:oldMenuMessage
|
|
195 |
]
|
|
196 |
].
|
|
197 |
|
|
198 |
|
|
199 |
! !
|
|
200 |
|
|
201 |
!GraphColumnView methodsFor:'accessing dimensions'!
|
|
202 |
|
|
203 |
windowSize
|
749
|
204 |
"get the number of horizontal steps ( X )
|
741
|
205 |
"
|
|
206 |
^ windowSize
|
|
207 |
|
|
208 |
|
|
209 |
!
|
|
210 |
|
|
211 |
windowSize:aValue
|
749
|
212 |
"set the number of horizontal steps ( X )
|
741
|
213 |
"
|
|
214 |
|sz|
|
|
215 |
|
754
|
216 |
sz := (self unsignedIntegerFrom:aValue onError:[101]) max:2.
|
741
|
217 |
|
|
218 |
sz ~~ windowSize ifTrue:[
|
|
219 |
windowSize := sz.
|
754
|
220 |
self doRecomputeGraph
|
741
|
221 |
]
|
|
222 |
|
|
223 |
!
|
|
224 |
|
|
225 |
zoomY
|
|
226 |
"returns current y-zoom factor
|
|
227 |
"
|
|
228 |
^ zoomY
|
|
229 |
|
|
230 |
|
|
231 |
!
|
|
232 |
|
|
233 |
zoomY:aValue
|
749
|
234 |
"set the current y-zoom factor; if the argument is nil,
|
|
235 |
the y-zoom is set to 1.
|
741
|
236 |
"
|
|
237 |
|zY|
|
|
238 |
|
|
239 |
(zY := self floatFrom:aValue onError:[1]) <= 0 ifTrue:[
|
|
240 |
zY := 1
|
|
241 |
].
|
|
242 |
|
|
243 |
zY = zoomY ifFalse:[
|
|
244 |
zoomY := zY.
|
754
|
245 |
self doInvalidateGraph
|
741
|
246 |
]
|
|
247 |
|
|
248 |
|
|
249 |
! !
|
|
250 |
|
|
251 |
!GraphColumnView methodsFor:'accessing look'!
|
|
252 |
|
|
253 |
backgroundColor
|
749
|
254 |
"returns the current background color of the graph
|
741
|
255 |
"
|
|
256 |
^ bgColor
|
|
257 |
|
|
258 |
|
|
259 |
!
|
|
260 |
|
|
261 |
backgroundColor:aColor
|
749
|
262 |
"set the background color of the graph
|
741
|
263 |
"
|
|
264 |
(aColor isColor and:[bgColor ~= aColor]) ifTrue:[
|
|
265 |
shown ifTrue:[
|
4870
|
266 |
bgColor := aColor onDevice:device.
|
754
|
267 |
self doInvalidateGraph
|
741
|
268 |
] ifFalse:[
|
|
269 |
bgColor := aColor
|
|
270 |
]
|
|
271 |
]
|
|
272 |
!
|
|
273 |
|
|
274 |
foregroundColor
|
749
|
275 |
"returns the default foreground color used to draw graphs which
|
|
276 |
has no foreground color specified.
|
741
|
277 |
"
|
|
278 |
^ fgColor
|
|
279 |
|
|
280 |
!
|
|
281 |
|
|
282 |
foregroundColor:aColor
|
749
|
283 |
"set the default foreground color used to draw graphs which
|
|
284 |
has no foreground color specified.
|
741
|
285 |
"
|
|
286 |
(aColor isColor and:[fgColor ~= aColor]) ifTrue:[
|
4870
|
287 |
shown ifTrue:[ fgColor := aColor onDevice:device ]
|
754
|
288 |
ifFalse:[ fgColor := aColor ].
|
|
289 |
|
|
290 |
columns notNil ifTrue:[
|
|
291 |
self updateColumns:#color with:nil from:nil
|
741
|
292 |
]
|
|
293 |
]
|
|
294 |
!
|
|
295 |
|
|
296 |
gridColor
|
749
|
297 |
"returns the foreground color of the grid
|
741
|
298 |
"
|
|
299 |
^ gridColor
|
|
300 |
|
|
301 |
!
|
|
302 |
|
|
303 |
gridColor:aColor
|
|
304 |
"set the foreground color of the grid
|
|
305 |
"
|
|
306 |
(aColor isColor and:[gridColor ~= aColor]) ifTrue:[
|
4870
|
307 |
shown ifTrue:[ gridColor := aColor onDevice:device ]
|
754
|
308 |
ifFalse:[ gridColor := aColor ].
|
|
309 |
|
|
310 |
self updateGrid:#color
|
|
311 |
]
|
|
312 |
!
|
|
313 |
|
|
314 |
referenceColor
|
|
315 |
"returns the foreground color used to draw the references
|
|
316 |
"
|
|
317 |
^ referenceColor
|
741
|
318 |
|
754
|
319 |
|
|
320 |
!
|
|
321 |
|
|
322 |
referenceColor:aColor
|
|
323 |
"set the foreground color used to draw the references
|
|
324 |
"
|
|
325 |
(aColor isColor and:[referenceColor ~= aColor]) ifTrue:[
|
4870
|
326 |
shown ifTrue:[referenceColor := aColor onDevice:device]
|
754
|
327 |
ifFalse:[referenceColor := aColor].
|
|
328 |
|
|
329 |
references notEmpty ifTrue:[
|
|
330 |
self updateReferences:#color atRelX:nil
|
741
|
331 |
]
|
|
332 |
]
|
|
333 |
!
|
|
334 |
|
|
335 |
showGrid
|
749
|
336 |
"returns true if the grid is enabled
|
|
337 |
"
|
741
|
338 |
^ showGrid
|
|
339 |
|
|
340 |
!
|
|
341 |
|
|
342 |
showGrid:aBool
|
749
|
343 |
"set the visibility state of the grid
|
|
344 |
"
|
741
|
345 |
|hasGrid|
|
|
346 |
|
|
347 |
showGrid ~~ aBool ifTrue:[
|
|
348 |
showGrid := aBool.
|
813
|
349 |
self updateGrid:#state
|
741
|
350 |
]
|
|
351 |
|
|
352 |
!
|
|
353 |
|
754
|
354 |
showReferences
|
|
355 |
"returns the visibility state of the references
|
741
|
356 |
"
|
754
|
357 |
^ showReferences
|
741
|
358 |
|
|
359 |
!
|
|
360 |
|
754
|
361 |
showReferences:aBool
|
|
362 |
"set the visibility state of the references
|
741
|
363 |
"
|
754
|
364 |
|hasGrid|
|
|
365 |
|
|
366 |
showReferences ~~ aBool ifTrue:[
|
|
367 |
showReferences := aBool.
|
|
368 |
|
|
369 |
references notEmpty ifTrue:[
|
|
370 |
self updateReferences:#state atRelX:nil
|
741
|
371 |
]
|
|
372 |
]
|
|
373 |
! !
|
|
374 |
|
|
375 |
!GraphColumnView methodsFor:'accessing mvc'!
|
|
376 |
|
749
|
377 |
graphOriginXHolder
|
|
378 |
"returns the valueHolder, which keeps the current graphOriginX (see: #graphOriginX:)
|
|
379 |
"
|
|
380 |
^ graphOriginXHolder
|
|
381 |
!
|
|
382 |
|
|
383 |
graphOriginXHolder:aHolder
|
|
384 |
"set the valueHolder, which keeps the current graphOriginX (see: #graphOriginX:)
|
|
385 |
"
|
|
386 |
graphOriginXHolder == aHolder ifFalse:[
|
|
387 |
graphOriginXHolder notNil ifTrue:[
|
|
388 |
graphOriginXHolder removeDependent:self
|
|
389 |
].
|
|
390 |
(graphOriginXHolder := aHolder) notNil ifTrue:[
|
|
391 |
graphOriginXHolder addDependent:self
|
|
392 |
].
|
|
393 |
].
|
|
394 |
self graphOriginX:(graphOriginXHolder value)
|
|
395 |
|
|
396 |
!
|
|
397 |
|
741
|
398 |
listHolder
|
749
|
399 |
"returns the valueHolder, which keeps the list of column descriptions (see: #column:)
|
741
|
400 |
"
|
|
401 |
^ listHolder
|
|
402 |
|
|
403 |
|
|
404 |
!
|
|
405 |
|
|
406 |
listHolder:aHolder
|
749
|
407 |
"set the valueHolder, which keeps the list of column descriptions (see: #column:)
|
741
|
408 |
"
|
|
409 |
listHolder == aHolder ifFalse:[
|
|
410 |
listHolder notNil ifTrue:[
|
|
411 |
listHolder removeDependent:self
|
|
412 |
].
|
|
413 |
(listHolder := aHolder) notNil ifTrue:[
|
|
414 |
listHolder addDependent:self
|
|
415 |
].
|
|
416 |
].
|
|
417 |
self columns:(listHolder value)
|
|
418 |
|
|
419 |
!
|
|
420 |
|
|
421 |
model:aModel
|
|
422 |
"set the valueHolder which holds the selection and maybe the list of columnms
|
|
423 |
"
|
|
424 |
(model respondsTo:#list) ifTrue:[
|
|
425 |
(model list == listHolder) ifTrue:[
|
|
426 |
self listHolder:nil
|
|
427 |
]
|
|
428 |
].
|
|
429 |
super model:aModel.
|
|
430 |
|
|
431 |
aModel notNil ifTrue:[
|
|
432 |
(aModel respondsTo:#list) ifTrue:[
|
|
433 |
self listHolder:model list
|
|
434 |
]
|
|
435 |
]
|
|
436 |
|
|
437 |
!
|
|
438 |
|
754
|
439 |
referenceHolder
|
|
440 |
"returns the valueHolder, which keeps the list of references (see: #references:)
|
749
|
441 |
"
|
754
|
442 |
^ referenceHolder
|
749
|
443 |
|
|
444 |
|
|
445 |
!
|
|
446 |
|
754
|
447 |
referenceHolder:aHolder
|
|
448 |
"set the valueHolder, which keeps the list of references (see: #references:)
|
749
|
449 |
"
|
754
|
450 |
referenceHolder == aHolder ifFalse:[
|
|
451 |
referenceHolder notNil ifTrue:[
|
|
452 |
referenceHolder removeDependent:self
|
749
|
453 |
].
|
754
|
454 |
(referenceHolder := aHolder) notNil ifTrue:[
|
|
455 |
referenceHolder addDependent:self
|
749
|
456 |
].
|
|
457 |
].
|
754
|
458 |
self references:(referenceHolder value)
|
749
|
459 |
|
|
460 |
!
|
|
461 |
|
741
|
462 |
windowSizeHolder
|
749
|
463 |
"returns the valueHolder, which keeps the windowSize (see: #windowSize:)
|
741
|
464 |
"
|
|
465 |
^ windowSizeHolder
|
|
466 |
|
|
467 |
!
|
|
468 |
|
|
469 |
windowSizeHolder:aHolder
|
749
|
470 |
"set the valueHolder, which keeps the windowSize (see: #windowSize:)
|
741
|
471 |
"
|
|
472 |
windowSizeHolder == aHolder ifFalse:[
|
|
473 |
windowSizeHolder notNil ifTrue:[
|
|
474 |
windowSizeHolder removeDependent:self
|
|
475 |
].
|
|
476 |
(windowSizeHolder := aHolder) notNil ifTrue:[
|
|
477 |
windowSizeHolder addDependent:self
|
|
478 |
].
|
|
479 |
].
|
|
480 |
self windowSize:(windowSizeHolder value)
|
|
481 |
|
|
482 |
!
|
|
483 |
|
|
484 |
zoomYHolder
|
749
|
485 |
"returns the valueHolder, which keeps the zoom Y factor (see: #zoomY:)
|
741
|
486 |
"
|
|
487 |
^ zoomYHolder
|
|
488 |
|
|
489 |
!
|
|
490 |
|
|
491 |
zoomYHolder:aHolder
|
749
|
492 |
"set the valueHolder, which keeps the zoom Y factor (see: #zoomY:)
|
741
|
493 |
"
|
|
494 |
zoomYHolder == aHolder ifFalse:[
|
|
495 |
zoomYHolder notNil ifTrue:[
|
|
496 |
zoomYHolder removeDependent:self
|
|
497 |
].
|
|
498 |
(zoomYHolder := aHolder) notNil ifTrue:[
|
|
499 |
zoomYHolder addDependent:self
|
|
500 |
]
|
|
501 |
].
|
|
502 |
self zoomY:(zoomYHolder value).
|
|
503 |
|
|
504 |
! !
|
|
505 |
|
754
|
506 |
!GraphColumnView methodsFor:'add & remove columns'!
|
741
|
507 |
|
|
508 |
add:aColumn
|
|
509 |
"insert a column at end; returns the inserted column
|
|
510 |
"
|
|
511 |
^ self add:aColumn beforeIndex:(1 + columns size)
|
|
512 |
|
|
513 |
!
|
|
514 |
|
|
515 |
add:aColumn afterIndex:anIndex
|
|
516 |
"add a new column after an index; returns the inserted column
|
|
517 |
"
|
|
518 |
^ self add:aColumn beforeIndex:(anIndex + 1)
|
|
519 |
|
|
520 |
!
|
|
521 |
|
|
522 |
add:aColumn beforeIndex:anIndex
|
|
523 |
"add a column before an index; returns the inserted column
|
|
524 |
"
|
|
525 |
aColumn isNil ifTrue:[^ nil].
|
|
526 |
|
|
527 |
columns isNil ifTrue:[
|
|
528 |
self columns:(Array with:aColumn).
|
|
529 |
^ aColumn.
|
|
530 |
].
|
|
531 |
columns add:aColumn beforeIndex:anIndex.
|
|
532 |
aColumn addDependent:self.
|
|
533 |
|
|
534 |
aColumn shown ifTrue:[
|
754
|
535 |
self updateColumns:#insert: with:nil from:aColumn.
|
741
|
536 |
].
|
|
537 |
|
|
538 |
!
|
|
539 |
|
|
540 |
addAll:aCollection beforeIndex:anIndex
|
|
541 |
"add a collection of columns before an index
|
|
542 |
"
|
|
543 |
aCollection size ~~ 0 ifTrue:[
|
|
544 |
columns size == 0 ifTrue:[
|
|
545 |
self columns:aCollection
|
|
546 |
] ifFalse:[
|
|
547 |
columns addAll:aCollection beforeIndex:anIndex.
|
754
|
548 |
self doRecomputeGraph.
|
741
|
549 |
]
|
|
550 |
]
|
|
551 |
|
|
552 |
!
|
|
553 |
|
|
554 |
addFirst:aColumn
|
|
555 |
"insert a column at start; returns the inserted column
|
|
556 |
"
|
|
557 |
^ self add:aColumn beforeIndex:1
|
|
558 |
|
|
559 |
!
|
|
560 |
|
|
561 |
removeAll
|
|
562 |
"remove all columns
|
|
563 |
"
|
|
564 |
self columns:nil
|
|
565 |
|
|
566 |
!
|
|
567 |
|
|
568 |
removeFirst
|
|
569 |
"remove first column; returns the removed column
|
|
570 |
"
|
|
571 |
^ self removeIndex:1
|
|
572 |
|
|
573 |
|
|
574 |
!
|
|
575 |
|
|
576 |
removeIndex:anIndex
|
|
577 |
"remove column at an index; returns the removed column
|
|
578 |
"
|
|
579 |
|col|
|
|
580 |
|
|
581 |
col := columns removeAtIndex:anIndex.
|
|
582 |
col removeDependent:self.
|
|
583 |
|
|
584 |
columns size == 0 ifTrue:[
|
|
585 |
columns := nil
|
|
586 |
].
|
|
587 |
col shown ifTrue:[
|
754
|
588 |
self updateColumns:#remove: with:nil from:col
|
741
|
589 |
].
|
|
590 |
^ col
|
|
591 |
|
|
592 |
|
|
593 |
!
|
|
594 |
|
|
595 |
removeLast
|
|
596 |
"remove last column; the removed column is returned
|
|
597 |
"
|
|
598 |
^ self removeIndex:(columns size)
|
|
599 |
|
|
600 |
! !
|
|
601 |
|
754
|
602 |
!GraphColumnView methodsFor:'add & remove references'!
|
|
603 |
|
|
604 |
referenceAdd:aReference
|
|
605 |
"add a reference to end of list
|
|
606 |
"
|
|
607 |
^ self referenceAdd:aReference beforeIndex:(references size + 1)
|
|
608 |
!
|
|
609 |
|
|
610 |
referenceAdd:aReference beforeIndex:anIndex
|
|
611 |
"add a reference before an index
|
|
612 |
"
|
|
613 |
references add:aReference beforeIndex:anIndex.
|
|
614 |
|
|
615 |
self visibleReference:aReference do:[:x|
|
|
616 |
self updateReferences:#insert: atRelX:x
|
|
617 |
].
|
|
618 |
^ aReference
|
|
619 |
!
|
|
620 |
|
|
621 |
referenceAddAll:aCollection beforeIndex:anIndex
|
|
622 |
"add a collection of references before an index
|
|
623 |
"
|
|
624 |
aCollection size ~~ 0 ifTrue:[
|
|
625 |
references size == 0 ifTrue:[
|
|
626 |
self references:aCollection
|
|
627 |
] ifFalse:[
|
|
628 |
references addAll:aCollection beforeIndex:anIndex.
|
|
629 |
self updateReferences:#size atRelX:nil
|
|
630 |
]
|
|
631 |
]
|
|
632 |
|
|
633 |
!
|
|
634 |
|
|
635 |
referenceRemove:aReference
|
|
636 |
"remove a reference
|
|
637 |
"
|
|
638 |
^ self referenceRemoveIndex:(references identityIndexOf:aReference)
|
|
639 |
|
|
640 |
!
|
|
641 |
|
|
642 |
referenceRemoveAll
|
|
643 |
"remove all references
|
|
644 |
"
|
|
645 |
self references:nil
|
|
646 |
!
|
|
647 |
|
|
648 |
referenceRemoveIndex:anIndex
|
|
649 |
"remove the reference at an index
|
|
650 |
"
|
|
651 |
|aReference|
|
|
652 |
|
|
653 |
aReference := references removeAtIndex:anIndex.
|
|
654 |
|
|
655 |
self visibleReference:aReference do:[:x|
|
|
656 |
self updateReferences:#remove: atRelX:x
|
|
657 |
].
|
|
658 |
^ aReference
|
|
659 |
! !
|
|
660 |
|
741
|
661 |
!GraphColumnView methodsFor:'change & update'!
|
|
662 |
|
|
663 |
update:what with:aPara from:chgObj
|
|
664 |
"catch and handle a change notification of any object
|
|
665 |
"
|
|
666 |
|list start size stop|
|
|
667 |
|
|
668 |
chgObj == windowSizeHolder ifTrue:[
|
|
669 |
^ self windowSize:(windowSizeHolder value)
|
|
670 |
].
|
|
671 |
|
|
672 |
chgObj == zoomYHolder ifTrue:[
|
|
673 |
^ self zoomY:(zoomYHolder value)
|
|
674 |
].
|
|
675 |
|
749
|
676 |
chgObj == graphOriginXHolder ifTrue:[
|
|
677 |
^ self graphOriginX:(graphOriginXHolder value)
|
|
678 |
].
|
|
679 |
|
754
|
680 |
chgObj == referenceHolder ifTrue:[
|
|
681 |
list := chgObj list.
|
|
682 |
|
749
|
683 |
(what == #insert:) ifTrue:[
|
754
|
684 |
^ self referenceAdd:(list at:aPara) beforeIndex:aPara
|
|
685 |
].
|
|
686 |
|
|
687 |
(what == #remove:) ifTrue:[
|
|
688 |
^ self referenceRemoveIndex:aPara
|
|
689 |
].
|
|
690 |
|
|
691 |
(what == #removeFrom:) ifTrue:[
|
|
692 |
chgObj value size == 0 ifTrue:[ ^ self references:nil ].
|
749
|
693 |
|
754
|
694 |
start := aPara first.
|
|
695 |
stop := aPara last.
|
|
696 |
|
|
697 |
(start - stop) == 0 ifTrue:[
|
|
698 |
^ self referenceRemoveIndex:start
|
|
699 |
]
|
|
700 |
] ifFalse:[
|
|
701 |
(what == #insertCollection:) ifTrue:[
|
|
702 |
start := aPara first.
|
|
703 |
size := aPara last.
|
|
704 |
|
|
705 |
size == 1 ifTrue:[
|
|
706 |
^ self referenceAdd:(list at:start) beforeIndex:start
|
|
707 |
].
|
|
708 |
stop := start + size - 1.
|
|
709 |
^ self referenceAddAll:(list copyFrom:start to:stop) beforeIndex:start
|
749
|
710 |
]
|
|
711 |
].
|
754
|
712 |
^ self referenceHolder:chgObj
|
749
|
713 |
].
|
|
714 |
|
741
|
715 |
chgObj == model ifTrue:[
|
|
716 |
(what == #selectionIndex or:[what == #selection]) ifTrue:[
|
|
717 |
^ self
|
|
718 |
].
|
|
719 |
what == #list ifTrue:[
|
|
720 |
^ self listHolder:model list
|
|
721 |
].
|
|
722 |
model == listHolder ifFalse:[
|
|
723 |
^ self
|
|
724 |
].
|
|
725 |
].
|
|
726 |
|
|
727 |
chgObj == listHolder ifTrue:[
|
|
728 |
list := listHolder value.
|
|
729 |
|
754
|
730 |
(what == #insert:) ifTrue:[ ^ self add:(list at:aPara) beforeIndex:aPara ].
|
|
731 |
(what == #remove:) ifTrue:[ ^ self removeIndex:aPara ].
|
|
732 |
|
|
733 |
(what == #insertCollection:) ifTrue:[
|
|
734 |
start := aPara first.
|
|
735 |
size := aPara last.
|
741
|
736 |
|
754
|
737 |
size ~~ 0 ifTrue:[
|
|
738 |
size == 1 ifTrue:[
|
|
739 |
self add:(list at:start) beforeIndex:start
|
741
|
740 |
] ifFalse:[
|
754
|
741 |
stop := start + size - 1.
|
|
742 |
self addAll:(list copyFrom:start to:stop) beforeIndex:start
|
741
|
743 |
]
|
754
|
744 |
].
|
|
745 |
^ self
|
|
746 |
].
|
|
747 |
|
|
748 |
(what == #removeFrom:) ifTrue:[
|
|
749 |
chgObj value size == 0 ifTrue:[
|
|
750 |
^ self columns:nil
|
|
751 |
].
|
|
752 |
start := aPara first.
|
|
753 |
stop := aPara last.
|
|
754 |
|
|
755 |
(start - stop) == 0 ifTrue:[
|
|
756 |
^ self removeIndex:start
|
741
|
757 |
]
|
|
758 |
].
|
754
|
759 |
^ self listHolder:chgObj
|
741
|
760 |
].
|
|
761 |
|
|
762 |
columns notNil ifTrue:[
|
|
763 |
(columns includesIdentical:chgObj) ifTrue:[
|
754
|
764 |
what ~~ #name ifTrue:[
|
|
765 |
^ self updateColumns:what with:aPara from:chgObj
|
|
766 |
]
|
741
|
767 |
]
|
|
768 |
].
|
|
769 |
|
|
770 |
super update:what with:aPara from:chgObj
|
|
771 |
|
|
772 |
! !
|
|
773 |
|
|
774 |
!GraphColumnView methodsFor:'conversion'!
|
|
775 |
|
|
776 |
floatFrom:aValue onError:aBlock
|
749
|
777 |
"converts something to a float, on error the result of the block is returned
|
741
|
778 |
"
|
|
779 |
^ aValue isNumber ifTrue:[aValue asFloat] ifFalse:[aBlock value]
|
|
780 |
!
|
|
781 |
|
|
782 |
unsignedIntegerFrom:aValue onError:aBlock
|
749
|
783 |
"converts something to an unsigned integer, on error the result of the block is returned
|
741
|
784 |
"
|
|
785 |
|v|
|
|
786 |
|
|
787 |
aValue isNumber ifTrue:[
|
|
788 |
v := aValue isInteger ifTrue:[aValue] ifFalse:[(aValue asFloat) rounded]. "/ no fractions
|
|
789 |
|
|
790 |
v >= 0 ifTrue:[ ^ v ]
|
|
791 |
].
|
|
792 |
^ aBlock value
|
|
793 |
! !
|
|
794 |
|
|
795 |
!GraphColumnView methodsFor:'initialization'!
|
|
796 |
|
|
797 |
create
|
2565
|
798 |
"set color on device"
|
|
799 |
|
741
|
800 |
super create.
|
|
801 |
|
2565
|
802 |
fgColor := (fgColor ? DefaultForegroundColor) onDevice:device.
|
|
803 |
bgColor := (bgColor ? DefaultBackgroundColor) onDevice:device.
|
|
804 |
gridColor := (gridColor ? DefaultGridColor) onDevice:device.
|
|
805 |
referenceColor := (referenceColor ? DefaultReferenceColor) onDevice:device.
|
741
|
806 |
!
|
|
807 |
|
|
808 |
destroy
|
|
809 |
"remove dependencies
|
|
810 |
"
|
|
811 |
super destroy.
|
|
812 |
|
749
|
813 |
listHolder removeDependent:self.
|
754
|
814 |
referenceHolder removeDependent:self.
|
749
|
815 |
windowSizeHolder removeDependent:self.
|
|
816 |
zoomYHolder removeDependent:self.
|
|
817 |
graphOriginXHolder removeDependent:self.
|
741
|
818 |
|
|
819 |
columns notNil ifTrue:[
|
|
820 |
columns do:[:aCol| aCol removeDependent:self ]
|
|
821 |
].
|
|
822 |
|
|
823 |
!
|
|
824 |
|
|
825 |
initialize
|
|
826 |
"setup default values
|
|
827 |
"
|
|
828 |
super initialize.
|
|
829 |
|
|
830 |
DefaultGridColor isNil ifTrue:[
|
|
831 |
self class updateStyleCache
|
|
832 |
].
|
|
833 |
|
754
|
834 |
references := OrderedCollection new.
|
|
835 |
windowSize := 101.
|
|
836 |
showGrid := false.
|
|
837 |
showReferences := true.
|
|
838 |
zoomY := 1.
|
|
839 |
graphOriginX := 1.
|
749
|
840 |
scrollUpdatesOriginX := false.
|
741
|
841 |
! !
|
|
842 |
|
|
843 |
!GraphColumnView methodsFor:'menu & submenus'!
|
|
844 |
|
|
845 |
defaultMenu
|
749
|
846 |
"returns the default middle button menu provided by the graph
|
741
|
847 |
"
|
|
848 |
|menu|
|
|
849 |
|
|
850 |
menu := self class defaultMenu decodeAsLiteralArray.
|
749
|
851 |
|
741
|
852 |
menu notNil ifTrue:[
|
|
853 |
menu receiver:self
|
|
854 |
].
|
2467
|
855 |
^ menu
|
741
|
856 |
!
|
|
857 |
|
|
858 |
doZoomY:aValue
|
749
|
859 |
"triggered by the default menu to change the current zoom Y factor;
|
|
860 |
on change, the corresponding model (zoomYHolder) is updated.
|
|
861 |
"
|
741
|
862 |
|old|
|
|
863 |
|
|
864 |
old := self zoomY.
|
|
865 |
self zoomY:aValue.
|
|
866 |
|
|
867 |
self zoomYHolder notNil ifTrue:[
|
|
868 |
zoomYHolder value:(self zoomY)
|
|
869 |
]
|
|
870 |
!
|
|
871 |
|
|
872 |
subMenuZoomY
|
749
|
873 |
"returns the submenu to configure the zoom Y factor
|
741
|
874 |
"
|
|
875 |
^ GraphColumn zoomMenuSelector:#doZoomY:
|
|
876 |
|
|
877 |
|
|
878 |
! !
|
|
879 |
|
|
880 |
!GraphColumnView methodsFor:'protocol'!
|
|
881 |
|
754
|
882 |
doInvalidateGraph
|
|
883 |
"called to set the graph to invalidate
|
|
884 |
"
|
|
885 |
self doRecomputeGraph
|
|
886 |
!
|
|
887 |
|
|
888 |
doRecomputeGraph
|
|
889 |
"called to recompute drawable objects and to set the
|
|
890 |
graph to invalidate
|
|
891 |
"
|
|
892 |
!
|
749
|
893 |
|
754
|
894 |
updateColumns:what with:oldValue from:aColumn
|
|
895 |
"called if the list of columns changed
|
|
896 |
#size the size of the columns
|
|
897 |
#color: color changed
|
|
898 |
or a specific column:( aColumn notNil )
|
|
899 |
#insert: insert a new column
|
|
900 |
#remove: remove a column
|
|
901 |
|
|
902 |
or a specific attribute derived from the
|
|
903 |
changed column.
|
741
|
904 |
"
|
754
|
905 |
self doRecomputeGraph
|
|
906 |
|
741
|
907 |
!
|
|
908 |
|
754
|
909 |
updateGrid:what
|
|
910 |
"called if the grid changed
|
|
911 |
#color the color of the grid changed
|
|
912 |
#state the visibility state of the grid changed
|
|
913 |
"
|
|
914 |
self doRecomputeGraph
|
|
915 |
!
|
|
916 |
|
|
917 |
updateOriginX:aDeltaX
|
|
918 |
"graph origin X changed; scroll n steps left (aDeltaX < 0) or right (aDeltaX > 0)
|
741
|
919 |
"
|
754
|
920 |
self doRecomputeGraph
|
|
921 |
!
|
|
922 |
|
|
923 |
updateReferences:what atRelX:aRelX
|
|
924 |
"called when the list of references changed.
|
|
925 |
#remove: the reference at the relative X index is removed
|
|
926 |
#insert: a reference is inserted at the relative X index
|
|
927 |
#size the list of references changed
|
|
928 |
#state visibility state changed
|
|
929 |
#color the foreground color changed
|
|
930 |
"
|
|
931 |
self doRecomputeGraph
|
|
932 |
! !
|
|
933 |
|
|
934 |
!GraphColumnView methodsFor:'queries'!
|
|
935 |
|
|
936 |
listOfVisibleColumns
|
|
937 |
"returns a list of visible lines (never nil)
|
|
938 |
"
|
|
939 |
^ columns notNil ifTrue:[ columns select:[:c| c shown] ] ifFalse:[ #() ]
|
741
|
940 |
|
|
941 |
|
|
942 |
!
|
|
943 |
|
754
|
944 |
listOfVisibleRefIndices
|
|
945 |
"returns a list of visible reference line indices or an empty
|
|
946 |
collection (nothing defined or disabled).
|
749
|
947 |
"
|
754
|
948 |
|list winSz x|
|
|
949 |
|
|
950 |
(showReferences and:[references notEmpty]) ifFalse:[
|
|
951 |
^ #()
|
|
952 |
].
|
|
953 |
winSz := self windowSize.
|
|
954 |
list := OrderedCollection new.
|
749
|
955 |
|
754
|
956 |
referenceSelector isNil ifTrue:[
|
|
957 |
references do:[:aReference|
|
|
958 |
x := aReference - graphOriginX.
|
|
959 |
(x >= 0 and:[x < winSz]) ifTrue:[ list add:x ]
|
|
960 |
]
|
|
961 |
] ifFalse:[
|
|
962 |
references do:[:aReference|
|
|
963 |
x := (aReference perform:referenceSelector) - graphOriginX.
|
|
964 |
(x >= 0 and:[x < winSz]) ifTrue:[ list add:x ]
|
|
965 |
]
|
|
966 |
].
|
|
967 |
^ list
|
741
|
968 |
!
|
|
969 |
|
754
|
970 |
visibleReference:aReference do:aOneArgBlock
|
|
971 |
"evaluate the block with the relative visible X value; if the reference line
|
|
972 |
is not visible, nothing will happen
|
741
|
973 |
"
|
754
|
974 |
|x|
|
741
|
975 |
|
754
|
976 |
referenceSelector isNil ifTrue:[ x := aReference ]
|
|
977 |
ifFalse:[ x := aReference perform:referenceSelector ].
|
741
|
978 |
|
754
|
979 |
((x := x - graphOriginX) >= 0 and:[x < self windowSize]) ifTrue:[
|
|
980 |
aOneArgBlock value:x
|
|
981 |
]
|
741
|
982 |
! !
|
|
983 |
|
749
|
984 |
!GraphColumnView methodsFor:'scrolling'!
|
|
985 |
|
|
986 |
halfWindowSizeLeft
|
|
987 |
"scroll left half window size
|
|
988 |
"
|
|
989 |
self scrollLeft:(windowSize // 2)
|
|
990 |
|
|
991 |
!
|
|
992 |
|
|
993 |
halfWindowSizeRight
|
|
994 |
"scroll right half window size
|
|
995 |
"
|
|
996 |
self scrollRight:(windowSize // 2)
|
|
997 |
|
|
998 |
!
|
|
999 |
|
|
1000 |
scroll:nIndices
|
|
1001 |
"scroll left or right n x-steps. a positive value scrolls to the right
|
|
1002 |
a negative value to the left.
|
|
1003 |
"
|
|
1004 |
|max|
|
|
1005 |
|
|
1006 |
nIndices ~~ 0 ifTrue:[
|
|
1007 |
scrollUpdatesOriginX ifTrue:[
|
|
1008 |
graphOriginX := graphOriginX - nIndices
|
|
1009 |
].
|
|
1010 |
|
|
1011 |
shown ifTrue:[
|
|
1012 |
max := 2 * (windowSize // 3).
|
|
1013 |
|
|
1014 |
(nIndices abs) > max ifTrue:[
|
754
|
1015 |
self doRecomputeGraph "/ full redraw
|
749
|
1016 |
] ifFalse:[
|
754
|
1017 |
self updateOriginX:nIndices "/ scroll
|
749
|
1018 |
]
|
|
1019 |
]
|
|
1020 |
].
|
|
1021 |
!
|
|
1022 |
|
|
1023 |
scrollLeft:nIndices
|
|
1024 |
"scroll n indices left
|
|
1025 |
"
|
|
1026 |
self scroll:(nIndices negated)
|
|
1027 |
|
|
1028 |
!
|
|
1029 |
|
|
1030 |
scrollRight:nIndices
|
|
1031 |
"scroll n indices right
|
|
1032 |
"
|
|
1033 |
self scroll:nIndices
|
|
1034 |
|
|
1035 |
!
|
|
1036 |
|
|
1037 |
windowSizeLeft
|
|
1038 |
"scroll left window size
|
|
1039 |
"
|
|
1040 |
self scrollLeft:windowSize
|
|
1041 |
|
|
1042 |
!
|
|
1043 |
|
|
1044 |
windowSizeRight
|
|
1045 |
"scroll right window size
|
|
1046 |
"
|
|
1047 |
self scrollRight:windowSize
|
|
1048 |
|
|
1049 |
! !
|
|
1050 |
|
741
|
1051 |
!GraphColumnView class methodsFor:'documentation'!
|
|
1052 |
|
|
1053 |
version
|
4870
|
1054 |
^ '$Header$'
|
741
|
1055 |
! !
|
4870
|
1056 |
|