Reference: Chapter 7 (Dialogs)
The assignment:
Modify the program of the previous assignments to allow the user to:
(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:
(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, color,
coordinates, and filled/unfilled info), 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 ).
(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.
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. (7 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. (12 points)
Do a demo of your modified program for the TA that demonstrates that
the program works correctly.