thinlet module

1. What is thinlet module?

This module provides a mechanism to utilize thinlet in Pnuts, which allows you to write GUI programs with XML and Pnuts scripts.

The details of the functions are described in 'thinlet module Reference'

Currently, pnuts-thinlet.jar contains modified Thinlet. If in the future our modification is incorporated into Thinlet, the modified code will be separated.

2. How to execute

Run from a Pnuts script

import javax.swing.*
use("thinlet")

parseThinlet("calculator.xml", f = JFrame())

function calculate(n1, n2, r){
  r.text = string(int(n1)+int(n2))
}
f.pack()
f.show()
<panel gap="4" top="4" left="4">
	<textfield name="number1" columns="4" />
	<label text="+" />
	<textfield name="number2" columns="4" />
	<button text="=" action="calculate(number1.text, number2.text, result)" />
	<textfield name="result" editable="false" />
</panel>

Run from a Java program

import pnuts.lang.Context;
import org.pnuts.thinlet.PnutsThinlet;
import javax.swing.JFrame;

public class Test {
    public static void main(String[] args) throws Exception {
	Context context = new Context();
	context.usePackage("pnuts.lib");
	PnutsThinlet thinlet = new PnutsThinlet(context);
	thinlet.add(thinlet.parse("calculator.xml"));
	thinlet.load("calculator");
	JFrame f = new JFrame();
	f.getContentPane().add(thinlet);
	f.pack();
	f.show();
    }
}
function calculate(n1, n2, r){
  r.text = string(int(n1)+int(n2))
}

3. Accessing Component Properties

When Thinlet is used in Java, appropriate setXXXX and getXXX methods must be used depending on the property type.

e.g.
public boolean setString(Object component, String key, String value)
When Thinlet is used in Pnuts, component's fields are specified as if it were Bean properties.
component . property
component . property = value

4. Operations on Components

When Thinlet is used in Java, operations on a component have a common pattern of method signature, which the target component is passed in the first parameter.

e.g.
public boolean requestFocus(Object component)
When Thinlet is used in Pnuts, this can be written in object oriented style.
e.g.
componet.requestFocus()
componet.repaint()
componet.remove()
componet.removeAll()
componet.find(name)
componet.add(component)
componet.add(component, idx)
componet.getProperty(prop)
componet.putProperty(prop, value)