FileDocCategorySizeDatePackage
Use.javaAPI DocphoneME MR2 API (J2ME)32383Wed May 02 18:00:36 BST 2007com.sun.perseus.model

Use

public class Use extends Group implements IDRef
Represents an SVG Tiny <use> element.
version
$Id: Use.java,v 1.13 2006/06/29 10:47:36 ln156897 Exp $

Fields Summary
static final String[]
REQUIRED_TRAITS_NS
xlink:href is required on
protected float
x
The x and y coordinates of the use element
protected float
y
protected ElementNodeProxy
proxy
Expanded content tree: the root ElementNodeProxy
protected String
idRef
The identifier of the referenced node
protected ElementNode
ref
The referenced element.
Constructors Summary
public Use(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode


                
        
        super(ownerDocument);
    
Methods Summary
com.sun.perseus.j2d.BoxaddBBox(com.sun.perseus.j2d.Box bbox, com.sun.perseus.j2d.Transform t)

        return proxy.addBBox(bbox, proxy.appendTransform(t, null));
    
protected com.sun.perseus.j2d.TransformappendTransform(com.sun.perseus.j2d.Transform tx, com.sun.perseus.j2d.Transform workTx)
Apply this node's x/y translation if it is not (0,0).

param
tx the Transform to apply additional node transforms to. This may be null.
param
workTx a Transform which can be re-used if a new Transform needs to be created and workTx is not the same instance as tx.
return
a transform with this node's transform added.

        if (transform == null 
            && 
            motion == null
            &&
            x == 0
            &&
            y == 0) {
            return tx;
        } 

        tx = recycleTransform(tx, workTx);
        
        if (motion != null) {
            tx.mMultiply(motion);
        }

        if (transform != null) {
            tx.mMultiply(transform);
        }

        tx.mTranslate(x, y);
        
        return tx;
    
ElementNodeProxybuildProxy()

return
an adequate ElementNodeProxy for this node.

        return new UseProxy(this);
    
protected voidclearLayouts()
Clears the text layouts, if any exist. This is typically called when the font selection has changed and nodes such as Text should recompute their layouts. This should recursively call clearLayouts on children node or expanded content, if any.

        clearLayouts(proxy);
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)

param
traitName the trait name.

        if (SVGConstants.SVG_X_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == traitName) {
            return new FloatTraitAnim(this, traitName, TRAIT_TYPE_FLOAT);
        } else {
            return super.createTraitAnimImpl(traitName);
        }
    
TraitAnimcreateTraitAnimNSImpl(java.lang.String traitNamespace, java.lang.String traitName)

param
traitName the trait name.
param
traitNamespace the trait's namespace. Should not be null.

        if (traitNamespace == SVGConstants.XLINK_NAMESPACE_URI
            &&
            traitName == SVGConstants.SVG_HREF_ATTRIBUTE) {
            return new StringTraitAnim(this, traitNamespace, traitName);
        }

        return super.createTraitAnimNSImpl(traitNamespace, traitName);
    
public org.w3c.dom.svg.SVGRectgetBBox()

        Transform t = null;
        
        if (x != 0 || y != 0) {
            t = new Transform(1, 0, 0, 1, x, y);
        }
        
        return addBBox(null, t);
    
public ModelNodegetFirstComputedExpandedChild()
Some node types (such as ElementNodeProxy) have expanded children that they compute in some specific way depending on the implementation.

return
a reference to the node's first expanded child, or null if there are no expanded children.

        return proxy;
    
protected ModelNodegetFirstExpandedChild()
Some node types (such as ElementNodeProxy) have expanded children that they compute in some specific way depending on the implementation.

return
a reference to the node's first expanded child, or null if there are no expanded children. This forces the computation of expanded content if needed.

        return proxy;
    
floatgetFloatTraitImpl(java.lang.String name)
Use handles x and y traits. Other attributes are handled by the super class.

param
name the requested trait name.
param
the requested trait's floating point value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if requested trait's computed value cannot be converted to a float
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.SVG_X_ATTRIBUTE == name) {
            return getX();
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            return getY();
        } else {
            return super.getFloatTraitImpl(name);
        }
    
