Program 2 - Essential Geometry

Goal Description Hints Passoff

Due Date - Sept 30

Goal

 
Learn to extract the geometry information that your controller will need from your view
 CS 456
Description
 

Problem:

1. Add a method

public GeometryDescriptor pointGeometry(Point mouseLoc)
{
}

to your PedigreeView class. This method will take a mouse location in component coordinates and will return a descriptor that indicates the person ID, surname or given name and character index of what was selected. Your GeometryDescriptor should have a field for the person ID. If the mouseLoc is not over the name or icon of any person then your person ID should be -1. If the mouseLoc is over a person then you need a flag to indicate whether it was over the surname, given name or icon of that person. If the mouse is over anything but the surname or given name, then report it as an icon. You also need a field in GeometryDescriptor to give the index of the character in the surname or given name that was selected if a name was selected. You can implement GeometryDescriptor as an inner class inside of your pedigree view or as a class of its own. Your code does not need to report anything about the children of the Root node. We will not be doing anything with those in later programs.

When reporting the index of the character selected by the mouse, this should not include the ID numbers and it should not treat the surname and given name as one string. If you look at your model those items are separate and to edit those names you will need to get separate selections.

Your mouse location may be over a Nobody icon. If that occurs you will want to return the fact that this is a Nobody. who is the father or mother of some other personID. You will need this information in later programs so that you know where in the pedigree a new person should be added.

2. Add an event handler to your PedigreeView class that can handle mouseReleased events. On every mouseReleased event you should call your pointGeometry() method and write out a line to System.out indicating what was selected by the mouse location. This should be one line that indicates the ID, name and character index that was selected or that nothing was selected. In the case of Nobody selections, the child's PersonID should be displayed along with whether the Nobody is the father or the mother.

Hints
 

For an example of how to create event handlers that handle mouse movement events see the java code CatChase_Comp.java. Look in the constructor for how to enable events and look at the processMouseMotionEvent() method for how to handle mouse movement. In your problem you want mouse up rather than mouse movement. Look in the Java API documentation for the Component class to find the method and enabling flags that you need.

It is also possible to accomplish the same goal by having your PedigreeView become a MouseListener and registering to receive events using the listener mechanism. Sun provides a tutoral on how to create mouse listeners.

The easiest way to figure out what part of your display the mouse is over is to duplicate the structure of your paint() method. Instead of drawing as you recursively work your way through the pedigree you are checking mouse positions. You will notice that the code for laying out your pedigree is almost the same as the code for checking mouse locations.

You will also have a problem finding the FontMetrics during your essential geometry because you do not have a Graphics object. The magical incantation in Java is the getLineMetrics() methods defined on the Font class.

Passoff
 
__ 3) The pointGeometry method is correctly implemented as part of the view and is based solely on the model's public methods and the current size of the component.
__ 5) Selecting any name or icon on the screen correctly outputs the ID number associated with the name.
__ 1) Selection occurs on mouse-up and not mouse down. Mouse down on a name followed by movement and mouse up that is not on any name will not report an individual selection.
__  1) Surname/given name/icon selection indications are correct
__  2) Correct selection of character index is reported.