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

Switch

public class Switch extends Group
The Switch class is a simple extension of the Group class which stops rendering its children after one as rendered (i.e., the child's canRender method returns true). This implements the behavior required by the SVG Tiny specification of the <switch> element.
version
$Id: Switch.java,v 1.7 2006/06/29 10:47:35 ln156897 Exp $

Fields Summary
Constructors Summary
public Switch(DocumentNode ownerDocument)
Constructor.

param
ownerDocument this element's owner DocumentNode

        super(ownerDocument);
    
Methods Summary
public com.sun.perseus.j2d.BoxaddBBox(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 to apply from the node's coordinate space to the target coordinate space. May be null for the identity transform.
return
the node's bounding box in the target coordinate space.

        ModelNode c = getFirstChildNode();
        while (c != null) {
            if ((c.canRenderState & CAN_RENDER_CONDITIONS_MET_BITS)
                == 0) {
                bbox = c.addBBox(bbox, c.appendTransform(t, null));
                break;
            }
            c = c.nextSibling;
        }

        return bbox;
    
public java.lang.StringgetLocalName()

return
the SVGConstants.SVG_SWITCH_TAG value

        return SVGConstants.SVG_SWITCH_TAG;
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype Switch.

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

        return new Switch(doc);
    
public ModelNodenodeHitAt(float[] pt)
Returns the ModelNode, if any, hit by the point at coordinate x/y.

param
pt the x/y coordinate. Should never be null and be of size two. If not, the behavior is unspecified. The coordinates are in viewport space.
return
the ModelNode hit at the given point or null if none was hit.

        // If a node does not render, it is never hit
        if (canRenderState != 0) {
            return null;
        }
        
        // Check for a hit on children
        ModelNode c = lastChild;
        while (c != null) {
            if ((c.canRenderState & CAN_RENDER_CONDITIONS_MET_BITS)
                == 0) {
                return c.nodeHitAt(pt);
            }
            c = c.prevSibling;
        }

        return null;
    
public voidpaint(com.sun.perseus.j2d.RenderGraphics rg)

param
rg this method paints this node into the input RenderGraphics

        if (canRenderState != 0) {
            return;
        }

        if (firstChild == null) {
            return;
        }

        //
        // Only go up to the first child which
        // renders
        //
        ElementNode c = firstChild;
        while (c != null) {
            // Paint child
            c.paint(rg);

            // Exit the loop if the child rendered
            if ((c.canRenderState & CAN_RENDER_CONDITIONS_MET_BITS)
                == 0) {
                break;
            }

            c = (ElementNode) c.nextSibling;
        }
    
ModelNodeproxyNodeHitAt(float[] pt, ElementNodeProxy proxy)
Returns the ModelNode, if any, hit by the point at coordinate x/y in the proxy tree starting at proxy.

param
pt the x/y coordinate. Should never be null and be of size two. If not, the behavior is unspecified. The coordinates are in viewport space.
param
proxy the root of the proxy tree to test.
return
the ModelNode hit at the given point or null if none was hit.

        // If a node does not render, it is never hit
        if (canRenderState != 0) {
            return null;
        }
        
        // Check for a hit on the proxy's expanded children
        ElementNodeProxy c = (ElementNodeProxy) proxy.getLastExpandedChild();
        while (c != null) {
            if ((c.proxied.canRenderState & CAN_RENDER_CONDITIONS_MET_BITS)
                == 0) {
                return c.nodeHitAt(pt);
            }
            c = (ElementNodeProxy) c.prevSibling;
        }

        return null;