List morph that uses printOn: ??
Bob Arning
arning at charm.net
Mon May 15 21:04:10 UTC 2000
On Mon, 15 May 2000 16:31:28 -0400 cgundel at domainpharma.com wrote:
>Is there an alternative to PluggableListMorph which will let you stuff
>non-String objects into it? I'm use to being able to put anything I like
>into a list widget, and rely on printOn: to produce what I see.
>VisualSmalltalk does this, and it also lets you optionally specify a
>selector to the list view by which to extract presentable strings from
>objects.
Carl,
It's pretty easy to do what you want with PluggableListMorph. See below.
Cheers,
Bob
===== code follows =====
'From Squeak2.8alpha of 13 January 2000 [latest update: #2121] on 15 May 2000 at 5:00:15 pm'!
Object subclass: #ListOfAnything
instanceVariableNames: 'currentIndex anythingGoes '
classVariableNames: ''
poolDictionaries: ''
category: 'Examples-Lists'!
!ListOfAnything commentStamp: 'RAA 5/15/2000 16:59' prior: 0!
An example of a using a PluggableListMorph to display objects of arbitrary classes.
ListOfAnything openOn: {'1'. 1. #(a b c d). #name->'Bob'. Smalltalk}!
!ListOfAnything methodsFor: 'as yet unclassified' stamp: 'RAA 5/15/2000 16:54'!
getIndex
^currentIndex! !
!ListOfAnything methodsFor: 'as yet unclassified' stamp: 'RAA 5/15/2000 16:53'!
getList
^anythingGoes collect: [ :x | x printString]
! !
!ListOfAnything methodsFor: 'as yet unclassified' stamp: 'RAA 5/15/2000 16:56'!
openOn: aCollection
| window |
anythingGoes _ aCollection.
currentIndex _ 1.
window _ (SystemWindow labelled: 'Anyting goes') model: self.
window
addMorph: (PluggableListMorph
on: self
list: #getList
selected: #getIndex
changeSelected: #setIndex:
menu: #nil
keystroke: #nil
)
frame: (0 at 0 extent: 1 at 1).
^ window openInWorld! !
!ListOfAnything methodsFor: 'as yet unclassified' stamp: 'RAA 5/15/2000 16:55'!
setIndex: anIntegerOrNil
currentIndex _ anIntegerOrNil.
currentIndex ifNotNil: [(anythingGoes at: currentIndex) explore].
! !
!ListOfAnything class methodsFor: 'as yet unclassified' stamp: 'RAA 5/15/2000 16:56'!
openOn: aCollection
self new openOn: aCollection
! !
More information about the Squeak-dev
mailing list
|