COP4226, Homework
Due Monday, 12/6.
Zip your entire project and upload on the web. Exclude the
Debug and Release directories.
Submitting
Homework Online.
This project will be a single instance, multiple SDI application. Each top
level window will have its own document containing a default font, default
color, and a list of lines of text. The location of a line can be changed, text
color can be changed, the font can be changed for each line of text. The
default color and font are used for adding new lines of text. Drag and drop is
used. The data classes are disposable and serializeable. Each line of text can
be dragged to a new position.
Data Class
Create a data class that represents a line of text.
- The class will have the following public properties: text, font, color
and location.
- Create a private solid brush for the color. Recreate the brush everytime
the color changes.
- Add private members, such as the graphics context of the main form, the
size needed to draw the text in the graphics context, the rectangle that
bounds the text in the graphics context, the string format for drawing the
text.
- Create a non-default constructor.
- The class should be serializable. Serialize all the public member
variables. Recreate and initialize nonserialized members when the class is
deserialized.
- Implement IDisposable. Dispose of resources appropriately. Optimize
garbage collection.
- Add a method for painting the text using a grahics context. Use the
location, font and brush that are in the class.
- Add a method that tests if a point is within the bounding rectangle that
is needed to draw the text in the grahics context.
- Add a method that updates the location by an offset represented by a
point.
- You may add other helper methods and variables as you see fit. The idea
is to encapsulate all access to the data inside this class.
Document Class
Create a document class that contains a generic list of the data class, a
default font, a default color. Add other properties and methods as needed.
Additional methods should be added to encapsulate access to the document
class.
- Create public properties for default font, default color, list of words,
default location, current item in list, fileName (if document has been
saved or opened).
- Make the class serializeable. Serialize the public member variables,
except filename and current item. Recreate and initialize nonserialized
members when the class is deserialized.
- Implement IDisposable. Dispose of resources appropriately. Optimize
garbage collection.
- Create an AddFile method that is passed the name of a text file. Open the
file and add its lines to the list. Use a StreamReader to open the file.
- Create an AddLines method that is passed a string. The method will break
the string into separate lines and add them all to the list. Use a
StringReader to access each line in the string.
- Create an Add method that will add a string to the list. Do not add all
lines at the same location; offset the starting location of each line that
is added (this applies to AddFile and AddLine, too).
- Create a method that will draw all the items in the list.
- Add a method for removing the current item from the list. Find another
current item afterwards.
- Add a method for changing the location of the current item in the list by
an offset represented by a point.
- Add a method that finds the first item in the list whose bounding
rectangle contains a point. If found, set the current item to the found
item.
Main Class
- Make this a single instance, multple SDI application. Use the visual
basic application base class.
- All files on the command line with a .txt or .hw4 extension should be
opened in top level windows.
- Do not open a file again, if it is already open, just activate its
window.
- Add a Window menu to each of the top level forms. The actual menu
will be generated in the application base class. The window menu will
show all the open windows, with the current window checked in the drop
down list.
- The title bar of each top level window should be unique.
- Derive the top level main form from the base form class from Homework 2.
- Change the cursor to an animated cursor.
- Add a new user control to the control library. The only thing to do is to
set the DoubleBuffered property to true. Add the new user control to the
main form so that it fills the client area.
- Add a label to the status bar for displaying the name of the current
file. If there is no file open, then display an appropriate string.
- Add a label to the status bar for the CAP lock key. It should always
reflect the current state of the CAP lock key.
- Add a main menu, in addition to the one that is already in the base form:
Add the default items. You may remove following from the edit menu: Undo,
Redo, Select All.
- File->Open: Open a file in a new top level window. The drop down list
of file choices should be for text files (*.txt) and for files created by
this application (*.hw4). Call the appropriate method in the data class,
depending on the extension.
- File->New: Open a new, empty, top level window.
- File->Save: serialize the documents class. If the file has already
been saved, then save it again. If it has not been saved, then call the
Save As handler.
- File->Save As: alow the user to choose a file; only save with the .hw4
extension. The drop down list of file choices should be for files created
by this application (*.hw4).
- File->Exit: close all open forms, so the application exits.
- File>Close: close the current top level form. Make another one the new
main form.
- File->Print and File->Print Preview.
- Use a monospaced font.
- Start each line on its own line. Do not allow word wrap. If the line
does not fit within the margin bounds, add the ellipsis after the last
character that fits.
- The lines should display within the correct margin bounds for the
current printer.
- If the entire line cannot fit in the remaining space on the page,
then start a new page.
- Print a header within the correct page bounds for the printer and
outside the margin bounds.
- Top, left: Title of homework
- Top, Right: Course name
- Bottom, Left: Student name
- Bottom, Center: Page number
- Bottom, Right: Date
- Edit->Cut: remove the current item from the list. Set a new current.
Shortcut is Ctrl-X.
- Edit->Copy: copy the text of the current item into the clipboard.
Shortcut is Ctrl-C.
- Edit->Paste: add new items to the list from the clipboard. Split the
string into separate lines and add each line to the list. Shortcut is
Ctrl-V.
- The toolstrip items for cut, copy, paste should only be enabled when the
action can be performed.
- When the main form is constrcuted, copy all the menu items into the base
menu, or use the ToolStripManager to merge menus like in the MDI
application.
- Tools->Options->Font: change the current font for the data class.
The default font is used for new lines that are added to the document, it
will not affect those that have already been added.
- Tools->Options->Color: change the current color for the data class.
The default color is used for new lines that are added to the document, it
will not affect those that have already been added.
- Tools->Customize: open a modal dialog for changing the font, color,
location and text of the current item from the list. The dialog should have
OK and Cancel buttons. If Cancel is clicked, then do not update the current
item.
- Window: show a list of all the top level windows. The current top level
window should be checked in the drop down list.
- Help->About, Help->Oath: override the Oath and About handlers and
open appropriate dialogs.
- Add a ToolStrip: Add the default items. Add a separator and two buttons
to the toolbar. Create simple images for the new buttons. One is for
changing the default font, one is for changing the default color. Map the
handlers for the tool items to existing handlers from the menu strip.
- Enable the dragging of any word on the page.
- Allow text to be dropped into the panel. Split the drag data into
separate lines and add them all to the list.
- If a word is double-clicked, then open the modal dialog for editing its
values (like Tools->Customize).
Screen Shots