Created
January 23, 2012 13:18
-
-
Save toby55kij/1663081 to your computer and use it in GitHub Desktop.
Apache PivotでGroovyを使うサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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