Top Level Namespace

Defined Under Namespace

Modules: AwtEvent, Swing

Instance Method Summary collapse

Instance Method Details

#border_fact_method(*syms) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/swing4rb.rb', line 66

def border_fact_method *syms
  syms.each{|sym|
    eval %Q|
      def #{sym.to_s} *args
        Java::JavaxSwing::BorderFactory.create#{camelcase(sym.to_s)} *args
      end
    |
  }
end

#border_panel(map) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/swing4rb.rb', line 221

def border_panel map
    panel {|p|
      p.layout = border_layout
      map.each {|key, value|
          p.add(value, constant(:BorderLayout, key))
      }
      if block_given?
        yield p
      end
    }
end

#box_panel(axis, *components) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/swing4rb.rb', line 245

def box_panel axis, *components
  panel {|p|
    p.layout = box_layout(p, constant(:BoxLayout, axis))
    components.each{|c|
      p.add(c)
    }
    if block_given?
      yield p
    end
  }
end

#camelcase(str) ⇒ Object



31
32
33
34
35
# File 'lib/swing4rb.rb', line 31

def camelcase str
  str.gsub!(/[^a-zA-Z_\- ]/," ")
  str = " " + str.split('_').join(" ")
  str.gsub!(/ (.)/) { $1.upcase }
end

#card_panel(map) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/swing4rb.rb', line 257

def card_panel map
  panel {|p|
    p.layout = card_layout
    map.each {|key, value|
      p.add(value, key.to_s)
    }
    if block_given?
      yield p
    end
  }
end

#constant(clazz, const) ⇒ Object



215
216
217
# File 'lib/swing4rb.rb', line 215

def constant clazz, const
  eval "Swing::#{clazz.to_s}::#{const.to_s.upcase}"
end

#fact_method(*syms) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/swing4rb.rb', line 195

def fact_method *syms
  syms.each {|sym|
    name = sym.to_s
    eval %Q|
      def #{name} *args
        #{name} = Swing::#{camelcase(name)}.new *args
        if block_given?
          yield #{name}
        end
        #{name}
      end
      |
  }
end

#fact_method_j(*syms) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/swing4rb.rb', line 180

def fact_method_j *syms
  syms.each {|sym|
    name = sym.to_s
    eval %Q|
      def #{name} *args
        #{name} = Swing::J#{camelcase(name)}.new *args
        if block_given?
          yield #{name}
        end
        #{name}
      end
      |
  }
end

#flow_panel(*components) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
# File 'lib/swing4rb.rb', line 233

def flow_panel *components
  panel {|p|
    p.layout = flow_layout
    components.each{|c|
      p.add(c)
    }
    if block_given?
      yield p
    end
  }
end

#grid_panel(columns, rows, *components) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/swing4rb.rb', line 269

def grid_panel columns, rows, *components
  panel {|p|
    p.layout = grid_layout columns, rows
    components.each{|c|
      p.add c
    }
    if block_given?
      yield p
    end
  }
end

#pretty_action_listener(*syms) ⇒ Object

AbstractButton JComboBox JFileChooser JTextField Timer



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/swing4rb.rb', line 43

def pretty_action_listener *syms
  syms.each{|sym|
    eval(
    %Q|class Java::JavaxSwing::#{camelcase(sym.to_s)}
      alias original_add_action_listener add_action_listener
      def add_action_listener &func
        l = AwtEvent::ActionListener.new
        l.instance_eval {
          @func = func
        }
        def l.actionPerformed(event)
          @func.call(event)
        end
        l
        original_add_action_listener l
      end
    end
    |)
  }
end