OrderedCollection if imageMorphs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

OrderedCollection if imageMorphs

Christine Wolfe

I want to put add an imageMorph on top of another imageMorph.

 

I can do this with the following method (note SymbolBlank is an imageMorph

MyBoard>>addSymbol

|im|

im := SymbolBlank new.

self addMorph: im.

im topLeft: 2@2.

 

I want to enhance this so I can choose one of a collection of imageMorphs to add.

 

I created a class, SymbolArray, that is a subclass of OrderedCollection with the following initialize method. Each of the items I’m adding (SymbolBlank, SymbolGet, etc) is an imageMorph.

 

SymbolArray>>initialize

super initialize.

self add: SymbolBlank new.

self add: SymbolGet new.

self add: SymbolProcess new.

self add: SymbolPut new.

self add: SymbolIf new.

self add: SymbolWhile new.

 

Then I tried to modify the addSymbol method as show below.

When I do, I get the following error message which sounds like I don’t have an element at index 1…

SymbolArray(OrderedCollection)>>errorNoSuchElement

SymbolArray(OrderedCollection)>>at:

 

| sa si |

sa := SymbolArray new.

si := sa at: 1.

self addMorph: si.

si topLeft:  2@2.

 

I hope someone can help me figure out how to accomplish what I want to do.

 


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Alex Schenkman
I think you might need to call SymbolArray>>intialize by your self.

If you look at the chain of message sends starting from 'SymbolArray new'
1) OrderedCollection new
2) OrderedCollection new:
3) Behavior basicNew

There is no call to initialize.

On Sat, Nov 7, 2009 at 16:28, Christine Wolfe <[hidden email]> wrote:

I want to put add an imageMorph on top of another imageMorph.

 

I can do this with the following method (note SymbolBlank is an imageMorph

MyBoard>>addSymbol

|im|

im := SymbolBlank new.

self addMorph: im.

im topLeft: 2@2.

 

I want to enhance this so I can choose one of a collection of imageMorphs to add.

 

I created a class, SymbolArray, that is a subclass of OrderedCollection with the following initialize method. Each of the items I’m adding (SymbolBlank, SymbolGet, etc) is an imageMorph.

 

SymbolArray>>initialize

super initialize.

self add: SymbolBlank new.

self add: SymbolGet new.

self add: SymbolProcess new.

self add: SymbolPut new.

self add: SymbolIf new.

self add: SymbolWhile new.

 

Then I tried to modify the addSymbol method as show below.

When I do, I get the following error message which sounds like I don’t have an element at index 1…

SymbolArray(OrderedCollection)>>errorNoSuchElement

SymbolArray(OrderedCollection)>>at:

 

| sa si |

sa := SymbolArray new.

si := sa at: 1.

self addMorph: si.

si topLeft:  2@2.

 

I hope someone can help me figure out how to accomplish what I want to do.

 


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Herbert König
In reply to this post by Christine Wolfe
Christine,

SymbolArray>>>initialize
CW> super initialize.
CW> self add: SymbolBlank new.
CW> self add: SymbolGet new.
CW> self add: SymbolProcess new.
CW> self add: SymbolPut new.
CW> self add: SymbolIf new.
CW> self add: SymbolWhile new.

the names of your symbols make me courious about what you try to build.

Care to share?

Cheers,

Herbert  

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe
In reply to this post by Alex Schenkman

That worked!!!  Thanks - I never would have figure it out on my own.

 

I’m so confused though.  I’ve never had to explicitly call an initialize method before – they seem to be invoked automatically when I use the word “new”.  Should I always call the initialize when I create a new instance?

 

@Herbert – I’m making a pinball machine in which the little ball follows the order of execution of a student entered flowchart…at least that’s what I’m trying to do ;-)

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alex Schenkman
Sent: Sunday, November 08, 2009 3:59 AM
To: A friendly place to get answers to even the most basic questions about Squeak.
Subject: Re: [Newbies] OrderedCollection if imageMorphs

 

