===================================================================================================================================================================
Challenge
Change propagation, widget customization, implementing a more authentic/involved GUI application.
Criteria
- Create a simple but usable spreadsheet application.
- The spreadsheet should be scrollable.
- The rows should be numbered from 0 to 99 and the columns from A to Z.
- Double-clicking a cell C lets the user change C's formula.
- When editing is finished, the formula is parsed and evaluated and its updated value is shown in C. In addition, all cells which depend on C must be reevaluated. This process repeats until there are no more changes in the values of any cell (change propagation). Note that one should not just recompute the value of every cell but only of those cells that depend on another cell's changed value.
- If there is an already provided spreadsheet widget it should not be used. Instead, another similar widget (like JTable in Swing) should be customized to become a reusable spreadsheet widget.
Cells is a more authentic and involved task that tests if a particular approach also scales to a somewhat bigger application. The two primary GUI-related challenges are intelligent propagation of changes and widget customization. Admittedly, there is a substantial part that is not necessarily very GUI-related but that is just the nature of a more authentic challenge. A good solution's change propagation will not involve much effort and the customization of a widget should not prove too difficult. The domain-specific code is clearly separated from the GUI-specific code. The resulting spreadsheet widget is reusable.
Cells is directly inspired by the SCells spreadsheet example from the book Programming in Scala. Please refer to the book (or the implementations in this repository) for more details especially with respect to the not directly GUI-related concerns like parsing and evaluating formulas and the precise syntax and semantics of the spreadsheet language.
Assumptions
- A formula is either an equal sign followed by an expression or text.
- An expression is either a number (5), a cell (A0), a range (A0:B5), or a function call (add(A0, 1)).
- The available functions are:
- add(a, b), sub(a, b), mul(a, b).
- div(a, b), mod(a, b). It is a runtime error if b evaluates to 0.
- sum(*), prod(*). For e.g. sum(), sum(A0), sum(A0:B5), sum(A0:B5, 1, C6), or prod(1, 2, 3, 4, 5).
- A cell reference must be of the form [A-Z][0-99]. For e.g. the following are valid: A0, B10, Z99, whereas the following are invalid: a0, B01, Z100.
- Empty cells, cells with text, and cells with syntax/runtime errors all evaluate to 0 when referenced in an expression.
- Cycles are detected and are not allowed. Try entering "=B8" in A8 and "=A8" in B8.
Code
After opening a code link below, hit the '.' key to open GitHub's browser editor for an improved reading experience.