| 7 | | trait GUIBuilder { |
| 8 | | val container = new DynamicVariable[Container](null) |
| 9 | | def Frame(params :Any*)(thunk : => Unit) : JFrame = { |
| | 12 | class GUIBuilder { |
| | 13 | val context :DynamicVariable[AnyRef] = new DynamicVariable[AnyRef](null) |
| | 14 | def setProperty(target :AnyRef, property :Symbol, value :Any) { |
| | 15 | invoke(context, "set" + property.name.capitalize, value) |
| | 16 | } |
| | 17 | def getProperty(target :AnyRef, property :Symbol, value :Any) :Any = { |
| | 18 | invoke(context, "set" + property.name.capitalize, value) |
| | 19 | } |
| | 20 | def frame(params :Any*)(thunk : => Unit) : JFrame = { |
| | 29 | def button(params :Any*) :JButton = { |
| | 30 | val button = new JButton |
| | 31 | context.value match { |
| | 32 | case frame:JFrame => frame.getContentPane.add(button) |
| | 33 | case container:Container => container.add(button) |
| | 34 | } |
| | 35 | params.foreach { |
| | 36 | case text:String => button.setText(text) |
| | 37 | case (property:Symbol, value:Any) => setProperty(button, property, value) |
| | 38 | } |
| | 39 | button |
| | 40 | } |
| | 41 | def action(handler :ActionEvent => Unit) :Action = { |
| | 42 | new AbstractAction { |
| | 43 | def actionPerformed(e :ActionEvent) = handler(e) |
| | 44 | } |
| | 45 | } |