View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Wu-Tang Cases: GUI Guide

I get errors when I try to extend a Morphic object.

If you get errors when you try to call messages on a Morphic that you extended you probably did not call super initialize. as the first line in your initialize function. Furthermore, you have to call initialize before any other function from the parent morph you extended.

This means you have to call:

yourMorph initialize.

before you can call

yourMorph position:(0@0).

What's the Morph that is a ...?

First of all, try searching the classes (to do this right click the classes section of the browser and click "find class...") for Pluggable. You will find lots of useful morphs

Simple Button use a PluggableButtonMorph

aButton := PluggableButtonMorph on: self getState: nil action: #doSomethingFunction.
aButton label: 'A Button'.
aButton position: (10@10).
aButton onColor: aColor offColor: aColor. "NOTE: buttons default to off even though clicking on them still calls the action function"
self addMorph: aButton.
OR otherMorph addMorph: aButton. OR aButton openInWorld.

String use a StringMorph

stringMorph := StringMorph new.
stringMorph contents: 'A String'.
stringMorph position: (25@65).
stringMorph color: (Color r: 0 g: .5 b: .75).
self addMorph: stringMorph .
OR otherMorph addMorph: stringMorph . OR stringMorph openInWorld.

Text Field/Area use a PluggableTextMorph NOTE: you will probably want to make a Rectangle Morph with the exact same extent and position as you're PuggableTextMorph for a background.

aTextField := PluggableTextMorph new.
aTextField hideScrollBarIndefinitely."NOTE: this is for very small text fields"
aTextField setText: 'I'm a text field.'.
aTextField position: (25@65).
aTextField extent: (150@20).
self addMorph: aTextField.
OR otherMorph addMorph: aTextField. OR aTextField openInWorld.

Container use a RectangleMorph (or any Morph for that matter)

containerRectangle := RectangleMorph new.
containgerRectangle openInWorld.
OR otherMorph addMorph: containerRectangle. OR self addMorph: containgerRectangle.
containgerRectangle extent: (235@235).
containgerRectangle position: (25@65).
containgerRectangle color: Color gray.
containgerRectangle beSticky. "NOTE: use this if you don't want a mouse click to pick up a morph."

"But how do I set the location/order of things I add to this morph?"
Simply set the positions/extents of the submorphs. Whichever item you add last will be in front. Check the Morph class for ways to add morphs to places other than the front.
NOTE: Morphs that have been deleted are automatically removed from their parent morph. Also, any morph can contain any other morph. Nothing stops you from adding submorphs outside the bounds of the parent morph.

Image use an ImageMorph

imageMorph := ImageMorph new.
imageMorph image: (Form fromFileNamed: 'myImage.gif').
self addMorph: imageMorph.
OR otherMorph addMorph: imageMorph. OR imageMorph openInWorld.

List use a PluggableListMorph NOTE: you will probably want to make a Rectangle Morph with the exact same extent and position as you're PuggableListMorph for a background.

listMorph := PluggableListMorph on: self list: nil selected: nil changeSelected: #listClicked:."NOTE: listClicked is a function that takes in aNumber (the item which was clicked, will pass in 0 if the list was clicked but no item was selected)."
listMorph position: (35@145).
listMorph extent: (215@65).
listMorph list: listOfStrings.
self addMorph: listMorph .
OR otherMorph addMorph: listMorph . OR listMorph openInWorld.

Keyboard Listener events in Sqeak are difficult because the event section of Squeak has few comments (even for Squeak). However, I made a class that when a mouse is over it will pick up keyboard events, which can contain something else you want to display. It's in the m6 design on our main cases page in the RoosterTossers--GUI section called KeyboardListenerMorph. It sometimes has a problem with another morph stealing keyboard focus and never giving it back. I derrived it from TextMorph since TextMorphs handle keyboard events.

Link to this Page