FileDocCategorySizeDatePackage
SVG.javaAPI DocphoneME MR2 API (J2ME)31895Wed May 02 18:00:34 BST 2007com.sun.perseus.model

SVG

public class SVG extends StructureNode implements org.w3c.dom.svg.SVGPoint, org.w3c.dom.svg.SVGSVGElement
An SVG node represents an <code> element. In addition to a standard StructureNode, an SVG node can have a view box which causes a transform to be applied before drawing its children. This transform maps children viewBox coordinates into the SVG's parent Viewport coordinate system.
see
Viewport
version
$Id: SVG.java,v 1.12 2006/06/29 10:47:34 ln156897 Exp $

Fields Summary
protected float[]
viewBox
This SVG node's viewBox. If null, then there is no viewBox.
protected int
align
Controls the way the svg viewBox is aligned in the parent viewport. For SVG Tiny, one of ALIGN_XMIDYMID or ALIGN_NONE.
protected float
width
The SVG document's requested width
protected float
height
The SVG document's requested height
protected float
currentScale
The current scale
protected float
tx
The current translate along the x axis
protected float
ty
The current translate along the y axis
protected float
currentRotate
The current rotation angle.
protected float
currentTimeDelta
Precision adjustment, needed to keep the delta between the current time and the long values used internally.
Constructors Summary
public SVG(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode


                
        
        super(ownerDocument);
    
Methods Summary
public booleananimationsPaused()

return
the state of the animation timeline.

        throw new Error("NOT IMPLEMENTED");
    
protected com.sun.perseus.j2d.TransformappendTransform(com.sun.perseus.j2d.Transform tx, com.sun.perseus.j2d.Transform workTx)
Appends the viewBox to viewport transform, if there is a viewBox.

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 (viewBox == null) {
            return tx;
        }

        tx = recycleTransform(tx, workTx);

        Viewport vp = (Viewport) getOwnerDocument();
        float w = vp.getWidth();
        float h = vp.getHeight();
        getFittingTransform(viewBox[0][0], viewBox[0][1],
                            viewBox[1][0], viewBox[2][0],
                            0, 0, w, h, align, tx);
        
        return tx;
    
voidapplyUserTransform()
Uses currentScale, currentRotate, tx and ty to compute the owner document's transform.

        if (ownerDocument.zoomAndPan == Viewport.ZOOM_PAN_MAGNIFY) {
            Transform txf = new Transform(currentScale, 0,
                                          0, currentScale,
                                          tx, ty);
            txf.mRotate(currentRotate);

            ownerDocument.setTransform(txf);

        } else {
            if (ownerDocument.getTransform() != null) {
                // ownerDocument's transform has been touched
                // so, set it to identity
                ownerDocument.setTransform(new Transform(null));
            }
        }
    
public org.w3c.dom.svg.SVGMatrixcreateSVGMatrixComponents(float a, float b, float c, float d, float e, float f)
This object can be used to modify value of traits which are compatible with {@link org.w3c.dom.svg.SVGMatrix SVGMatrix} type using {@link org.w3c.dom.svg.SVGElement#setMatrixTrait setMatrixTrait} method. The internal representation of the matrix is as follows:

[ a c e ]
[ b d f ]
[ 0 0 1 ]

see
org.w3c.dom.svg.SVGMatrix
param
a the 0,0 matrix parameter
param
b the 1,0 matrix parameter
param
c the 0,1 matrix parameter
param
d the 1,1 matrix parameter
param
e the 0,2 matrix parameter
param
f the 1,2 matrix parameter
return
a new SVGMatrix object with the requested components.

        return new Transform(a, b, c, d, e, f);
    
public org.w3c.dom.svg.SVGPathcreateSVGPath()

return
new {@link org.w3c.dom.svg.SVGPath SVGPath} object. This object can be used to modify value of traits which are compatible with {@link org.w3c.dom.svg.SVGPath SVGPath} type using {@link org.w3c.dom.svg.SVGElement#setPathTrait setPathTrait} method.

        return new Path();
    
public org.w3c.dom.svg.SVGRGBColorcreateSVGRGBColor(int red, int green, int blue)

return
new {@link org.w3c.dom.svg.SVGRGBColor SVGRGBColor} object. This object can be used to modify value of traits which are compatible with {@link org.w3c.dom.svg.SVGRGBColor SVGRGBColor} type using {@link org.w3c.dom.svg.SVGElement#setRGBColorTrait setRGBColorTrait} method.
throws
SVGException with error code SVG_INVALID_VALUE_ERR: if any of the parameters is not in the 0..255 range.
param
red the red rgb component.
param
green the green rgb component.
param
blue the blue rgb component.

        if (red < 0 
            || red > 255 
            || green < 0 
            || green > 255 
            || blue < 0 
            || blue > 255) {
            throw new SVGException(SVGException.SVG_INVALID_VALUE_ERR, null);
        }

        return new RGB(red, green, blue);
    
public org.w3c.dom.svg.SVGRectcreateSVGRect()

return
a new {@link org.w3c.dom.svg.SVGRect SVGRect} object. This object can be used to modify value of traits which are compatible with {@link org.w3c.dom.svg.SVGRect SVGRect} type using {@link org.w3c.dom.svg.SVGElement#setRectTrait setRectTrait} method. The intial values for x, y, width, height of this new SVGRect are zero.

        return new Box(0, 0, 0, 0);
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)

param
traitName the trait name.

        if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE == traitName) {
            return new FloatTraitAnim(this, traitName, TRAIT_TYPE_SVG_RECT);
        } else {
            return super.createTraitAnimImpl(traitName);
        }
    
public intgetAlign()

return
this node's align property

        return align;
    
public floatgetCurrentRotate()

        return currentRotate;
    
public floatgetCurrentScale()

        return currentScale;
    
public floatgetCurrentTime()

        return ownerDocument.timeContainerRootSupport
            .lastSampleTime.value / 1000f + currentTimeDelta;
    
public org.w3c.dom.svg.SVGPointgetCurrentTranslate()
The initial values for currentTranslate is SVGPoint(0,0).

        return this;
    
public java.lang.String[][]getDefaultTraits()
The default value for the width trait and the height trait is '100%'.

return
an array of trait default values, used if this element requires that the default trait value be explicitly set through a setTrait call. This happens, for example, with the begin trait value on animation elements.

        return new String[][] { {SVGConstants.SVG_WIDTH_ATTRIBUTE, "100%"},
                                {SVGConstants.SVG_HEIGHT_ATTRIBUTE, "100%"}};
    
floatgetFloatTraitImpl(java.lang.String name)
SVG handles width and height float 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_WIDTH_ATTRIBUTE == name) {
            return getWidth();
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            return getHeight();
        } else {
            return super.getFloatTraitImpl(name);
        }
    
public floatgetHeight()

return
the viewport height

        return this.height;
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_SVG_TAG value

        return SVGConstants.SVG_SVG_TAG;
    
org.w3c.dom.svg.SVGRectgetRectTraitImpl(java.lang.String name)
SVG handles the viewBox Rect trait.

param
name the requested trait name (e.g., "viewBox")
return
the requested trait SVGRect 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 {@link org.w3c.dom.svg.SVGRect SVGRect}
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE.equals(name)) {
            return toSVGRect(viewBox);
        } else {
            return super.getRectTraitImpl(name);
        }
    
public java.lang.StringgetTraitImpl(java.lang.String name)
SVG handles the version, baseProfile, viewBox and zoomAndPan traits.

param
name the requested trait's name (e.g., "zoomAndPan")
return
the requested trait string value (e.g., "disable")
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_VERSION_ATTRIBUTE == name) {
            return SVGConstants.SVG_VERSION_1_1_VALUE;
        } else if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE == name) {
            if (viewBox == null) {
                return "";
            } else {
                return "" + viewBox[0][0] + SVGConstants.COMMA 
                    + viewBox[0][1] + SVGConstants.COMMA 
                    + viewBox[1][0] + SVGConstants.COMMA 
                    + viewBox[2][0];
            }
        } else if (SVGConstants.SVG_ZOOM_AND_PAN_ATTRIBUTE == name) {
            switch (ownerDocument.zoomAndPan) {
            case Viewport.ZOOM_PAN_MAGNIFY:
                return SVGConstants.SVG_MAGNIFY_VALUE;
            case Viewport.ZOOM_PAN_DISABLE:
                return SVGConstants.SVG_DISABLE_VALUE;
            default:
                throw new Error();
            }
        } else if (SVGConstants.SVG_BASE_PROFILE_ATTRIBUTE == name) {
            return SVGConstants.SVG_BASE_PROFILE_TINY_VALUE;
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
            return Float.toString(getWidth());
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            return Float.toString(getHeight());
        } else if (SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE == name) {
            return alignToStringTrait(align);
        } else {
            return super.getTraitImpl(name);
        }
    
