CPSC 124, Spring 2006
Programming Assignment 2: Mosaic Draw Continued
This is the second of three programming projects. It is due on Wednesday, April 19. The project is a continuation of the Mosaic Draw program that you worked on for Lab 9. If you did not complete that lab successfully, you can ask me for a copy of my solution to use as a basis for further work.
Remember that this is an individual assignment. You should not give help to or receive help from any other member of the class. You should not discuss your program or show your work to other people in the class. You can get help from me or from the computer science TA's, but not from anyone else. You should not copy code from the Internet or from any other source.
The basic assignment, which will be worth a maximum of about 80%, is to add an "Undo" command, several new "Color"commands, and "Rectangle" and "Filled Rectangle" tools. Furthermore, you must post the applet versin of your program on your web site, along with one or two images that were created using your program. Here is a working version of the applet that meets the basic requirements:
(An executable jar file for the stand-alone application version can be found in the file MosaicDrawCompleteBasic.jar.)
Here are some more details on the required features:
- Undo command: The Undo command should restore the state of the image to what it was before the previous operation. To implement this, you have to save the state before you perform any operation that affects the appearance of the image. The MosaicPanel class already has support for saving and restoring the state of the image. The copyColorData() method returns a value of type Object that contains the entire state of the image. This object can be passed to the restoreColorData(Object) method to restore the state. You just have to figure out when to call these methods. Note that "Undo" can only undo the single most recent change; this is not a "multi-level" undo.
- Set Background Color and Set Grouting Color commands: The background color is the color used for squares which have not yet been painted. At the beginning, it is black. The grouting color is the color used for the thin lines that are drawn between the colored squares. By default, it is gray. The Background Color and Grouting Color commands allow the user to change these colors. You should look at the implementation of the "Set Color" command to find out how to get a color from the user. But note that these commands differ from the "Set Color" command in that they make an immediate change to the image.
- Hide/Show Grouting command: It is possible to turn off the grouting completely in a MosaicPanel by setting the grouting color to null. The "Hide/Show Grouting" command should hide the grouting if it is currently shown and should show it if it is currently hidden.
- Rectangle and Filled Rectangle tools: These tools can be used to draw the outline of a rectangle and a filled in rectangle respectively. When the user drags the mouse, the rectangle is drawn between the position where the mouse started and its current position. In order to implement these tools, you have to save the starting position of the mouse in the mousePressed() method, so that it will be available in the mouseDragged() method. A new rectangle is drawn each time mouseDragged() is called. Furthermore, in the mouseDragged() method, before drawing the new rectangle, you should restore the state of the image to what it was at the beginning of the mousePressed() method. (This is related to the "Undo" command.)
For full credit, and possibly extra credit, you should implement some additional features. Here is a version that implements a large number of features, more than I would expect you to do (but note that the command-key equivalents for the menu commands are probably not active in this applet version):
(An executable jar file for the stand-alone application version can be found in the file MosaicDrawCompleteFull.jar.)
This version has a "Redo" command and an "Undo" that can undo multiple actions. It has added command-key equivalents for some commands and uses radio buttons and checkboxes in the menus for some of the commands. (The command-key equivalents are probably not functional in the appet version.) The applet has a "Line" tool. A new "Mode" menu has been added, and the "Tools" menu has been redesigned. In this version, the "Tool" tells which squares will be affected when the user drags the mouse, and the "Mode" determines what will happen to those squares. For example, the "Brush 3x3" tool combined with the "Erase" mode allows you to erase 3-by-3 blocks of squares. In the "Draw Under" mode, drawing will only affect uncolored squares, while in "Draw Over", drawing only affects squares that already have a color and background squares are left unchanged. In "Blend" the color of a square is set to a combination of 25% of the drawing color and 75% of the current color; "Blend Over" applies this operation only to squares that already have a color. If the "Symmetric" option is turned on, then whenever one square is colored, its horizontal and vertical reflections are also drawn. There is also a more subtle change: Wiggling the mouse around inside a square does not cause that square to continuously change color. These are not by any means the only changes that could be made. It would be nice to have tools for drawing ovals and filled ovals, but these would be even harder than lines. It would be nice to save information about the current picture to a file so that you could reload it later and continue to work on it. It would be nice to be able to choose the amount of blending used in the blend tools. You might be able to think of even more possibilities.
Some of the options are fairly easy to implement, others are quite difficult, and one of them (multiple undos) requires a technique that we have not yet covered in class. I will discuss the implementation of some of these options in class, but you will probably want to come in to discuss your ideas with me and get some help about how to implement them.
David Eck, March 2006