Class WebSim

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----java.applet.Applet
                                   |
                                   +----WebSim

public class WebSim
extends Applet
implements Parsable
Parse a string (from the Web page, a file, or a URL), and build and run the objects that it describes. It should describe one or more objects of type Project. The first will be embedded on the Web page, and each of the others will be placed in a separate window.

This code is (c) 1996-1998 Leemon Baird <leemon@cs.cmu.edu>, http://www.cs.cmu.edu/~baird
The source and object code may be redistributed freely. If the code is modified, please state so in the comments.

Version:
1.05, 11 May 97
Author:
Leemon Baird

Variable Index

 o myThreadGroup
The thread group containing this thread (and all other WebSim threads)
 o restartNumber
All projects check this occasionally, and restart when it changes
 o watchManager
This static variable allows any thread in memory (such as another Applet like VRMLInterface) to communicate with WebSim's WatchManager.
 o watchManagerGuard
Synchronize on watchManagerGuard before attempting to read or write watchManager.

Constructor Index

 o WebSim()
constructor for WebSim includes setting the background color and layout manager
 o WebSim(String, int, int, int, int)
Instantiate a WebSim manually rather than with a browser or applet viewer.

Method Index

 o BNF(int)
 o destroy()
The browser calls this when quitting.
 o destroyAll()
close all windows, kill all threads, dispose of all Graphics contexts
 o getAppletInfo()
Information about the applet that a browser or Java interpretor can give the user
 o getParameterInfo()
Parameter info that a browser or Java interpretor can give the user
 o getParameters(int)
Return a parameter array if BNF(), parse(), and unparse() are to be automated, null otherwise.
 o initialize(int)
Initialize, either partially or completely.
 o parse(Parser, int)
 o parseAndRun()
parses the BNF string and runs a set of projects.
 o resumeAllThreads()
resume all threads created by WebSim that have been suspended
 o saveFile()
save everything as a WebSim HTML file.
 o setWatchManager(WatchManager, String)
Register all variables with this WatchManager.
 o start()
Parse projects and start them running in separate threads
 o stop()
The browser calls this when the document is no longer on the screen, either because another Web page has been loaded, or because the current window was minimized.
 o stopAllThreads()
stop all threads created by WebSim
 o suspendAllThreads()
suspend all threads created by WebSim
 o unparse(Unparser, int)
 o unparseAll()
Unparse everything into a file, asking the user for the filename and whether to overwrite it if it exists.
 o unparseAll(String, boolean)
Unparse everything into the given file, and if it is overwriting an existing file, and makeBackup, then rename the old file *.BAK, and delete any existing .BAK with that same name

Variables

 o watchManager
 public static WatchManager watchManager
This static variable allows any thread in memory (such as another Applet like VRMLInterface) to communicate with WebSim's WatchManager. If there are several WatchManagers, then it gives the one belonging to the last WebSim Project that finished initializing. To wait for the WatchManager to become available then put it into a new local variable called watchManager, run the following code:
            WatchManager watchManager;
            synchronized(WebSim.watchManagerGuard) {
                if (WebSim.watchManager==null)
                        try {
                            WebSim.watchManagerGuard.wait();
                        } catch(InterruptedException e) {
                        }
                watchManager=WebSim.watchManager;
            }
                                                                          

 o watchManagerGuard
 public static Double watchManagerGuard
Synchronize on watchManagerGuard before attempting to read or write watchManager. Why is there a separate variable just for the guard? This is a workaround for a BUG: it's needed in Netscape 3.0 for SunOs 4, but not in Netscape for Win95/NT.

 o restartNumber
 public static int restartNumber
All projects check this occasionally, and restart when it changes

 o myThreadGroup
 public ThreadGroup myThreadGroup
The thread group containing this thread (and all other WebSim threads)

Constructors

 o WebSim
 public WebSim()
constructor for WebSim includes setting the background color and layout manager

 o WebSim
 public WebSim(String bnfString,
               int x,
               int y,
               int width,
               int height)
Instantiate a WebSim manually rather than with a browser or applet viewer. The BNF code is in bnfString, and the window has upper-left corner (x,y) and dimensions (width,height).

Methods

 o getParameters
 public Object[][] getParameters(int lang)
Return a parameter array if BNF(), parse(), and unparse() are to be automated, null otherwise.

See Also:
getParameters
 o getAppletInfo
 public String getAppletInfo()
Information about the applet that a browser or Java interpretor can give the user

Overrides:
getAppletInfo in class Applet
 o getParameterInfo
 public String[][] getParameterInfo()
Parameter info that a browser or Java interpretor can give the user

Overrides:
getParameterInfo in class Applet
 o start
 public void start()
Parse projects and start them running in separate threads

Overrides:
start in class Applet
 o parseAndRun
 public void parseAndRun()
parses the BNF string and runs a set of projects.

 o stop
 public void stop()
The browser calls this when the document is no longer on the screen, either because another Web page has been loaded, or because the current window was minimized. It should kill all threads and release all graphics contexts.

Overrides:
stop in class Applet
 o destroyAll
 public void destroyAll()
close all windows, kill all threads, dispose of all Graphics contexts

 o destroy
 public void destroy()
The browser calls this when quitting. It should kill all threads and release all graphics contexts.

Overrides:
destroy in class Applet
 o stopAllThreads
 public void stopAllThreads()
stop all threads created by WebSim

 o suspendAllThreads
 public void suspendAllThreads()
suspend all threads created by WebSim

 o resumeAllThreads
 public void resumeAllThreads()
resume all threads created by WebSim that have been suspended

 o unparseAll
 public void unparseAll()
Unparse everything into a file, asking the user for the filename and whether to overwrite it if it exists.

 o unparseAll
 public void unparseAll(String filename,
                        boolean makeBackup)
Unparse everything into the given file, and if it is overwriting an existing file, and makeBackup, then rename the old file *.BAK, and delete any existing .BAK with that same name

 o saveFile
 public void saveFile()
save everything as a WebSim HTML file.

 o initialize
 public void initialize(int level)
Initialize, either partially or completely.

See Also:
initialize
 o setWatchManager
 public void setWatchManager(WatchManager wm,
                             String name)
Register all variables with this WatchManager. This method should register all the variables in this object and in those it links to. The name of each variable should be appended to the end of the String name.

 o BNF
 public String BNF(int lang)
 o unparse
 public void unparse(Unparser u,
                     int lang)
 o parse
 public Object parse(Parser p,
                     int lang) throws ParserException