COP4226, Homework 2
Due Monday, October 27 (late 6am 10/28)
Create an application that will use a separate class for a document. The document will
contain a list of shape ojects. Define a separate class for the shape information. Be sure
to encapsulate operations in the class they work on.
Avoid long methods. Each method that you create should be short, to promote
encapsulation. If you have a method that is longer than 25 lines, then it
probably needs to be divided into smaller methods.
Do not create a new data structure if one that already exists will
solve the problem.
Control Library
Use the control library from homework 1. Be sure to include the file in the zip that you upload.
- Add a form that will be used as a base form for the main form in the main
project.
- Add a menu strip, docked to the top.
- Add a top level menu item named Help to the menu strip.
- Add a menu item named Oath
- Add a menu item named About.
- Add handlers for both of these menu options; make them virtual.
The implementation of each should throw a new NotSupportedException
with an appropriate message.
- Add tool tips to the top level menu item and to each submenu
item.
- Add a top level menu item named File to the menu strip.
- Add a menu item named Close. When clicked, close the application.
- Add a status strip, docked to the bottom.
- Add a name control from your user library, dock it to the top, so
that it abuts the bottom of the menu strip.
- Add a main panel that fills the remaining area of the form; if the
form is resized, the panel should still fill the rest of the client
area.
- Change the access modifier for all of these so that derived classes
can access them.
Interfaces
Use interfaces to encapsulate implementation details. Design code so that the implementation details of data could be changed in the future without having to rewrite all the code that accesses that data.
Oath Dialog
Create a dialog in the main application that will display the pledge of honesty.
- Extend from the base dialog from HW1 in the control library.
- Add the oath control. Center it in the remaining space.
- The dialog should be a fixed size. Remove the icon, minimize button and maximize button.
About Dialog
Create a dialog in the main application that will display a description of the assignment.
- Extend from the base dialog from HW1 in the control library.
- Add a description of the assignment in your own words. Center it in the remaining space.
- The dialog should be a fixed size. Remove the icon, minimize button and maximize button.
Shape Enumeration
Create an enumeration for shapes that contains the values Ellipse, Rectangle and Triangle.
Shape Class
Create a class that will hold data for a shape. The shape will have text, location, size, rotation, scale, translation and shape type.
Add properties to improve encapsulation. Add more properties and helper methods that contain operations that work on shapes. Encapsulate shape processes in this class.
Document Class
Create a document class that will store shapes. Add properties and helper methods to encapsulate document processes in this class.
Shape Options Dialog
Create a dialog in the main application that will allow the user to modify information for a shape.
- Extend it from the base dialog from the control library.
- Add controls to change all the properties in a shape.
- The interface for the shape should be a ComboBox that is set as a DropDownList. Fill it with the values from the shape enumeration. Make this dynamic, in case shape types are added or removed in the future.
- Perform thorough validation. Allow focus change.
- Anchor the OK, Apply and Cancel buttons so that they remain in the lower right
area of the form when the form is resized.
- When using an interface, it is better to encapsulate actual properties in the dialog or components than to create additional variables.
- The dialog may not access any members from the main form, application settings or user settings.
Main Form
Extend the main form from the form that was added to the control library for this assignment.
- Override the handlers for the Oath and About menu items so they open the Oath and About dialogs modelesslly. Only allow one of each to be open at a time. Open the dialogs so they do not cover the main window. The main form should own the dialogs.
- Add a main menu to the form. Merge it with the menu in the base form (refer to the link on the class page about inherited menus).
- Add a Shape menu item with drop down items for each type of shape.
- When an item is clicked, it should be checked.
- Only allow one item to be checked at a time.
- Set one as checked.
- Add a Pen menu item with drop down items for three types of pens: solid, custom dashed, compound.
- When an item is clicked, it should be checked.
- Only allow one item to be checked at a time.
- Set one as checked.
- Create a pen for each item. Each pen should use the pen color. Create a custom dashing for one pen. Create a compound pen for another. Use a big enough width so the dashing and compound can be seen easily.
- When an item is clicked, set the current pen to the selected item's pen.
- Add a Brush menu item with drop down items for three types of brushes: texture, hatch, path gradient.
- When an item is clicked, it should be checked.
- Only allow one item to be checked at a time.
- Set one as checked.
- Create a brush for each item.
- The texture brush should be drawn with the color of all pixels in the image that match the lower left pixel color changed to the brush color. Choose a simple texture. I used one of my toolstrip images.
- The hatch brush should use the brush and pen colors.
- The path gradient brush should use more than two colors by alternating the brush and pen colors. The shape of the brush should match the shape type. Set the center color to the brush color. Use a small size for the brush and tile it.
- When an item is clicked, set the current brush to the selected item's brush.
- Add a Color menu item with drop down items for two colors: pen color, brush color.
- When an item is clicked, it should be checked.
- Only allow one item to be checked at a time.
- Set one as checked.
- When an item is clicked, open a color dialog to let the user select each color.
- Add a Font menu item without any drop down items. Open a font dialog to select the font to draw the text in a shape. Allow the font dialog to change the color of the font, too.
- Add a tool strip. Add items for each of the above menu items. Reuse the handlers for the menu items, do not create new handlers. Create your own images or find useful ones on the web.
User Interface
When the user clicks and drags the mouse, create the currently checked shape from the shape menu.
- The upper left and lower right corners of the shape are defined by the original mouse down and the current mouse positions.
- Draw the shape on the main panel using the current colors, pen and brush. Draw and fill the shape. Add a label to the shape and display its shape type.
- In the status bar, list the current colors, the type of shape, the type of pen and the type of brush.
- As the mouse is being dragged, show the shape being resized.
- Be sure the shape draws when the mouse is dragged in any direction, not just down and to the right.
-
When a shape is right-clicked, open the options dialog modelessly.
- When the user clicks apply, the main form will retrieve the updated properties and redraw itself.
- The scale, rotation and translation properties will be used to draw the shape using a matrix.
- The text should be drawn inside the shape. The text might be clipped by some of the shapes. Use the selected font and font color to draw the text.
- Be sure the dialog can still be opened after the shape has been transformed.
Upload Assignment
Zip your entire project and upload on the web. Exclude the
Debug and Release directories.
Submitting
Homework Online.
Be sure to include your control library in your uploaded file.