I think you might need to call SymbolArray>>intialize by your self.

 

If you look at the chain of message sends starting from 'SymbolArray new'

1) OrderedCollection new

2) OrderedCollection new:

3) Behavior basicNew

 

There is no call to initialize.

 

On Sat, Nov 7, 2009 at 16:28, Christine Wolfe <[hidden email]> wrote:

I want to put add an imageMorph on top of another imageMorph.

 

I can do this with the following method (note SymbolBlank is an imageMorph

MyBoard>>addSymbol

|im|

im := SymbolBlank new.

self addMorph: im.

im topLeft: 2@2.

 

I want to enhance this so I can choose one of a collection of imageMorphs to add.

 

I created a class, SymbolArray, that is a subclass of OrderedCollection with the following initialize method. Each of the items I’m adding (SymbolBlank, SymbolGet, etc) is an imageMorph.

 

SymbolArray>>initialize

super initialize.

self add: SymbolBlank new.

self add: SymbolGet new.

self add: SymbolProcess new.

self add: SymbolPut new.

self add: SymbolIf new.

self add: SymbolWhile new.

 

Then I tried to modify the addSymbol method as show below.

When I do, I get the following error message which sounds like I don’t have an element at index 1…

SymbolArray(OrderedCollection)>>errorNoSuchElement

SymbolArray(OrderedCollection)>>at:

 

| sa si |

sa := SymbolArray new.

si := sa at: 1.

self addMorph: si.

si topLeft:  2@2.

 

I hope someone can help me figure out how to accomplish what I want to do.

 


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

 


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Alex Schenkman


On Sun, Nov 8, 2009 at 14:28, Christine Wolfe <[hidden email]> wrote: 

I’m so confused though.  I’ve never had to explicitly call an initialize method before – they seem to be invoked automatically when I use the word “new”.  Should I always call the initialize when I create a new instance?

I'm not sure, but I think so. 
Maybe the super classes you have been so far using are sending #initialize as part of their instantiation routine? 


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe

For sure I’m going to start now – I don’t see where it could ever hurt anything if I initialize twice…

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alex Schenkman
Sent: Sunday, November 08, 2009 9:00 AM
To: A friendly place to get answers to even the most basic questions about Squeak.
Subject: Re: [Newbies] OrderedCollection if imageMorphs

 

 

On Sun, Nov 8, 2009 at 14:28, Christine Wolfe <[hidden email]> wrote: 

I’m so confused though.  I’ve never had to explicitly call an initialize method before – they seem to be invoked automatically when I use the word “new”.  Should I always call the initialize when I create a new instance?

I'm not sure, but I think so. 

Maybe the super classes you have been so far using are sending #initialize as part of their instantiation routine? 

 


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re[2]: OrderedCollection if imageMorphs

Herbert König
In reply to this post by Christine Wolfe
Hi Christine,

CW> @Herbert – I’m making a pinball machine in which thelittle
CW> ball follows the order of execution of a student entered
CW> flowchart…atleast that’s what I’m trying to do ;-)

sounds fun to build and fun to use when it's finished.


Thanks,

Herbert  

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Randal L. Schwartz
In reply to this post by Christine Wolfe
>>>>> "Christine" == Christine Wolfe <[hidden email]> writes:

Christine> For sure I'm going to start now - I don't see where it could ever hurt
Christine> anything if I initialize twice.

It can, so I wouldn't conclude so quickly, or cargo-cult this one
without some more research.

Behavior>>#new calls #initialize, so someone broke the chain between there
and your classes of interest by overriding #new without respecting the
existing protocol.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: OrderedCollection if imageMorphs

Christine Wolfe
In reply to this post by Christine Wolfe

------Original Message------
From: Herbert König
Sender: [hidden email]
To: A friendly place to get answers to even the most basic questions aboutSqueak.
ReplyTo: A friendly place to get answers to even the most basic questionsabout Squeak.
Subject: Re[2]: [Newbies] OrderedCollection if imageMorphs
Sent: Nov 8, 2009 10:45 AM