public java.lang.StringgetIdRef()

return
the Use element's idRef.

        return idRef;
    
protected ModelNodegetLastExpandedChild()
Some node types (such as ElementNodeProxy) have expanded children that they compute in some specific way depending on the implementation.

return
a reference to the node's last expanded child, or null if there are no expanded children. This forces the computation of expanded content if needed.

        return proxy;
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_USE_TAG value

        return SVGConstants.SVG_USE_TAG;
    
public java.lang.String[][]getRequiredTraitsNS()

return
an array of namespaceURI, localName trait pairs required by this element.

        return REQUIRED_TRAITS_NS;
    
public org.w3c.dom.svg.SVGMatrixgetScreenCTM()

        SVGMatrix m = super.getScreenCTM();
        if (m != null) {
            m = m.mTranslate(-x, -y);
        } 

        return m;
    
public java.lang.StringgetTraitImpl(java.lang.String name)
Use handles x and y traits. Other traits are handled by the super class.

param
name the requested trait's name.
return
the requested trait's value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if requested trait's computed value cannot be converted to a String (SVG Tiny only).

        if (SVGConstants.SVG_X_ATTRIBUTE == name) {
            return Float.toString(getX());
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            return Float.toString(getY());
        } else {
            return super.getTraitImpl(name);
        }
    
java.lang.StringgetTraitNSImpl(java.lang.String namespaceURI, java.lang.String name)
Use handles the xlink href attribute

param
namespaceURI the requested trait's namespace URI.
param
name the requested trait's local name (i.e., un-prefixed, as "href")
return
the requested trait's string value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if requested trait's computed value cannot be converted to a String (SVG Tiny only).
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.XLINK_NAMESPACE_URI == namespaceURI
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE == name) {
            if (idRef == null) {
                return "";
            } 
            return "#" + idRef;
        } else {
            return super.getTraitNSImpl(namespaceURI, name);
        }
    
public floatgetX()

return
x-axis use origin

        return x;
    
public floatgetY()

return
y-axis use origin

        return y;
    
public booleanhasDescendants()

return
true if proxy is set

        return super.hasDescendants() 
            || 
            proxy != null;
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype Use.

param
doc the DocumentNode for which a new node is should be created.
return
a new Use for the requested document.

        return new Use(doc);
    
public ModelNodenodeHitAt(float[] pt)
Returns the ModelNode, if any, hit by the point at coordinate x/y.

param
pt the x/y coordinate. Should never be null and be of size two. If not, the behavior is unspecified. The coordinates are in viewport space.
return
the ModelNode hit at the given point or null if none was hit.

        // If a node does not render, it is never hit
        if (canRenderState != 0) {
            return null;
        }
        
        // Check for a hit on expanded content
        return nodeHitAt(getLastExpandedChild(), pt);
    
voidnodeHookedInDocumentTree()
When a Use element is hooked into the document tree, it may expand immediately if its reference has already been set.

        super.nodeHookedInDocumentTree();

        if (ref != null) {
            setProxy(ref.buildProxy());
        }
    
final voidnodeUnhookedFromDocumentTree()
When a Use in unhooked from the document tree, it needs to set its proxy to null and cleanly remove references to itself.

        super.nodeUnhookedFromDocumentTree();

        if (proxy != null) {
            unhookExpandedQuiet();
            proxy = null;
        }
    
public voidpaint(com.sun.perseus.j2d.RenderGraphics rg)
Paints this node into the input RenderGraphics.

param
rg the RenderGraphics where the node should paint itself

        if (canRenderState != 0) {
            return;
        }

        paint(getFirstExpandedChild(), rg);
    
protected voidpreValidate()
This method is called before an element is hooked into the tree to validate it is in a state where it can be added. For a Use element, the reference must have been set and resolved or must still be null (i.e., not set).

        if (loaded && proxy == null) { 
            if (ref == null && (idRef != null) && !"".equals(idRef)) {
                throw new DOMException(DOMException.INVALID_STATE_ERR,
                                       Messages.formatMessage
                                       (Messages.ERROR_MISSING_REFERENCE, 
                                        new String[] {
                                            getNamespaceURI(),
                                            getLocalName(),
                                            getId()}));
            }
        }
    
protected voidpropagateFloatPropertyState(int propertyIndex, float parentPropertyValue)
Called when the computed value of the given float property has changed. On a use element, this propagates only to expanded content.

param
propertyIndex index for the property whose value has changed.
param
parentPropertyValue the value that children of this node should now inherit.

  
        // Propagate to proxies.
        if (firstProxy != null) {
            ElementNodeProxy proxy = firstProxy;
            while (proxy != null) {
                ((CompositeGraphicsNodeProxy) proxy)
                        .proxiedFloatPropertyStateChange(propertyIndex, 
                                                         parentPropertyValue);
                proxy = proxy.nextProxy;
            }
        }

        // Propagate to expanded children.
        ModelNode node = getFirstExpandedChild();
        while (node != null) {
            node.recomputeFloatPropertyState(propertyIndex, 
                                             parentPropertyValue);
            node = node.nextSibling;
        }
    
protected voidpropagatePackedPropertyState(int propertyIndex, int parentPropertyValue)
Called when the computed value of the given packed property has changed. On a use element, this propagates only to expanded content.

param
propertyIndex index for the property whose value has changed.
param
parentPropertyValue the value that children of this node should now inherit.

        // Propagate to proxies.
        if (firstProxy != null) {
            ElementNodeProxy proxy = firstProxy;
            while (proxy != null) {
                ((CompositeGraphicsNodeProxy) proxy)
                        .proxiedPackedPropertyStateChange(propertyIndex, 
                                                          parentPropertyValue);
                proxy = proxy.nextProxy;
            }
        }

        // Propagate to expanded children.
        ModelNode node = getFirstExpandedChild();
        while (node != null) {
            node.recomputePackedPropertyState(propertyIndex, 
                                              parentPropertyValue);
            node = node.nextSibling;
        }
    
protected voidpropagatePropertyState(int propertyIndex, java.lang.Object parentPropertyValue)
Called when the computed value of the given property has changed. On a use element, this propagates only to expanded content.

param
propertyIndex index for the property whose value has changed.
param
parentPropertyValue the value that children of this node should now inherit.

        
        // Propagate to proxies.
        if (firstProxy != null) {
            ElementNodeProxy proxy = firstProxy;
            while (proxy != null) {
                ((CompositeGraphicsNodeProxy) proxy)
                        .proxiedPropertyStateChange(propertyIndex, 
                                                    parentPropertyValue);
                proxy = proxy.nextProxy;
            }
        }

        // Propagate to expanded children.
        ModelNode node = getFirstExpandedChild();
        while (node != null) {
            node.recomputePropertyState(propertyIndex, parentPropertyValue);
            node = node.nextSibling;
        }
    
ModelNodeproxyNodeHitAt(float[] pt, ElementNodeProxy proxy)
Returns the ModelNode, if any, hit by the point at coordinate x/y in the proxy tree starting at proxy.

param
pt the x/y coordinate. Should never be null and be of size two. If not, the behavior is unspecified. The coordinates are in viewport space.
param
proxy the root of the proxy tree to test.
return
the ModelNode hit at the given point or null if none was hit.

        // If a node does not render, it is never hit
        if (canRenderState != 0) {
            return null;
        }
        
        // Check for a hit on expanded content
        return nodeHitAt(proxy.getLastExpandedChild(), pt);
    
protected voidrecomputeTransformState(com.sun.perseus.j2d.Transform parentTransform)
Recomputes the transform cache, if one exists. This should recursively call recomputeTransformState on children node or expanded content, if any. By default, because a ModelNode has no transform and no cached transform, this only does a pass down.

param
parentTransform the Transform applied to this node's parent.

        txf = appendTransform(parentTransform, txf);
        inverseTxf = null;
        computeCanRenderTransformBit(txf);
        // inverseTxf = computeInverseTransform(txf, parentTransform, 
        //                                      inverseTxf);
        recomputeTransformState(txf, getFirstExpandedChild());
    
public voidresolveTo(ElementNode ref)
IDRef implementation.

param
ref the resolved reference (mapped from the id passed to the setIdRef method).

        // Only set the proxy if the use is in the document tree.
        if (isInDocumentTree()) {
            setProxy(ref.buildProxy());
        } else {
            this.ref = ref;
        }
    
voidsetFloatArrayTrait(java.lang.String name, float[][] value)
Set the trait value as float.

param
name the trait's name.
param
value the trait's value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a float
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait.

        if (SVGConstants.SVG_X_ATTRIBUTE == name) {
            setX(value[0][0]);
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            setY(value[0][0]);
        } else {
            super.setFloatArrayTrait(name, value);
        }
    
public voidsetFloatTraitImpl(java.lang.String name, float value)
Use handles x and y traits. Other traits are handled by the super class.

param
name the trait's name.
param
value the new trait's floating point value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a float
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait.
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.SVG_X_ATTRIBUTE == name) {
            setX(value);
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            setY(value);
        } else {
            super.setFloatTraitImpl(name, value);
        }
    
public voidsetIdRef(java.lang.String idRef)
Sets this Use element's idRef

param
idRef the identifier of the referenced node. Should not be null

        if (idRef == this.idRef
            ||
            (idRef != null && idRef.equals(this.idRef))) {
            // No change
            return;
        }

        this.idRef = idRef;
        ownerDocument.resolveIDRef(this, idRef);

        // If the node is hooked into the document tree and the idRef has not
        // been resolved as a result of ownerDocument.resolveIDRef, then
        // we go into error.
        if (isInDocumentTree()) {
            if (proxy == null && (idRef != null) && !"".equals(idRef)) {
                throw new DOMException(DOMException.INVALID_ACCESS_ERR,
                                       Messages.formatMessage
                                       (Messages.ERROR_MISSING_REFERENCE, 
                                        new String[] {
                                            getNamespaceURI(),
                                            getLocalName(),
                                            getId()}));
            }
        }
    
voidsetProxy(ElementNodeProxy proxy)
Sets the ElementNodeProxy as this use's expanded content.

param
proxy the proxy that references the <use>'s expanded content.
throws
NullPointerException if the input proxy node is null

        if (proxy == null) {
            throw new IllegalArgumentException();
        }

        // If this node already had a proxy, make sure we remove that
        // proxy from the node's expanded content.
        if (this.proxy != null) {
            modifyingNode();
            unhookExpandedQuiet();
            modifiedNode();
        } 

        this.proxy = proxy;
        this.proxy.setParentQuiet(this);
        nodeInserted(this.proxy);
        this.proxy.nextSibling = null;

        // Now, notify potential proxies that the proxy has been set.
        ElementNodeProxy useProxy = firstProxy;
        while (useProxy != null) {
            ((UseProxy) useProxy).useProxySet();
            useProxy = useProxy.nextProxy;
        }
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
Use handles x and y traits. Other traits are handled by the super class.

param
name the trait's name.
param
value the new trait string value.
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a String
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait or null.
throws
DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if attempt is made to change readonly trait.

        if (SVGConstants.SVG_X_ATTRIBUTE == name) {
            setX(parseFloatTrait(name, value));
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            setY(parseFloatTrait(name, value));
        } else {
            super.setTraitImpl(name, value);
        }
    
public voidsetTraitNSImpl(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)
Use supports the xlink:href trait.

param
namespaceURI the trait's namespace.
param
name the trait's local name (un-prefixed, e.g., "href");
param
value the new trait value (e.g., "http://www.sun.com/mypng.png")
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a String
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait or null.
throws
DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if attempt is made to change readonly trait.
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.XLINK_NAMESPACE_URI == namespaceURI
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE == name) {
            if (value == null || !value.startsWith("#")) {
                throw illegalTraitValue(name, value);
            }
            setIdRef(value.substring(1));
        } else {
            super.setTraitNSImpl(namespaceURI, name, value);
        }
    
public voidsetX(float newX)

param
newX new x-axis origin

        if (newX == x) {
            return;
        }

        modifyingNode();
        this.x = newX;
        recomputeTransformState();
        recomputeProxyTransformState();        
        modifiedNode();
    
public voidsetY(float newY)

param
newY new y-axis origin

        if (newY == y) {
            return;
        }

        modifyingNode();
        this.y = newY;
        recomputeTransformState();
        recomputeProxyTransformState();
        modifiedNode();
    
booleansupportsTrait(java.lang.String traitName)
Supported traits: x, y

param
traitName the name of the trait which the element may support.
return
true if this element supports the given trait in one of the trait accessor methods.

        if (SVGConstants.SVG_X_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == traitName) {
            return true;
        } else {
            return super.supportsTrait(traitName);
        }
    
booleansupportsTraitNS(java.lang.String namespaceURI, java.lang.String traitName)
Supported traits: xlink:href

param
namespaceURI the trait's namespace.
param
traitName the name of the trait which the element may support.
return
true if this element supports the given trait in one of the trait accessor methods.

        if (SVGConstants.XLINK_NAMESPACE_URI == namespaceURI
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE == traitName) {
            return true;
        } else {
            return super.supportsTraitNS(namespaceURI, traitName);
        }
    
java.lang.StringtoStringTrait(java.lang.String name, float[][] value)

param
name the name of the trait to convert.
param
value the float trait value to convert.

        if (SVGConstants.SVG_X_ATTRIBUTE == name
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == name) {
            return Float.toString(value[0][0]);
        } else {
            return super.toStringTrait(name, value);
        }
    
protected voidunhookExpandedQuiet()
Utility method. Unhooks the expanded content.

        unhookQuiet(proxy);
        proxy = null;

        ElementNodeProxy p = firstProxy;
        while (p != null) {
            p.unhookExpandedQuiet();
            p = p.nextProxy;
        }
        
    
public float[][]validateFloatArrayTrait(java.lang.String traitName, java.lang.String value, java.lang.String reqNamespaceURI, java.lang.String reqLocalName, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)
Validates the input trait value.

param
traitName the name of the trait to be validated.
param
value the value to be validated
param
reqNamespaceURI the namespace of the element requesting validation.
param
reqLocalName the local name of the element requesting validation.
param
reqTraitNamespace the namespace of the trait which has the values value on the requesting element.
param
reqTraitName the name of the trait which has the values value on the requesting element.
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is incompatible with the given trait.

        if (SVGConstants.SVG_X_ATTRIBUTE == traitName) {
            return toAnimatedFloatArray(parseFloatTrait(traitName, value));
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == traitName) {
            return toAnimatedFloatArray(parseFloatTrait(traitName, value));
        } else {
            return super.validateFloatArrayTrait(traitName,
                                                 value,
                                                 reqNamespaceURI,
                                                 reqLocalName,
                                                 reqTraitNamespace,
                                                 reqTraitName);
        }
    
java.lang.StringvalidateTraitNS(java.lang.String namespaceURI, java.lang.String traitName, java.lang.String value, java.lang.String reqNamespaceURI, java.lang.String reqLocalName, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)
Validates the input trait value.

param
namespaceURI the trait's namespace URI.
param
traitName the name of the trait to be validated.
param
value the value to be validated
param
reqNamespaceURI the namespace of the element requesting validation.
param
reqLocalName the local name of the element requesting validation.
param
reqTraitNamespace the namespace of the trait which has the values value on the requesting element.
param
reqTraitName the name of the trait which has the values value on the requesting element.
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is incompatible with the given trait.

        if (SVGConstants.XLINK_NAMESPACE_URI == namespaceURI
            &&
            SVGConstants.SVG_HREF_ATTRIBUTE == traitName) {
            if (value == null || !value.startsWith("#")) {
                throw illegalTraitValue(traitName, value);
            }
            return value;
        } else {
            return super.validateTraitNS(namespaceURI,
                                         traitName,
                                         value,
                                         reqNamespaceURI,
                                         reqLocalName,
                                         reqTraitNamespace,
                                         reqTraitName);
        }