Wednesday, February 7, 2007

Hitting a brick wall

I've been working adding undo/redo functionality to Jig and I've just encountered a slight hinderence. Each tool that Jig has uses a Controller class to manage the mouse events. To add undo/redo, these Controller classes simply tell the Commander object to execute a desired Command class. For example, the polygon tool uses the PolygonController class for creating new JPolygons. The PolygonController class adds the polygon to the canvas once the user has released the mouse button. To add undo/redo, I created a class called AddPolygonCommand which implements the Command interface within the shag library. The PolygonController class then simply tells the commnder object to execute a new instance of this command.

Simple enough, but while writing the MovePolygonCommand, which would be used by the PointerController when a user uses the pointer tool to move a polygon, I discovered that the PointerController doesn't differenciate when the user clicks on a polygon to move it, and when a user clicks on a vertex of a polygon to move only the vertex, not the whole polygon itself. That functionality is in the JPolygon class. This poses a problem because that functionality needs to be abstracted out of the JPolygon class so that the PointerController can undo/redo the different movement commands correctly.

I'll update on the progress towards fixing this problem.

No comments: