From: Charles Oliver Nutter Date: 2007-11-01T03:16:11+09:00 Subject: [JRuby] Ruby and Swing: Profligacy Profligacy is a JRuby/Swing framework created by Zed Shaw. It takes a different approach from the previously posted Cheri, in that it doesn't try to hide the Swing API. Instead, it just provides solutions for some of the ugliest parts of Swing like component layout. http://ihate.rubyforge.org/profligacy/ From the page: "Profligacy is a JRuby library that makes building Swing Graphical User Interface much easier than with Raw code. It�s not a builder as with many other projects, but instead a simple Ruby way to structure the UI for the 80% common cases you�ll encounter." "The purpose of Profligacy is not to be a complete way of hiding Swing components from you. You�ll still be making JButtons and JLabels, you�ll just be putting them into a Ruby idiomatic code structure that doesn�t make your eyes hemorrhage diarrhea like when you try to code in Java." It's a much lighter-weight approach to doing Swing GUI development. The most interesting bit, however, is the layout engine: The only real innovation in Profligacy is a simpler way to configure a GroupLayout using a simple regex/wiki style syntax. This is a work in progress, but it should make building GUIs much much easier. Here's a medium-sized sample of building a simple GUI with layout in Profligacy: require 'profligacy/swing' require 'profligacy/lel' class PhoneBookDemo include_package 'javax.swing' include_package 'java.awt' include_package 'javax.swing.border' include Profligacy def initialize @search_style = :exact layout = "[>lab_name][*name][>lab_number][*number][*lab_options][ proc {|t,e| @ui.number.text = find(@names, e.source.text) } } i.number = {:action => proc {|t,e| @ui.name.text = find(@numbers, e.source.text) } } i.exact = {:action => proc {|t,e| @search_style = :exact } } i.starts = {:action => proc {|t,e| @search_style = :starts } } i.ends = {:action => proc {|t,e| @search_style = :ends } } end @ui.build(:args => "Phone Book") @names = { "Zed A. Shaw" => "917-555-5555", "Frank Blank" => "212-554-5555" } @numbers = { "917-555-5555" => "Zed A. Shaw", "212-554-5555" => "Frank Blank" } end protected def find(inside, text) results = case @search_style when :exact; inside.keys.grep /^#{text}$/ when :starts; inside.keys.grep /^#{text}/ when :ends; inside.keys.grep /#{text}$/ end inside[results[0]] || "" end end SwingUtilities.invoke_later proc { PhoneBookDemo.new }.to_runnable - Charlie