CPSC 170 Post Lab 2
Drawing
Due Before Lab on Tuesday, January 31st

bricks

For this assignment you will create a simple vector graphics drawing program like Adobe Illustrator or the open source Inkscape. A vector graphics program is different from a raster graphics program in that all objects that are drawn to a scene are stored parametrically instead of in a raster image, like in Adobe photoshop or Microsoft Paint. Storing objects this way allows the user of the program to zoom without losing detail and to more easily edit objects that have already been added. However, it also requires that the scene be re-rendered to a raster image for display every time a change is made.

Details

  1. Begin by creating classes to store the objects that are drawn by the user. Create a parent class, called Shape, that will be extended for each of the different shapes that can be drawn, oval, rectangle, and line. The class should have instance variables that define the bounding region for an object to be drawn. Four integers representing the two points that define opposite corners of the object's bounding rectangle are sufficient. Also add a constructor that specifies the instance data and a paint method that takes a graphics object as a parameter, but does nothing.
  2. Next, define classes for the oval, rectangle, and line. Each of these classes should extend the shape class and will need to define a constructor that calls the Shape class constructor. These classes should also override the paint method to draw the object of each particular class.
  3. The last class you will need is a class that contains the main method and displays the window for the program. The window's main panel should contain two sub-panels. The Left sub-panel should contain radio buttons, aligned vertically, that represent the current tool that is selected by the user (oval, rectangle, or line). You can use the images in the tar file DrawIcons.tar.gz for the radio buttons. The right sub-panel should be where the user can draw and, therefore, should override the paintComponent method.
  4. The main class should have an initially empty ArrayList of drawable objects as an instance variable. When the user clicks and drags the mouse the panel should display the shape corresponding to the currently selected radio button with its upper-left corner where the mouse button was first pressed and its lower right corner where the mouse is currently located. When the mouse button is released the shape should remain with its lower-right corner where the mouse button was released. To accomplish this, the shape should be added to the array list and the paintComponent method should paint every shape in the array list.

  5. Submission: Submit your code as a zip file with your name as the zip file name on the course Inquire site.

    Extra

    Erase

    The vector drawing program delays converting the drawing into a raster until it is drawn to the window. This has several advantages over a raster based drawing programs. For example, it is possible to remove shapes without using an eraser tool that erases everything. Add to the drawing program a button that when pressed removes the most recently drawn shape by removing it from the list of shapes and redrawing the window.

    Zoom

    Another thing that vector drawing programs can do that raster programs can not is change the zoom at which the drawing is viewed. Add to the drawing program a button that when pressed zooms in on the drawing. In order to zoom, the coordinates the shapes do not need to be changed. Instead their coordinates as they are drawn can be modified. For example, if the image is zoomed to double magnification, then the line width and all of the coordinates should be doubled.