Tcl Bean

Remote Places to go:
  • Scriptics Jacl and Tcl Blend page
  • Sun Java Studio
  • Java Studio FAQ
  • Local Places to go:
  • Tcl Blend
  • Contents:
  • Introduction
  • Tcl Bean under Windows
  • Tcl Bean under Solaris
  • The Tcl Bean
  • Examples
  • Java Stack Traces
  • CLASSPATH
  • Customizers

  • NOTE: This page is somewhat out of date. Tcl Blend 1.2 probably won't have the Tcl Bean in it, it will be removed.

    Introduction

    The Tcl Bean is a Java Bean for use with Sun's Java Studio. The Tcl Bean provides two main features:
    1. Dynamic allocation of Bean ports from a Tcl Script
    2. Bean Customizers using Tcl Blend scripts that call java.awt methods
    Java Beans have control panels called Customizers that are used to set Bean parameters like the name of the bean and the names of the connections. Using a Tcl scripts to develop the Customizer is much faster that writing Java code, compiling it, reloading it into Java Studio and testing it. With a Tcl script implementation of the customizer, modifications can be made and tested on-the-fly.

    Tcl Bean under Windows

    The Tcl Bean will work with either Jacl or Tcl Blend. I found it easier to get started with Jacl and then to try out Tcl Blend.

    Tcl Bean under Windows with Jacl

    1. Download and install Sun Java Studio
    2. Download and install Jacl from the Scriptics Jacl and Tcl Blend page
    3. Start up Java Studio to create a js10 directory in your home directory, which varies from machine to machine. A typical location is c:\js10. Find your js10 directory and make a directory called js10\PlugIns\classes.
    4. In the directory where you installed Jacl, find the jacl.jar and tclbean.jar files. Copy these two jar files to js10\PlugIns\classes
    5. You will need to expand the jacl.jar file, so start up a shell and do
      cd js10\PlugIns\classes
      jar xf jacl.jar
      
    6. In the Java Studio toolbar window, import the js10\PlugIns\classes\tclbean.jar file by selecting Import -> Java Beans

    Tcl Bean under Windows with Tcl Blend

    The Tcl Bean instructions say to use Tcl Blend.
    1. If you have not yet done so, download and install Sun Java Studio
    2. Follow the instructions in tclbean_install.txt and README

    Tcl Bean under Window Hints

    Getting Tcl Blend and the Tcl Bean to work can be a little tricky. If you have problems, try using Jacl instead of Tcl Blend.

    If you have problems, look in js10\vj\VJLog for hints.

    To get the Tcl bean to install, I had to set my Path so that tclblend.dll was in it. Locally, this file is in C:\Program Files\Tcl\lib\tclblend1.1. Without this change, I got messages about Link errors in line 132 of Interp.java because the create method could not be loaded.


    Tcl Bean under Solaris

    1. Download Sun Java Studio
    2. Follow the instructions in tclbean_install.txt and README
    3. Locally, I did the following
      unsetenv LD_LIBRARY_PATH
      mkdir -p .js1.0/PlugIns/classes
      cd .js1.0/PlugIns/classes
      ln -s /users/ptdesign/obj.sol2.5/jacl1.1/jacl.jar .
      ln -s /users/ptdesign/obj.sol2.5/tcltk/tclBlend1.0up2/tclbean.jar .
      jar -xf jacl.jar
      /users/ptdesign/vendors/sun/Java-Studio1.0/JS/sparc-S2/bin/js
      

    The Tcl Bean

    Once you have installed the Tcl Bean, you can start experimenting with it. The Tcl Bean is usually installed in the User palette. The Tcl Bean icon has the Tcl feather in it.

    Looking at the Tcl Bean features

    1. Java Studio has three windows: a toolbar, a GUI window and a design window. In the toolbar window, select the User thumbtab, click on the Tcl Interp Tcl Bean and then click on the GUI window.
    2. You will get a message about how the Tcl Interp1 component does not have a graphical representation. Click on OK. Click on OK in the next dialog as well
    3. The Tcl Interp icon will appear in the design window, and the Tcl Interp Customizer window will come up.
    4. The Tcl Interp Customizer window has a Variables thumbtab that has a File entry field which can be used to load a Tcl file into the Script text widget below. There is also and a Browse button and a combo box that lists predefined scripts.
    5. The predefined scripts are worth looking at. In the combo box, Select each script in turn and then hit apply. Below is a description of each script
      choiceValue.tcl
      Simple example that prints the toString value of the input. This script probably should not be part of the release.
      distrib.tcl
      A Tcl Bean implementation of the Java Studio Distrib bean.
      eval.tcl
      Reads in a string, evaluates it and sends the results to the output. (Note that the comment at the top is probably wrong, it is a duplicate of the comment in memory.tcl below)
      exec.tcl
      Uses the Tcl exec command to run ls and cat. This script is likely to have problems under Windows unless you have ls and cat.
      inspect.tcl
      Reads a Tcl handle to a Java object and then prints out informatin about the object using java::info.
      memory.tcl
      Tcl Bean implementation of the Memory bean that is shipped with Java Studio
      switch.tcl
      Tcl Bean implementation of the Switch bean that is shipped with Java Studio. The Switch bean is like the Tcl switch command:
      switch $foo {
      	a {puts "foo is an a"}
      	b {puts "foo is an b"}
      	default {puts "I have no idea what foo is"}
      }
      
      An input value is checked against values associated with an output connector. If the values match, then a second input value is set to the output connector. If the input value does not match any of the values associated with the output connectors, then the second input value goes to the default output connector
      customDistrib.tcl
      Read an input and distributes it to user defined outputs. This script is an example of how Tcl Beans can modify the Customizer. The customizer allows the user to choose the name, description and location of the output(s)
      customMemory.tcl
      This script uses a customizer that allows the user to choose what values the bean stores.
      customSwitch.tcl
      This script uses a customizer that allows the user to choose the values and orientations of the output connectors.

    Examples

  • I created a simple demonstration that uses the Tcl Bean to pass data from an input to an output. TclPassThrough.tcl is the script for the Tcl Bean. I connected a Text Field to the input of the Tcl Bean and a Text Area to the output.
  • Tcleval - A primitive Tcl shell inside a bean.
  • Tclmath - Read two inputs, run Tcl expr and print the results.
  • Problems with Tcl Bean applications under Windows

    I saved the Example as an application.
  • To run the application under Cygwin-32, I had to edit the .sh start up script and change the CLASSPATH so it was separated by a semicolon:
     CLASSPATH=$CLS\;$CLASSPATH
    
  • When I ran the application, I got:
    java.lang.ClassNotFoundException: com.sun.jpropub.vj.vjcomp.VJDynamicPortDescriptor
    
    To fix this, I added jws.zip to the CLASSPATH
    CLASSPATH=D:\\Program\ Files\\Java-Studio1.0\\js\\lib\\jws.zip
    
  • The next error was:
    java.lang.NoClassDefFoundError: tcl/lang/Notifier
    
    The fix was to add the Tcl classes to the CLASSPATH
    CLASSPATH=D:\\Program\ Files\\Java-Studio1.0\\js\\lib\\jws.zip\;C:\\users\\cxh\\js10\\PlugIns\\classes
    
  • The next error was
    java.lang.UnsatisfiedLinkError:init
    
    I have not yet figured out a solution.

  • Java Stack Traces

    ErrorBean.tcl contains a Tcl Bean that will print the Java stack if there is an error.

    CLASSPATH

    Searching the Java Studio FAQ for CLASSPATH yields: When I try to import a component into JS, I get "Unable to load JAR file". .
       On Microsoft Windows systems:
          C:> js -classpath -your_classpath
          Notice the hyphen before your_classpath. 
          On UNIX systems:
          % js "-classpath your_classpath" 
    

    Unfortunately, those instructions do not seem to work under Windows.

    I also tried setting the CLASSPATH and TCL_CLASSPATH variable from within a Tcl Bean, but that did not work.

    The Tcl Bean classes are installed in js10\PlugIns\classes. Placing the Java .class files below that directory seems to work.


    Customizers

    Customizers are Java Studio graphical user interfaces to Beans. See the studiocustom::custom documentation for details
  • The list of built in Customizers is compiled into the VJInterpPage class. I placed the Customizer I was developing in a subdirectory of js10\tcl\bean\scripts. To reload the script, I just used the Browse button in the Customizer to find the script and reload it.

  • Last updated: 10/09/05, cxh at eecs