Lab Assignment 9 -- Demo and Writeup Due Nov. 7 in the lab session
CS 5551, Fall Semester, 2013
20 Points
Topic: Dialogs

Reference: Chapter 7 (Dialogs)

The assignment: Modify the program of the previous assignments to allow the user to:
(0) keep the data for each shape the user drew in a vector/array,
(1) pop up a ColorChooser that sets the current drawing color,
(2) Load a file that describes a drawing by clicking on the "Load" button on the "File" menu,
(3) Save a file that describes a drawing by clicking on the "Save" button on the "File" menu or in response to a dialog that will pop up when the user exits by clicking the window manager "X".

Discussion:
(0) If you haven't done so already, for each shape the user makes, store the data for that shape (type: rectangle/oval, color, filled/unfilled, bounding rectangle) in a vector/array. It would probably be useful to have a MyShape class for this data.
(1) There should be two ways of choosing colors: (a) by pulling down the "Color" menu and choosing a new menu item "Others" (in addition to Red, Green, and Blue), and (b) by clicking on a "color swatch" that is a new icon on the toolbar (the "icon" should simply be a rectangle of the current drawing color); choosing "Others" from the color menu or clicking on the "color swatch" on the toolbar should both bring up a color chooser dialog. Here is the code for the ColorChooserDemo2 program file, which has an example of a color chooser dialog.
(2) To load picture data from a file (that contains information about the picture: number of objects, and the MyShape data for each shape/object), pull down the File menu and select "Load", which should pop up a "loadFile" dialog that allows you to choose a file name. Once that is done, read the file and use that data to create a vector of drawing objects, then use it to repaint the drawing area. After that, the user should be able to add more objects.
(3) To save picture data to a file, pull down the File menu and select "Save", which should pop up a "saveFile" dialog that allows you to choose a file name. Once that is done, iterate through the vector of drawing objects (just rectangles and ovals for now) and write their data to that file (maybe starting with the length of the the vector). Here is the code for the FileChooserDemo program file, which has examples of load and save dialogs (also here are links to the file open/load icon , and file save icon ; Note: these are 16-by-16 pixel icons - you might want to use the 24-by-24 pixel icons at the Java Graphics Repository ).
For information about reading and writing files in Java see the tutorial: Basic I/O . Note: Object Streams may be most useful, and the ObjectStreams example in particular (note that Java Color objects are serializable). Another option is to use formatters and scanners (but this entails converting Color objects to 3 ints for writing, and converting back when scanning), which deals with human-readable files.
(4) You can exit the program by either pulling down the File menu and selecting "Exit" or clicking on the window manager "X" decoration. Either way should pop up and ordinary "yes-no" option (question) dialog that has the text "Save changes?"; clicking the "yes" button should pop up the "saveFile" dialog that would allow the user to save the current drawing, clicking "no" should just exit. For information about dialogs, see the tutorial on dialogs: How to Make Dialogs
- the DialogDemo example has a Yes/No dialog as the second option on the first pane of the tabbed pane component. Note: you no longer need the popup menu from Lab 7 to choose the exit mode.

What to turn in: Turn in the following items from the Computer Science Lab Report Format:
1. (1 point) The Basic Information (your name, class, section, TA's name, assignment number, and date) can be on a separate cover sheet or as (highlighted) comments at the top of your main program file.
11. (5 points) Include the program listings. This listing should show good style, be appropriately commented, have the important/new parts highlighted, and include handwritten explanations if it helps the reader's understanding of the code.
13./14. (9 points) Do a demo of your modified program for the TA that demonstrates that the program works correctly.


Page URL: http://www.d.umn.edu /~ddunham/cs5551f13/assignments/lab9/assignment.html
Page Author: Doug Dunham
Last Modified: Thursday, 07-Nov-2013 16:38:44 CST
Comments to: ddunham@d.umn.edu