The Artima Developer Community
Sponsored Link

Java Buzz Forum
Scripting Integration with SwiXml

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Toyokazu Tomatsu

Posts: 66
Nickname: tomatsu
Registered: Jul, 2003

Toyokazu Tomatsu is a developer of Pnuts.
Scripting Integration with SwiXml Posted: Mar 29, 2006 12:53 PM
Reply to this message Reply

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

Topic: "be surprising yet self-evident" - Walter Murch Previous Topic   Next Topic Topic: Some RDF thoughts…

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use