Program 5 - Drawing

Goal Description Hints Passoff

Due Date - Nov 18

Goal

 
Build a simple drawing program with correct selection of geometric objects.
CS 456
Description
 

1.  Build a completely new model implementation for an application that draws simple lines and ellipses. The file format for this model is as follows.

File Format

The file consists of lines of text. Each line defines an object to draw. For this program there are only two types of lines: lines and ellipses. They each have the format:

  • line - "L" <x1> <y1> <x2> <y2> <red> <green> <blue>
  • ellipse - "E" <left> <top> <right> <bottom> <red> <green> <blue>

Each should be drawn at the coordinates specified and with the specified color. Ellipses are filled.

There are no quotes around the "L" and the "E" in the data file.

The model must be defined and implemented in a similar pattern to what we used for the genealogy file.

2. The program should accept a file as a command line argument and should open a window that displays the drawing. This window should have four buttons, a menu,  and the drawing. This is referred to as the DrawingView window. The four buttons are: Select, Create Line, Create Ellipse and Change Color. They should generally (not exactly) appear as follows:
Draw Program



The Select button (arrow) puts the view into select mode. In select mode any line can be selected by clicking within three pixels of it and any ellipse can be selected by clicking inside of it. You should not use Java's built in methods for these tests. You should program your own.

When a line is selected, little square control handles should appear at the end points. When an ellipse is selected little square control points should appear at the corners of the ellipse's bounding rectangle.

If while selecting a line or an ellipse, the user drags the mouse by more than three pixels, the object should follow the mouse around the screen and be left where the mouseup occurred. This should be a smooth normal drag, not some hack that makes your code easier to write. Select and drag are NOT two seperate clicks.

While in select mode the user may also drag the control points of any selected object. This should cause the object to change in the normal way.

The line button puts the view into line drawing mode. While in line drawing mode, mouse-down starts a line that should rubber-band with the mouse until the mouse-up event occurs. This creates a new line to add to the model.

The ellipse button puts the view into ellipse drawing mode. The mouse-down point is one corner of the ellipse's bounding rectangle and the mouse-move and mouse-up points are the other corner. This ellipse should dynamically expand with mouse movement events until mouse-up occurs.An ellipse should be drawn correctly no matter what direction the user may drag the mouse.

The color button should open Swing's color chooser widget and allow the user to select a new color. The current color should become the background color of the color button. Whenever any line or ellipse is drawn, it should be created with the current color.

The Menu for this view operates as follows:

File - Open - pops up a file chooser, as in the pedigree program, so that the user can select a drawing file to open. As with the pedigree file, if this is a file that is already open in some view, then both views should share the same model and should update simultaneously.

File - Save - saves the changes to the model for this view, not for all models.

View - Delete - if there is a currently selected object, it should be deleted from the model.
View - Text View - This should open a new view of the model that is a single text area widget. This shows the textual representation of the model as it will be stored in the file. This view should be updated whenever any model changes are made. The user may also edit the text in this view, which can change the model. Those changes should appear in all other views of the model whenever key-focus leaves the text area widget.

Hints
 
Passoff
 
__ 2) Files open and a correct view of the drawing appears
__ 1) The select, line, and ellipse buttons each remain depressed when selected to show the application's current mode.
__ 2) Line selection works correctly
__ 2) Ellipse selection works correctly
__ 1) Line dragging works correctly
__ 1) Ellipse dragging works correctly
__ 1) Line control point dragging works
__ 1) Ellipse control point dragging works
__ 2) Current color can be changed and future drawing uses that color
__ 1) Delete works
__ 3) Opening new views works and shared views of the same model works correctly when edited.
__ 1) The Text View menu item opens a correct text view
__ 1) Editing the text view correctly updates the other views of the same model.
__ 3) The Model-View-Controller implementations are organized appropriately and not hacked.