I finally got around to extracting some of the semi-experimental UI components out into their own project: LemurProto.
The point of the LemurProto project is to incubate things that will eventually make it into Lemur core once they are hardened. I try very hard not to check in half-baked things into core… well, I try. LemurProto gives me (and others) a place to put things that may need a little work before being finalized.
Consequently, the GUI elements in LemurProto may change and break from one version to the next… part of the growing pains.
The project source can be found here:
And the current release is here:
Right now the main GUI element folks would be interested in is the ListBox and I’ve prioritized this motivated by @nehon so you can thank him.
By default, the list will render its elements as text labels and use a standard String.valueOf() for list model values. This behavior can be changed with cell renderers.
Basic usage is as follows:
VersionedList myList = new VersionedList(myListOfStrings);
ListBox listBox = new ListBox(myList);
If items are added or removed from myList then the list box is automatically updated (thus the VersionedList).
Selection can be watched by grabbing a versioned reference to the selection model.
Custom renderers can be specified be setting the CellRenderer. A cell renderer can either create new cells every time it is accessed or it can reuse existing cells. One cell is created for every visible item in the list and as it is scrolled the renderer is asked for new cells (and can simply just reset the value of the existing one if it likes). This is slightly different than Swing’s model which tends to reuse on JLabel and uses it to paint every item (and then has tons of infrastructure built just to support using a Swing component to paint). Lemur opts to prefer a static set of components based on the visible size of the list. Anyway, you don’t have to worry about that unless you want a custom renderer… and then you can just look at DefaultCellRenderer’s source.
I think it’s pretty straight-forward:
There are probably some things yet missing from this implementation of ListBox (and its underlying GridPanel) because I haven’t used it “in anger” yet… but it’s functional and has all of the obvious parts. Please feel free to report issues or missing pieces you might find.