Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
An example of how to implement PluggableListMorph
1. Create a new class such as MyListMorph
Object subclass: #MyListMorph
instanceVariableNames: 'list listMenu selectedIndex xCoord yCoord aListMorph '
2. Modify the initialize method to take in the list you want the PluggableListMorph to display.
initialize: aList x: xNum y: yNum
list _ aList. "Set the list to be displayed"
xCoord _ xNum. "Set the x coordinate of the morph"
yCoord _ yNum. "Set the y coordinate of the morph"
selectedIndex _ 1. "Set the index to be highlighted to be 1."
3. Create the accessor and modifier methods.
"get the list that is being displayed"
"get the index of what is currently selected"
"get the menu of the PluggableListMorph"
"change the selectedIndex"
selectedIndex _ anInteger.
self changed: #listIndex. "note: this is needed, or the list won't update when you click on it!"
"set the menu of the pluggableListMorph"
listMenu _ aMenu.
4. Create the openView method which will be called to display the PluggableListMorph at the point you specified.
| window aListMorph |
aListMorph _ PluggableListMorph
on: self "I am the model that has the list to display"
list: #list "This is how the morph gets the list from me"
selected: #listIndex "This is how the morph knows which item to highlight"
changeSelected: #listIndex: "This is how the morph informs me of a user selection"
menu: #listMenu. "This is how the morph requests a menu for the list"
aListMorph color: Color random. "Get a random color for the morph"
aListMorph x: xCoord y: yCoord. "Set the position of the morph"
5. To use MyListMorph:
w _ MyListMorph new initialize: #list x: 100 y: 200.
Here's the link to the original PluggableListMorph help page that inspired this page: http://minnow.cc.gatech.edu/squeak/1093.
Here's the code for the PluggableListMorph we used in our project:
Here's the code for P7 so you can see the PluggableListMorph in action.
Link to this Page
- Cases last edited on 30 July 2011 at 2:33 am by r59h132.res.gatech.edu