CSE 509 -- HW #3 ================== Date Due: Wednesday, 30 January 2002 Goals: ====== - Write more Smalltalk code. - Gain familiarity with the Model-View-Controller and Morphic paradigms. - Play with some user interfaces. - Gain familiarity with the graphics classes and the classes associated with the user interface. Part 1 - From the Squeak Textbook: ==================================== (1) Go through Chapter 4 and type in the code for the Clock example as you go. (Do not simply "file it in" from somewhere else.) Note: You'll need to open a Transcript window, if one is not on the screen. A Transcript window is someplace you can print stuff out. Using the world menu, open a Transcript and, from a workspace, execute this "Transcript show: 'hello'; cr. You should see output on the Transcript window. (2) Read from section 4.3 on in Chapter 4, but you don't need to type in the code. (3) Go through Chapter 5 through page 151. Type in the code and make sure it works. Note: This chapter is based on the MVC interface. You'll probably need to open an MVC project and execute this code in that project. (4) Play around with the Clock interface you have created; experiment. Part 2 - An MVC Interface for the Tree Class: =============================================== (1) The following files are available: cs.pdx.edu/~harry/public_html/ Tree-MVC.st Tree-Morphic.st (Also accessible through the class web page, www.cs.pdx.edu/~harry) (2) File-in the file: Tree-MVC.st This file contains the classes Tree3 and TreeView. It is meant to be used in an MVC project and may crash Squeak if used in Morphic. Note: This version of Tree is a little different from the previous version. Each node now contains a pointer to its parent (if any) as well as to its two children. The parent pointer is needed since we might now be able to delete a node just by pointing to it. When deleting a node, we must be able to modify its parent as well. I have also made other minor modifications to the methods as shown in class. I renamed the class Tree so to prevent conflicts with your version of Tree. (3) Get a Tree displayed on the screen. See the class method TreeView>>example for a start. Read through and understand the code. (4) Enhance this user interface for the Tree3/TreeView classes. Part 3 - A Morphic Interface for the Tree Class: ================================================== (1) File-in the file: Tree-Morphic.st This file contains the classes Tree2 and TreeMorph. It is meant to be used in a Morphic project. (2) Get a Tree displayed on the screen. See the class method TreeMorph>>example for a start. Read through and understand the code. (3) Try some enhancement for the Morphic user interface for Trees. Ideas for Enhancements: ======================= A Tree is always displayed the same way, regardless of the shape of the window. In particular, if the window is too small, the tree will be clipped. Modify the code so that the tree is displayed differently depending of the window size. (Hint: Modify the x- and y- increments. Dealing with vertical spacing involves thinking about the total available height of the window and the height of the tree, then figuring how much of a y-increment is reasonable.) If a tree has a huge left branch, but nothing on the right side, it will waste about half of the window. The result looks unbalanced. Figure out how to position the nodes based on the shape of the tree, to produce a more aesthetic picture. (Hint: Horizontal spacing can be done with this algorithm: Count the number of leaf nodes in the entire tree and position them with equal horizontal spacing in whatever width the window allows. Then position each non-leaf ("interior") node by centering it above its immediate children.) When the label of a node exceeds more than a couple of letters, the display of the node doesn't look very pretty. Modify the code so that the node is displayed as an oval (or rounded rectangle, or something) that encloses the text and looks better. Create a way to interact with the tree. Perhaps you can add a way to add, delete, or rename nodes. Perhaps you will include both "delete by name" and a "delete by pointing at" capabilities. Make modifications appropriate for a Tree that is always ordered. Write a class that handles n-ary trees, which may have any number of children. Any other enhancements/modifications that you think of. What to hand in: ================ Part 1: File out the "ClockWorks" category and e-mail it to harry@cs.pdx.edu with subject "HW #3 - ClockWorks". Part 2: File out the "Tree-MVC" category as you have modified it and e-mail that file with subject "HW #3 - Tree-MVC". Part 3: File out the "Tree-Morphic" category as you have modified it and e-mail that file with subject "HW #3 - Tree-Morphic". There should be three files sent. Please don't submit multiple times without prior approval. Summary: Please hand-in a single hard copy paper with your name and email address on it. Answer the following questions: - Did you do part 1 (ClockWorks) completely? - Tree-MVC: What extensions did you complete? - Tree-Morphic: What extensions did you complete? - How does your interface work? The idea is to make sure the grader fully appreciates all of the functionality you have provided and to make sure the grader can successfully use your user interface. Include a few of sentences such as "The user can add a new node to the tree by..." and "After selecting the 'add' menu option, the user should..." - Comments on the assignment? Difficulties? Please keep the summary to a single sheet of paper.