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

Viewport

public abstract class Viewport extends CompositeNode implements Transformable
A Viewport describes a ModelNode into which rendering may happen.

A ViewportNode has a width and height which a child SVG uses to compute the viewbox to viewport transform.

In addition, a Viewport has a user transform limited to its scale and translation components.

The Viewport is the root of any SVG fragment hierarchy.

version
$Id: Viewport.java,v 1.9 2006/06/29 10:47:36 ln156897 Exp $

Fields Summary
public static final int
DEFAULT_VIEWPORT_WIDTH
Default width for viewports.
public static final int
DEFAULT_VIEWPORT_HEIGHT
Default height for viewports
public static final int
ZOOM_PAN_MAGNIFY
As in the SVG 1.1 specification
public static final int
ZOOM_PAN_DISABLE
As in the SVG 1.1 specification
public static final int
ZOOM_PAN_UNKNOWN
As in the SVG 1.1 specification
protected int
width
Viewport width
protected int
height
Viewport height
protected com.sun.perseus.j2d.Transform
transform
The Transform applied to this node.
protected com.sun.perseus.j2d.Transform
inverseTxf
The inverse of the Transform applied to this node.
protected int
zoomAndPan
The zoomAndPan setting
Constructors Summary
public Viewport()
Default constructor


           
      
    
Methods Summary
protected com.sun.perseus.j2d.TransformappendTransform(com.sun.perseus.j2d.Transform tx, com.sun.perseus.j2d.Transform workTx)
Appends this node's transform, if it is not null.

param
tx the Transform to apply additional node transforms to. This may be null.
param
workTx a Transform which can be re-used if a new Transform needs to be created and workTx is not the same instance as tx.
return
a transform with this node's transform added.

        if (transform == null) {
            return tx;
        }

        tx = recycleTransform(tx, workTx);
        tx.mMultiply(transform);
        
        return tx;
    
public intgetHeight()

return
the viewport height

        return this.height;
    
public com.sun.perseus.j2d.TransformgetInverseTransformState()

return
this node's cached inverse transform.

        if (((canRenderState & CAN_RENDER_NON_INVERTIBLE_TXF_BIT) == 0)) {
            if (inverseTxf == null) {
                inverseTxf = new Transform(null);
                try {
                    inverseTxf = (Transform) transform.inverse(inverseTxf);
                } catch (Exception e) {
                    // If we get an exception, then we have a real error
                    // condition, because we just checked that the
                    // transform was invertible.
                    throw new Error();
                }
            }
        } else {
        inverseTxf = null;
        }
        return inverseTxf;
    
public com.sun.perseus.j2d.TransformgetTransform()

return
This Transformable's transform.

        return transform;
    
public com.sun.perseus.j2d.TransformgetTransformState()

return
this node's cached transform.

        return transform;
    
public intgetWidth()

return
the viewport width

        return this.width;
    
public intgetZoomAndPan()

return
The zoomAndPan setting for this viewport (read-only)

        return zoomAndPan;
    
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.

        // Check for a hit on children
        return nodeHitAt(getLastChildNode(), pt);
    
protected voidrecomputeTransformState(com.sun.perseus.j2d.Transform parentTransform)
Recomputes the transform cache, if one exists. This should recursively call recomputeTransformState on children node or expanded content, if any. By default, because a ModelNode has no transform and no cached transform, this only does a pass down.

param
parentTransform the Transform applied to this node's parent.

        if (parentTransform != null) {
            throw new IllegalArgumentException();
        }

        computeCanRenderTransformBit(transform);
        inverseTxf = null;
        recomputeTransformState(transform, getFirstChildNode());
    
public voidsetSize(int newWidth, int newHeight)
Sets the viewport size

param
newWidth the new viewport width. Should be greater than 0
param
newHeight the new viewport height. Should be greater than 0.

        if (newWidth < 0 || newHeight < 0) {
            throw new IllegalArgumentException();
        }

        if (newWidth == width && newHeight == height) {
            return;
        }

        modifyingNode();
        this.width = newWidth;
        this.height = newHeight;
        recomputeTransformState(null);
        computeCanRenderWidthBit(width);
        computeCanRenderHeightBit(height);
        modifiedNode();
    
public voidsetTransform(com.sun.perseus.j2d.Transform newTransform)

param
newTransform The new Transformable's transform.

        if (ElementNode.equal(newTransform, this.transform)) {
            return;
        }

        modifyingNode();
        this.transform = newTransform;
        recomputeTransformState(null);
        modifiedNode();
    
public voidsetZoomAndPan(int newZoomAndPan)

param
newZoomAndPan the new value for the zoom and pan setting

        if (newZoomAndPan != ZOOM_PAN_MAGNIFY
            &&
            newZoomAndPan != ZOOM_PAN_DISABLE
            &&
            newZoomAndPan != ZOOM_PAN_UNKNOWN) {
            throw new IllegalArgumentException();
        }

        if (newZoomAndPan == zoomAndPan) {
            return;
        }
        modifyingNode();
        this.zoomAndPan = newZoomAndPan;
        modifiedNode();