http://ptolemy.eecs.berkeley.edu/~cxh/java/tclblend
Below are a few Jacl Applets. These code for these applets is
fairly rough, but shows some of the promise and the limitations in Jacl.
The source code for these applets is available in
jaclapplet.tar.gz
.
TclShell.java
class
provides an interactive Tcl Shell that can be embedded in a Java
application.
TclShell extends the Java Panel Component and uses Jacl to provide the Tcl backend.
Below is how we embedded TclShell in a preexisting Plotter Java application called Ptplot
TclShell.java
to
the ptplot directory and added
package pt.plot;to the top.
TclShell.java
to the makefile
.
jacl.jar
to the CLASSPATH
in the
makefile
.
_makeButtons
,
so we added a button labeled Tcl Prompt
which calls
the method _tclPrompt()
when it is depressed.
_tclPrompt()
looks like:
private void _tclPrompt() { TclShell tclShell = new TclShell(); Frame shellFrame = new Frame(); shellFrame.pack(); shellFrame.resize(200,200); shellFrame.add(tclShell); tclShell.init(); shellFrame.show(); }
Pxgraph.java
and TclShell.java
.
pxgraph
is a shell script calls java
with the appropriate arguments, including the proper classpath,
so we added the complete path to jacl.jar
to
the classpath.
pxgraph
, the following command
is what is actually run:
/usr/java/bin/java -classpath /users/cxh/pt/tycho/java:/users/ptdesign/tcltk/itcl/lib/jacl.jar:/usr/java/lib/classes.zip pt.plot.Pxgraph demo/data.plt
pxgraph
and hitting the
Tcl Prompt
button, the TclShell console appears.
set argv [java::new {String []} 1 "demo/data.plt"] set plotter [java::new pt.plot.Pxgraph $arg]
java::info properties $p
java::prop $p title
java::prop $p title "This is my plot"For other commands, see the
java
Tcl command man page
java::new
need to be made
available in Jacl applets under Netscape and Internet Explorer.
Perhaps this requires the use of certificates.
Be sure that Jacl will run as an applet in a vanilla Netscape4.04 without the JDK1.1 patch.
Under Netscape4.04 without the JDK1.1 patch, the following messages appeared in the Java console when I attempted to run an applet that used Jacl:
# Security Exception: checkResourceAccess security.checkResourceAccess # UniversalPropertyRead privilege not enabled: Reading information stored in your computer, such as your user name netscape.security.AppletSecurityException: security.checkResourceAccess # UniversalPropertyRead privilege not enabled: Reading information stored in your computer, such as your user nameThese problems are caused by doing things like
System.getPropertyValue()
. One fix for this would be to use certificates.
Another fix is to install the JDK1.1 patch.
I never did track down the cause of these errors, but Another fix
is that catching SecurityException in
jacl1.0/src/java/tcl/lang
helped. Below is a diff:
------- Interp.java ------- *** /tmp/da001mz Wed Dec 31 16:00:00 1969 --- Interp.java Fri Feb 13 08:36:21 1998 *************** *** 356,363 **** * Create the built-in commands. */ ! createCommands(); ! try { /* * Set up tcl_platform, tcl_version, tcl_library and other --- 356,368 ---- * Create the built-in commands. */ ! try { ! createCommands(); ! } catch (SecurityException e) { ! e.printStackTrace(); ! System.err.println("java/tcl/lang/Interp Interp(): CreateCommands: " ! +e); ! } try { /* * Set up tcl_platform, tcl_version, tcl_library and other *************** *** 411,418 **** * Source the init.tcl script to initialize auto-loading. */ ! evalResource("/tcl/lang/library/init.tcl"); ! } catch (TclException e) { System.out.println(getResult()); e.printStackTrace(); --- 416,428 ---- * Source the init.tcl script to initialize auto-loading. */ ! try { ! evalResource("/tcl/lang/library/init.tcl"); ! } catch (SecurityException e) { ! System.err.println( ! "java/tcl/lang/Interp Interp(): after evalResource:" + ! e); ! } } catch (TclException e) { System.out.println(getResult()); e.printStackTrace(); *************** *** 708,716 **** (new BlendExtension()).init(this); RegexpCmd.init(this); } catch (TclException e) { ! System.out.println(getResult()); ! e.printStackTrace(); ! throw new TclRuntimeError("unexpected TclException: " + e); } } --- 718,735 ---- (new BlendExtension()).init(this); RegexpCmd.init(this); } catch (TclException e) { ! try { ! System.err.println(getResult()); ! e.printStackTrace(); ! throw new TclRuntimeError("unexpected TclException: " + e); ! } catch (SecurityException e2) { ! System.err.println( ! "java/tcl/lang/Interp createCommands(): BlendExt2:" + e2); ! } ! } catch (SecurityException e) { ! e.printStackTrace(); ! System.err.println( ! "java/tcl/lang/Interp createCommands(): BlendExt:" + e); } } *************** *** 1876,1882 **** *---------------------------------------------------------------------- */ ! void evalURL( URL context, // URL context under which s is interpreted. String s) // The name of URL. --- 1895,1901 ---- *---------------------------------------------------------------------- */ ! public void evalURL( URL context, // URL context under which s is interpreted. String s) // The name of URL. *************** *** 2074,2079 **** --- 2093,2101 ---- eval(new String(charArray), 0); } catch (IOException e) { return; + } catch (SecurityException e2) { + e2.printStackTrace(); + System.err.println("java/tcl/lang/Interp evalResource():" + e2); } finally { closeInputStream(stream); }
evalURL
is a non-public method in tcl.lang.Interp.
Perhaps it should be made public?
I tried to use it, but under Netscape4.04 with the JDK1.1 patch, it was failing because the content Object was not an instance of InputStream, instead it seemed to be an instance of netscape.net.URLInputStream.
Last updated: 03/07/98
cxh at eecs