BT

InfoQ Homepage News Wiki-style GUI Layout with Profligacy and LEL

Wiki-style GUI Layout with Profligacy and LEL

Bookmarks
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.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Great

    by Michael Neale /

  • Great

    by Michael Neale /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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 !

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.