[Newbies] OrderedCollection if imageMorphs

Christine Wolfe cwdw01 at earthlink.net
Wed Nov 11 16:57:27 UTC 2009

Oops - I sent this too soon.  I changed owner addMorph to self addMorph and
it works ;-)

I still have a question though.  I have an instance variable cells that I
defined as 
cells := Matrix rows: 7 columns: 11 tabulate: [ :i :j | self newCellAt: i
at: j].

Each cell of the matrix is going to be an orderedcollection of images.  How
can I refer to an individual cell of the matrix?  

Bert, I followed your suggestion for making an orderedcollection and just
adding ImageMorph as the items in the collection.  Now I am trying to figure
out how to assign an image to each item and then display it in another

Here's what I have so far but I can't get it to show up.

newCellAt: i at: j
| c sa leftValue topValue | 
sa := OrderedCollection new.
sa add: ImageMorph new.
sa add: ImageMorph new.
sa add: ImageMorph new.

c := sa at: 2.
c image: (Form fromFileNamed: 'FCIf.png').
leftValue := 10.
c width: 100. 
topValue := 20.
c height: 70].

c position: (leftValue) @ (topValue).
owner addMorph: c.

-----Original Message-----
From: beginners-bounces at lists.squeakfoundation.org
[mailto:beginners-bounces at lists.squeakfoundation.org] On Behalf Of Bert
Sent: Monday, November 09, 2009 11:25 AM
To: A friendly place to get answers to even the most basic questions about
Subject: Re: [Newbies] OrderedCollection if imageMorphs

On 09.11.2009, at 02:08, Christine Wolfe wrote:

> Oh wow! thanks - having the sample code will be a huge help.  I'll  
> give it a
> try.
> -----Original Message-----
> From: Randal L. Schwartz [mailto:merlyn at stonehenge.com]
> Sent: Sunday, November 08, 2009 8:03 PM
> To: Christine Wolfe
> Cc: beginners at lists.squeakfoundation.org
> Subject: Re: [Newbies] OrderedCollection if imageMorphs
>>>>>> "Christine" == Christine Wolfe <cwdw01 at earthlink.net> writes:
> Christine> Oh, I'm so so sorry - I thought it was OK to ask dumb  
> questions
> on
> Christine> the newbie forum (blush) I'll try to figure out how to  
> make an
> Christine> instance variable an order collection.
> It's perfectly OK, and that's why you were corrected. :)
> Basically, you'll do the following:
> * add an instance variable: contents
> on your instance side, add:
>    initialize
>      super initialize.
>      contents := OrderedCollection new.
> then for each item of the collection protocol, delegate it, as in:
>    add: anItem
>      ^contents add: anItem.
>    includes: anItem
>      ^contents includes: anItem.
>    size
>      ^contents size.
> and so on.  If you get really tired of adding all of them,
> just add them as you need them (when the debugger tells you :).

Why would you want to add all these methods and your own class in the  
first place? They are there already, perfectly usable.

> If you wanna get really tricky, you can add a #doesNotUnderstand:  
> handler to
> perform the method on the contents variable, but that can mess up your
> debugging, so it's better if you don't.

Err, now that goes into the land of advanced applied magic. Please  
ignore that last paragraph ;)

Christine, if you want an OrderedCollection of ImageMorphs (as you  
wrote in the subject) then do just that. Create an OrderedCollection,  
not a subclass of it. And add ImageMorphs, not subclasses of  
ImageMorphs (unless they indeed do specific processing - but even then  
I'd probably make only one ImageMorph subclass and customize that).

It is often unnecessary to create your own classes for everything. For  
example, if the only difference of a regular ImageMorph and your own  
Morph subclass is the image it shows, then do not create a subclass.  
Just assign the right image. And maybe assign an event handler, no  
need for subclassing there either.

OTOH, when I look at your high-level goal "I'm making a pinball  
machine in which the little ball follows the order of execution of a  
student entered flowchart" I don't really see the need for a  
"SymbolArray" nor even "OrderedCollection of ImageMorphs". Maybe you  
should design the UI first and then implement whatever is necessary to  
make it work?

- Bert -

Beginners mailing list
Beginners at lists.squeakfoundation.org

More information about the Beginners mailing list