This post originated from an RSS feed registered with Java Buzz
by Toyokazu Tomatsu.
Original Post: Scripting Integration with SwiXml
Feed Title: Pnuts Addict
Feed URL: http://jroller.com/tomatsu/feed/entries/rss
Feed Description: Toyokazu Tomatsu's Weblog
Latest Java Buzz Posts
Latest Java Buzz Posts by Toyokazu Tomatsu
Latest Posts From Pnuts Addict
Advertisement
What I wanted to do is to use SwiXml without writing Java code.
The original code uses Reflection API to associate components and actions
with object fields. I had to add a little more abstract interface
to the original code, but backward compatibility is preserved.
Three files are modified in this change. (diff )
Since the integration is based on JSR223 scripting API, any scripting language that supports the scripting API can be used.
Example
calculator.xml:
<?xml version="1.0" encoding="UTF-8"?>
<frame name="mainframe" title="Calculator">
<panel Bounds="10,10,150,150" Layout="FlowLayout" Visible="true" Resizable="true">
<textfield id="t1" Columns="3" text=""/>
<label text="+"/>
<textfield id="t2" Columns="3" text=""/>
<button id="btn" label="=" Action="add"/>
</panel>
</frame>
Pnuts
calc.pnut:
function add(e){
println(int(t1.text) + int(t2.text))
flush()
}
C:\> set CLASSPATH=pnuts.jar;pnuts-modules.jar;pnuts-jsr223.jar;swixml.jar;jdom.jar
C:\> c:/jdk1.6.0/bin/java org.swixml.ScriptingSwingEngine calculator.xml calc.pnut
Pnuts JSR223 scripting engine can be found in Extension Module Repository .
Rhino
calc.js:
function add(e){
print(parseInt(t1.text) + parseInt(t2.text))
}
C:\> set CLASSPATH=swixml.jar;jdom.jar
C:\> c:/jdk1.6.0/bin/java org.swixml.ScriptingSwingEngine calculator.xml calc.js
Rendering in Pnuts
Download pnuts-swixml.jar and add to your CLASSPATH or copy to $PNUTS_HOME\modules.
use("swixml")
renderSwixml("calculator.xml")
function add(e){
println(int(t1.text) + int(t2.text))
flush()
}
Read: Scripting Integration with SwiXml