The ListBox has been greatly improved and got itself a new Nifty Java API. You can find an example right here (click the image for a webstart demo) or keep reading for all the details below.
Example</strong></p>
You can check the first example of the new ListBox online with the following Webstart URL: <img title="Bildschirmfoto 2010-12-12 um 23.40.53" src="../wp-content/2010/12/Bildschirmfoto-2010-12-12-um-23.40.53-300x225.png" alt="" width="300" height="225" /></a></p>
The source code of this project is available online. You can check out the source directly from SVN using https://nifty-gui.svn.sourceforge.net/svnroot/nifty-gui/nifty-default-controls-examples/trunk</a> or you can browse it online here: http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-default-controls-examples/trunk/</a>.</p>
And if that is not enough ... we've done the same new API treatment to the CheckBox and we plan to do the same to the remaining Nifty Standard Controls! Reference in the Wiki</strong></p>
You can find a complete reference about the new standard controls in Nifty 1.3 already on the Wiki (for the ListBox and the CheckBox): http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Nifty_Standard_Controls_%28Nifty_1.3%29</a></p>
And you can keep reading about all the little Nifty details we've changed and improved and especially why. It all started with a feature request for Nifty 1.3</a> which seems easy to add at first. Removing all or single elements from a Nifty ListBox sounds like a reasonable feature to have available. So I'd try to add this ... and failed miserable! :) The closer I looked into it the more despaired I've become.</p>
What a mess! Something I'd really love to do with Nifty 2.0 is to add a nice and clean API to the standard Nifty controls. The current way of interacting with most of the Nifty controls is kinda awkward (at least) and I want to improve this. So, I thought, hey, why not try to define a new API for the ListBox as a preparation for this and see how everything works out. Well, it turns out that in the end I've pretty much rewrote the whole ListBox! =) And that the new one is way better than what you currently have available! One of the shortcomings of the old ListBox was speed. Internally it directly added the Nifty element tree adding elements dynamically and then used a Scrollpanel to scroll around that (maybe) huge list of elements. So basically it always rendered all elements and used the clipping of the element to hide everything that was not currently seen. Not a great idea after all :) Another problem was the API and that's a little difficult to interact with Niftys internal screen representation. Although it's not impossible to dynamically add/remove elements from Nifty this might not be the ideal solution to the ListBox problem. So what did we changed? Well, actually a lot! :) The new ListBox:</strong></p>
In the process of updating the ListBox we've noticed that we're missing a nice way to allow the controls to notify other components of the system about things happening. If the selection of the ListBox is changed we'd like other parts to be notified about that event. Well, the first thing that comes to ones mind is of course the Listener/Observer pattern. But there are some problems with this approach, mostly the strong binding between the objects that communicate. There is a great PDF available from the OSGI people</a> that discusses some of the problems of the Listener pattern.</p>
Having previously worked with GWT 2.x and its event bus architecture we'd like to have someting similar for Nifty too. What we want is a loose coupling between Nifty (as the creator of events) and your application (as the receiver of the events). As it turns out a publish/subscribe mechanism allows us to do just that! Nifty publishes events to some "global" EventBus. And your application on the other hand subscribes to this EventBus for all the events that it needs to handle. What sounds not very different from the standard Listener pattern at first is in fact a great improvement! There is only a dependency to the EventBus and not between the objects that communicate! Which helps a lot to decouple the objects from one another. Nifty does not need to know who will receive the event in the end. It just creates the event and publishes it to the EventBus and everybody interessted in it will be notified. As it turns out there is a neat little project available that implements that mechanism for us. It is called EventBus</a> and is available as Open Source under the Apache License, Version 2.0. It's only 80KB in size, so it should not hurt the download/memory footprint of Nifty that much. Nifty is now using the EventBus project for ListBox and CheckBox notifications which worked very very well so far! You subscribe to the EventBus using the id of the element as a topic and you'll receive all events that the control with the given id produces. In the case of the ListBox this means that you receive instances of the ListBoxSelectionChangedEvent</a>. This basically sends you the current selection of the ListBox everytime the selection has been changed :)</p>
Good Times, PS: And if you NOW don't feel like christmas is already here then I can't help you =)
</ul></p>
</ul></p>
</ul></p>
</ul></p>
</ul>
EventBus Notification</strong></p>
void