Programming Assignment 5

A Simple Text Editor using Java Swing

Code Review for Jade Cheng

Build Results

No errors; no warnings

Requirements Verification

REQ-SP1

All source code should be submitted in one file, and that file should be named according to the following pattern: LastFirstX.java, where Last is the student’s last name, First is the student’s first name, and X is the assignment number.

For example, student John Doe would submit DoeJohn3.java for programming assignment 3.

PASS.

REQ-SP2

The first lines of the submitted file should include a comment with the following information and format:

/**
 * A short description of the program.
 *
 * @author     Last Name, First Name
 * @assignment CSCI 2912 Assignment X
 * @date       Date
 */

PASS.

REQ-SP3

The submitted file should be emailed to ycheng@hpu.edu.

PASS.

REQ-SP4

The subject line of the email sent to the instructor should follow the pattern: [2912] assignment number.

For example, for assignment 3, student John Doe would write “[2912] assignment 3” as the subject line of his submission email.

PASS.

REQ-SP5

The submission email sent to the instructor should include exactly one attachment, the Java implementation file. Students should not attach any other files to their submission email.

PASS.

REQ-GG1

The implementation file must include JavaDoc for all definitions: classes, interfaces, fields, methods, enumerations, and so on.

PASS.

REQ-A5.1.1

You will implement a Java Swing application that allows the user to open, edit, and save text files.

PASS.

REQ-A5.2.1

When the application starts, it displays a JFrame (window) that is centered both horizontally and verticallty on the screen.

PASS.

REQ-A5.2.2

The application allows the user to move and resize the window using the standard controls provided by the host operating system.

PASS.

REQ-A5.2.3

Initially, the title of the window is “Untitled - CSCI 2912 Editor”.

PASS.

REQ-A5.2.4

When the window is closed, the application terminates.

PASS.

REQ-A5.3.1

The application sets the content area of the window to a JScrollPane.

PASS.

REQ-A5.3.2

The initial size of the scroll pane is 500x500 pixels.

PASS.

REQ-A5.3.3

When the window size changes, the scroll pane stretches to fill the entire bounds of the content area.

PASS.

REQ-A5.4.1

The application adds to the scroll pane an editable JTextArea.

PASS.

REQ-A5.4.2

The text area displays text with a 14-pt “Monospace” font.

PASS.

REQ-A5.4.3

The text within the area is left justified and does not wrap automatically.

PASS.

REQ-A5.4.4

When the size of the scroll pane changes, the text area stretches to fill the entire bounds of the scroll pane.

PASS.

REQ-A5.4.5

If the size of the text exceeds the size of the scroll pane, horizontal or vertical scroll bars appear that allow the user to scroll through the text area content.

PASS.

REQ-A5.5.1

The application displays a JMenuBar.

PASS.

REQ-A5.5.2

The menu bar contains one JMenu with the text “File”.

PASS.

REQ-A5.5.3

The application uses the letter “F” as the mnemonic for the File Menu.

PASS.

REQ-A5.6.1

Hint: When hosted on Mac OS X, to cause the Menu Bar to appear at the top of the screen, set the system property “apple.laf.useScreenMenuBar” to “true”. Setting this property on Windows or Linux hosts has no effect.

PASS.

REQ-A5.8.1

The File Menu contains five JMenuItem instances; ordered from top to bottom, the names of these items are “New”, “Open”, “Save”, “Save As...”, and “Exit”.

PASS.

REQ-A5.8.2

The application adds a separator between the Open Menu Item and the Save Menu Item, and it adds another separator between the Save As... Menu Item and the Exit Menu Item.

PASS.

REQ-A5.9.1

The application assigns mnemonics to all menu items.

PASS.

REQ-A5.9.2

The application assigns accelerators to all menu items except the Exit Menu Item.

PASS.

REQ-A5.9.3

The mnemonics and accelerators are defined in the table below.

PASS.

REQ-A5.9.4

The application determines the appropriate shortcut key using the Toolkit.getMenuShortcutKeyMask method.

PASS.

REQ-A5.10.1

When the user selects the New Menu Item, the application clears the text shown in the text area.

PASS.

REQ-A5.10.2

The application then sets the title of the window to “Untitled - CSCI 2912 Editor”.

PASS.

REQ-A5.11.1

When the user selects the Open Menu Item, the application shows an Open File dialog using JFileChooser.

PASS.

REQ-A5.11.2

If the user selects a file from this dialog, the contents of the text area is replaced by the contents of the file.

PASS.

REQ-A5.11.3

The application then sets the title of the window to “XXX - CSCI 2912 Editor”, where “XXX” is the name of the file not including its directory.

PASS.

REQ-A5.12.1

If an I/O error occurs while opening or reading the file, the application does not clear the contents of the text area or change the title of the window but instead displays an error dialog using JOptionPane.showMessageDialog.

PASS.

REQ-A5.12.2

The application sets the title of this dialog to “Error Opening File”, the message type to JOptionPane.ERROR_MESSAGE, and the message text itself to the value returned by Exception.getMessage().

PASS.

REQ-A5.13.1

When the user selects the Save Menu Item before successfully opening or saving the file since the time the application was started or since the user selected the New Menu Item, then the application proceeds as if the user selected the Save As... Menu Item.

PASS.

REQ-A5.13.2

Otherwise, the application saves the contents of the text area to the path most recently selected by the user.

PASS.

REQ-A5.14.1

If an I/O error occurs while recreating or writing to the file, the application displays an error dialog using JOptionPane.showMessageDialog.

PASS.

REQ-A5.14.2

The application sets the title of this dialog to “Error Saving File”, the message type to JOptionPane.ERROR_MESSAGE, and the message text itself to the value returned by Exception.getMessage().

PASS.

REQ-A5.15.1

When the user selects the Save As... Menu Item, the application shows a Save File dialog using JFileChooser.

PASS.

REQ-A5.15.2

If the user selects a file path from this dialog, the contents of the text area are written to the path selected by the user.

PASS.

REQ-A5.15.3

The application then sets the title of the window to “XXX - CSCI 2912 Editor”, where “XXX” is the name of the file not including its directory.

PASS.

REQ-A5.16.1

If an I/O error occurs while creating or writing the file, the application does not change the title of the window but instead displays an error dialog using JOptionPane.showMessageDialog.

PASS.

REQ-A5.16.2

The application sets the title of this dialog to “Error Saving File”, the message type to JOptionPane.ERROR_MESSAGE, and the message text itself to the value returned by Exception.getMessage().

PASS.

REQ-A5.17.1

When the user selects the Exit Menu Item, the application terminates.

PASS.

Screenshots

Main Frame

Menu

Open

Open Error

Save

Save Error