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

Stop

public class Stop extends CompositeGraphicsNode
Stop class represents the <stop> SVG Tiny 1.2 element.
version
$Id: Stop.java,v 1.5 2006/06/29 10:47:34 ln156897 Exp $

Fields Summary
static final String[]
REQUIRED_TRAITS
offset is required on <stop>
static final com.sun.perseus.j2d.RGB
DEFAULT_STOP_COLOR
The default stop color.
static final float
DEFAULT_STOP_OPACITY
The default stop opacity.
com.sun.perseus.j2d.RGB
stopColor
The stop's color
float
stopOpacity
The stop's opacity
float
offset
The stop offset value.
Constructors Summary
public Stop(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode


                
        
        super(ownerDocument);
    
Methods Summary
ElementNodeProxybuildProxy()

return
an adequate ElementNodeProxy for this node.

        return new CompositeGraphicsNodeProxy(this);
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)

param
traitName the trait name.

        if (SVGConstants.SVG_STOP_OPACITY_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_OFFSET_ATTRIBUTE == traitName) {
            return new FloatTraitAnim(this, traitName, TRAIT_TYPE_FLOAT);
        } else if (SVGConstants.SVG_STOP_COLOR_ATTRIBUTE == traitName) {
            return new FloatTraitAnim(this, traitName, 
                                      TRAIT_TYPE_SVG_RGB_COLOR);
        } 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_STOP_OPACITY_ATTRIBUTE == name) {
            return stopOpacity;
        } else if (SVGConstants.SVG_OFFSET_ATTRIBUTE == name) {
            return offset;
        } else {
            return super.getFloatTraitImpl(name);
        }
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_STOP_TAG value

        return SVGConstants.SVG_STOP_TAG;
    
public intgetNumberOfProperties()

return
the number of properties supported by this node

        return GraphicsNode.NUMBER_OF_PROPERTIES;
    
public floatgetOffset()

return
the stop's offset

        return offset;
    
org.w3c.dom.svg.SVGRGBColorgetRGBColorTraitImpl(java.lang.String name)

param
name the requested trait's name.
return
the requested trait's value, as an SVGRGBColor.
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.SVGRGBColor SVGRGBColor}
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        // We use .equals here because name is not interned.
        if (SVGConstants.SVG_STOP_COLOR_ATTRIBUTE.equals(name)) {
            return stopColor;
        } else {
            return super.getRGBColorTraitImpl(name);
        }
    
public java.lang.String[]getRequiredTraits()

return
an array of traits that are required by this element.

        return REQUIRED_TRAITS;
    
public com.sun.perseus.j2d.RGBgetStopColor()

return
the current stopColor property.

        return stopColor;
    
public floatgetStopOpacity()

