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

📄 textviewerform.java

📁 textviewer 一个手机上的文本浏览器实现
💻 JAVA
字号:
package textViewer;import java.lang.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import java.io.InputStream;import java.util.Vector;public class TextViewerForm extends Form implements CommandListener, PageChangable {    private MIDlet myMidlet;    private Command moreCmd, gotoCmd, findCmd;    Command[] jumpCommands;    String[] jumpCommandStrings = {"Prev", "Jump +10", "Jump -10", "Jump +50", "Jump -50", "Jump +100", "Jump -100", "Jump +500", "Jump -500", "Jump +1000", "Jump -1000"};    int[] jumpCommandValues = {-1,10,-10,50,-50,100,-100,500,-500,1000,-1000};    private String text;        private StringItem textItem;    private StringItem pageString;     private GotoDialog gotoDialog;    private FindDialog findDialog;    private Paginator paginator;    private Vector pages;    private PageCounter pageCounter;    public TextViewerForm (String name, String text, MIDlet myMidlet) {	super(name);	this.myMidlet = myMidlet;	this.pageCounter = new PageCounter(this);	this.paginator = new Paginator();	initFormElems();	setInitText(text);    }    public void setInitText (String text) {	setText(text);    }    private void initFormElems() {	textItem = new StringItem("","");	/* PORTABILITY: "More" should not be of category BACK, but that's the only way I could get my Nokia Series 40 phone (6800) to display it outside of the menu -- priority alone didn't work, neither did ITEM or OK. It would have an "Options" menu and just leave the other soft menu slot blank. didn't try switching the ORDER yet, though! TODO*/	moreCmd = new Command("More", Command.BACK,1);	this.addCommand(moreCmd);	gotoCmd = new Command("Goto", Command.SCREEN,3);	this.addCommand(gotoCmd);	initJumpCommands();	findCmd = new Command("Find", Command.SCREEN,3);	this.addCommand(findCmd);	this.setCommandListener(this);	//	this.setItemStateListener(this);	this.append(textItem);	pageString = new StringItem(" -- \n","1");				  //TODO: constant	this.append(pageString);	gotoDialog = new GotoDialog(this, (Display.getDisplay(myMidlet)), pageCounter); 	// note that pageCounter must be initialized before this	findDialog = new FindDialog(this, (Display.getDisplay(myMidlet)), text, paginator, pageCounter);     }        private void initJumpCommands() {		jumpCommands = new Command[jumpCommandStrings.length];	for(int i=0; i<jumpCommands.length; i++) {	    jumpCommands[i] = new Command(jumpCommandStrings[i], Command.SCREEN,3);	    this.addCommand(jumpCommands[i]);	}    }    public void setText(String text)    {	this.text = text;	findDialog.setText(text);	pages = paginator.paginate(text);	//	pageField.setLabel("Goto page # (max " + Integer.toString(pages.size()) + "):");	pageCounter.setMax(pages.size());	pageChanged();	    }    public void commandAction(Command cmd, Displayable target)    {	if (target instanceof Form) {	    Form targetForm = (Form) target;	    if (targetForm == this) {		if (cmd == moreCmd) {		    pageCounter.addAsFarAsYouCan(1);		}		else if (handleJumpCommands(cmd)) {}		else if (cmd == gotoCmd) {		    gotoDialog.setMaxPage(pageCounter.getMax());		    (Display.getDisplay(myMidlet)).setCurrent(gotoDialog);		}		else if (cmd == findCmd) {		    (Display.getDisplay(myMidlet)).setCurrent(findDialog);		} 	    }	}     }    // TODO: cleanup previous    private boolean handleJumpCommands (Command cmd)    {	boolean ret = false;	for(int i=0; i<jumpCommands.length; i++)	    {		if (cmd == jumpCommands[i]) {		    pageCounter.addAsFarAsYouCan( jumpCommandValues[i] );		    ret = true;		    break;		}	    }		return ret;    }    private void gotoPage(int newPage)    {	pageCounter.setValue(newPage);    }    //    protected void pageChanged() {    public void pageChanged() {	textItem.setText((pages.elementAt(pageCounter.getValue()-1)).toString());	updatePageString();	System.gc();    }    protected void updatePageString() {		pageString.setText(Integer.toString(pageCounter.getValue()));   }   public int getTextChunkLength() {return paginator.getTextChunkLength();}}

⌨️ 快捷键说明

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