Class: Profligacy::Swing::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/profligacy/swing.rb

Direct Known Subclasses

LEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*children) {|@contents, @interactions| ... } ⇒ Build

Returns a new instance of Build.

Yields:



66
67
68
69
70
# File 'lib/profligacy/swing.rb', line 66

def initialize(*children)
  @container_class = children.shift
  setup_children_and_interactions(children)
  yield @contents, @interactions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symb, *args) ⇒ Object



101
102
103
# File 'lib/profligacy/swing.rb', line 101

def method_missing(symb, *args)
  @contents[symb]
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



58
59
60
# File 'lib/profligacy/swing.rb', line 58

def children
  @children
end

#containerObject

Returns the value of attribute container.



62
63
64
# File 'lib/profligacy/swing.rb', line 62

def container
  @container
end

#contentsObject

Returns the value of attribute contents.



59
60
61
# File 'lib/profligacy/swing.rb', line 59

def contents
  @contents
end

#interactions {|@contents, @interactions| ... } ⇒ Object

Returns the value of attribute interactions.

Yields:



60
61
62
# File 'lib/profligacy/swing.rb', line 60

def interactions
  @interactions
end

#layoutObject

Returns the value of attribute layout.



61
62
63
# File 'lib/profligacy/swing.rb', line 61

def layout
  @layout
end

Instance Method Details

#build(*args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/profligacy/swing.rb', line 76

def build(*args)
  # create the container they ask for with these args
  @container = @container_class.new *args
  # tack on the layout they wanted
  @container.layout = layout if layout

  # go through all the children, add them on and tack on the callbacks
  @children.each {|child|
    if @contents[child]
      # if this component answers the each call then go through all
      component = @contents[child]
      each_or_one(component) {|c| @container.add(c) }

      configure_interactions_for child, component
    end
  }

  # even though swing doesn't do this, we do
  @container.pack if @container.respond_to? :pack
  @container.visible = true if @container.respond_to? :visible

  # and now they can do whatever they want to the container
  @container
end