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

AbstractShapeNode

public abstract class AbstractShapeNode extends AbstractRenderingNode
All nodes which represent geometry (complex or simple shapes) are represented by descendants of this class.
version
$Id: AbstractShapeNode.java,v 1.16 2006/06/29 10:47:29 ln156897 Exp $

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

param
ownerDocument this element's owner DocumentNode

        super(ownerDocument);
    
Methods Summary
ElementNodeProxybuildProxy()

return
an adequate ElementNodeProxy for this node.

        return new AbstractShapeNodeProxy(this);
    
protected voidcomputeRenderingTile(com.sun.perseus.j2d.Tile tile, com.sun.perseus.j2d.Transform t, com.sun.perseus.j2d.GraphicsProperties gp)
Computes the rendering tile for the given set of GraphicsProperties.

param
tile the Tile instance whose bounds should be set.
param
t the Transform to the requested tile space, from this node's user space.
param
gp the GraphicsProperties for which the tile should be computed.
return
the screen bounding box when this node is rendered with the given render context.

        if (gp.getStroke() == null) {
            // No stroking on the shape, we can use the geometrical bounding 
            // box.
            tile.snapBox(addNodeBBox(null, t));
        } else {
            // Need to account for stroking, with a more costly operation to 
            // compute the stroked bounds.
            Object strokedPath = getStrokedPath(gp);
            PathSupport.computeStrokedPathTile(tile, strokedPath, t);
        }
    
public abstract 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.

public abstract voiddrawShape(com.sun.perseus.j2d.RenderGraphics rg)

param
rg the RenderGraphics on which to draw the shape.

public abstract voidfillShape(com.sun.perseus.j2d.RenderGraphics rg)

param
rg the RenderGraphics on which to fill the shape.

abstract 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.

protected booleanisHitVP(float[] pt)
Returns true if this node is hit by the input point. The input point is in viewport space. For an AbstractShapeNode this method returns true if:
  • the node is visible and
    • the node's fill is not NONE and the associated shape contains the input point, or
    • the node's stroke is not NONE and the associated stroked shape contains the input point.
This implements the equivalent of the visiblePainted value for the pointerEvents attribute. That attribute is not part of SVG Tiny, but the default behavior in SVG Tiny is that of visiblePainted.

param
pt the x/y coordinate. Should never be null and be of size two. If not, the behavior is unspecified. The x/y coordinate is in viewport space.
return
true if the node is hit by the input point.
see
#nodeHitAt

        // Node has to be visible to be a hit target
        if (!getVisibility() 
            ||
            (fill == null && stroke == null)) {
            return false;
        }
        
        getInverseTransformState().transformPoint(pt, ownerDocument.upt);
        pt = ownerDocument.upt;
        
        // If the node is filled, see if the shape is hit
        if (fill != null) {
            if (contains(pt[0], pt[1], getFillRule())) {
                return true;
            }
        }

        // Test detection on the edge if the stroke color
        // is set.
        if (stroke != null) {
            if (strokedContains(pt[0], pt[1], this)) {
                return true;
            }
        }

        return false;
    
protected booleanisProxyHitVP(float[] pt, AbstractRenderingNodeProxy proxy)
Returns true if this proxy node is hit by the input point. The input point is in viewport space.

param
pt the x/y coordinate. Should never be null and be of size two. If not, the behavior is unspecified. The x/y coordinate is in viewport space.
param
proxy the tested ElementNodeProxy.
return
true if the node is hit by the input point.
see
#isHitVP

        // Node has to be visible to be a hit target
        if (!proxy.getVisibility() 
            ||
            (proxy.fill == null && proxy.stroke == null)) {
            return false;
        }

        proxy.getInverseTransformState().transformPoint(pt, ownerDocument.upt);
        pt = ownerDocument.upt;
        
        // If the node is filled, see if the shape is hit
        if (proxy.fill != null) {
            if (contains(pt[0], pt[1], proxy.getFillRule())) {
                return true;
            }
        }

        // Test detection on the edge if the stroke color
        // is set.
        if (((AbstractShapeNodeProxy) proxy).stroke != null) {
            if (strokedContains(pt[0], pt[1], proxy)) {
                return true;
            }
        }

        return false;
    
protected voidpaintRendered(com.sun.perseus.j2d.RenderGraphics rg, com.sun.perseus.j2d.GraphicsProperties gp, com.sun.perseus.j2d.PaintTarget pt, com.sun.perseus.j2d.Transform tx)
Paints this node into the input RenderGraphics, assuming the node is rendered.

