001: package jsint;
002:
003: /**
004: * A jsint.SchemeApplet is an applet wrapper for a jsint.Scheme program
005: * It reads the applet parameters to find which program to run
006: * and then it creates a scheme interpreter to run that program.
007: * @author Timothy J. Hickey, Copyright 2000, tim@cs.brandeis.edu, <a href="license.txt">license</a>
008: * subsequently modified by Jscheme project members
009: * licensed under zlib licence (see license.txt)
010: */
011:
012: import java.awt.*;
013: import java.net.URL;
014: import java.net.MalformedURLException;
015: import java.util.*;
016: import java.applet.*;
017:
018: import jsint.*;
019:
020: /**
021: * this class defines an applet which will read
022: * a file name from the applet parameter list and
023: * will invoke the Jscheme interpreter on that file
024: */
025: public class SchemeApplet extends java.applet.Applet {
026: Symbol init, start, stop, destroy;
027:
028: public void init() {
029: String progS = this .getParameter("prog"), // Scheme program to load
030: exprS = this .getParameter("expr"), // Scheme expression to evaluate
031: codeS = this .getParameter("compiledprog"), // compiled Scheme program to load
032: initS = this .getParameter("init"), // Scheme procedure to call when initializing
033: startS = this .getParameter("start"), // Scheme procedure to call when initializing
034: stopS = this .getParameter("stop"), // Scheme procedure to call when initializing
035: destroyS = this .getParameter("destroy"); // Scheme procedure to call when initializing
036:
037: if (initS != null)
038: init = Symbol.intern(initS);
039: if (startS != null)
040: start = Symbol.intern(startS);
041: if (stopS != null)
042: stop = Symbol.intern(stopS);
043: if (destroyS != null)
044: destroy = Symbol.intern(destroyS);
045:
046: setBackground(new Color(250, 150, 255));
047: setVisible(true);
048:
049: try {
050: if (codeS != null)
051: Scheme.eval(new Pair(Symbol.intern(codeS
052: .concat(".load")), Pair.EMPTY));
053:
054: if (progS != null)
055: try {
056: Scheme.load(new InputPort(new URL(
057: getDocumentBase(), progS).openStream()));
058: } catch (Exception e) {
059: Scheme.eval(U.list(Symbol.intern("load"), progS));
060: }
061:
062: if (exprS != null)
063: Scheme.eval((new InputPort((new java.io.StringReader(
064: exprS)))).read());
065:
066: if (init != null)
067: Scheme.eval(new Pair(init, new Pair(this , Pair.EMPTY)));
068:
069: } catch (Exception e) {
070: E.warn("I/O Exception: " + e);
071: e.printStackTrace();
072: }
073: }
074:
075: public void start() {
076: try {
077: if (start != null)
078: Scheme
079: .eval(new Pair(start,
080: new Pair(this , Pair.EMPTY)));
081: } catch (Exception e) {
082: E.warn("I/O Exception: " + e);
083: e.printStackTrace();
084: }
085: }
086:
087: public void stop() {
088: try {
089: if (stop != null)
090: Scheme.eval(new Pair(stop, new Pair(this , Pair.EMPTY)));
091: } catch (Exception e) {
092: E.warn("I/O Exception: " + e);
093: e.printStackTrace();
094: }
095: }
096:
097: public void destroy() {
098: try {
099: if (destroy != null)
100: Scheme.eval(new Pair(destroy,
101: new Pair(this , Pair.EMPTY)));
102: } catch (Exception e) {
103: E.warn("I/O Exception: " + e);
104: e.printStackTrace();
105: }
106: }
107:
108: }
|