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

Line

public class Line extends AbstractShapeNode
A Line node models an SVG <line> element.
version
$Id: Line.java,v 1.9 2006/06/29 10:47:32 ln156897 Exp $

Fields Summary
protected float
x1
Starting position along the x-axis
protected float
y1
Starting position along the y-axis
protected float
x2
Ending position along the x-axis
protected float
y2
Ending position along the y-axis
Constructors Summary
public Line(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode

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

param
bbox the bounding box to which this node's bounding box should be appended. That bounding box is in the target coordinate space. It may be null, in which case this node should create a new one.
param
t the transform from the node coordinate system to the coordinate system into which the bounds should be computed.
return
the bounding box of this node, in the target coordinate space,

        float x1 = this.x1;
        float x2 = this.x2;
        float y1 = this.y1;
        float y2 = this.y2;

        if (t != null) {
            x1 = t.getComponent(0) * this.x1 
                + t.getComponent(2) * this.y1 
                + t.getComponent(4);
            y1 = t.getComponent(1) * this.x1 
                + t.getComponent(3) * this.y1 
                + t.getComponent(5);
            x2 = t.getComponent(0) * this.x2 
                + t.getComponent(2) * this.y2 
                + t.getComponent(4);
            y2 = t.getComponent(1) * this.x2 
                + t.getComponent(3) * this.y2 
                + t.getComponent(5);
        }
        
        if (x1 > x2) {
            float x = x2;
            x2 = x1;
            x1 = x;
        }

        if (y1 > y2) {
            float y = y2;
            y2 = y1;
            y1 = y;
        }

        return addBBox(bbox, x1, y1, x2 - x1, y2 - y1);
    
public booleancontains(float x, float y, int fillRule)

param
x the hit point coordinate along the x-axis, in user space.
param
y the hit point coordinate along the y-axis, in user space.
param
fillRule the fillRule to apply when testing for containment.
return
true if the hit point is contained within the shape.

        return false;
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)

param
traitName the trait name.

        if (SVGConstants.SVG_X1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y1_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_X2_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y2_ATTRIBUTE == traitName) {
            return new FloatTraitAnim(this, traitName, TRAIT_TYPE_FLOAT);
        } else {
            return super.createTraitAnimImpl(traitName);
        }
    
public voiddrawShape(com.sun.perseus.j2d.RenderGraphics rg)

param
rg the RenderGraphics on which to draw the shape.

        rg.drawLine(x1, y1, x2, y2);
    
public voidfillShape(com.sun.perseus.j2d.RenderGraphics rg)

param
rg the RenderGraphics on which to fill the shape.

    
floatgetFloatTraitImpl(java.lang.String name)
Supported traits: x1, x2, y1, y2

param
name the requested trait's name.
return
the requested trait's float 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_X2_ATTRIBUTE == name) {
            return x2;
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            return y1;
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            return y2;
        } else {
            return super.getFloatTraitImpl(name);
        }
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_LINE_TAG value

        return SVGConstants.SVG_LINE_TAG;
    
java.lang.ObjectgetStrokedPath(com.sun.perseus.j2d.GraphicsProperties gp)
Returns the stroked shape, using the given stroke properties.

param
gp the GraphicsProperties defining the rendering context.
return
the shape's stroked path.

        return PathSupport.getStrokedLine(x1, 
                                          y1, 
                                          x2, 
                                          y2,
                                          gp);
    
public java.lang.StringgetTraitImpl(java.lang.String name)
Supported traits: x1, x2, y1, y2

param
name the requested trait's name.
return
the 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).

        if (SVGConstants.SVG_X1_ATTRIBUTE == name) {
            return Float.toString(x1);
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            return Float.toString(x2);
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            return Float.toString(y1);
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            return Float.toString(y2);
        } else {
            return super.getTraitImpl(name);
        }
    
public floatgetX1()

return
x-axis coordinate of the starting point

        return x1;
    
public floatgetX2()

return
x-axis coordinate of the termination point

        return x2;
    
public floatgetY1()

return
y-axis coordinate of the starting point

        return y1;
    
public floatgetY2()

return
y-axis coordinate of the termination point

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

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

        return new Line(doc);
    
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_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) {
            checkPositive(name, value[0][0]);
            setX2(value[0][0]);
        } else if (SVGConstants.SVG_Y2_ATTRIBUTE == name) {
            checkPositive(name, value[0][0]);
            setY2(value[0][0]);
        } else {
            super.setFloatArrayTrait(name, value);
        }
    
public voidsetFloatTraitImpl(java.lang.String name, float value)
Supported traits: x1, x2, y1, y2

param
name the trait's name.
param
value the new trait float 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_X1_ATTRIBUTE == name) {
            setX1(value);
        } else if (SVGConstants.SVG_X2_ATTRIBUTE == name) {
            setX2(value);
        } else if (SVGConstants.SVG_Y1_ATTRIBUTE == name) {
            setY1(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: x1, x2, y1, y2

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

param
newX1 new value for the termination point on the x-axis

        if (newX1 == x1) {
            return;
        }
        modifyingNode();
        renderingDirty();
        x1 = newX1;
        modifiedNode();
    
public voidsetX2(float newX2)

param
newX2 new value for the termination point on the x-axis

        if (newX2 == x2) {
            return;
        }
        modifyingNode();
        renderingDirty();
        x2 = newX2;
        modifiedNode();
    
public voidsetY1(float newY1)

param
newY1 new value for the starting point on the y-axis

        if (newY1 == y1) {
            return;
        }
        modifyingNode();
        renderingDirty();
        y1 = newY1;
        modifiedNode();
    
public voidsetY2(float newY2)

param
newY2 new value for the termination point on the y-axis

        if (newY2 == y2) {
            return;
        }
        modifyingNode();
        renderingDirty();
        y2 = newY2;
        modifiedNode();
    
booleansupportsTrait(java.lang.String traitName)
Supported traits: 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.equals(traitName)
            ||
            SVGConstants.SVG_X2_ATTRIBUTE.equals(traitName)
            ||
            SVGConstants.SVG_Y1_ATTRIBUTE.equals(traitName)
            ||
            SVGConstants.SVG_Y2_ATTRIBUTE.equals(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_X2_ATTRIBUTE == name
            ||
            SVGConstants.SVG_Y1_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);
        }