param
rg the RenderGraphics where the node should paint itself.
param
gp the GraphicsProperties controlling the operation's rendering
param
pt the PaintTarget for the paint operation.
param
txf the Transform from user space to device space for the paint operation.

        if (!gp.getVisibility()) {
            return;
        }
        
        rg.setPaintTarget(pt);
        rg.setPaintTransform(tx);
        rg.setTransform(tx);

        // Fill the shape. Only apply the fill property
        if (gp.getFill() != null) {
            rg.setFillRule(gp.getFillRule());
            rg.setFill(gp.getFill());
            rg.setFillOpacity(gp.getFillOpacity());
            fillShape(rg);
        }

        // Stroke the shape. Only apply the stroke properties
        if (gp.getStroke() != null) {
            rg.setStroke(gp.getStroke());
            rg.setStrokeOpacity(gp.getStrokeOpacity());
            rg.setStrokeWidth(gp.getStrokeWidth());
            rg.setStrokeLineCap(gp.getStrokeLineCap());
            rg.setStrokeLineJoin(gp.getStrokeLineJoin());
            rg.setStrokeDashArray(gp.getStrokeDashArray());
            rg.setStrokeMiterLimit(gp.getStrokeMiterLimit());
            rg.setStrokeDashOffset(gp.getStrokeDashOffset());
            drawShape(rg);
        }
    
voidsetComputedFill(com.sun.perseus.j2d.PaintServer newFill)

param
newFill the new computed fill property.

        this.fill = newFill;
        renderingDirty();
    
voidsetComputedFillOpacity(float newFillOpacity)

param
newFillOpacity the new computed value for the fill opacity property.

                
        super.setComputedFillOpacity(newFillOpacity);
        
        if (fill != null) {
            renderingDirty();
        }
    
voidsetComputedStroke(com.sun.perseus.j2d.PaintServer newStroke)

param
newStroke the new computed stroke property.

        this.stroke = newStroke;
        renderingDirty();
    
voidsetComputedStrokeDashArray(float[] newStrokeDashArray)

param
newStrokeDashArray the new computed stroke-dasharray property value.

        strokeDashArray = newStrokeDashArray;

        if (stroke != null) {
            renderingDirty();
        }
    
voidsetComputedStrokeDashOffset(float newStrokeDashOffset)

param
newStrokeDashOffset the new stroke-dashoffset computed property value.

        strokeDashOffset = newStrokeDashOffset;

        if (stroke != null && strokeDashArray != null) {
            renderingDirty();
        }
    
voidsetComputedStrokeLineCap(int newStrokeLineCap)

param
newStrokeLineCap the new value for the stroke-linecap property.

        super.setComputedStrokeLineCap(newStrokeLineCap);

        if (stroke != null) {
            renderingDirty();
        }
    
voidsetComputedStrokeLineJoin(int newStrokeLineJoin)

param
newStrokeLineJoin the new computed value for stroke-line-join

        super.setComputedStrokeLineJoin(newStrokeLineJoin);

        if (stroke != null) {
            renderingDirty();
        }
    
voidsetComputedStrokeMiterLimit(float newStrokeMiterLimit)

param
newStrokeMiterLimit the new computed stroke-miterlimit property.

        strokeMiterLimit = newStrokeMiterLimit; 

        if (stroke != null && getStrokeLineJoin() == JOIN_MITER) {
            renderingDirty();
        }
    
voidsetComputedStrokeOpacity(float newStrokeOpacity)

param
newStrokeOpacity the new computed stroke-opacity property.

        super.setComputedStrokeOpacity(newStrokeOpacity);
        
        if (stroke != null) {
            renderingDirty();
        }
    
voidsetComputedStrokeWidth(float newStrokeWidth)

param
newStrokeWidth the new computed stroke-width property value.

        strokeWidth = newStrokeWidth;

        // Only dirty rendering if the object is actually stroked.
        if (stroke != null) {
            renderingDirty();
        }
    
public final booleanstrokedContains(float x, float y, com.sun.perseus.j2d.GraphicsProperties gp)

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
gp the GraphicsProperties instance defining the rendering context.
return
true if the hit point is contained within the shape.

        Object strokedPath = getStrokedPath(this);
        return PathSupport.isStrokedPathHit(strokedPath, gp.getFillRule(), x, 
                                            y);