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 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 allThreadsSuspended
Have all threads created by WebSim (and the applet thread itself) been suspended?
 o bnf
If nonnull, the string containing the BNF code
 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 unparseAtEnd
 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.
 o wins
array of all the Projects

Constructor Index

 o WebSim()
constructor that does nothing
 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 init()
Initialize the applet with a white background
 o initialize(int)
Initialize, either partially or completely.
 o parse(Parser, int)
Parse the input file to get the parameters for this object.
 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()
 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.
 o stopAllThreads()
stop all threads created by WebSim
 o suspendAllThreads()
suspend all threads created by WebSim
 o unparse(Unparser, int)
Output a description of this object that can be parsed with parse().
 o unparseAll()
Unparse everything into a file.

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 wins
 protected ProjWin wins[]
array of all the Projects

 o unparseAtEnd
 protected boolean unparseAtEnd
 o myThreadGroup
 protected ThreadGroup myThreadGroup
The thread group containing this thread (and all other WebSim threads)

 o bnf
 protected String bnf
If nonnull, the string containing the BNF code

 o allThreadsSuspended
 protected PBoolean allThreadsSuspended
Have all threads created by WebSim (and the applet thread itself) been suspended?

Constructors

 o WebSim
 public WebSim()
constructor that does nothing

 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 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 init
 public void init()
Initialize the applet with a white background

Overrides:
init 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. 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 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 BNF
 public String BNF(int lang)
 o unparse
 public void unparse(Unparser u,
                     int lang)
Output a description of this object that can be parsed with parse().

See Also:
Parsable
 o parse
 public Object parse(Parser p,
                     int lang) throws ParserException
Parse the input file to get the parameters for this object.

Throws: ParserException
parser didn't find the required token
 o unparseAll
 public void unparseAll()
Unparse everything into a file.

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

See Also:
initialize