Neurogami SwingSet: Ruby Wrappers for Swing Components
One of the nice things about the Monkeybars library[0] is that you can create the Swing UI using a spiffy (and free) WYSIWYG UI editor such as NetBeans, and use the resulting Java class with straight-up Ruby code in your application.
However, when watching presentations about other JRuby tools that work with Swing (or SWT), much was made of how you can just use some Ruby "DSL" to create the UI and not be dependent on some UI editor.
Different strokes and all that, but some folks seemed to get the impression that to use Monkeybars you *had* to use NetBeans.
That has never been the case, but using inline Ruby code to define the Swing code was not really an option, either.
I was curious about this, and thought that being able to easily hand-roll a UI class could be handy, and it makes for some nice "Ooh, ahhh" demo stuff (even if real life would prompt you to use a UI editor for anything serious).
I hacked a bit on Monkeybars, and it was fairly simple to change how the view.rb class loads and interacts with the Swing code. The result was that the current version of Monkeybars now allows you to use both compiled Java classes and plain Ruby inline Swing code.
Now, for the most part, I still prefer to use NetBeans for anything non-trivial. It's just too easy. But while working out this Monkeybars addition I started creating a basic set of Ruby wrappers around some Swing components. Nothing too fancy, but enough to save the trouble of repeatedly typing out the full javax Swing name, and with blocks and default values to simplify initialization.
This code was part of my original fork, but it did not get merged back into the Monkeybars master branch. That makes sense; it works better as an add-on than as part of the Monkeybars core.
I've been using this code in a few of my projects, and finally got around to rolling it up into a gem.
The project is called Neurogami SwingSet, and the code lives on GitHub[1].
You should be able to install this as a gem (once you've added GitHub as a gem source), and then use the 'swingset' command. This will copy over the swingset.rb file to lib/ruby in your current location.
(Yes, this is really low-tech and feature-free. At some point I may add the option to define what path to use, but since this is how I lay out *my* code, that's how it works right now.)
There's an example in the README.txt file. Once you define your UI class using SwingSet, you can set this in your view code by using the name of the class (as a constant, not as a string; if you pass a string, Monkeybars attempts to load a Java class file with that name).
You will most likely also want to grab the MiG Swing layout manager[2], which was designed for this sort of hand-rolled Swing code hacking.
[0] http://www.monkeybars.org
[1] http://github.com/jamesbritt/swingset/tree/master
[2] http://www.miglayout.com

