?? textreader.java
字號:
/*
* Created on 2004-10-21
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.zmc.ebook.reader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Screen;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
/**
* TextReader <br>
* Copyright (c) 2000, 2004 e-Channels Corporation <br>
* <br>
* Created on 2004-10-21 <br>
*
* @author ZHONGMC <br>
* <br>
* Last modified on 2004-10-21 <br>
* Last modified by ZHONGMC <br>
*
* <p>
* Comment here
* </p>
*
*/
public class TextReader extends MIDlet implements CommandListener, ItemStateListener, Runnable
{
/** The Command object for the About command */
private Command aboutCommand;
/** The Command object for the Exit command */
private Command exitCommand;
/** The Command object for the Ok command */
private Command okCommand;
/** The Command object for the Options command */
private Command optionsCommand;
/** The Command object for the Back command */
private Command backCommand;
/** The Command object for the Cancel command */
private Command cancelCommand;
/** The Form object for the Progress form */
private Form progressForm;
/** The Gauge object for the Progress gauge */
private Gauge progressGauge;
/** The Form object for the Options command */
private Form optionsForm;
/** Set of choices for the border styles */
private ChoiceGroup forColorChoice;
/** Set of choices for the speeds */
private ChoiceGroup backColorChoice;
/** The current display for this MIDlet */
private Display display;
/** The PhotoFrame that displays images */
private ReaderFrame frame;
/** The Alert for messages */
private Alert alert;
/** Contains Strings with the file names */
private Vector fileNames;
/** List of Image titles for user to select */
private List chapterList;
/** Name of current image, may be null */
private String fileName;
/** Current thread loading images, may be null */
private Thread thread;
/** Name of persistent storage */
private final String optionsName = "PhotoAlbum";
/** Persistent storage for options */
private RecordStore optionsStore;
private boolean firstTime = true;
private int curChapter = 0;
private int curPagraph = 0;
public TextReader()
{
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 1);
optionsCommand = new Command("選項", Command.SCREEN, 1);
okCommand = new Command("確認", Command.OK, 3);
backCommand = new Command("返回", Command.BACK, 3);
cancelCommand = new Command("取消", Command.CANCEL, 1);
aboutCommand = new Command("About", Command.HELP, 30);
frame = new ReaderFrame();
// frame.setStyle(2);
// frame.setSpeed(2);
frame.addCommand(optionsCommand);
frame.addCommand(backCommand);
frame.setCommandListener(this);
alert = new Alert("Warning");
setupChapterList();
firstTime = true;
}
/**
* Check the attributes in the descriptor that identify chapter files and
* titles and initialize the lists of file and imageList.
* <P>
* The attributes are named "Chapter-n" and "ChapterTitle-n". The value "n"
* must start at "1" and increment by 1.
*/
private void setupChapterList()
{
fileNames = new Vector();
chapterList = new List("chapters", List.IMPLICIT);
chapterList.addCommand(exitCommand);
chapterList.addCommand(aboutCommand);
chapterList.setCommandListener(this);
for (int n = 1; n < 20; n++)
{
String nthChapter = "Chapter-" + n;
String file = getAppProperty(nthChapter);
if (file == null || file.length() == 0)
break;
String nthTitle = "ChapterTitle-" + n;
String title = getAppProperty(nthTitle);
if (title == null || title.length() == 0)
title = file;
fileNames.addElement(file.trim());
chapterList.append(title, null);
}
System.out.println("Set to curChapter:" + curChapter);
chapterList.setSelectedIndex(curChapter, true);
}
/*
* (non-Javadoc)
*
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException
{
if (firstTime)
{
if (chapterList.size() > 0)
{
display.setCurrent(chapterList);
openOptions();
restoreOptions();
}
else
{
alert.setString("No chapters configured.");
display.setCurrent(alert, chapterList);
}
firstTime = false;
}
openOptions();
restoreOptions();
}
/*
* (non-Javadoc)
*
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp()
{
saveOptions();
}
/*
* (non-Javadoc)
*
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
saveOptions();
closeOptions();
frame.reset(); // Discard images cached in the frame.
}
/*
* (non-Javadoc)
*
* @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command,
* javax.microedition.lcdui.Displayable)
*/
public void commandAction(Command c, Displayable s)
{
if (c == exitCommand)
{
// Cleanup and notify that the MIDlet has exited
try
{
destroyApp(false);
notifyDestroyed();
} catch (Exception e)
{
}
}
else if (c == optionsCommand)
{
// Display the options form
display.setCurrent(genOptions());
}
else if (c == okCommand && s == optionsForm)
{
// Return to the PhotoFrame, the option values have already
// been saved by the item state listener
display.setCurrent(frame);
}
else if (c == List.SELECT_COMMAND)
{
// Display the progress screen and
// start the thread to read the images
int i = chapterList.getSelectedIndex();
fileName = (String) fileNames.elementAt(i);
display.setCurrent(genProgress(chapterList.getString(i)));
thread = new Thread(this);
thread.start();
}
else if (c == backCommand)
{
// Display the list of chapters.
display.setCurrent(chapterList);
}
else if (c == cancelCommand)
{
// Signal thread to stop and put an alert.
thread = null;
alert.setString("Loading File cancelled.");
display.setCurrent(alert, chapterList);
}
else if (c == aboutCommand)
{
About.showAbout(display);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -