/* Jacl Tcl Shell

@Author: Christopher Hylands

@Version: %W% %G%

@Copyright (c) 1998 The Regents of the University of California.
All rights reserved.

Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that the
above copyright notice and the following two paragraphs appear in all
copies of this software.

IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.

                                                PT_COPYRIGHT_VERSION_2
                                                COPYRIGHTENDKEY
*/

import tcl.lang.*;
import java.applet.Applet;
import java.awt.*;

//////////////////////////////////////////////////////////////////////////
//// TclShellApplet
/** TclShell front end to Jacl.
 * @author Christopher Hylands
 * @version %W% %G%
 */
public class TclShellApplet extends Applet implements Runnable {

    /** Return a string describing this applet.
     */
    public String getAppletInfo() {
        return "Hello World, a Jacl Applet\n" +
            "By: Christopher Hylands, cxh@eecs.berkeley.edu\n" +
            "@(#)TclShell.java	1.5 02/19/98";
    }

    /** Return information about parameters.
     */
    public String[][] getParameterInfo () {
        String pinfo[][] = {
            {"background", "hexcolor value", "background color"},
            {"foreground", "hexcolor value", "foreground color"},
        };
        return pinfo;
    }

    /**
     * Initialize the applet.  Read the applet parameters.
     */
    public void init() {
        if (_debug > 8) System.out.println("TclShellApplet: init");
        int width,height;

        setLayout(new BorderLayout());
        _tclShell = new TclShell();

        add("Center", _tclShell);

        //show();
        // The Java Programmnig FAQ at http://www.best.com/~pvdl/javafaq.html
        // says:
        // 6.20 How do I redirect the System.err stream to a file? 
        // A. You cannot assign a new FileOutputStream to System.err, as it is
        // final. Instead use the System.setErr() library call, like this: 
        //  System.setErr(new FileOutputStream("myerrors.txt"));
        // This was introduced with JDK 1.1. There is also a corresponding
        // setIn() for redirecting standard in, and a setOut() for
        // standard out. 
        //
        // We should use this to redirect the output.

        // Process the documentBase applet parameter.
        // Process the width and height applet parameters
        width = Integer.valueOf(getParameter("width")).intValue();
        height = Integer.valueOf(getParameter("height")).intValue();

        if (_debug > 8)
            System.out.println("TclShellApplet: init: about to resize"+width);
        resize(width,height);

        Color background = Color.white;
        //background = PlotBox.getColorByName(getParameter("background"));
        //setBackground(background);
        

        // Process the foreground parameter.
        try {
            Color foreground = Color.white;
        } catch (NullPointerException e) {}

        // Process the scripturl parameter.
        String scripturl = null;
        try {
            scripturl = getParameter("scripturl");
        } catch (NullPointerException e) {}
        _tclShell.init();
        super.init();
    }

    /** Paint the screen with our message
     */
    public void paint(Graphics g) {
        if (_debug > 8) System.out.println("TclShellApplet: paint");
        super.paint(g);
    }

    public void run () {
        if (_debug > 8) System.out.println("TclShellApplet: run");
	repaint();
    }

    /** Start the applet.
     */
    public void start () {
        if (_debug > 8) System.out.println("TclShellApplet: start");
	_tclShellThread = new Thread(this);
        _tclShellThread.start();
        super.start();
    }

    /** Stop the applet.
     */
    public void stop () {
        if (_debug > 8) System.out.println("TclShellApplet: stop");
        _tclShellThread.stop();
    }


    // If non-zero, print out debugging messages.
    protected int _debug = 20;

    //////////////////////////////////////////////////////////////////////
    ////                      private variables                       ////

    // TclShell Panel
    private TclShell _tclShell;

    // Thread for this applet.
    private Thread _tclShellThread;
}