return
the current stopOpacity property.

        return stopOpacity;
    
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_STOP_COLOR_ATTRIBUTE == name) {
            return stopColor.toString();
        } else if (SVGConstants.SVG_STOP_OPACITY_ATTRIBUTE == name) {
            return Float.toString(stopOpacity);
        } else if (SVGConstants.SVG_OFFSET_ATTRIBUTE == name) {
            return Float.toString(offset);
        } else {
            return super.getTraitImpl(name);
        }
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype Stop.

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

        return new Stop(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_STOP_COLOR_ATTRIBUTE == name) {
            setStopColor(toRGB(name, value));
        } else if (SVGConstants.SVG_STOP_OPACITY_ATTRIBUTE == name) {
            if (value[0][0] < 0 || value[0][0] > 1) {
                throw illegalTraitValue(name, Float.toString(value[0][0]));
            }
            setStopOpacity(value[0][0]);
        } else if (SVGConstants.SVG_OFFSET_ATTRIBUTE == name) {
            setOffset(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_STOP_OPACITY_ATTRIBUTE == name) {
            setStopOpacity(value);
        } else if (SVGConstants.SVG_OFFSET_ATTRIBUTE == name) {
            setOffset(value);
        } else {
            super.setFloatTraitImpl(name, value);
        }
    
public voidsetOffset(float newOffset)
Sets the stop offset

param
newOffset the new offset

        if (newOffset == offset) {
            return;
        }

        offset = newOffset;
        updateGradient();
    
voidsetRGBColorTraitImpl(java.lang.String name, org.w3c.dom.svg.SVGRGBColor color)
Set the trait value as {@link org.w3c.dom.svg.SVGRGBColor SVGRGBColor}. Supported color traits: color, fill, stroke

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 an {@link org.w3c.dom.svg.SVGRGBColor SVGRGBColor}
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is null.
throws
SecurityException if the application does not have the necessary privilege rights to access this (SVG) content.

        try {
            if (SVGConstants.SVG_STOP_COLOR_ATTRIBUTE.equals(name)) {
                setStopColor((RGB) color);
            } else {
                super.setRGBColorTraitImpl(name, color);
            }
        } catch (IllegalArgumentException iae) {
            throw new DOMException(DOMException.INVALID_ACCESS_ERR, 
                                   iae.getMessage());
        }
    
public voidsetStopColor(com.sun.perseus.j2d.RGB newStopColor)
Sets the stop-color property.

param
newStopColor the new stop-color property

        if (stopColor.equals(newStopColor)) {
            return;
        }

        stopColor = newStopColor;
        updateGradient();
    
public voidsetStopOpacity(float newStopOpacity)
Sets the stop-opacity property.

param
newStopOpacity the new stop-opacity property

        if (newStopOpacity == stopOpacity) {
            return;
        }

        stopOpacity = newStopOpacity;
        updateGradient();
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
CompositeGraphicsNode handles the graphics node traits. Other attributes are handled by the super class. 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_STOP_OPACITY_ATTRIBUTE == name) {

            // ======================= stop-opacity ===================== //

            if (SVGConstants.CSS_INHERIT_VALUE.equals(value)) {
                setStopOpacity(DEFAULT_STOP_OPACITY);
            } else {
                setStopOpacity(parsePositiveFloatTrait(name, value));
            }
        } else if (SVGConstants.SVG_STOP_COLOR_ATTRIBUTE
                   .equals(name)) {

            // ======================== stop-color ===================== //

            if (SVGConstants.CSS_INHERIT_VALUE.equals(value)) {
                setStopColor(DEFAULT_STOP_COLOR);
            } else if (SVGConstants.CSS_CURRENTCOLOR_VALUE.equals(value)) {
                setStopColor(getColor());
            } else {
                setStopColor(parseColorTrait
                              (SVGConstants.SVG_STOP_COLOR_ATTRIBUTE, value));
            }
        } else if (SVGConstants.SVG_OFFSET_ATTRIBUTE == name) {
            setOffset(parseFloatTrait(name, value));
        } else {
            super.setTraitImpl(name, value);
        }
    
booleansupportsTrait(java.lang.String traitName)

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_STOP_COLOR_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_STOP_OPACITY_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_OFFSET_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_STOP_OPACITY_ATTRIBUTE == name
            ||
            SVGConstants.SVG_OFFSET_ATTRIBUTE == name) {
            return Float.toString(value[0][0]);
        } else if (SVGConstants.SVG_STOP_COLOR_ATTRIBUTE == name) {
            return toRGBString(name, value);
        } else {
            return super.toStringTrait(name, value);
        }
    
voidupdateGradient()
Should be called by the stop every time its parent gradient should recompute its state.

        if (parent != null) {
            if (parent instanceof GradientElement) {
                ((GradientElement) parent).onPaintChange();
            }
        }
    
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_STOP_COLOR_ATTRIBUTE == traitName) {
            RGB color = parseColorTrait
                (SVGConstants.SVG_COLOR_ATTRIBUTE, value);
            if (color == null) {
                throw illegalTraitValue(traitName, value);
            }
            return new float[][] {
                        {color.getRed(), color.getGreen(), color.getBlue()}
                    };
        } else if (SVGConstants.SVG_STOP_OPACITY_ATTRIBUTE == traitName) {
            return new float[][] {{parseFloatTrait(traitName, value)}};
        } else if (SVGConstants.SVG_OFFSET_ATTRIBUTE == traitName) {
            return new float[][] {{parseFloatTrait(traitName, value)}};
        } else {
            return super.validateFloatArrayTrait(traitName,
                                                 value,
                                                 reqNamespaceURI,
                                                 reqLocalName,
                                                 reqTraitNamespace,
                                                 reqTraitName);
        }