Hi Christine,

CW> @Herbert – I’m making a pinball machine in which thelittle
CW> ball follows the order of execution of a student entered
CW> flowchart…atleast that’s what I’m trying to do ;-)

sounds fun to build and fun to use when it's finished.


Thanks,

Herbert  

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Sent from my Verizon Wireless BlackBerry
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: Re[2]: OrderedCollection if imageMorphs

Christine Wolfe
Hi Herbert,

If I get it to work, I will send you a copy

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of
[hidden email]
Sent: Sunday, November 08, 2009 12:10 PM
To: A friendly place to get answers to even the most basic questionsabout
Squeak.
Subject: Re: Re[2]: [Newbies] OrderedCollection if imageMorphs


------Original Message------
From: Herbert König
Sender: [hidden email]
To: A friendly place to get answers to even the most basic questions
aboutSqueak.
ReplyTo: A friendly place to get answers to even the most basic
questionsabout Squeak.
Subject: Re[2]: [Newbies] OrderedCollection if imageMorphs
Sent: Nov 8, 2009 10:45 AM

Hi Christine,

CW> @Herbert – I’m making a pinball machine in which thelittle ball
CW> follows the order of execution of a student entered
CW> flowchart…atleast that’s what I’m trying to do ;-)

sounds fun to build and fun to use when it's finished.


Thanks,

Herbert  

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


Sent from my Verizon Wireless BlackBerry

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe
In reply to this post by Randal L. Schwartz
Thanks - I thought it odd that I had to explicitly call this initialize.  I
went back and took out the call to initialize just to be sure that was what
making the difference and it was. So for some reason my SymbolArray>>new is
not calling the method unlike all my other ones.  If I find that it is
something that I've done, I'll be sure to let the forum know.

-----Original Message-----
From: Randal L. Schwartz [mailto:[hidden email]]
Sent: Sunday, November 08, 2009 10:55 AM
To: Christine Wolfe
Cc: 'A friendly place to get answers to even the most basic questions about
Squeak.'
Subject: Re: [Newbies] OrderedCollection if imageMorphs

>>>>> "Christine" == Christine Wolfe <[hidden email]> writes:

Christine> For sure I'm going to start now - I don't see where it could ever
hurt
Christine> anything if I initialize twice.

It can, so I wouldn't conclude so quickly, or cargo-cult this one
without some more research.

Behavior>>#new calls #initialize, so someone broke the chain between there
and your classes of interest by overriding #new without respecting the
existing protocol.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Randal L. Schwartz
In reply to this post by Christine Wolfe
>>>>> "Christine" == Christine Wolfe <[hidden email]> writes:

Christine> I created a class, SymbolArray, that is a subclass of
Christine> OrderedCollection with the following initialize method. Each of the
Christine> items I'm adding (SymbolBlank, SymbolGet, etc) is an imageMorph.

Ahh, there's the mistake... missed it before.

You really really really do *not* want to create a subclass
of OrderedCollection.

Your object will *have* an OrderedCollection, but should not *be* one.

If you want to respond to all of the protocol of OrderedCollection,
feel free to delegate it to your actual instance variable.

Yes, it's a bright shiny object to want to subclass that, but just like
subclassing SmallInteger, it's both legal and dumb. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe
Oh, I'm so so sorry - I thought it was OK to ask dumb questions on the
newbie forum (blush)  I'll try to figure out how to make an instance
variable an order collection.

-----Original Message-----
From: Randal L. Schwartz [mailto:[hidden email]]
Sent: Sunday, November 08, 2009 4:06 PM
To: Christine Wolfe
Cc: [hidden email]
Subject: Re: [Newbies] OrderedCollection if imageMorphs

>>>>> "Christine" == Christine Wolfe <[hidden email]> writes:

