COP4226, Homework
Due Saturday, 12/3.
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. The application shows a graphical view and a
table view.
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 as needed, 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. Pass a grahics context to the method. Use the
location, font and brush that are in the class to draw the text.
- 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 lines,
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, .htm, .html, .xml 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 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, Print, Print Preview, Help.
- File
- Open: Open a file in a new top level window. The drop down list of
file choices should be for text files (*.txt, *.htm, *.html, *.xml) and
for files created by this application (*.hw4). Call the appropriate
method in the data class, depending on the extension.
- New: Open a new, empty, top level window.
- 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.
- 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).
- Exit: close all open forms, so the application exits.
- Close: close the current top level form. Make another one the new
main form.
- Edit
- Cut: remove the current item from the list. Set a new current.
Shortcut is Ctrl-X.
- Copy: copy the text of the current item into the clipboard. Shortcut
is Ctrl-C.
- 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 constructed, copy all the menu items into the base
menu, or use the ToolStripManager to merge menus.
- Tools->Options
- Font: change the current font for the document 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.
- Color: change the current color for the document 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.
- 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.
- Tools->Search Menu Item
- Open an owned, modeless dialog containing the following:
- A list box that will display all the files found.
- Buttons for starting, stopping and pausing a search.
Enabled/disable these buttons as appropriate.
- Pause a thread by calling the static method Sleep from the Thread
class. Sleep for short periods of time, checking to see if the
thread should resume.
- A combo box with drop down style of drop down list, containing
the different extensions for text files. Include .txt, .html, .html
and .xml at the least. You may add other extensions if to the list
if you choose. You can type an extension into the combo box.
- The search should be run in a separate thread.
- When the search is paused, change the name on the pause button to
continue. If clicked a second, this button will continue the search.
- Search for all files with specific extension on the current computer.
- Find all files with the extension selected from the drop down
list.
- If the drop down list is changed during the search, then the file
extension that the search is seeking will also change.
- I have provided a text file with
methods that will search your hard drive for .txt files.
- You will need to modify the code for different
extensions.
- You will need to modify the code to work in a thread.
- You will need to test for cancellation and pause at several
places, to guarantee a fast response to the command.
- Every time files are found in a directory, add the full path of each
file to the list box.
- Double-clicking the name in the list box should open or activate a
window for that file.
- Only allow one search dialog to be open at a time.
- Only allow one search to proceed at any time.
- If the dialog is closed before the search ends, be sure that the
search is cancelled before the dialog closes.
- When the search is complete, display a message box stating how many
files were found.
- I strongly suggest that you use a BackgroundWorker.
- 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 any line in the view can be be clicked and dragged with the
mouse to a new location. This is not drag and drop, it is similar to moving
a control with the mouse.
- Add a label to the status bar that indicates if the cap lock key is
toggled.
- If a line is double-clicked, then open the modal dialog for editing its
values (like Tools->Customize).
- Drag and drop
- Implement drag and drop. Start a drag operation when the letter C is
down and a mouse drag is started.
- Allow for copy and move. If the C key is down, perform copy; if the C
key is up, perform move.
- If the operation is move, you must delete the original text after the
move is done.
- Allow text to be dragged from one open window to another.
- Allow text to be dropped into an open window in the application from
a different application. Split the drag data into separate lines and
add them all to the list.
- Do not allow text to be dropped in the same open window that started
the drag operation.
- Main layout. The main form should have a layout that has a panel, a
splitter and a data grid view.
- Arrange the panel so it fills the area above the splitter.
- Arrange the grid view so it fills the area below the panel.
- Start the splitter in the middle of the main form.
- Bind the document to the grid view. Update the binding when a
document is deserialized. Since both views are visible at the same
time, changes to one will automatically change the other, if you have
bound it correctly.
Screen Shots: Property Dialog. Search Dialog. The second screen shot has many
windows. There is a new window, with no file attached; there is a window with a
modified file (the font and color have been changed for two lines of text); the
search dialog is open and paused.