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

Rect

public class Rect extends AbstractShapeNode
Rect represents and SVG Tiny <rect> element.
Negative width, height, rx or ry value is illegal. A value of zero for the rectangle's width or height disables its rendering.
version
$Id: Rect.java,v 1.11 2006/06/29 10:47:33 ln156897 Exp $

Fields Summary
static final String[]
REQUIRED_TRAITS
width and height are required on
protected float
width
The rect's width.
protected float
height
The rect's height.
protected float
x
The rect's x-axis origin.
protected float
y
The rect's y-axis origin.
protected float
aw
The rect's x-axis arcwidth.
protected float
ah
The rect's y-axis archeight.
Constructors Summary
public Rect(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode


                
        
        super(ownerDocument);

        // Initially, the rect's width and height are zero, so we
        // set the corresponding bits accordingly.
        canRenderState |= CAN_RENDER_ZERO_WIDTH_BIT;
        canRenderState |= CAN_RENDER_ZERO_HEIGHT_BIT;
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,

        return addTransformedBBox(bbox, x, y, width, height, t);
    
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.

        if (aw == 0 && ah == 0) {
            return x >= this.x &&
		y >= this.y &&
		x < this.x + width &&
		y < this.y + height;
        } else {
            // This code is derived from the java.awt.geom.Rectangle2D and 
            // java.awt.geom.RoundRectangle2D
            float rrx0 = this.x;
            float rry0 = this.y;
            float rrx1 = rrx0 + width;
            float rry1 = rry0 + height;

            // Check for trivial rejection - point is outside bounding rectangle
            if (x < rrx0 || y < rry0 || x >= rrx1 || y >= rry1) {
                return false;
            }

            float aw = Math.min(width, this.aw) / 2.0f;
            float ah = Math.min(height, this.ah) / 2.0f;

            // Check which corner point is in and do circular containment
            // test - otherwise simple acceptance
            if (x >= (rrx0 += aw) && x < (rrx0 = rrx1 - aw)) {
                return true;
            }

            if (y >= (rry0 += ah) && y < (rry0 = rry1 - ah)) {
                return true;
            }

            x = (x - rrx0) / aw;
            y = (y - rry0) / ah;
            return (x * x + y * y <= 1.0);
        }
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)
Rect handles x, y, rx, ry, width and height traits as FloatTraitAnims

param
traitName the trait name.

        if (SVGConstants.SVG_X_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_RX_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_RY_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_WIDTH_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_HEIGHT_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.drawRect(x, y, width, height, aw, ah);
    
public voidfillShape(com.sun.perseus.j2d.RenderGraphics rg)

param
rg the RenderGraphics on which to fill the shape.

        rg.fillRect(x, y, width, height, aw, ah);
    
floatgetFloatTraitImpl(java.lang.String name)
Rect handles x, y, rx, ry, width and height traits. Other attributes are handled by the super class.

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_X_ATTRIBUTE == name) {
            return x;
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            return y;
        } else if (SVGConstants.SVG_RX_ATTRIBUTE == name) {
            return aw / 2;
        } else if (SVGConstants.SVG_RY_ATTRIBUTE == name) {
            return ah / 2;
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
            return width;
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            return height;
        } else {
            return super.getFloatTraitImpl(name);
        }
    
public floatgetHeight()

return
this rectangle's height

        return height;
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_RECT_TAG value

        return SVGConstants.SVG_RECT_TAG;
    
public java.lang.String[]getRequiredTraits()

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

        return REQUIRED_TRAITS;
    
public floatgetRx()

return
x-axis corner radius

        return aw / 2;
    
public floatgetRy()

return
y-axis corner radius

        return ah / 2;
    
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.

        if (aw > 0 || ah > 0) {
            return PathSupport.getStrokedRect(x, 
                                              y, 
                                              width, 
                                              height,
                                              aw,
                                              ah,
                                              gp);
        } 

        return PathSupport.getStrokedRect(x, 
                                          y,
                                          width, 
                                          height,
                                          gp);
    
public java.lang.String[][]getTraitAliases()

return
an array of trait aliases. These are used when the value of a trait can be used to set the value of another trait. For example, on a , if the rx trait is not specified in the original XML document, the value fot eh ry trait should be used.

        return new String[][] {
            {SVGConstants.SVG_RX_ATTRIBUTE, SVGConstants.SVG_RY_ATTRIBUTE},
            {SVGConstants.SVG_RY_ATTRIBUTE, SVGConstants.SVG_RX_ATTRIBUTE} };
    
public java.lang.StringgetTraitImpl(java.lang.String name)
Rect handles x, y, rx, ry, width and height traits. Other traits are handled by the super class.

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_X_ATTRIBUTE == name) {
            return Float.toString(x);
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            return Float.toString(y);
        } else if (SVGConstants.SVG_RX_ATTRIBUTE == name) {
            return Float.toString(aw / 2);
        } else if (SVGConstants.SVG_RY_ATTRIBUTE == name) {
            return Float.toString(ah / 2);
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
            return Float.toString(width);
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            return Float.toString(height);
        } else {
            return super.getTraitImpl(name);
        }
    
public floatgetWidth()

return
this rectangle's width

        return width;
    
public floatgetX()

return
this rectangle's x-axis origin

        return x;
    
public floatgetY()