public float[][]getViewBox()

return
this SVG's viewBox

        return viewBox;
    
public org.w3c.dom.svg.SVGRectgetViewport()
The object itself and its contents are both readonly. {@link org.w3c.dom.DOMException DOMException} with error code NO_MODIFICATION_ALLOWED_ERR is raised if attempt is made to modify it. The returned SVGRect object is "live", i.e. its x, y, width, height is automatically updated if viewport size or position changes.

        throw new Error("NOT IMPLEMENTED");
    
public floatgetWidth()

return
the viewport's width

        return this.width;
    
public floatgetX()
Returns the x component of the point.

return
the x component of the point.

        return tx;
    
public floatgetY()
Returns the y component of the point.

return
the y component of the point.

        return ty;
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype SVG.

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

        return new SVG(doc);
    
public voidpauseAnimations()
Pauses animation timeline. If user agent has pause/play control that control is changed to paused state. Has no effect if timeline already paused.

        throw new Error("NOT IMPLEMENTED");
    
public voidsetAlign(int newAlign)

param
newAlign new alignment property

        if (newAlign != ALIGN_XMIDYMID
            &&
            newAlign != ALIGN_NONE) {
            throw new IllegalArgumentException();
        }

        if (newAlign == align) {
            return;
        }

        modifyingNode();
        this.align = newAlign;
        recomputeTransformState();
        modifiedNode();
    
public voidsetCurrentRotate(float value)

        currentRotate = value;
        applyUserTransform();
    
public voidsetCurrentScale(float value)

        if (value == 0) {
            throw new DOMException
                (DOMException.INVALID_ACCESS_ERR, 
                 Messages.formatMessage
                 (Messages.ERROR_INVALID_PARAMETER_VALUE,
                  new String[] {"SVGSVGElement",
                                "setCurrentScale",
                                "value",
                                Float.toString(value)}));
        } else {
            currentScale = value;
            applyUserTransform();
        }
    
public voidsetCurrentTime(float seconds)

        currentTimeDelta = seconds - ((long) (seconds * 1000)) / 1000f;
        ownerDocument.timeContainerRootSupport.seekTo
            (new Time((long) (seconds * 1000)));
        ownerDocument.applyAnimations();
    
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_WIDTH_ATTRIBUTE == name) {
            checkPositive(name, value[0][0]);
            setWidth(value[0][0]);
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            checkPositive(name, value[0][0]);
            setHeight(value[0][0]);
        } else if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE == name) {
            setViewBox(value);
        } else {
            super.setFloatArrayTrait(name, value);
        }
    
public voidsetFloatTraitImpl(java.lang.String name, float value)
SVG handles width and height 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.

        try {
            if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
                setWidth(value);
            } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
                setHeight(value);
            } else {
                super.setFloatTraitImpl(name, value);
            }
        } catch (IllegalArgumentException iae) {
            throw illegalTraitValue(name, Float.toString(value));
        }
    
public voidsetHeight(float newHeight)
Sets the viewport height.

param
newHeight Should be greater than 0

        if (newHeight < 0) {
            throw new IllegalArgumentException();
        }

        if (newHeight == height) {
            return;
        }

        modifyingNode();
        this.height = newHeight;
        computeCanRenderHeightBit(height);
        modifiedNode();
    
public voidsetRectTraitImpl(java.lang.String name, org.w3c.dom.svg.SVGRect rect)
SVG handles the viewBox Rect trait.

param
name the trait name (e.g., "viewBox"
param
rect the trait 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 an {@link org.w3c.dom.svg.SVGRect SVGRect}
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait or null. SVGRect is invalid if the width or height values are set to negative.
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        // Note that here, we use equals because the string 
        // has not been interned.
        if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE.equals(name)) {
            if (rect == null) {
                throw illegalTraitValue(name, null);
            }
            
            if (rect.getWidth() < 0 || rect.getHeight() < 0) {
                throw illegalTraitValue(name, toStringTrait(new float[]
                    {rect.getX(), 
                     rect.getY(), 
                     rect.getWidth(), 
                     rect.getHeight()}));
            }
                
            setViewBox(new float[][]
                {new float[] {rect.getX(), rect.getY()}, 
                 new float[] {rect.getWidth()}, 
                 new float[] {rect.getHeight()}
                });
            
        } else {
            super.setRectTraitImpl(name, rect);
        }
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
SVG handles the version, baseProfile, viewBox and zoomAndPan traits.

