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

LinearGradient

public class LinearGradient extends GradientElement
LienarGraident represents an SVG Tiny 1.2 <linearGradient> element.
version
$Id: LinearGradient.java,v 1.6 2006/06/29 10:47:32 ln156897 Exp $

Fields Summary
float
x1
Gradient start on the x-axis
float
y1
Gradient start on the y-axis
float
x2
Gradient end on the x-axis
float
y2
Gradient end on the y-axis
Constructors Summary
public LinearGradient(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode


                
        
        super(ownerDocument);

        isObjectBBox = true;
    
Methods Summary
protected com.sun.perseus.j2d.PaintDefcomputePaint()
Computes the paint in user space on use.

return
the computed PaintDef.

        if (computedPaint == null) {
            buildGradientColorMap();
            computedPaint =
                new LinearGradientPaintDef(x1, 
                                           y1,
                                           x2, 
                                           y2,
                                           lastColorMapFractions,
                                           lastColorMapRGBA,
                                           LinearGradientPaintDef.CYCLE_NONE,
                                           isObjectBBox,
                                           transform);
        }      
        return computedPaint;
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)
LinearGradient handles x1, y1, x2, y2 traits as FloatTraitAnims.

param
traitName the trait name.

        if (SVGConstants.SVG_X1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_X2_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y2_ATTRIBUTE == traitName) {
            return new FloatTraitAnim(this, traitName, TRAIT_TYPE_FLOAT);
        } else {
            return super.createTraitAnimImpl(traitName);
        }
    
floatgetFloatTraitImpl(java.lang.String name)

param
name the requested trait name (e.g., "y")
return
the requested 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 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_X1_ATTRIBUTE == name) {
            return x1;
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            return y1;
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            return x2;
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            return y2;
        } else {
            return super.getFloatTraitImpl(name);
        }
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_LINEAR_GRADIENT_TAG value

        return SVGConstants.SVG_LINEAR_GRADIENT_TAG;
    
public java.lang.StringgetTraitImpl(java.lang.String name)

param
name the requested trait name (e.g., "ry")
return
the trait's value, as a string.
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_X1_ATTRIBUTE == name) {
            return Float.toString(x1);
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            return Float.toString(y1);
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            return Float.toString(x2);
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            return Float.toString(y2);
        } else {
            return super.getTraitImpl(name);
        }
    
public floatgetX1()

return
the origin of the gradient starting point on the x-axis.

        return x1;
    
public floatgetX2()

return
the end of the gradient starting point on the x-axis.

        return x2;
    
public floatgetY1()

return
the origin of the gradient starting point on the y-axis.

        return y1;
    
public floatgetY2()

return
the end of the gradient starting point on the y-axis.

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

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

        return new LinearGradient(doc);
    
voidsetFloatArrayTrait(java.lang.String name, float[][] value)
Set the trait value as float array.

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_X1_ATTRIBUTE == name) {
            setX1(value[0][0]);
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            setY1(value[0][0]);
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            setX2(value[0][0]);
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            setY2(value[0][0]);
        } else {
            super.setFloatArrayTrait(name, value);
        }    
    
public voidsetFloatTraitImpl(java.lang.String name, float value)
Set the trait value as float. Supported float traits: stroke-width, stroke-miterlimit, stroke-dashoffset, fill-opacity, stroke-opacity.

param
name the name of the trait to set.
param
value the value of the trait to set.
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_X1_ATTRIBUTE == name) {
            setX1(value);
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            setY1(value);
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            setX2(value);
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            setY2(value);
        } else {
            super.setFloatTraitImpl(name, value);
        }
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
Supported traits: stroke-width, stroke-miterlimit, stroke-dashoffset, fill-rule, stroke-linejoin, stroke-linecap, display, visibility, color, fill, stroke, fill-opacity, stroke-opacity, stroke-dasharray

param
name the name of the trait to set.
param
value the value of the trait to set.
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_X1_ATTRIBUTE == name) {
            setX1(parseFloatTrait(name, value));
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            setY1(parseFloatTrait(name, value));
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            setX2(parseFloatTrait(name, value));
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            setY2(parseFloatTrait(name, value));
        } else {
            super.setTraitImpl(name, value);
        }
    
public voidsetX1(float newX1)
Sets the x1 property.

param
newX1 the new origin along the x-axis

        if (newX1 == x1) {
            return;
        }

        this.x1 = newX1;
        onPaintChange();
    
public voidsetX2(float newX2)
Sets the x2 property.

param
newX2 the new end along the x-axis

        if (newX2 == x2) {
            return;
        }

        this.x2 = newX2;
        onPaintChange();
    
public voidsetY1(float newY1)
Sets the y1 property.

param
newY1 the new origin along the y-axis

        if (newY1 == y1) {
            return;
        }

        this.y1 = newY1;
        onPaintChange();
    
public voidsetY2(float newY2)
Sets the y2 property.

param
newY2 the new end along the y-axis

        if (newY2 == y2) {
            return;
        }

        this.y2 = newY2;
        onPaintChange();
    
booleansupportsTrait(java.lang.String traitName)
LinearGradient handles x1, x2, y1, y2.

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_X1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_X2_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y2_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_X1_ATTRIBUTE == name
            ||
            SVGConstants.SVG_Y1_ATTRIBUTE == name
            ||
            SVGConstants.SVG_X2_ATTRIBUTE == name
            ||
            SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            return Float.toString(value[0][0]);
        } else {
            return super.toStringTrait(name, value);
        }
    
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_X1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_X2_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y2_ATTRIBUTE == traitName) {
            return new float[][] {{parseFloatTrait(traitName, value)}};
        } else {
            return super.validateFloatArrayTrait(traitName,
                                                 value,
                                                 reqNamespaceURI,
                                                 reqLocalName,
                                                 reqTraitNamespace,
                                                 reqTraitName);
        }