return
this rectangle's y-axis origin

        return y;
    
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 Rect for the requested document.

        return new Rect(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_X_ATTRIBUTE == name) {
            setX(value[0][0]);
        } else if (SVGConstants.SVG_Y_ATTRIBUTE == name) {
            setY(value[0][0]);
        } else if (SVGConstants.SVG_RX_ATTRIBUTE == name) {
            checkPositive(name, value[0][0]);
            setRx(value[0][0]);
        } else if (SVGConstants.SVG_RY_ATTRIBUTE == name) {
            checkPositive(name, value[0][0]);
            setRy(value[0][0]);
        } else 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 {
            super.setFloatArrayTrait(name, value);
        }
    
public voidsetFloatTraitImpl(java.lang.String name, float value)
Rect handles x, y, rx, ry, width and height traits. Other traits are handled by the super class.

param
name the trait's name (e.g., "x")
param
value the new trait value (e.g., 20f)
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 if (SVGConstants.SVG_RX_ATTRIBUTE == name) {
            checkPositive(name, value);
            setRx(value);
        } else if (SVGConstants.SVG_RY_ATTRIBUTE == name) {
            checkPositive(name, value);
            setRy(value);
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
            checkPositive(name, value);
            setWidth(value);
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            checkPositive(name, value);
            setHeight(value);
        } else {
            super.setFloatTraitImpl(name, value);
        }
    
public voidsetHeight(float height)

param
height new rectangle height. Should be strictly positive.

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

        if (this.height == height) {
            return;
        }

        modifyingNode();
        renderingDirty();
        this.height = height;
        computeCanRenderHeightBit(height);
        modifiedNode();
    
public voidsetRect(float x, float y, float width, float height)

param
x new x-axis origin
param
y new y-axis origin
param
width new width
param
height new height

        if (width < 0 || height < 0) {
            throw new IllegalArgumentException();
        }

        if (this.x == x 
            && this.y == y 
            && this.width == width 
            && this.height == height) {
            return;
        }

        modifyingNode();
        renderingDirty();

        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        
        computeCanRenderWidthBit(width);
        computeCanRenderHeightBit(height);
        modifiedNode();
    
public voidsetRx(float rx)

param
rx new x-axis corner radius. Should be strictly positive.

        if (rx < 0) {
            throw new IllegalArgumentException();
        }
        
        if (2 * rx == aw) {
            return;
        }

        modifyingNode();
        renderingDirty();

        if (rx > 0) {
            aw = 2 * rx;
        } else {
            aw = 0;
        }
        modifiedNode();
    
public voidsetRy(float ry)

param
ry new y-axis radius. Shoud be strictly positive.

        if (ry < 0) {
            throw new IllegalArgumentException();
        }
        
        if (2 * ry == ah) {
            return;
        }
        
        modifyingNode();
        renderingDirty();
        
        if (ry > 0) {
            ah = 2 * ry;
        } else {
            ah = 0;
        }
        modifiedNode();
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
Rect handles x, y, rx, ry, width and height traits. Other traits are handled by the super class.

param
name the trait's name (e.g., "rx")
param
value the new trait string value (e.g., "10")
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 if (SVGConstants.SVG_RX_ATTRIBUTE == name) {
            setRx(parsePositiveFloatTrait(name, value));
        } else if (SVGConstants.SVG_RY_ATTRIBUTE == name) {
            setRy(parsePositiveFloatTrait(name, value));
        } else if (SVGConstants.SVG_WIDTH_ATTRIBUTE == name) {
            setWidth(parsePositiveFloatTrait(name, value));
        } else if (SVGConstants.SVG_HEIGHT_ATTRIBUTE == name) {
            setHeight(parsePositiveFloatTrait(name, value));
        } else {
            super.setTraitImpl(name, value);
        }
    
public voidsetWidth(float width)

param
width new rectangle width. Should be strictly positive.

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

        if (this.width == width) {
            return;
        }

        modifyingNode();
        renderingDirty();
        this.width = width;
        computeCanRenderWidthBit(width);
        modifiedNode();
    
public voidsetX(float x)

param
x new rectangle x-axis origin

        if (this.x == x) {
            return;
        }

        modifyingNode();
        renderingDirty();
        this.x = x;
        modifiedNode();
    
public voidsetY(float y)

param
y new rectangle y-axis origin

        if (this.y == y) {
            return;
        }
        modifyingNode();
        renderingDirty();
        this.y = y;
        modifiedNode();
    
booleansupportsTrait(java.lang.String traitName)
Rect handles x, y, rx, ry, width and height 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_X_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_RX_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_RY_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_WIDTH_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_HEIGHT_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_X_ATTRIBUTE == name
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == name
            ||
            SVGConstants.SVG_RX_ATTRIBUTE == name
            ||
            SVGConstants.SVG_RY_ATTRIBUTE == name
            ||
            SVGConstants.SVG_WIDTH_ATTRIBUTE == name
            ||
            SVGConstants.SVG_HEIGHT_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_X_ATTRIBUTE == traitName
            ||
            SVGConstants.SVG_Y_ATTRIBUTE == traitName) {
            return new float[][] {{parseFloatTrait(traitName, value)}};
        } else if (SVGConstants.SVG_RX_ATTRIBUTE == traitName
                   ||
                   SVGConstants.SVG_RY_ATTRIBUTE == traitName
                   ||
                   SVGConstants.SVG_WIDTH_ATTRIBUTE == traitName
                   ||
                   SVGConstants.SVG_HEIGHT_ATTRIBUTE == traitName) {
            return new float[][] {{parsePositiveFloatTrait(traitName, value)}};
        } else {
            return super.validateFloatArrayTrait(traitName,
                                                 value,
                                                 reqNamespaceURI,
                                                 reqLocalName,
                                                 reqTraitNamespace,
                                                 reqTraitName);
        }