FileDocCategorySizeDatePackage
ScalableGraphics.javaAPI DocphoneME MR2 API (J2ME)6488Wed May 02 18:00:36 BST 2007javax.microedition.m2g

ScalableGraphics

public class ScalableGraphics extends Object

Fields Summary
static final com.sun.perseus.j2d.RGB
CLEAR_PAINT
Paint used to clear offscreens.
javax.microedition.lcdui.Graphics
g
The Graphics object bound to this class
com.sun.pisces.GraphicsSurfaceDestination
gsd
The GraphicsSurfaceDestination used to blit the native surface to the Graphics.
int
qualityMode
The current quality mode.
com.sun.perseus.model.DirtyAreaManager
dirtyAreaManager
The DirtyAreaManager used to minimize renderings.
float
alpha
The current transparency for rendering images.
com.sun.pisces.NativeSurface
offscreen
The offscreen buffer, used for temporary rendering of the image.
com.sun.pisces.PiscesRenderer
pr
The PiscesRenderer associated with the offscreen.
int
offscreenWidth
The offscreen width.
int
offscreenHeight
The offscreen height.
com.sun.perseus.j2d.RenderGraphics
rg
The RenderGraphics used to draw to the PiscesRenderer
public static final int
RENDERING_QUALITY_LOW
public static final int
RENDERING_QUALITY_HIGH
Constructors Summary
private ScalableGraphics()
Constructor


         
      
    
Methods Summary
public voidbindTarget(java.lang.Object target)

        if (target == null) {
            throw new NullPointerException();
        }
        
        if (!(target instanceof Graphics)) {
            throw new IllegalArgumentException();
        }
        
        if (g != null) {
            throw new IllegalStateException("bindTarget(" + target + ") with g : " + g);
        }
        
        g = (Graphics) target;
        gsd = new GraphicsSurfaceDestination(g);
    
voidcheckOffscreen(int width, int height)
Get an offscreen buffer big enough to draw a widht by height image.

param
width the desired minimal width
param
height the desired minimal height.

        int w = width;
        int h = height;
        if (w <= 0) {
            w = 1;
        }
        
        if (h <= 0) {
            h = 1;
        }
        
        if (offscreen == null
            ||
            offscreenWidth != w
            ||
            offscreenHeight != h) {
            offscreen = new NativeSurface(w, h);
            offscreenWidth = w;
            offscreenHeight = h;

            pr = new PiscesRenderer(offscreen, w, h, 0, w, 1, 
                                    RendererBase.TYPE_INT_ARGB);
            rg = new RenderGraphics(pr, offscreenWidth, offscreenHeight);
        } 
    
public static javax.microedition.m2g.ScalableGraphicscreateInstance()

        return new ScalableGraphics();
    
public voidreleaseTarget()

        if (g == null) {
            throw new IllegalStateException("releaseTarget() with null current target");
        }

        g = null;
        gsd = null;
    
public voidrender(int x, int y, ScalableImage image)

        if (image == null) {
            throw new NullPointerException();
        }

        if (g == null) {
            throw new IllegalStateException();
        }

        DocumentNode documentNode = 
            (DocumentNode) ((SVGImage) image).getDocument();

        int vpw = image.getViewportWidth();
        int vph = image.getViewportHeight();
        checkOffscreen(vpw, vph);

        if (DirtyAreaManager.ON) {
            dirtyAreaManager.setViewport(documentNode);
            documentNode.setUpdateListener(dirtyAreaManager);
        }

        rg.setRenderingQuality(qualityMode == RENDERING_QUALITY_HIGH);

        documentNode.sample(documentNode.getCurrentTime());
        documentNode.applyAnimations();

        if (DirtyAreaManager.ON) {
            dirtyAreaManager.refresh(documentNode, rg, CLEAR_PAINT);
        } else {
            // Clear offscreen and paint
            pr.setColor(0, 0, 0, 0);
            pr.setClip(0, 0, offscreenWidth, offscreenHeight);
            pr.clearRect(0, 0, offscreenWidth, offscreenHeight);
            documentNode.paint(rg);
        }
        
        // Now, render the image with alpha.
        gsd.drawSurface(offscreen, 0, 0, x, y, offscreenWidth, offscreenHeight, alpha);
    
public voidsetRenderingQuality(int mode)

        if (mode != RENDERING_QUALITY_LOW && mode != RENDERING_QUALITY_HIGH) {
            throw new IllegalArgumentException("" + mode);
        }

        this.qualityMode = mode;
    
public voidsetTransparency(float alpha)

        if (alpha < 0f || alpha > 1f) {
            throw new IllegalArgumentException();
        }

        this.alpha = alpha;