CS365 Spreadsheet Interface Project Assignment

My interpreter notes can be found here.

In this assignment your team is going to create a user interface using Swing widgets for the spreadsheet interpreter that you wrote in the previous assignment. A minimal acceptable interface is shown below:

It contains the following items:

  1. An 11x11 grid of JLabels or JTextFields (I used JTextFields and set the editable property to false).

    1. The top row contains fixed column labels with the values a-j
    2. The leftmost column contains the row subscripts 0-9.
    3. The remaining labels should display the current value of the cell at that location (e.g., the label at b3 should display the current value of the cell b3).

      • If the formula cannot be evaluated because it depends on an undefined cell, then the cell's value should be displayed as "undef".
      • If the cell has never been assigned a formula, its value should be blank.
      • A cell's numeric value should be displayed with two decimal places. You can format a floating point number as a string using the String command:
        String.format(format string, args)
        For example:
        String formattedString = String.format("%3.2f", 65.3868);

  2. A text box for entering new formulas. For this assignment you may pass the new formula to either your antlr parser, or to one that I will provide. If the formula is correctly parsed and evaluated, then the text box should be cleared and the cell's new value should appear in the spreadsheet. When a parse error occurs, either because of a syntax error or a semantic error, your interface should pop up a dialog box describing the error. Your program should not clear the text box in this case, so that the user has an opportunity to correct the user's error. My interpreter notes describe the exceptions thrown by my code.

  3. A button for explaining why a cell's value is displayed as "undef". To utilize this feature, the user will need to select a cell, and then press the button. Your interface should pop up a dialog box that names the undefined cell on which this formula depends. For example, if the formula is "c[5] = a[5] + b[5]" and b[5] is undefined, then your interface will show that c[5] is undefined. When the use clicks the inquiry button, your interface will pop up a dialog box saying that b[5] is undefined.

  4. A quit button for exiting the spreadsheet.
Your team should feel free to do some creative design for extra credit on this assignment. Some of the opportunities include:

  1. Being able to edit the column labels before any formula has been assigned to a cell in that column.

  2. Adding new columns to the end of the spreadsheet.

  3. Entering a new formula directly into a cell (you will need to use JTextFields to represent each cell rather than JLabels). This would probaby work only with non-generic formulas, although you are free to try to work out a design for generic formulas as well. Since the left hand side of the formula is known, the user should just be able to enter the formula (e.g., b[2] + c[2]) without specifying the left hand side variable. You can append the left hand side variable and an equal sign to the formula entered by the user and then pass the string to the parser.

  4. Using a JTable, rather than JTextFields or JLabels, for the grid.

  5. Feel free to use your imagination to add other features, but please document them in a README.txt file.

Required Behaviors

The previous section described most of the required behaviors for this interface. However, please make sure that your interface also supports the following behaviors:

  1. When a formula is entered in the formula text box, the cell(s) it is assigned to should be updated, as well as any cells that depend on the cell(s) with the new formula. If you use my parser, you can call Cell.updateCells() to re-evaluate all the cells and bring their values up to date. Then you can simply traverse through each location in your spreadsheet grid, request the value of that cell, and assign it to the appropriate JLabel or JTextField.

  2. When the user mouse clicks on a cell, the formula associated with that cell should appear in the formula textbox (the formula may be a simple number). If you use my interpreter, the Cell class has a method named setFormulaExpression that you can use to store a formula's text string with a cell, and a method named getFormulaExpression that you can use to retrieve this string. You will need to call setFormulaExpression on each cell that is assigned a formula by the parser. My parser will return a linked list of cell objects, and you can iterate through them and set each one to point to the string for this formula. Antlr does not provide a way of getting at the original string that is passed to the parser, so the parser cannot be responsible for storing the formula string into a cell.

  3. When the user press the quit button, the spreadsheet should exit.

Sample Executable

A sample executable with the minimal interface that I just described is available as a jar file at /home/bvz/cs365/project/project4/spreadsheet.jar. This jar file will only work on the CS machines, because it depends on the antlr implementation on the CS machines. If you want to make it work on your machine, you will need to copy my class files from /home/bvz/cs365/project/project4/formula and then jar it up with your own version of antlr.

Submission Instructions

  1. Place your code in a package named formula.
  2. Your main class should be called Spreadsheet.
  3. Jar up your .g, .java, and .class files and include a manifest.txt file with the following lines:
    Main-Class: formula.Spreadsheet
    Class-Path: /usr/share/java/antlr3.jar
  4. Use the 365_submit script and type "p4".