param
name the trait's name (e.g., "viewBox")
param
value the new trait's string value (e.g., "0 0 400 300")
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 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_VERSION_ATTRIBUTE == name) {
            checkWriteLoading(name);
            if (!SVGConstants.SVG_VERSION_1_1_VALUE.equals(value)
                &&
                !SVGConstants.SVG_VERSION_1_2_VALUE.equals(value)) {
                throw illegalTraitValue(name, value);
            }
        } else if (SVGConstants.SVG_BASE_PROFILE_ATTRIBUTE == name) {
            checkWriteLoading(name);
            if (!SVGConstants.SVG_BASE_PROFILE_TINY_VALUE.equals(value)) {
                throw illegalTraitValue(name, value);
            }
        } else if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE == name) {
            setViewBox(toViewBox(name, value));
        } else if (SVGConstants.SVG_ZOOM_AND_PAN_ATTRIBUTE == name) {
            if (SVGConstants.SVG_MAGNIFY_VALUE.equals(value)) {
                ownerDocument.setZoomAndPan(Viewport.ZOOM_PAN_MAGNIFY);
                applyUserTransform();
            } else if (SVGConstants.SVG_DISABLE_VALUE.equals(value)) {
                ownerDocument.setZoomAndPan(Viewport.ZOOM_PAN_DISABLE);
                applyUserTransform();
            } else {
                throw illegalTraitValue(name, value);
            }
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setWidth(parsePositiveLengthTrait(name, value, true));
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            checkWriteLoading(name);
            setHeight(parsePositiveLengthTrait(name, value, false));
        } else if (SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE == name) {
            checkWriteLoading(name);
            if (SVGConstants
                .SVG_SVG_PRESERVE_ASPECT_RATIO_DEFAULT_VALUE.equals(value)) {
                setAlign(ALIGN_XMIDYMID);
            } else if (SVGConstants.SVG_NONE_VALUE.equals(value)) {
                setAlign(ALIGN_NONE);
            } else {
                throw illegalTraitValue(name, value);
            }
        } else {
            super.setTraitImpl(name, value);
        }
    
public voidsetViewBox(float[][] newViewBox)
Sets a new value for the viewBox.

param
newViewBox the new viewBox for this SVG
throws
IllegalArgumentException if the input viewBox is not null and not of a float {float[2], float[1], float[1]} array.


        if (newViewBox != null) {
            if (newViewBox.length != 3 
                ||
                newViewBox[0] == null
                ||
                newViewBox[1] == null
                ||
                newViewBox[2] == null
                ||
                newViewBox[0].length != 2
                ||
                newViewBox[1][0] < 0 
                || 
                newViewBox[2][0] < 0) {
                throw new IllegalArgumentException();
            }
        }

        if (equal(newViewBox, viewBox)) {
            return;
        }

        modifyingNode();

        if (newViewBox == null) {
            viewBox = null;
        } else {
            if (viewBox == null) {
                viewBox = new float[3][];
                viewBox[0] = new float[2];
                viewBox[1] = new float[1];
                viewBox[2] = new float[1];
            }
            
            viewBox[0][0] = newViewBox[0][0];    
            viewBox[0][1] = newViewBox[0][1];    
            viewBox[1][0] = newViewBox[1][0];    
            viewBox[2][0] = newViewBox[2][0];    
        }

        recomputeTransformState();
        computeCanRenderEmptyViewBoxBit(viewBox);
        modifiedNode();
    
public voidsetWidth(float newWidth)
Sets the viewport width.

param
newWidth Should be greater than 0

        if (newWidth < 0) {
            throw new IllegalArgumentException();
        }

        if (newWidth == width) {
            return;
        }

        modifyingNode();
        this.width = newWidth;
        computeCanRenderWidthBit(width);

        modifiedNode();
    
public voidsetX(float value)
Sets the x component of the point to the specified float value.

param
value the x component value

        tx = value;
        applyUserTransform();
    
public voidsetY(float value)
Sets the y component of the point to the specified float value.

param
value the y component value

        ty = value;
        applyUserTransform();
    
booleansupportsTrait(java.lang.String traitName)
SVG handles the version, baseProfile, viewBox, zoomAndPan, width, height and preserveAspectRatio traits.

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_BASE_PROFILE_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_VERSION_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_VIEW_BOX_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_ZOOM_AND_PAN_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_WIDTH_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_HEIGHT_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE == traitName) {
            return true;
        } else {
            return super.supportsTrait(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_WIDTH_ATTRIBUTE == name
            ||
            SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            return Float.toString(value[0][0]);
        } else if (SVGConstants.SVG_VIEW_BOX_ATTRIBUTE == name) {
            float[] vb = {value[0][0], value[0][1], value[1][0], value[2][0]};
            return toStringTrait(vb);
        } else {
            return super.toStringTrait(name, value);
        }
    
public voidunpauseAnimations()
Resumes animation timeline. If user agent has pause/play control that control is changed to playing state. Has no effect if timeline is already playing.

        throw new Error("NOT IMPLEMENTED");
    
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_VIEW_BOX_ATTRIBUTE == traitName) {
            return ownerDocument.viewBoxParser.parseViewBox(value);
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == traitName
                   ||
                   SVGConstants.SVG_HEIGHT_ATTRIBUTE == traitName) {
            return new float[][] {
                        {parsePositiveLengthTrait(traitName, value, false)}
                    };
        } else {
            return super.validateFloatArrayTrait(traitName,
                                                 value,
                                                 reqNamespaceURI,
                                                 reqLocalName,
                                                 reqTraitNamespace,
                                                 reqTraitName);
        }