Changeset 6961 for lang/scala
- Timestamp:
- 02/20/08 03:43:41 (9 months ago)
- Location:
- lang/scala/sandbox
- Files:
-
- 3 modified
-
lib/scala-sandbox.jar (modified) (previous)
-
src/jp/gr/java_conf/mizu/gui/GUIBuilder.scala (modified) (4 diffs)
-
webpages/lib/scala-sandbox.jar (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
lang/scala/sandbox/src/jp/gr/java_conf/mizu/gui/GUIBuilder.scala
r6933 r6961 7 7 import java.awt.event.ActionEvent 8 8 import java.awt.event.ActionListener 9 import javax.swing.AbstractAction 10 import javax.swing.Action 11 import javax.swing.Box 12 import javax.swing.BoxLayout 13 import javax.swing.JButton 9 14 import javax.swing.JFrame 10 import javax.swing.JButton 15 import javax.swing.JLabel 16 import javax.swing.JPanel 11 17 import javax.swing.JTextField 12 import javax.swing.Action13 import javax.swing.AbstractAction14 18 import jp.gr.java_conf.mizu.util.ReflectionWrapper.invoke 15 19 … … 21 25 _context.withValue(value)(thunk) 22 26 } 23 def setProperty(target :AnyRef, property :Symbol, value :Any) {24 invoke(target, "set" + property.name.capitalize, value)25 }27 def setProperty(target :AnyRef, property :Symbol, value :Any) { 28 invoke(target, "set" + property.name.capitalize, value) 29 } 26 30 def getProperty(target :AnyRef, property :Symbol, value :Any) :Any = { 27 31 invoke(target, "get" + property.name.capitalize, value) … … 29 33 def asContainer :Container = { 30 34 context match { 31 case frame:JFrame => frame.getContentPane32 case container:Container => container35 case frame:JFrame => frame.getContentPane 36 case container:Container => container 33 37 } 34 38 } 35 39 def frame(params :Any*)(thunk : => Unit) : JFrame = { 36 val frame= new JFrame40 val widget = new JFrame 37 41 params.foreach { 38 case title:String => frame.setTitle(title)39 case (property:Symbol, value:Any) => setProperty(frame, property, value)42 case title:String => widget.setTitle(title) 43 case (property:Symbol, value:Any) => setProperty(widget, property, value) 40 44 } 41 withContext( frame)(thunk)42 frame45 withContext(widget)(thunk) 46 widget 43 47 } 44 48 def button(params :Any*) :JButton = { 45 val button= new JButton46 asContainer.add( button)49 val widget = new JButton 50 asContainer.add(widget) 47 51 params.foreach { 48 case text:String => button.setText(text)49 case handler:ActionListener => button.addActionListener(handler)50 case (property:Symbol, value) => setProperty(button, property, value)52 case text:String => widget.setText(text) 53 case handler:ActionListener => widget.addActionListener(handler) 54 case (property:Symbol, value) => setProperty(widget, property, value) 51 55 } 52 button 56 widget 53 57 } 54 58 def textField(params :Any*) :JTextField = { … … 56 60 asContainer.add(widget) 57 61 params.foreach { 58 case text:String => widget.setText(text)59 case (property:Symbol, value) => setProperty(widget, property, value)62 case text:String => widget.setText(text) 63 case (property:Symbol, value) => setProperty(widget, property, value) 60 64 } 65 widget 66 } 67 def label(params :Any*): JLabel = { 68 val widget = new JLabel 69 asContainer.add(widget) 70 params.foreach { 71 case (property:Symbol, value) => setProperty(widget, property, value) 72 } 73 widget 74 } 75 def panel(params :Any*)(thunk : => Unit) :JPanel = { 76 val widget = new JPanel 77 asContainer.add(widget) 78 params.foreach { 79 case (property:Symbol, value) => setProperty(widget, property, value) 80 } 81 withContext(widget)(thunk) 82 widget 83 } 84 def hbox(params :Any*)(thunk : => Unit) :Box = { 85 val widget = new Box(BoxLayout.X_AXIS) 86 asContainer.add(widget) 87 params.foreach { 88 case (property:Symbol, value) => setProperty(widget, property, value) 89 } 90 withContext(widget)(thunk) 91 widget 92 } 93 def vbox(params :Any*)(thunk : => Unit) :Box = { 94 val widget = new Box(BoxLayout.Y_AXIS) 95 asContainer.add(widget) 96 params.foreach { 97 case (property:Symbol, value) => setProperty(widget, property, value) 98 } 99 withContext(widget)(thunk) 61 100 widget 62 101 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)