Package org.web3d.vrml.nodes.proto
Class AbstractProto
java.lang.Object
org.web3d.vrml.nodes.proto.AbstractProto
- All Implemented Interfaces:
VRMLNodeTemplate
- Direct Known Subclasses:
ExternalPrototypeDecl
,ProtoInstancePlaceHolder
,PrototypeDecl
Base representation of the common functionality for the PROTO and
EXTERNPROTO node types.
Note: This implementation does not handle IS values to pass field information to body nodes.
- Version:
- $Revision: 1.12 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
A standard message for when the supplied node is wrong.protected org.j3d.util.ErrorReporter
Reporter instance for handing out errorsprotected static final String
When the same field is defined twice, but with different typesprotected final List
<VRMLFieldDeclaration> List of the field maps registered in order for their definitions.Data mapping holding the field name -> index (Integer) mappingprotected final ThreadLocal
<VRMLFieldData> Scratch class var for returning field data.protected boolean
Flag indicating VRML97 semanticsprotected final String
The name of the node.protected NodeTemplateToInstanceCreator
The proto creator that is responsible for creating new instances of this node.protected static final String
Message when the field type is not valid in VRML97protected final int
The major version of the spec this instance belongs to.protected final int
The minor version of the spec this instance belongs to. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractProto
(String name, int majorVersion, int minorVersion, NodeTemplateToInstanceCreator creator) Create a new instance of a proto that has the given name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener to this node instance.int
appendField
(VRMLFieldDeclaration field) Append a field declaration to this node.protected void
checkNodeType
(VRMLNodeType node) Check to see if the supplied node type is the same as this node.void
deleteField
(int index) Delete the field at the given index.void
deleteField
(VRMLFieldDeclaration field) Delete the named field.protected void
fireFieldChanged
(int index) Send a notification to the registered listeners that a field has been changed.Make a listing of all fields that are currently registered in this node.int
Get the count of the number of fields currently registered.getFieldDeclaration
(int index) Get the declaration of the field at the given index.int
getFieldIndex
(String fieldName) Get the index of the given field name.int
Get the number of fields defined for this node.Get the name of this node as a string.boolean
isVRML97()
Check to see if the node is using VRML97 semanticsvoid
Remove a listener from this node instance.void
setErrorReporter
(org.j3d.util.ErrorReporter reporter) Register an error reporter with the engine so that any errors generated by the node's internals can be reported in a nice, pretty fashion.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.web3d.vrml.lang.VRMLNodeTemplate
createNewInstance, getPrimaryType
-
Field Details
-
BAD_NODE_MSG
A standard message for when the supplied node is wrong. Just add the node name of the wrong type to the end.- See Also:
-
VRML97_FIELD_MSG
Message when the field type is not valid in VRML97- See Also:
-
FIELD_CLASH_MSG
When the same field is defined twice, but with different types- See Also:
-
fieldIndexMap
-
vrmlMajorVersion
protected final int vrmlMajorVersionThe major version of the spec this instance belongs to. -
vrmlMinorVersion
protected final int vrmlMinorVersionThe minor version of the spec this instance belongs to. -
isVrml97
protected boolean isVrml97Flag indicating VRML97 semantics -
fieldDeclList
List of the field maps registered in order for their definitions. When created, this list will have a null value in each index position for the size of the number of declared fields. This allows a user to set(int, object) the value if they want. However, it is recommended that you use theappendField(VRMLFieldDeclaration)
method instead. -
nodeName
The name of the node. "Script" or the proto name. -
fieldLocalData
Scratch class var for returning field data. Assigned at construction. -
errorReporter
protected org.j3d.util.ErrorReporter errorReporterReporter instance for handing out errors -
protoCreator
The proto creator that is responsible for creating new instances of this node. This will be, by necessity a renderer-specific class based on this abstract interface.
-
-
Constructor Details
-
AbstractProto
public AbstractProto(String name, int majorVersion, int minorVersion, NodeTemplateToInstanceCreator creator) Create a new instance of a proto that has the given name.- Parameters:
name
- The name of the proto to usemajorVersion
- The major version number of this sceneminorVersion
- The minor version number of this scenecreator
- The node creator for generating instances of ourself
-
-
Method Details
-
setErrorReporter
public void setErrorReporter(org.j3d.util.ErrorReporter reporter) Register an error reporter with the engine so that any errors generated by the node's internals 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.- Specified by:
setErrorReporter
in interfaceVRMLNodeTemplate
- Parameters:
reporter
- The instance to use or null
-
addNodeListener
Add a listener to this node instance. If the listener is already added or null the request is silently ignored.- Parameters:
l
- The listener instance to add
-
removeNodeListener
Remove a listener from this node instance. If the listener is null or not registered, the request is silently ignored.- Parameters:
l
- The listener to be removed
-
fireFieldChanged
protected void fireFieldChanged(int index) Send a notification to the registered listeners that a field has been changed. If no listeners have been registered, then this does nothing, so always call it regardless.- Parameters:
index
- The index of the field that changed
-
getVRMLNodeName
Get the name of this node as a string.- Specified by:
getVRMLNodeName
in interfaceVRMLNodeTemplate
- Returns:
- The name of the node
-
getFieldCount
public int getFieldCount()Get the count of the number of fields currently registered.- Specified by:
getFieldCount
in interfaceVRMLNodeTemplate
- Returns:
- The number of fields available
-
appendField
public int appendField(VRMLFieldDeclaration field) throws FieldExistsException, InvalidFieldException Append a field declaration to this node. This is added to the current list on the end. If the field already exists with the given name but different values exception will be generated. If the field has exactly the same signature it will silently ignore the request.- Specified by:
appendField
in interfaceVRMLNodeTemplate
- Parameters:
field
- The new field to add- Returns:
- The index that this field was added at
- Throws:
FieldExistsException
- A conflicting field of the same name already exists for this nodeInvalidFieldException
- The field type is not valid for this specification version
-
deleteField
Delete the field at the given index. This will not shuffle fields down from higher index values. That index just becomes invalid to set values to. If no field exists at that index or it is out of range, an exception will be generated.- Specified by:
deleteField
in interfaceVRMLNodeTemplate
- Parameters:
index
- The index of the field to delete- Throws:
InvalidFieldException
- The field does not exist at the indexIndexOutOfBoundsException
- The index provided is out of range for the current field numbers
-
deleteField
public void deleteField(VRMLFieldDeclaration field) throws InvalidFieldException, IndexOutOfBoundsException Delete the named field. This will not shuffle fields down from higher index values. That index just becomes invalid to set values to. If no field exists at that index or it is out of range, an exception will be generated.- Specified by:
deleteField
in interfaceVRMLNodeTemplate
- Parameters:
field
- The field to delete- Throws:
InvalidFieldException
- The named field does not existIndexOutOfBoundsException
- The index provided is out of range for the current field numbers
-
getAllFields
Make a listing of all fields that are currently registered in this node. The list contains instances ofVRMLFieldDeclaration
.- Specified by:
getAllFields
in interfaceVRMLNodeTemplate
- Returns:
- A list of the current field declarations
-
isVRML97
public boolean isVRML97()Check to see if the node is using VRML97 semantics- Returns:
- true if this is a VRML97 node
-
checkNodeType
Check to see if the supplied node type is the same as this node. It does a case sensitive string comparison based on their node name. If they are not the same then an IllegalArgumentException is thrown. If the same, nothing happens.- Parameters:
node
- The node to check- Throws:
IllegalArgumentException
- The nodes are not the same
-
getFieldIndex
Get the index of the given field name. If the name does not exist for this node then return a value of -1.- Specified by:
getFieldIndex
in interfaceVRMLNodeTemplate
- Parameters:
fieldName
- The name of the field we want the index from- Returns:
- The index of the field name or -1
-
getFieldDeclaration
Get the declaration of the field at the given index. This allows for reverse lookup if needed. If the field does not exist, this will give a value of null.- Specified by:
getFieldDeclaration
in interfaceVRMLNodeTemplate
- Parameters:
index
- The index of the field to get information- Returns:
- A representation of this field's information
-
getNumFields
public int getNumFields()Get the number of fields defined for this node.- Specified by:
getNumFields
in interfaceVRMLNodeTemplate
- Returns:
- The number of fields.
-