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

📄 readerframe.java

📁 JAVA手机的电子书编辑器以及阅读器
💻 JAVA
字号:
/* * @(#)PhotoFrame.java	1.3 03/09/26 * * Copyright (c) 2000-2003 Sun Microsystems, Inc. All rights reserved.  * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms */package com.zmc.ebook.reader;import java.util.Vector;import javax.microedition.lcdui.*;/** * This PhotoFrame provides the picture frame and drives the animation * of the frames and the picture. It handles the starting and stopping * of the Animation and contains the Thread used to do * the timing and requests that the Canvas be repainted * periodically. * It controls the border style and animation speed. */class ReaderFrame extends Canvas{    private int[] paragraphOffset = new int[4000];    private int pCount = 0;            private String content;       private int totalLen = 0;//    private Vector paragraphs;    private int currentParagraph;    private int forColorIdx = 0;    private int backColorIdx = 3;    //     0 "Black"    //     1 "Green"    //     2 "Blue"    //     3 "White"    //     4 "Red"    int backColor = 0xffffff;    int forColor = 0;    //Color     public void setContent(String content)    {        this.content = content;//        this.totalLen = content.length();                int len = content.length();	System.out.println("ContentLen:" + len);	        totalLen = len;    }        public void setCurrentParagraph(int p)    {        currentParagraph = p;        int fh = 17;        int fw = 16;        int w = this.getWidth();        int h = this.getHeight();        int wpl = w/16 -1;                int lines = h / fh ;                 //       paragraphs = new Vector(len/wpl*lines);        int idx = 0;        int offset = idx;        int cw = 0;        int cl = 0;//        char[] aline = new char[2 * w / fw];//        this.paragraphs.addElement(aPage);                pCount = 0;        this.paragraphOffset[pCount++] = 0;                while (idx < totalLen && pCount <= currentParagraph )        {            char ch = content.charAt(idx++);            if (ch == '\r' || ch == '\n') //new line            {//                aPage.addLine(offset, idx); // new String(aline, 0, cw));                cw = 0;                if (idx < (totalLen-1) && content.charAt(idx + 1) == '\n')                    idx++;                	                offset = idx;                cl++;                if (cl >= lines) //new page                {  //                  aPage = new PageContent();                    this.paragraphOffset[pCount++] = idx;//                    this.paragraphs.addElement(aPage);                    cl = 0;                }            }            cw++;            if (cw > wpl) //new line            {//                aPage.addLine(offset, idx); //new String(aline, 0, cw));                cw = 0;                cl++;                if (cl >= lines) //new page                {//                    aPage = new PageContent();                    this.paragraphOffset[pCount++] = idx;//                    this.paragraphs.addElement(aPage);                    cl = 0;                }                 offset = idx;            }        }                repaint();    }    public void setForgroundColor(int idx)    {        this.forColorIdx = idx;        switch (idx)        {        case 0:            forColor = 0;            break;        case 1:            forColor = 0x00ff00;            break;        case 2:            forColor = 0x0000ff;            break;        case 3:            forColor = 0xffffff;            break;        case 4:            forColor = 0xff0000;            break;        }        repaint();    }    public void setBackgroundColor(int idx)    {        this.backColorIdx = idx;        switch (idx)        {        case 0:            backColor = 0;            break;        case 1:            backColor = 0x00ff00;            break;        case 2:            backColor = 0x0000ff;            break;        case 3:            backColor = 0xffffff;            break;        case 4:            backColor = 0xff0000;            break;        }        repaint();    }    public int getForgroundColor()    {        return this.forColorIdx;    }    public int getBackgroundColor()    {        return this.backColorIdx;    }    public int getCurrentParagraph()    {        return this.currentParagraph;    }    ReaderFrame()    {    }    /**     * Advance to the next image and wrap around if necessary.     */    void next()    {        if( this.paragraphOffset[currentParagraph]<totalLen)        {	        this.currentParagraph++;        }        repaint();    }    /**     * Back up to the previous image.     * Wrap around to the end if at the beginning.     */    void previous()    {        if( currentParagraph > 0 )        {            currentParagraph--;            repaint();        }    }    /**     * Reset the PhotoFrame so it holds minimal resources.     * The animation thread is stopped.     */    void reset()    {    }    /**     * Handle key events. FIRE events toggle between     * running and stopped.  LEFT and RIGHT key events     * when stopped show the previous or next image.     * @param keyCode of the key pressed     */    protected void keyPressed(int keyCode)    {        int action = getGameAction(keyCode);        switch (action)        {        case RIGHT:            next();            break;                    case DOWN:            next();            break;        case UP:            previous();            break;                    case LEFT:            previous();            break;        }    }    /**     * Handle key repeat events as regular key events.     * @param keyCode of the key repeated     */    protected void keyRepeated(int keyCode)    {        keyPressed(keyCode);    }    /**      * Paint is called whenever the canvas should be redrawn.     * It clears the canvas and draws the frame and the current      * current frame from the animation.     * @param g the Graphics context to which to draw     */    protected void paint(Graphics g)    {        int w = g.getClipWidth();        int h = g.getClipHeight();        g.setColor(backColor);        //        g.setGrayScale(255);        g.fillRect(0, 0, w, h);        //paint the scroll bar        g.setColor(0xc0c0c0);        g.drawLine(0, 0, w, 0);        g.drawLine(0, 2, w, 2);        //        g.setColor(0xffffff);        g.drawLine(0, 1, w, 1);        //        g.setColor(0x0000ff);        if( pCount == 0)            pCount = 1;         //       int p = (w*(currentParagraph + 1)) / pCount ;           int p = (w * paragraphOffset[currentParagraph] )/totalLen;        g.drawLine(0, 0, p, 0);        g.drawLine(0, 1, p, 1);                g.setColor(forColor);                int fh = 17;        int fw = 16;        int wpl = w/16 -1;                int lines = h / fh ;//        int len = content.length(); //       paragraphs = new Vector(len/wpl*lines);        int idx = this.paragraphOffset[this.currentParagraph];        int offset = idx;        int cw = 0;        int cl = 0;//        char[] aline = new char[2 * w / fw];//        this.paragraphs.addElement(aPage);                 int y = 2;                while (idx < totalLen)        {            char ch = content.charAt(idx++);            if (ch == '\r' || ch == '\n') //new line            {               	g.drawString( content.substring(offset, idx).trim(), 0, y + cl *17, 0 );//                aPage.addLine(offset, idx); // new String(aline, 0, cw));                cw = 0;                if (idx < (totalLen-1) && content.charAt(idx + 1) == '\n')                    idx++;                	                offset = idx;                cl++;                if (cl >= lines) //new page                {                    break;                }            }            cw++;            if (cw > wpl) //new line            {//                aPage.addLine(offset, idx); //new String(aline, 0, cw));               	g.drawString( content.substring(offset, idx).trim(), 0, y + cl *17, 0 );                cw = 0;                cl++;                if (cl >= lines) //new page                {                    break;                }                 offset = idx;            }        }                this.paragraphOffset[currentParagraph + 1] = idx;            }}

⌨️ 快捷键说明

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