SDL/Swing is a very simple declarative framework for building rich cross platform desktop and Web Start applications. Our company has been involved in writing many, many desktop applications in Swing, Flex, WinForms, Silverlight, WPF and other frameworks. Its always seemed like more work than it should be. SDL/Swing is the product of our frustration with other frameworks. Our goal is to build the simplest, most developer friendly desktop application framework on the planet.
SDL/Swing applications use the Simple Declarative Language to define screens in a terse, human readable definition file. Controllers can be written in Java, or any other JVM targeted language.
Why Another Java Rich Client Framework
The Eclipse and NetBeans RCP platforms are very powerful but they are not declarative and have a steep learning curve. JSR-296, the Swing Application Framework, was intended to provide a simple Swing framework but there has been little activity on this JSR in recent months and it too lacks a declarative component.
JavaFX has some nice capabilities including a declarative scripting language, a rich effects engine, data-binding, mutation triggers and declarative animation. I like the fact it doesn't use giant ugly XML files for UI definitions, but it is a relatively large framework that introduces a new, rather involved language. SDL/Swing definitions are much more concise, the framework is tiny (283k) and its very simple to learn.
To get started simply download the SDL Pad sample application, double click to launch, type "Hello World" in the text pane on the right, and click "Refresh". You should see the results below:
Easy, eh? SDL/Swing interprets string literals (text in quotes) as a label, menu, menu item, list item, or combobox item depending on context. Here is an example of a menu definition:
The strings in the menubar are automatically interpreted as menus and menu items. The "do" attributes call an action method in the controller associated with the form containing this menubar. SDL attributes are converted to bean properties. This allows you to easily configure components like so:
The "button" tag below is mapped to javax.swing.JButton in a bindings property file. There are default bindings for common components. See the Component Tags area for a complete list of components. Application developers can add their own bindings or override default bindings like so:
Container components take a "layout" attribute that maps to one of about a dozen layout managers ranging from simple vertical and horizontal stacking layouts to complex table layouts. Here is a browser bar (the area with the URL and buttons at the top of your browser) using a vertical layout:
We can build this layout with a single API call referencing the file containing this definition:
Examples of more complex layouts including table and spring can be seen here:
The UI in this example was constructed entirely with SDL/Swing. It would require approximately 5 times the number of lines to create the same UI in Java procedurally and the results would be much harder to read.
The formpane component allows you to easily define and interact with forms:
The SDL / Pad example itself has a very simple screen definition:
The controller code is equally simple:
UI.startApplication in main(String) above takes two parameters. The first is the name of the application, which is also set as the title on the main frame. The second is the filename, sans the .sdl extension, of the component definition file found in the resources/components directory.
The SDL and the Java code shown above constitute the entire Ooi Pad application. The best way to learn SDL/Swing is to practice creating simple UIs with Ooi Pad. Once you are comfortable creating UIs, crack open the Ooi pad application source and see how the parts work.
Forms and Controllers
All controllers are placed in a package specified in resource/ui_global.properties. For OoiPad the contents of this file are:
Controllers use (package name).(form ID)Controller as a naming convention. In the example above, the form having the ID "App" is connected to the controller com.ooi.swing.ooipad.AppController. SDL/Swing automatically wires the controller to the form using this naming association. Controllers have two life cycle events - initialize() which is called after the form is configured by its SDL definition, and shown() which is called when the form is made visible.
I'll leave you with an example of a browser defined in SDL/Swing:
Note: This example uses an excellent Swing friendly browser component provided by JadeLiquid.
SDL/Swing has a number of other interesting features including declarative CSS-like styles and integration with the SwingX painters framework. We will include more detailed documentation about these features in the near future.
New! We just set up a Google Group to facilitate conversation about the framework. The mailing list is firstname.lastname@example.org.