COMP 310

Lec07: Compositionbased Ballworld considerations and even more fun... 
HW02 will be turned in via Owlspace again.
GUI:
JComboBox.add(x) will add the item x to the end of the list while JComboBox.insertAt(x, 0) will add the item x to the beginning of the list.
Be sure to retrieve the selected item (the factory!), not the selected index or text.
Tooltips: Use the setToolTipText method to set the popup tool tip (or set property in Jigloo GUI editor).
Be sure to always check if the text field's text is null before proceeding.
Be sure to always check if the return value from a lambda command is null, which means that an error occurred.
Demo control panel layout is 3 panels and a button in a Flow layout. Each subpanel is a Grid layout with 1 column and 2 or 4 rows. Students need not replicate this component layout exactly, but it should be something reasonable, i.e. not everything in a row.
Controller:
If an error occurs while processing a lambda command, return null.
Since the IStrategyFac.make() method is assumed to return a valid IUpdateStrategy, then if an error occurs you need to return some valid strategy, e.g. a StraightStrategy. Think very carefully about where this correction would take place.
If you use a utility method like"FixName" to save typing by the user, be sure to reconstruct the "fully qualified" class name, which includes the package name.
What happens to all the ABall subclasses? What happens to ABall?
After all your changes, which do you think had more lines of code, the inheritancebased or compositionbased systems? Which had more capabilities?
How does Fishworld create fish that are not only the correct size, but are always swimming forward?
Remember that a fish (ball) knows where it is and which way it is going because it has a position and a velocity. It has a radius too, so it knows its size as well. Thus any given ball can take a common representation of an image, e.g. a fish, scale it as per its radius, rotate it as per its velocity and translate it as per its position and end up with an image that is always oriented correctly with respect to its movement. The mathematical process of scaling, rotating and translating is called an "affine transform".
An affine transform is the mathematical process of scaling (making larger or smaller), rotating (pivoting around the origin) and translating (moving a specified distance and direction) of a point in space. Remember that a point is really a vector from the origin, so a affine transformation technically transforms vectors, not points.
Affine transforms may seem mathematically daunting, but they are actually quite straightforward. Plus, Java provides an AffineTransform class that encapsulates the mathematics and makes dealing with affine transformation very easy.
Example of the operations involved in a single Affine transformation, showing the individual steps of rotating, scaling and translating:
Original vector: then Rotated vector:
then Scaled vector and then Translated vector:
Note that the order of operation is important:
Original vector: then Rotated vector: then Translated vector:
as compared to
Original vector: then Translated vector: then Rotated vector:
In fancy mathematical words, we same that rotation and translation are noncommutative. A net Affine transformation is thus dependent on not only what operations (rotate, scale, translate) are defined, but also in what order those operations are defined.
© 2010 by Stephen Wong