Christine> I created a class, SymbolArray, that is a subclass of
Christine> OrderedCollection with the following initialize method. Each of
the
Christine> items I'm adding (SymbolBlank, SymbolGet, etc) is an imageMorph.

Ahh, there's the mistake... missed it before.

You really really really do *not* want to create a subclass
of OrderedCollection.

Your object will *have* an OrderedCollection, but should not *be* one.

If you want to respond to all of the protocol of OrderedCollection,
feel free to delegate it to your actual instance variable.

Yes, it's a bright shiny object to want to subclass that, but just like
subclassing SmallInteger, it's both legal and dumb. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Randal L. Schwartz
>>>>> "Christine" == Christine Wolfe <[hidden email]> 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 :).

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.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe
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:[hidden email]]
Sent: Sunday, November 08, 2009 8:03 PM
To: Christine Wolfe
Cc: [hidden email]
Subject: Re: [Newbies] OrderedCollection if imageMorphs

>>>>> "Christine" == Christine Wolfe <[hidden email]> 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 :).

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.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Bert Freudenberg

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:[hidden email]]
> Sent: Sunday, November 08, 2009 8:03 PM
> To: Christine Wolfe
> Cc: [hidden email]
> Subject: Re: [Newbies] OrderedCollection if imageMorphs
>
>>>>>> "Christine" == Christine Wolfe <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Christine Wolfe
Hi Bert,

Thanks for the info.  I have finished the IU and have it working fine in
PowerPoint ;-) animations.  Now I want to move it to a real programming
language. The reason for the ordered collection is this.   For each
position in the flowchart, there is a space on the pinball machine were the
user can click - with each click, the next symbol in the ordered collection
is displayed.  When the user sees the symbol he wants in that position, he
will stop clicking and move on to the next position.  (The spaces for the
flowcharting symbols is a matrix of these ordered collections.)

My original misunderstanding was in thinking that I should use
orderedcollection as an object (which I know it is) instead of thinking of
it as more of a datatype kind of thing.....  This forum has been super helpful.

At 11:24 AM 11/9/2009, Bert Freudenberg wrote:

>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:[hidden email]]
>>Sent: Sunday, November 08, 2009 8:03 PM
>>To: Christine Wolfe
>>Cc: [hidden email]
>>Subject: Re: [Newbies] OrderedCollection if imageMorphs
>>
>>>>>>>"Christine" == Christine Wolfe <[hidden email]> 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
>[hidden email]
>http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe
In reply to this post by Bert Freudenberg
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
morph.

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: [hidden email]
[mailto:[hidden email]] On Behalf Of Bert
Freudenberg
Sent: Monday, November 09, 2009 11:25 AM
To: A friendly place to get answers to even the most basic questions about
Squeak.
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:[hidden email]]
> Sent: Sunday, November 08, 2009 8:03 PM
> To: Christine Wolfe
> Cc: [hidden email]
> Subject: Re: [Newbies] OrderedCollection if imageMorphs
>
>>>>>> "Christine" == Christine Wolfe <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: OrderedCollection if imageMorphs

Christine Wolfe
In reply to this post by Bert Freudenberg
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
morph.

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: [hidden email]
[mailto:[hidden email]] On Behalf Of Bert
Freudenberg
Sent: Monday, November 09, 2009 11:25 AM
To: A friendly place to get answers to even the most basic questions about
Squeak.
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:[hidden email]]
> Sent: Sunday, November 08, 2009 8:03 PM
> To: Christine Wolfe
> Cc: [hidden email]
> Subject: Re: [Newbies] OrderedCollection if imageMorphs
>
>>>>>> "Christine" == Christine Wolfe <[hidden email]> 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
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: OrderedCollection if imageMorphs

Bert Freudenberg
On 11.11.2009, at 17:57, Christine Wolfe wrote:

> 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?  

Just have a look at the "accessing" protocol in class Matrix.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners