For JDraw Developers

I. Adding a new Shape to JDraw

1. The shape must be of type GraphicObject. The shape must be serializeable so check the bundle method and make sure all the fields are assigned. If you need to add additional fields be very careful about the position you add these fields to because the class JDraw/Canvas unravels the junkbundle and assigns the various fields in order to the current shape type. Look at the method addGraphicObject(vector junkbundle) in JDraw/Canvas and add your shape and any additional data fields to this method. You can test if this is done correctly by drawing your shape along with a couple other shape types, saving and closing the window. If you can open the file and all the shapes are redrawn appropriately without error messages you are OK.

2. New shapes are added to the JDraw/Tools Class. Assign the next available number to this shape. This is the number other classes will reference when the new shape is the active tool. You will also need to add the new shape to the Tool Menu.

3. The 3 most important classes in JDraw are Canvas, CanvasPage, and CanvasWindow.You can think of them in the following way:

Canvas contains a working list of all the graphic objects added to a canvas window. The list is separated into window layers. The methods in Canvas involve keeping track of the layers, graphic objects and manipulating the layers and lists of graphic objects.

CanvasPage is responsible for printing the layers of graphic objects of a canvas window to the monitor or printer. Its methods are concerned with page layouts, printer layouts, and drawing the shapes in the correct position and zoom, with the current graphicObject properties. It also revises the window as needed.

CanvasWindow handles the mouse and key events with methods that use switch statements for the corresponding active tool number in the JDraw/Tools Class. Drawing,selecting, moving, scaling, etc. are all handled by manipulating the current and previous points that are selected by mouse movements. The canvasPage is redrawn as the shapes in the window change. The methods in Canvas Window are performed either on a single GraphicObject or on multiple GraphicObjects that have been selected using the Select Tool in the Tools Menu.

4. The new shape has an associated active tool number(assigned in Tools)and needs to be implemented in the switch statements of the CanvasWindow mouse event methods.

5. Your new shape must be able to handle all the transformations of the Tool menu, for example move, scale, reshape etc. So if a particular shape can not do a transformation then make sure to overwrite the method in your ShapeObject. This will prevent problems when the shape is selected in a group transformation performed by CanvasWindow methods. If you have a new transformation you will also need to add this to the JDraw/Tools class (assigning it the next available number) and to the JDraw/ToolsMenu. You must also implement the new transformation in CanvasWindow methods.