Class BaseText
- All Implemented Interfaces:
VRMLNode
,FrameStateListener
,VRMLGeometryNodeType
,VRMLNodeType
,VRMLTextNodeType
Common base implementation of a Text node.
This base class provides a number of convenience methods for generating the visible text. It is not required that the derived implementation make use of them, but it assumes that you know when you create the class whether you will need them or not.
Text generation is provided by a texture that is an alpha mask over the stock texture and geometry. VRML requires that a text object be fully textured using the normal appearance node information, so this is just used as an alpha mask to control what geometry is actually visible.
The texture generation does not do the full rendering of the text. It assumes that the derived class will also contribute to the process by playing with texture coordinates. The following fields from the FontStyle require the derived class to do something.
- leftToRight: If set to FALSE, then reverse the texture coordinates to render in the mirror image.
Properties
The following properties are used by this class
org.web3d.vrml.nodes.fontstyle.font.antialiased
Boolean to indicate the rendering should use antialiased text rather than normal rendering. The default is false.
- Version:
- $Revision: 1.28 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Index of the fontstyle node fieldprotected static final int
Index of the length fieldprotected static final int
Index of the maxExtents fieldprotected static final int
Index of the solid fieldprotected static final int
Index of the string fieldprotected int
The height of the texture imageprotected int
The width of the texture imageprotected static final int
The last field index used by this classprotected int
The number of pixels a single line of text takes up on the imageprotected int
The number of pixels of spacing between the bottom of one line and the top of the next.protected static final int
Number of fields constantprotected int
Number of valid values in vfLengthprotected int
Number of valid values in vfStringprotected VRMLProtoInstance
The proto version of the fontstyleprotected TextLayout[]
The stringTextLayoutArray matching the appropriate string in the order list depending on the fontstyle topToBottom field.protected BufferedImage
The texture currently being displayedprotected int
The number of pixels actually used in the height of the texture.protected int
The number of pixels actually used in the width of the texture.protected VRMLFontStyleNodeType
exposedField SFNode fontStyle NULLprotected float[]
exposedField MFFloat length []protected float
exposedField SFFloat maxExtentprotected boolean
field SFBool solidprotected String[]
exposedField MFString string []Fields inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
errorReporter, FIELD_METADATA, fieldLocalData, hasChanged, inSetup, isDEF, isStatic, LAST_NODE_INDEX, layerIds, nodeName, pMetadata, refCounts, removedLayerIds, stateManager, STATIC_SCENE_GRAPH, vfMetadata, vrmlMajorVersion, vrmlMinorVersion
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseText
(boolean useTexture) Construct a new default instance of this class.protected
BaseText
(VRMLNodeType node, boolean useTexture) Construct a new instance of this node based on the details from the given node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener for local color changes.void
Add a listener for texture coordinate generation mode changes.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.getFieldValue
(int index) Get the value of a field.Get the currently set fontstyle.int[]
Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode).int
Get the number of fields.int
Get the number of texture coordinate sets contained by this nodeint
Get the primary type of this node.getTexCoordGenMode
(int setNum) Get the texture coordinate generation mode.String[]
getText()
Get the current text being rendered.boolean
Specified whether this node has alpha values in the local colour information.boolean
Specified whether this node has color information.boolean
isCCW()
Get the value of the CCW field.boolean
Specifies whether this node requires lighting.boolean
isSolid()
Specifies whether a geometry object is a solid object.void
Remove a listener for local color changes.void
Remove a listener for texture coordinate generation mode changes.void
sendRoute
(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.void
setFontStyle
(VRMLNodeType newFont) Convenience method to set a node child for the fontstyle.void
Convenience method to set the text information.void
setTextureCount
(int count) Set the number of textures that were found on the accompanying Appearance node.void
Notification that the construction phase of this node has finished.void
setValue
(int index, boolean value) Set the value of the field at the given index as an boolean.void
setValue
(int index, float value) Set the value of the field at the given index as a float.void
setValue
(int index, float[] value, int numValid) Set the value of the field at the given index as an array of floats.void
Set the value of the field at the given index as a string.void
Set the value of the field at the given index as an array of strings.void
setValue
(int index, VRMLNodeType child) Set the value of the field at the given index as a node.protected void
textUpdated
(boolean sizeChanged) Notification by the base class to the derived class that the texture representing the text has been changed.Methods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
addNodeListener, allEventsComplete, checkNodeType, checkSecondaryType, checkSecondaryType, clearRemovedLayerIds, fireFieldChanged, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, getSecondaryType, getUserData, getVRMLNodeName, hasFieldChanged, isDEF, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setErrorReporter, setFrameStateManager, setMetadataObject, setUserData, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setVersion, throwInitOnlyWriteException, throwInputOnlyWriteException, throwInvalidNodeException, throwInvalidProtoException, throwOutputOnlyWriteException, updateRefCount, updateRefs
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.nodes.FrameStateListener
allEventsComplete
Methods inherited from interface org.web3d.vrml.lang.VRMLNode
getSecondaryType, getUserData, getVRMLNodeName, isDEF, setErrorReporter, setUserData, setVersion
Methods inherited from interface org.web3d.vrml.nodes.VRMLNodeType
addNodeListener, clearRemovedLayerIds, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, hasFieldChanged, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setFrameStateManager, setMetadataObject, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, updateRefCount
-
Field Details
-
FIELD_STRING
protected static final int FIELD_STRINGIndex of the string field- See Also:
-
FIELD_FONTSTYLE
protected static final int FIELD_FONTSTYLEIndex of the fontstyle node field- See Also:
-
FIELD_LENGTH
protected static final int FIELD_LENGTHIndex of the length field- See Also:
-
FIELD_MAXEXTENT
protected static final int FIELD_MAXEXTENTIndex of the maxExtents field- See Also:
-
FIELD_SOLID
protected static final int FIELD_SOLIDIndex of the solid field- See Also:
-
LAST_TEXT_INDEX
protected static final int LAST_TEXT_INDEXThe last field index used by this class- See Also:
-
NUM_FIELDS
protected static final int NUM_FIELDSNumber of fields constant- See Also:
-
vfString
exposedField MFString string [] -
numString
protected int numStringNumber of valid values in vfString -
vfFontStyle
exposedField SFNode fontStyle NULL -
pFontStyle
The proto version of the fontstyle -
vfLength
protected float[] vfLengthexposedField MFFloat length [] -
numLength
protected int numLengthNumber of valid values in vfLength -
vfMaxExtent
protected float vfMaxExtentexposedField SFFloat maxExtent -
vfSolid
protected boolean vfSolidfield SFBool solid -
texturedImage
The texture currently being displayed -
imgWidth
protected int imgWidthThe width of the texture image -
imgHeight
protected int imgHeightThe height of the texture image -
usedPixelWidth
protected int usedPixelWidthThe number of pixels actually used in the width of the texture. -
usedPixelHeight
protected int usedPixelHeightThe number of pixels actually used in the height of the texture. -
linePixelHeight
protected int linePixelHeightThe number of pixels a single line of text takes up on the image -
linePixelSpacing
protected int linePixelSpacingThe number of pixels of spacing between the bottom of one line and the top of the next. Based on the bounding box and therefore the line height. -
stringTextLayoutArray
The stringTextLayoutArray matching the appropriate string in the order list depending on the fontstyle topToBottom field.
-
-
Constructor Details
-
BaseText
protected BaseText(boolean useTexture) Construct a new default instance of this class.- Parameters:
useTexture
- True if the derived class wants textures generated
-
BaseText
Construct a new instance of this node based on the details from the given node. If the node is not a light node, an exception will be thrown.- Parameters:
node
- The node to copyuseTexture
- True if the derived class wants textures generated- Throws:
IllegalArgumentException
- Incorrect Node Type
-
-
Method Details
-
hasLocalColors
public boolean hasLocalColors()Specified whether this node has color information. If so, then it will be used for diffuse terms instead of materials.- Specified by:
hasLocalColors
in interfaceVRMLGeometryNodeType
- Returns:
- true Use local color information for diffuse lighting.
-
hasLocalColorAlpha
public boolean hasLocalColorAlpha()Specified whether this node has alpha values in the local colour information. If so, then it will be used for to override the material's transparency value.- Specified by:
hasLocalColorAlpha
in interfaceVRMLGeometryNodeType
- Returns:
- true when the local color value has inbuilt alpha
-
addLocalColorsListener
Add a listener for local color changes. Nulls and duplicates will be ignored.- Specified by:
addLocalColorsListener
in interfaceVRMLGeometryNodeType
- Parameters:
l
- The listener.
-
removeLocalColorsListener
Remove a listener for local color changes. Nulls will be ignored.- Specified by:
removeLocalColorsListener
in interfaceVRMLGeometryNodeType
- Parameters:
l
- The listener.
-
addTexCoordGenModeChanged
Add a listener for texture coordinate generation mode changes. Nulls and duplicates will be ignored.- Specified by:
addTexCoordGenModeChanged
in interfaceVRMLGeometryNodeType
- Parameters:
l
- The listener.
-
removeTexCoordGenModeChanged
Remove a listener for texture coordinate generation mode changes. Nulls will be ignored.- Specified by:
removeTexCoordGenModeChanged
in interfaceVRMLGeometryNodeType
- Parameters:
l
- The listener.
-
getTexCoordGenMode
Get the texture coordinate generation mode. NULL is returned if the texture coordinates are not generated.- Specified by:
getTexCoordGenMode
in interfaceVRMLGeometryNodeType
- Parameters:
setNum
- The set which this tex gen mode refers- Returns:
- The mode or NULL
-
setTextureCount
public void setTextureCount(int count) Set the number of textures that were found on the accompanying Appearance node. Used to set the number of texture coordinates that need to be passed in to the renderer when no explicit texture coordinates were given. * @param count The number of texture coordinate sets to add- Specified by:
setTextureCount
in interfaceVRMLGeometryNodeType
- Parameters:
count
- The number of texture coordinate sets to add
-
getNumSets
public int getNumSets()Get the number of texture coordinate sets contained by this node- Specified by:
getNumSets
in interfaceVRMLGeometryNodeType
- Returns:
- the number of texture coordinate sets
-
isSolid
public boolean isSolid()Specifies whether a geometry object is a solid object. If true, then back-face culling can be performed- Specified by:
isSolid
in interfaceVRMLGeometryNodeType
- Returns:
- The current value of solid
-
isCCW
public boolean isCCW()Get the value of the CCW field. If the node does not have one, this will return true.- Specified by:
isCCW
in interfaceVRMLGeometryNodeType
- Returns:
- true if the vertices are CCW ordered
-
isLightingEnabled
public boolean isLightingEnabled()Specifies whether this node requires lighting.- Specified by:
isLightingEnabled
in interfaceVRMLGeometryNodeType
- Returns:
- Should lighting be enabled
-
setFontStyle
Convenience method to set a node child for the fontstyle.- Specified by:
setFontStyle
in interfaceVRMLTextNodeType
- Parameters:
newFont
- the new node to set- Throws:
InvalidFieldValueException
- The node passed in is not a fontstyle or fontstyle proto.
-
getFontStyle
Get the currently set fontstyle. If none is set, null is returned.- Specified by:
getFontStyle
in interfaceVRMLTextNodeType
- Returns:
- The current fontstyle information
-
setText
Convenience method to set the text information. May be overridden by the derived class, but should call this method first to ensure the field values are properly set.- Specified by:
setText
in interfaceVRMLTextNodeType
- Parameters:
str
- The string(s) to set
-
getText
Get the current text being rendered. If no text is available, returns null.- Specified by:
getText
in interfaceVRMLTextNodeType
- Returns:
- The text being rendered
-
setupFinished
public void setupFinished()Notification that the construction phase of this node has finished. If the node would like to do any internal processing, such as setting up geometry, then go for it now.- Specified by:
setupFinished
in interfaceVRMLNodeType
- Overrides:
setupFinished
in classAbstractNode
-
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 interfaceVRMLNode
- Parameters:
fieldName
- The name of the field we want the index from- Returns:
- The index of the field name or -1
-
getNodeFieldIndices
public int[] getNodeFieldIndices()Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode). Used for blind scene graph traversal without needing to spend time querying for all fields etc. If a node does not have any fields that contain nodes, this shall return null. The field list covers all field types, regardless of whether they are readable or not at the VRML-level.- Specified by:
getNodeFieldIndices
in interfaceVRMLNode
- Returns:
- The list of field indices that correspond to SF/MFnode fields or null if none
-
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 interfaceVRMLNode
- 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.- Specified by:
getNumFields
in interfaceVRMLNode
- Returns:
- The number of fields.
-
getPrimaryType
public int getPrimaryType()Get the primary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getPrimaryType
in interfaceVRMLNode
- Returns:
- The primary type
-
getFieldValue
Get the value of a field. If the field is a primitive type, it will return a class representing the value. For arrays or nodes it will return the instance directly.- Specified by:
getFieldValue
in interfaceVRMLNodeType
- Overrides:
getFieldValue
in classAbstractNode
- Parameters:
index
- The index of the field to change.- Returns:
- The class representing the field value
- Throws:
InvalidFieldException
- The field index is not known
-
sendRoute
Send a routed value from this node to the given destination node. The route should use the appropriate setValue() method of the destination node. It should not attempt to cast the node up to a higher level. Routing should also follow the standard rules for the loop breaking and other appropriate rules for the specification.- Specified by:
sendRoute
in interfaceVRMLNodeType
- Overrides:
sendRoute
in classAbstractNode
- Parameters:
time
- The time that this route occurred (not necessarily epoch time. Should be treated as a relative value only)srcIndex
- The index of the field in this node that the value should be sent fromdestNode
- The node reference that we will be sending the value todestIndex
- The index of the field in the destination node that the value should be sent to.
-
setValue
public void setValue(int index, boolean value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as an boolean. This would be used to set SFBool field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knowInvalidFieldValueException
- The value provided is out of range for the field type.
-
setValue
public void setValue(int index, float value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a float. This would be used to set SFFloat field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is not in range or not appropriate for this field
-
setValue
public void setValue(int index, float[] value, int numValid) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as an array of floats. This would be used to set SFColor and SFVec3f field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is not in range or not appropriate for this fieldInvalidFieldAccessException
- The call is attempting to write to a field that does not permit writing now
-
setValue
public void setValue(int index, String value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a string. This would be used to set SFString field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The raw value string to be parsed- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is out of range for the field type.
-
setValue
public void setValue(int index, String[] value, int numValid) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as an array of strings. This would be used to set MFString field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The strings to be renderednumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is out of range for the field type.
-
setValue
public void setValue(int index, VRMLNodeType child) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a node. This would be used to set SFNode field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setchild
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is out of range for the field type.
-
textUpdated
protected void textUpdated(boolean sizeChanged) Notification by the base class to the derived class that the texture representing the text has been changed. The derived should now change their texture representation.- Parameters:
sizeChanged
- true if the underlying texture size changed
-