WebStart Editor -- Due date: Last day of class 2011

Your job for this lab is to build a simple editor and post a Web Start link to it on your web page.

Minimum requirements

  1. Two menus: File and Edit
  2. File commands
    1. Open, shortcut cmnd-o
    2. Save, shortcut cmnd-s (saves the current file, don't make them navigate to it again!)
    3. New, shortcut cmnd-n
  3. Edit commands - just like almost every editor!
    1. Copy, shortcut cmnd-c
    2. Paste, shortcut cmnd-v
    3. Cut, shortcut cmnd-x

Details

  1. As seen in class, you can read and write files using a MyReader and a MyWriter. They are here, and here.
  2. You should create new files in NetBeans with those names and copy their contents into the classes in your project (be sure they are in the same package as your editor!).
  3. To implement save without forcing the user to renavigate the path to the directory they opened the file in, you must save the pathname they navigated to to open the file. To do that send the getPath() message to the MyReader (*after* they have selected the file!), and store it in a String variable for later use. Like this:
            MyReader mr;
            mr = new MyReader();
            currentPath = mr.getPath();
    
  4. Now when they save the file you can create a MyWriter pointed to it by:
            MyWriter mw = new MyWriter(currentPath);
    
            mw.println(theTA.getText());
            mw.close();
    
  5. If the user creates a new file, it will not have a path, so, when they save it you should create the MyWriter like this:
        MyWriter mw = new MyWriter();
    instead.
  6. To know which of the above to do, you will need a variable. Like this:
        boolean needPath = true;
    
        ...
    
        void save() {
            MyWriter mw;
            if (needPath) {
                mw = new MyWriter();
                needPath = false;
                currentPath = mw.getPath();
            } else {
                mw = new MyWriter(currentPath);
            }
    
            mw.println(theTA.getText());
            mw.close();
        }
                    
    and, when they open a file, set needPath = false, and when they make a new file, set needPath = true;.
  7. When they say New File, try new EditorFrame()

Distributing your code

To make your program available on the web you must package it so that Java WebStart can start it. Here's how:
  1. Select "Customize" in the drop-down menu (beneath Navigate) that currently says "<default config>" (this will open the "Project Properties - editor" window)
  2. Under Categories (the left pane): click Web Start
  3. Check Enable Web Start
  4. After "Codebase:" select "User defined (e.g. HTTP deployment)" instead of "Local Exectution"
  5. In the "Codebase Preview" TextField, fill in the entire web path to your distribution directory, starting with http: -- for instance mine says: http://willamette.edu/~levenick/cs130/examplesFromClass/editor/dist/
  6. Click OK, then use the broom (Clean and Build Main Project)
  7. Use the Finder to navigate to your dist directory, and double-click the HTML file there, click the link there to launch your program
  8. Assuming that all worked (!!), you can put a link to that HTML file on your home page

How to get credit:

Post an easy to find link to your working editor on your web page.

Extra credit!

  1. Add Save As
  2. Add a formatting option. This converts your simple editor to a word processor! To start, interpret double newlines as paragraph breaks, convert single newlines to spaces and break lines only at word boundaries (i.e. convert the space between them back to newlines). See class notes for particulars.