Class Profligacy::Swing::Build
In: lib/profligacy/swing.rb
Parent: Object

The Swing::Build class doesn‘t actually do any swing stuff, but instead it organizes the common pattern of constructing components, attaching interaction procs or methods.

See the many examples and instructions at ihate.rubyforge.org/profligacy/ for more information.

Methods

Attributes

children  [RW] 
container  [RW] 
contents  [RW] 
interactions  [RW] 
layout  [RW] 

Public Class methods

When you construct a Swing::Build you pass in the container to use as the first argument, and then symbols for the names of the contents as the rest of the arguments.

  ui = Swing::Build.new JFrame, :left, :right, :top do |c,i|
    ...
  end

The Build class doesn‘t actually do anything with this until you call the Swing::Build.build method. It just collects up the contents and interactions you attach to the c and i parameters in the block.

The c and i parameters stand for contents and interactions and are a Ruby Struct objects that have the names you gave as elements. This means if you try to set one that doesn‘t exist you‘ll get an error (which is pretty handy).

Public Instance methods

Build will finally build the container you configured, passing any arguments to that container. When it‘s done it returns the resulting container for you to modify.

You can also attach a block to the method call that will be called with the container right before it‘s completed. This lets you modify it at the right moment. For example, if you need to set some options to a JFrame right before it‘s made visible.

Finally, it‘s so common to make containers visible and pack them that this method will do that if the container has those methods.

It‘s kind of a pain to always access ui.contents.thename so the method_missing simply lets you do ui.thename. Won‘t work of course if your component is named "build", "children", "contents", "interactions", "layout", "container" since those exist in the Build object already.

Protected Instance methods

allows for a block of code to be run on each element of anything responding to each, or just on one item

[Validate]