JavaFX: Pivot and JavaFX
Rather than jump straight in with something which needs lots of features I decided to try something simple. My mavenize tool needs a front end so I thought that would be a good candidate. Mavenize takes a source and target directory and produces a ‘mavenized’ version of the source project in the target folder. It will create the appropriate folders and move all the files into the appropriate place. It is the dogs-bollocks and I have used it a lot to save me lots of boring graft. Stop being a mug and just download the command line version from here and better still there is a version with a proper UI coming in the next post.
Since I was once a big Flex user I decided to look at the two SDK’s available for Java which use a ‘flex’-like approach. These are Apache Pivot and JavaFX that is now part of the standard Java 7 SDK. Both of these have the UI layout and components defined in an XML file and the logic for the UI in the code. Also, these SDK’s embody the concept of a scene-graph for assembling the interface components which at least promises to deliver something more elegant than the somewhat old-skool collection of composite objects which make up Swing.
I put a basic Pivot version together fairly quickly. I am not entirely sure why they need to have their own version of the collection classes, I am not going to speculate as I am sure there is a good reason. This put me off for a start. Does the world need another set of collection classes beyond those tried and trusted from the JDK? This is a desktop app and they were always going to have to use the JDK. As you can see from the screenshot below there was also a custom file chooser dialog. Somewhat frustrating.
Also, as I was trying to write a desktop application I was a bit confused by the data model that the table view used. It turned out to be a list of maps which was fine but I couldn’t find a single example of how to use this in a programmatic way outside the bxml examples. I figured it out the end but was left with a sense that this is glaring gap in their otherwise exhaustive set of examples. If you try to use a framework and suddenly find yourself rushing towards an edge case that is a bad sign.
I am not going to spend much time on my Pivot version of the application. The framework is usable but pales into insignificance against JavaFX in terms of ease of use.
So, then I decided to take a look at JavaFX. I have to say I am pleasantly surprised. The scene graph and concept of data binding is very close to Flex. So much so that I think I might be a bit miffed if I was Adobe. There is a lot of (ahem) influence from Flex in the feature set. The scene builder tool is probably one of the nicest UI builder tools I have ever used with lots of cleverness to help you layout your user interface. Here is screenshot of the finished tool.
There is a whole bunch of JavaFX goodness here where I have solved the issue of updating the table view from a background service and have a nice custom cell with selectable images. I put the last one in because I knew I would need it for my proposed OSC router application.
I am going to outline what I did in the next post.