⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgimage.java.svn-base

📁 j2me设计的界面包
💻 SVN-BASE
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.sun.lwuit;import com.sun.lwuit.animations.Animation;import java.io.IOException;import java.io.InputStream;import javax.microedition.m2g.ScalableGraphics;import org.w3c.dom.Document;import org.w3c.dom.svg.SVGPoint;import org.w3c.dom.svg.SVGSVGElement;/** * * @author cf130546 */public class SVGImage extends Image implements Animation {    private javax.microedition.m2g.SVGImage im;    private static final String SVG_NAMESPACE = "http://www.w3.org/2000/svg";    private boolean animated;    private long startTime = -1;    private int id = 0;    private static int idCounter = 0;    private static final boolean IS_SUPPORTED;    static {        boolean supported = false;        try {            Class.forName("javax.microedition.m2g.SVGImage");            supported = true;        } catch (Throwable t) {        }        IS_SUPPORTED = supported;    }        SVGImage(javax.microedition.m2g.SVGImage im, boolean animated) {        super(null);        this.im = im;        this.animated = animated;    }    public static Image createSVGImage(InputStream stream, boolean animated) throws IOException {        SVGImage instance = new SVGImage((javax.microedition.m2g.SVGImage) javax.microedition.m2g.SVGImage.createImage(stream, null), animated);        return instance;    }    public static Image createSVGImage(java.lang.String url, boolean animated) throws IOException {        return createSVGImage(SVGImage.class.getResourceAsStream(url), animated);    }    /**     * Returns the width of the image     *      * @return the width of the image     */    public int getWidth() {        return im.getViewportWidth();    }    /**     * Returns the height of the image     *      * @return the height of the image     */    public int getHeight() {        return im.getViewportHeight();    }    void drawImage(Graphics g, int x, int y) {        ScalableGraphics svgGraphics = ScalableGraphics.createInstance();        javax.microedition.lcdui.Graphics gr = g.getGraphics();        gr.setClip(g.getTranslateX() + g.getClipX(), g.getTranslateY() + g.getClipY(), g.getClipWidth(), g.getClipHeight());        svgGraphics.bindTarget(gr);        svgGraphics.render(x + g.getTranslateX(), y + g.getTranslateY(), im);        svgGraphics.releaseTarget();    }    public Image scaled(int width, int height) {        im.setViewportWidth(width);        im.setViewportHeight(height);        return this;    }    public Image rotate(int degrees) {        Document dom = im.getDocument();        SVGSVGElement e = getSVGElement();        SVGPoint p = e.getCurrentTranslate();        p.setX(-getWidth()/2);        p.setY(-getHeight()/2);        e.setCurrentRotate(degrees);        p.setX(0);        p.setY(0);                return this;    }            public Document getDocument(){        return im.getDocument();    }        private SVGSVGElement getSVGElement(){        SVGSVGElement retVal = null;        Document dom = im.getDocument();        retVal = (SVGSVGElement)dom.getElementById(this.getClass().getName() + id);        if(retVal == null){            retVal = (SVGSVGElement) dom.createElementNS(SVG_NAMESPACE, "svg");            id = idCounter++;            retVal.setId(this.getClass().getName() + id);        }        return retVal;    }    public boolean animate() {        long currentTime = System.currentTimeMillis();        //if this is the first time init the start time.        if (startTime == -1) {            startTime = currentTime;        }        im.incrementTime((currentTime - startTime) / 1000.0f);        startTime = currentTime;        return animated;    }    public void paint(Graphics g) {    }    /**     * Returns true if this is an animated image     */    public boolean isAnimation() {        return true;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -