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

📄 midpsvgcanvas.java

📁 一个mobile svg
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            alertError("Not in SVGT format");        }        finally        {            try            {               if (is != null) is.close();               if (c != null) c.close();            }            catch( IOException ioe) {}        }        load = false;        return doc;    }    /**     * Draws the canvas     * @param g The Graphics surface.     */    protected void paint(Graphics g)    {        // pixels        if(!load)        {           TinyPixbuf pixbuf = raster.getPixelBuffer();           // NOKIA UI Series 60/*           com.nokia.mid.ui.DirectGraphics dg = com.nokia.mid.ui.DirectUtils.getDirectGraphics(g);           dg.drawPixels(               pixbuf.pixels32,false,               0,               pixbuf.width,               0,               0,               pixbuf.width,               pixbuf.height,               0,               com.nokia.mid.ui.DirectGraphics.TYPE_INT_8888_ARGB);*//**/           // MIDP2.0           g.drawRGB(                pixbuf.pixels32,               0,               pixbuf.width,               0,               0,               pixbuf.width,               pixbuf.height,               false); /**/        }        else //if(load)        {           //draw the clock           g.setColor(0xffffff);           g.fillRect(0,0,width,height);           g.setColor(0x000000);           g.drawString("Wait ...", width/2, height/2,  Graphics.LEFT|Graphics.TOP);           if(wait!=null)           {              g.drawImage(wait,0,height-MENU_HEIGHT,                                g.TOP|g.LEFT);           }        }    }    /**     * Handle keyboard input.     * @param keyCode pressed key.     */    protected void keyRepeated(int keyCode)    {        keyPressed(keyCode);    }    /**     * Handle keyboard input.     * @param keyCode pressed key.     */    protected void keyPressed(int keyCode)    {        if(load) return;        int action = getGameAction(keyCode);        SVGEvent  event = null;        switch (action)        {             case Canvas.LEFT:                 if(mode == MODE_LINK)                 {                      event = new SVGEvent(SVGEvent.EVENT_FOCUSPREV, null );                      postEvent(event);                 }                 else if(mode == MODE_PAN)                 {                      event = new SVGEvent(SVGEvent.EVENT_SCROLL,new TinyPoint(-PAN_STEP,0));                      postEvent(event);                 }                 else if(mode == MODE_NEXTPREV)                 {                      previous();                 }                 break;             case Canvas.RIGHT:                 if(mode == MODE_LINK)                 {                      event = new SVGEvent(SVGEvent.EVENT_FOCUSNEXT, null );                      postEvent(event);                 }                 else if(mode == MODE_PAN)                 {                      event = new SVGEvent(SVGEvent.EVENT_SCROLL,new TinyPoint(PAN_STEP,0));                      postEvent(event);                 }                 else if(mode == MODE_NEXTPREV)                 {                      next();                 }                 break;             case Canvas.UP:                 if(mode == MODE_LINK)                 {                      event = new SVGEvent(SVGEvent.EVENT_FOCUSPREV, null );                      postEvent(event);                 }                 else if(mode == MODE_PAN)                 {                      event = new SVGEvent(SVGEvent.EVENT_SCROLL,new TinyPoint(0,-PAN_STEP));                      postEvent(event);                 }                 else if(mode == MODE_ZOOM)                 {                      event = new SVGEvent(SVGEvent.EVENT_ZOOM, new TinyNumber(0));                      postEvent(event);                 }                 break;             case Canvas.DOWN:                 if(mode == MODE_LINK)                 {                      event = new SVGEvent(SVGEvent.EVENT_FOCUSNEXT, null );                      postEvent(event);                 }                 else if(mode == MODE_PAN)                 {                      event = new SVGEvent(SVGEvent.EVENT_SCROLL,new TinyPoint(0,PAN_STEP));                      postEvent(event);                 }                 else if(mode == MODE_ZOOM)                 {                      event = new SVGEvent(SVGEvent.EVENT_ZOOM, new TinyNumber(1));                      postEvent(event);                 }                 break;             case Canvas.FIRE:                 if(mode == MODE_LINK)                 {                      event = new SVGEvent(SVGEvent.EVENT_FOCUSPRESSED, null);                      postEvent(event);                 }                 break;        } // end of switch    }    /**     * Go to the given image and update controls.     * @param i index of the given image.     */    void go(int i)    {        index = i;        goImpl(index);    }    /**     * The go implemetation.     * @param i index of the given image.     */    private void goImpl(int i)    {        if( (bookmarkList == null) ||  (bookmarks == null) ) return;        // update the List seletced position        bookmarkList.setSelectedIndex(i,true);        Bookmark bookmark = (Bookmark)bookmarks.elementAt(i);        if(bookmark == null) return;        goURL(bookmark.url);    }    /**     * Advance to the next image and wrap around if necessary.     */    void next()    {        if( bookmarks == null ) return;        if ( index == bookmarks.size()-1)        {            return;        }        index++;        goImpl(index);    }    /**     * Back up to the previous image.     * Wrap around to the end if at the beginning.     */    void previous()    {        if (index == 0)        {            return;        }        index--;        goImpl(index);    }    /**     * Fetch the image.  If the name begins with "http:"     * fetch it with connector.open and http.     * If it starts with "/" then load it from the     * resource file.     * @param      name of the image to load     * @return     image created     * @exception  IOException if errors occuring doing loading     */    private Image createImage(String name) throws IOException    {        if (name.startsWith("/"))        {            // Load as a resource with Image.createImage            if(name.endsWith(".png"))            {                return Image.createImage(name);            }            else                throw new IOException("Expecting PNG image");        }        else if (name.startsWith("http:"))        {            // Load from a ContentConnection            HttpConnection c = null;            DataInputStream is = null;            try            {               c = (HttpConnection)Connector.open(name);               int status = c.getResponseCode();               if (status != 200)               {                  throw new IOException("HTTP Response Code = " + status);               }               int len = (int)c.getLength();               String type = c.getType();               if (!type.equals("image/png"))               {                  throw new IOException("Expecting image, received " + type);               }               if (len > 0)               {                   is = c.openDataInputStream();                   byte[] data = new byte[len];                   is.readFully(data);                   return Image.createImage(data, 0, len);               }               else               {                  throw new IOException("Content length is missing");               }            }            finally            {               if (is != null)                    is.close();               if (c != null)                    c.close();            }        }        else        {            throw new IOException("Unsupported media");        }    } //////////////////////////////////////////////////////////////////    /**     * Posts an event to the event queue.     *     * @param theEvent an instance of Event, or a     * subclass of it.     */    public synchronized void postEvent(SVGEvent theEvent)    {        //IMPORTANT        theEvent.eventTarget = this;        eventQueue.postEvent(theEvent);    }    /*     * Methods inherited from interface org.w3c.dom.events.EventTarget     */    /**     * <b>uDOM:</b> This method allows the registration of event listeners on the event target.     *     * @param type The event type for which the user is registering     *     * @param listener The listener parameter takes an interface implemented by the     * user which contains the methods to be called when the event occurs.     *     * @param useCapture If true, useCapture indicates that the user wishes     * to initiate capture. After initiating capture, all events of the     * specified type will be dispatched to the registered EventListener     * before being dispatched to any EventTargets beneath them in the tree.     * Events which are bubbling upward through the tree will not trigger an     * EventListener designated to use capture.     */     public void addEventListener(java.lang.String type,                                  org.w3c.dom.events.EventListener listener,                                  boolean useCapture)     {        listeners.addElement(listener);     }     /**      * <b>uDOM:</b> This method allows the removal of event listeners from the event target.      *      * @param type Specifies the event type of the EventListener being removed.      * @param listener The listener parameter indicates the EventListener to be removed.      * @param useCapture Specifies whether the EventListener being removed was      * registered as a capturing listener or not.      */     public void removeEventListener(java.lang.String type,                                org.w3c.dom.events.EventListener listener,                                boolean useCapture)     {        int i = listeners.indexOf(listener,0);        if(i>0)        {          listeners.removeElementAt(i);        }     }     /**      * <b>uDOM:</b> This method allows the dispatch of events into the implementations event model.      * Events dispatched in this manner will have the same behavior as events dispatched      * directly by the implementation.      *      * @param evt  Specifies the event type, behavior, and contextual      * information to be used in processing the event.      * @return    The return value of dispatchEvent indicates whether      * any of the listeners which handled the event called preventDefault.      * If preventDefault was called the value is false, else the value is true.      */     public boolean dispatchEvent(org.w3c.dom.events.Event evt)     {        org.w3c.dom.events.EventListener h;        for(int i=0; i < listeners.count; i++)        {           h = (org.w3c.dom.events.EventListener)listeners.data[i];           if(h!=null) h.handleEvent(evt);        }        return true;     }     /**      * Display error message.      * @param message the error message      */     void alertError(String message)     {        Alert alert = new Alert("Error", message, null, AlertType.ERROR);        Displayable current = display.getCurrent();        if (!(current instanceof Alert))        {            alert.setTimeout(Alert.FOREVER);            // This next call can't be done when current is an Alert            display.setCurrent(alert, current);        }     }}

⌨️ 快捷键说明

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