import netscape_beta.application.*;
import netscape_beta.util.*;

/**
 * The Visual Traversal application.  Allows users
 * to load class dictionaries, edit them via a gui
 * and save the resulting behavior file.
 *
 * Runs as either an Applet or a stand-alone 
 * application.
 *
 * Put the following HTML code in your web page to 
 * see the applet.
 *
 * <applet
 *   name="trav"
 *   code="NetscapeApplet"
 *   codebase="d:/java/trav"
 *   width="800"
 *   height="600"
 *   hspace="0"
 *   vspace="0"
 *   align="Top"
 *   alt="If you had a java-enabled browser, you would see an applet here."
 * >
 * <param name="ApplicationClass" value="DemTrav">
 * <hr>If your browser recognized the applet tag, you would see an applet here.<hr>
 * </applet>
 *
 * @version        1.0 12 Dec 1996
 * @author         Andrew Miller
 */
public class DemTrav extends Application {

	protected DemDoc m_doc          = null;
    protected DemFrame m_frame      = null;
    protected AppletIOView m_ioview = null;

    /** This method gets called to initialize an application. We'll take
      * this opportunity to set up the View hierarchy.
      */
    public void init() {
        super.init();

        // if the frame is null, our main() didn't get called
        // therefore we're an applet!
        if(m_frame == null)
        {
            // make an IOView so we can import/export data
            // since applet can't touch the disk
            if(m_ioview != null)
            {
                m_ioview.removeFromSuperView();
            }

            m_ioview = new AppletIOView(mainRootView());

            // now run traversal studio in an external window
            setFrame(new DemFrame(this, true /*applet*/)); 
            getFrame().show();
        }
        
	getFrame().newDoc();

	// force theses classes to be loaded for faster response
	Visitor vis = new Visitor();
	Bitmap bmpVisitor = Bitmap.bitmapNamed("Visitor.gif", true);
	Bitmap bmpNoe = Bitmap.bitmapNamed("TreeNode.gif", true);
    }

    /** Provides access to the application's document.
      * @return The application's document.
      */
    public DemDoc doc()
    {
        return m_doc;
    }

    /** Set the application's document.
      * @param doc   The new document.
      */
    public void setDoc(DemDoc doc)
    {
        m_doc = doc;
    }


    /** Provides access to the application's frame.
      * @return The application's frame. 
      */
    public DemFrame getFrame()
    {
        return m_frame;
    }

    /** Set the application's frame.
      * @param frame   The new frame.
      */
    public void setFrame(DemFrame frame)
    {
        m_frame = frame;
    }

    /** Provides access to the application's AppletIOView.
      * Should only be used when run as an applet.
      * @return The application's AppletIOView. 
      */
    public AppletIOView getIOView()
    {
        return m_ioview;
    }

    /** Allows Traval Studio to run as a stand-alone 
      * application.  Creats a new frame and runs
      * the app.
      */
    public static void main(String args[]) {
        DemTrav app;
        Size size;

        app = new DemTrav();
        app.setFrame(new DemFrame(app, false /*applet?*/)); 
        app.getFrame().show();

        app.run();
    }
}

