InfoQ

News

Wiki-style GUI Layout with Profligacy and LEL

Posted by Werner Schuster on Jul 13, 2007 10:00 AM

Community
Java,
Ruby
Topics
Domain Specific Languages ,
JRuby ,
Dynamic Languages
Tags
GUI ,
JRuby ,
Swing
Creating GUI layouts has been a problem for Java ever since the first AWT release. Many LayoutManagers have since been created, but none of them completely solved the issues with coding the layouts by hand. In fact, the recent addition, GroupLayout, is well suited to be configured by GUI builders like Matisse.

The latest attempt at a solution uses JRuby. Zed Shaw, creator of Mongrel, created a JRuby GUI library called Profligacy (InfoQ reported about JRuby GUI libraries Profligacy, Cheri and Swiby). It includes Layout Expression Language (LEL) which aims to tackle the GUI layout problem.

LEL uses a Wiki-style formatting language to define the layout as text. This makes the layout specification a compact string, instead of many lines of code specifying constraints or setting up hierarchies of panels. The language is parsed by a parser written using the Ruby library Ragel.

A sample:
layout = "
[ label_1 | label3 ]
[ (300,300)*text1| (150)people ]
[ <label2 | _ ]
 [ message | buttons ]
"
This creates a layout decoupled from the creation of the actual components, by setting up named placeholders for the layout elements. Layout and components are then connected with a  bit of Ruby code:

ui = Swing::LEL.new(JFrame,layout) do |c,i|
c.label_1 = JLabel.new "The chat:"
c.label2 = JLabel.new "What you're saying:"
c.label3 = JLabel.new "The people:"
c.text1 = JTextArea.new
c.people = JComboBox.new
c.message = JTextArea.new
# we'll replace this later with a subcomponent
c.buttons = JPanel.new
end

The placeholders defined in the layout specification (label_1, text1, etc) are assigned concrete components by referring to their names, which is done using Ruby's metaprogramming features.

While there are other LayoutManagers that use the approach of text layout constraints, for instance MigLayout, Profligacy and LEL show an interesting approach to help with GUI programming by using Ruby's features. LEL is not specific to a particular LayoutManager, although the current version uses GroupLayout to set up the GUI.
Great by Michael Neale Posted Jul 16, 2007 1:52 AM
  1. Back to top

    Great

    Jul 16, 2007 1:52 AM by Michael Neale

    I think this is pretty neat ! I think its a shame that something like this wasn't looked at by sun for JavaFX (I know there are plenty of other reasons for a new script - but still, it reeks of the dark days of Sun's Not Invented Here disease which they are just recovering from now). nice work !

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.