Class Browser
- All Implemented Interfaces:
org.mozilla.javascript.Scriptable
The current implementation ignores any parameter values provided by the world when requesting a loadURL.
The standard Java interface does not allow us to print output. The way that
all VRML vendors seem to have gotten around this is to add
println
methods to the Browser object. We've done this as
well. The current implementation just calls System.out directly, but a
later revision will probably use a callback for a listener provided
instance to send the output to. In addition, this class has to be made
public so that Rhino can access the various print methods. Note that the
constructor is not private because you should never directly be creating
instances of this class.
- Version:
- $Revision: 1.21 $
- Author:
- Justin Couch
-
Field Summary
Fields inherited from class org.web3d.vrml.scripting.ecmascript.builtin.AbstractScriptableObject
BAD_FORMAT_MSG, dataChanged, INVALID_TYPE_MSG, JS_FUNCTION_PREFIX, readOnly, READONLY_MSG
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
-
Constructor Summary
ConstructorsConstructorDescriptionBrowser
(VRMLExecutionSpace space, BrowserCore browser, ViewpointManager vpm, RouteManager rm, FrameStateManager fsm, WorldLoaderManager wlm) Create a browser instance that represents the given universe details. -
Method Summary
Modifier and TypeMethodDescriptionGet the value of the named function.Get the list of fields that have changed.boolean
Check for the named property presence.boolean
Check to see if any of the scene variables have been changed, such as the root nodes, proto definitions etc.void
jsFunction_addBrowserListener
(String functionName) jsFunction_createX3DFromString
(String vrmlSyntax) Parse the given string and turn this into a list of VRML nodes.Create and load VRML from the given URL and place the returned values as nodes into the given VRML node in the scene.void
Bind the first viewpoint in the list.void
Bind the last viewpoint in the list.void
jsFunction_loadURL
(MFString url, MFString parameter) Load the URL as the new root of the scene.void
Bind the next viewpoint in the list.void
Bind the previous viewpoint in the list.void
jsFunction_print
(Object obj) Print an object instance to the output.void
jsFunction_print
(String str) Print a string to the output.void
jsFunction_println
(Object obj) Print an object instance to the output.void
jsFunction_println
(String str) Print a string to the output.void
jsFunction_removeBrowserListener
(String functionName) void
jsFunction_replaceWorld
(Scene scene) Replace the current world with the given nodes.protected org.mozilla.javascript.FunctionObject
locateFunction
(String methodName) Convenience method to locate a function name for this object and create an appropriate Function instance to represent it.void
Sets the named property with a new value.protected void
registerFunction
(String name, Object value) Register a function object with this field typevoid
setErrorReporter
(org.j3d.util.ErrorReporter reporter) Register an error reporter with the engine so that any errors generated by the script code can be reported in a nice, pretty fashion.Methods inherited from class org.web3d.vrml.scripting.ecmascript.builtin.AbstractScriptableObject
delete, delete, get, getClassName, getDefaultValue, getIds, getParentScope, getPrototype, has, hasInstance, put, setParentScope, setPrototype, setReadOnly
-
Constructor Details
-
Browser
public Browser(VRMLExecutionSpace space, BrowserCore browser, ViewpointManager vpm, RouteManager rm, FrameStateManager fsm, WorldLoaderManager wlm) Create a browser instance that represents the given universe details.- Parameters:
space
- The execution space we need a browser forbrowser
- The core representation of the browservpm
- The viewpoint manager for next/previous callsrm
- A route manager for users creating/removing routesfsm
- State manager for coordinating inter-frame processingwlm
- Loader for full files- Throws:
IllegalArgumentException
- Any one of the parameters is null
-
-
Method Details
-
has
Check for the named property presence.- Specified by:
has
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
has
in classAbstractScriptableObject
- Parameters:
name
- name of the scriptstart
- the script corresponding to the given name- Returns:
- true if it is a defined eventOut or field
-
get
Get the value of the named function. If no function object is registered for this name, the method will return null.- Specified by:
get
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
get
in classAbstractScriptableObject
- Parameters:
name
- The variable namestart
- The object where the lookup began- Returns:
- the corresponding function object or null
-
put
Sets the named property with a new value. A put usually means changing the entire property. So, if the property has changed using an operation likee = new SFColor(0, 1, 0);
then a whole new object is passed to us.- Specified by:
put
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
put
in classAbstractScriptableObject
- Parameters:
name
- The name of the property to definestart
- The object who's property is being setvalue
- The value being requested
-
jsFunction_replaceWorld
Replace the current world with the given nodes. Replaces the entire contents of the VRML world with the new nodes. Any node references that belonged to the previous world are still valid but no longer form part of the scene graph (unless it is these nodes passed to this method). The URL of the world still represents the just unloaded world.Calling this method causes a SHUTDOWN event followed by an INITIALIZED event to be generated.
- Parameters:
scene
- The list of nodes to use as the new root of the world
-
jsFunction_createX3DFromString
Parse the given string and turn this into a list of VRML nodes. Method is a blocking call that won't return until all of the top level nodes defined in the string have been returned.At the point that this method returns, external files such as textures, sounds and inlines may not have been loaded.
The string may contain all legal VRML syntax. The VRML header line is not required to be present in the string.
- Parameters:
vrmlSyntax
- The string containing VRML string syntax- Returns:
- A list of the top level nodes in VRML representation as defined in the parameter
-
jsFunction_createX3DFromURL
Create and load VRML from the given URL and place the returned values as nodes into the given VRML node in the scene. The difference between this and loadURL is that this method does not replace the entire scene with the contents from the URL. Instead, it places the return values as events in the nominated node and MFNode eventIn.- Parameters:
url
- The list of URLs in decreasing order of preference as defined in the VRML97 specification.- Returns:
- the Scene created from the given nodes
-
jsFunction_loadURL
Load the URL as the new root of the scene. Replaces all the current scene graph with the new world. A non-blocking call that will change the contents at some time in the future.Generates an immediate SHUTDOWN event and then when the new contents are ready to be loaded, sends an INITIALIZED event.
- Parameters:
url
- The list of URLs in decreasing order of preference as defined in the VRML97 specification.parameter
- The list of parameters to accompany the load call as defined in the Anchor node specification of VRML97
-
jsFunction_getRenderingProperty
-
jsFunction_addBrowserListener
-
jsFunction_removeBrowserListener
-
jsFunction_println
Print a string to the output.- Parameters:
str
- The string to print
-
jsFunction_println
Print an object instance to the output.- Parameters:
obj
- The object to print
-
jsFunction_print
Print a string to the output.- Parameters:
str
- The string to print
-
jsFunction_print
Print an object instance to the output.- Parameters:
obj
- The object to print
-
jsFunction_nextViewpoint
public void jsFunction_nextViewpoint()Bind the next viewpoint in the list. The definition of "next" is not specified, and may be browser dependent. If only one viewpoint is declared, this method does nothing. -
jsFunction_previousViewpoint
public void jsFunction_previousViewpoint()Bind the previous viewpoint in the list. The definition of "previous" is not specified, and may be browser dependent. If only one viewpoint is declared, this method does nothing. -
jsFunction_firstViewpoint
public void jsFunction_firstViewpoint()Bind the first viewpoint in the list. This is the first viewpoint declared in the user's file. ie The viewpoint that would be bound by default on loading. -
jsFunction_lastViewpoint
public void jsFunction_lastViewpoint()Bind the last viewpoint in the list. -
hasSceneChanged
public boolean hasSceneChanged()Check to see if any of the scene variables have been changed, such as the root nodes, proto definitions etc.- Returns:
- true if any of the scene structures have changed
-
getChangedData
Get the list of fields that have changed. The return value may be either a singleNodeFieldData
instance or anArrayList
of field data instances if more than one has changed. When called, this is recursive so that all fields and nodes referenced by this node field will be included. If no fields have changed, this will return null. However, that should never happen as the user should always checkFieldScriptableObject.hasChanged()
which would return false before calling this method.- Returns:
- A single
NodeFieldData
,ArrayList
or null
-
setErrorReporter
public void setErrorReporter(org.j3d.util.ErrorReporter reporter) Register an error reporter with the engine so that any errors generated by the script code can be reported in a nice, pretty fashion. Setting a value of null will clear the currently set reporter. If one is already set, the new value replaces the old. Also changes the ErrorReporter used by the CommonBrowser instance.- Parameters:
reporter
- The instance to use or null
-
registerFunction
-
locateFunction
Convenience method to locate a function name for this object and create an appropriate Function instance to represent it. It assumes that the name you give it is the normal name and will add a "jsFunction_" prefix to locate that from the method details. There is also the implicit assumption that you have made a check for this name being a valid function for this object before you call this method. If a function object is found for this method, it will automatically be registered and you can also have a copy of it returned to use.- Parameters:
methodName
- The real method name to look for- Returns:
- The function object corresponding to the munged method name
-