Step 4:

Implement the functionality so that the user can change the colour of a line. A colour change is trigger when the user clicks on or near a line and that click is not within the line's centre segment. The centre segment is defined as follows: if the line's length were to be calculated and divided into four quarters, the centre segment corresponds to the two quarters of the line segment that are not adjacent to the line's endpoints. To implement this, define a set of at least three possible colors in some sort of order (e.g., in the example below, the possible colours are black, red, and green). The order of the colours determines the order of the transitions. Each qualifying mouse click causes the colour to advance to the next possible value. When the next value after the last value in the list is reached should be the first value (e.g., cycle through the values). Depending on where along the line segment the mouseClicked event triggered, the user should be able to both change the line thickness and change the line colour.


(Advanced) Aspect to consider: once the step 3 and step 4 specifications have been completed, consider how is the state space represented and how are the state transitions are implemented. Consider the State design pattern. For discussion and examples: http://home.earthlink.net/~huston2/dp/state.html and http://blogs.sun.com/jkumaran/entry/state_design_pattern_using_java.


Examples - initial state and after successive mouseClicked events

Pasted Graphic
Pasted Graphic 1
Pasted Graphic 2
Pasted Graphic 3