This is a worksheet where the cells contain arbitrary Java objects. They are described by a Java-like expression language: you can type a "Java" expression into a cell, and it will be parsed, executed, and the result will be cached as the contents of the cell. From this page, the worksheet is available both as an applet and as a Web Start application: in the latest release of jga (0.7), it is included as a stand-alone application as well. Both the standalone and the Web Start versions can read and write files on your local filesystem (with an appropriate warning in the case of the Web Start version).
The langauge is a subset of a Java 1.5 grammar, whose BNF form is available here. While it is an incomplete subset of the Java expression syntax, what's already implemented is enough to be interesting. You can do basic arithmetic (with all standard Number implementations, including BigDecimal and BigInteger), relational comparisons, shifts, boolean expressions, conditionals, call constructors and methods, reference member variables, cast values, test instanceof, and reference class constants.
There are minor extensions to cover the spreadsheet-like functionality that is inherent in this form.
- Cells may only contain objects -- there is no primitive/object dichotomy. When primitives need to be unboxed/reboxed in order to be passed to methods or constructors, it is done automatically.
- Cells are weakly-typed, in that they do not ensure that the result of the expression that they contain are of any particular type: this will be an optional setting eventually (such that a strongly typed cell will reject any value or formula that is not of the correct type).
- Cells may reference values in other cells, using
a keyword cell, as in
cell(0,0)
or
cell("foo")
cell takes either the name of the target cell, or a pair of integers, representing the absolute 0-based address of the cell being referenced. - Relative addressing is implemented in the form of a pair of keywords, row
and col which will represent of the row and column number of the cell whose
formula is being set. row and col can be used in arithmetic operations, as in
cell(row, col+1)
which would refer to the value of the cell immediately to the right of the cell in which that reference appears - Cells may be referenced before they have been initialized: their default value is the Integer 0 (the default type and value will eventually be configurable).
- Cells may be named via a menu choice on either the main menu (if any) or via a right click menu.
- 'this' refers to the spreadsheet, making the net.sf.jga.swing.Spreadsheet API available within the spreadsheet itself. It is very possible that careless use of the API can lead to endless loops, memory exhaustion, and other undesirable results. It may also be possible to analyze and prevent some of this, but it isn't happening yet, so consider this your one and only (official) warning.
The following expression syntax is not yet implemented
- arrays
- numeric coercion (arithmetic and relational operands must cast if necessary)
- Nested class constructor calls (ie, the rarely used "foo.new bar()" syntax)
- assignments or assignment forms (i.e.: +=, -=, etc)
- pre- or post- increment or decrements
- anonymous class creation
Note that this is running the jga-0.7.jar, and it makes very heavy
use of the FunctorParser, which
allows you to programatically parse expressions into Functors, doing
things like:
UnaryFunctor fn = parser.parseUnary("x.length()", String.class);to create a functor that returns the length of any string you pass it (as an Integer). The parser (and its generified derivitive GenericParser) is available programaticlly, allowing functors to be described using a more natural expression syntax. The visual basis of the Hacker's Worksheet is the net.sf.jga.swing.spreadsheet.Spreadsheet class that forms the basis of the: this is a JTable derivative that can be used like any other Swing widget in rich client applications.