Skip to content

Instantly share code, notes, and snippets.

@toby55kij
Created January 23, 2012 13:18
Show Gist options
  • Save toby55kij/1663081 to your computer and use it in GitHub Desktop.
Save toby55kij/1663081 to your computer and use it in GitHub Desktop.
Apache PivotでGroovyを使うサンプル
@Grapes([
@Grab("org.apache.pivot:pivot-core:2.0"),
@Grab("org.apache.pivot:pivot-wtk:2.0"),
@Grab("org.apache.pivot:pivot-wtk-terra:2.0")
])
import org.apache.pivot.wtk.*
//メソッドはバインディング変数(クロージャ)で作成しないといけない
createLabel = { window ->
def label = new Label()
label.text = "Hello Groovy! 2"
label.styles << [font:"Arial BOLD 24", color:"#ff0000",
horizontalAlignment:HorizontalAlignment.CENTER,
verticalAlignment:VerticalAlignment.CENTER]
window.content = label
}
@Grapes([
@Grab("org.apache.pivot:pivot-core:2.0"),
@Grab("org.apache.pivot:pivot-wtk:2.0"),
@Grab("org.apache.pivot:pivot-wtk-terra:2.0")
])
import org.apache.pivot.wtk.*
//stylesに一括で設定できる様に細工
Component.StyleDictionary.class.metaClass {
leftShift << { Map map ->
map.each {
put(it.key, it.value)
}
}
}
@Grapes([
@Grab("org.apache.pivot:pivot-core:2.0"),
@Grab("org.apache.pivot:pivot-wtk:2.0"),
@Grab("org.apache.pivot:pivot-wtk-terra:2.0")
])
import org.apache.pivot.wtk.ScriptApplication
/**
* GroovyからApache PivotのBXMLを実行
*/
public class GroovyScriptApplication {
/**
* BXMLファイルを実行
* @param args --src=/BXMLファイル名
*/
public static void main(String[] args) {
ScriptApplication.main(args)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?language groovy?>
<Window title="Hello Groovy!" maximized="true"
xmlns:bxml="http://pivot.apache.org/bxml"
xmlns="org.apache.pivot.wtk">
<windowStateListeners>
<![CDATA[
import org.apache.pivot.wtk.*
windowOpened = { window ->
def label = new Label()
label.text = "Hello Groovy!"
label.styles.put "font", "Arial BOLD 24"
label.styles.put "color", "#ff0000"
label.styles.put "horizontalAlignment", HorizontalAlignment.CENTER
label.styles.put "verticalAlignment", VerticalAlignment.CENTER
window.content = label
}
]]>
</windowStateListeners>
</Window>
<?xml version="1.0" encoding="UTF-8"?>
<?language groovy?>
<Window title="Hello Groovy! 2" maximized="true"
xmlns:bxml="http://pivot.apache.org/bxml"
xmlns="org.apache.pivot.wtk" WindowStateListener.windowOpened="createLabel(arguments[0])">
<bxml:script src="GroovyPivotInit.groovy"/>
<bxml:script src="CreateLabel.groovy"/>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment