?? searchscreen.java
字號:
package org.zblog.zenghelper.screen;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import org.zblog.zenghelper.util.Navigator;
import org.zblog.zenghelper.dbtool.WordGroup;
import org.zblog.zenghelper.dbtool.EnWord;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Choice;
import java.util.Vector;
import org.zblog.zenghelper.dbtool.CnWord;
import org.zblog.zenghelper.dbtool.NumGenerator;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.Item;
import org.zblog.zenghelper.screen.sub.DelWordScreen;
/**
* <br><strong>Z英語學習助手-英漢查詢屏幕</strong><br>
* <br>該屏幕包括:
* <br>1.一個TextField(用于輸入英或漢關鍵字)
* <br>2.一個choiceGroup(用于列表查詢結果,主要是為了再次對查詢結果進行搜索)
* <br>3.一個Back按鈕用于返回主菜單
* <br>4.其它Command:查詢,詳細信息,解釋查詢
* @author <a href="mailto:zcw@zblog.org">朱傳偉</a><br>
* <a href="http://www.zblog.org">www.zblog.org</a></p>
* @version <strong>ZEnHelper</strong> Ver 1.0
*/
public class SearchScreen extends Form implements CommandListener,ItemStateListener{
private static SearchScreen instance;
private TextField text=null;
public ChoiceGroup cgp=null;
private Command back=null;
private Command search=null;
private Command info=null;
private Command summary=null;
private Command delete=null;
//當前查詢的類型:"英漢查詢"或"漢英查詢"
public boolean isEn=true;
//當前查詢關鍵字在RMS中rsId
public int current =-1;
public Vector currentIds=null;
private SearchScreen(){
super("英漢查詢");
text=new TextField(null,"",100,TextField.ANY);
cgp=new ChoiceGroup("查詢結果",Choice.EXCLUSIVE);
append(text);
append(cgp);
back=new Command("返回",Command.BACK,1);
search=new Command("查詢",Command.ITEM,1);
summary=new Command("查詢解釋",Command.ITEM,2);
info=new Command("詳細信息",Command.ITEM,3);
addCommand(search);
addCommand(back);
//addCommand(summary);
//addCommand(info);
setCommandListener(this);
setItemStateListener(this);
}
/**
* 清除該對象的各種屬性,將對象還原為初始狀態,因為該類的對象采用static方式創建,所以
* 有時需要將對象的屬性還原為初始狀態.
*/
public void clear(){
text.setString(null);
for(int n=cgp.size()-1;n>=0;n--)
cgp.delete(n);
current=-1;
currentIds=null;
removeCommand(delete);
removeCommand(summary);
removeCommand(info);
}
/**
* 該方法是工廠方法,用于創建SearchScreen對象
* @return SearchScreen
*/
public synchronized static SearchScreen getInstance(){
if(instance==null)
instance=new SearchScreen();
else
instance.clear();
return instance;
}
/**
* CommandListener回調方法,用于捕獲該類定義的幾的Command
* @param command Command
* @param displayable Displayable
*/
public void commandAction(Command command, Displayable displayable) {
String lb=command.getLabel();
if(lb.equals("返回")){
//clear();
Navigator.current=Navigator.Main_Screen;
Navigator.show();
}
else if(lb.equals("查詢")){
search();
}
else if(lb.equals("詳細信息")){
showInfo();
}
else if(lb.equals("查詢解釋")){
searchSummary();
}
else if(lb.equals("刪除單詞")){
Navigator.show(new DelWordScreen("單詞",this));
}
else if(lb.equals("刪除解釋")){
Navigator.show(new DelWordScreen("解釋",this));
}
}
/**
* 對于"查詢"的操作方法,查詢完畢后,將查詢的類型和rsId分別保存到isEn和current屬性中,
* 如果沒有找到待查詢的關鍵字,則將代表rsId的屬性current置為-1.
*/
private void search(){
String word=text.getString();
if(word!=null&&!word.equals("")){
word=word.trim();
WordGroup wg=new WordGroup(word);
isEn=wg.isen;
current=wg.searchWord(word);
}
else{
current=-1;
}
showResult();
}
/**
* 針對"查詢解釋"的操作:<br>
* 查詢解釋,主要是根據用戶選擇的解釋,把解釋作為查詢"關鍵字"進行逆向查詢.
*/
private void searchSummary(){
if(current!=-1&¤tIds.size()>0){
int i=cgp.getSelectedIndex();
current=Integer.parseInt((String)currentIds.elementAt(i));
isEn=!isEn;
showResult();
}
}
/**
* 顯示查詢結果方法:<br>
* 本方法一般是在執行完查詢后調用,以顯示查詢結果.
*/
private void showResult(){
//首先清除以前的查詢結果
for(int n=cgp.size()-1;n>=0;n--)
cgp.delete(n);
//顯示查詢結果
removeCommand(delete);
removeCommand(summary);
removeCommand(info);
if(current!=-1){
//設置刪除Command
if(isEn)
delete=new Command("刪除單詞",Command.ITEM,4);
else
delete=new Command("刪除解釋",Command.ITEM,4);
addCommand(delete);
//添加查詢解釋Command
addCommand(summary);
//顯示查詢結果
String str=null;
if(isEn){
//添加查看詳細信息Command
addCommand(info);
EnWord ew=new EnWord(current);
text.setString(ew.word);
Vector cns=ew.cnRSId;
currentIds=cns;
Vector adjs=ew.cnAdj;
CnWord tcw=null;
for(int i=0;i<cns.size();i++){
tcw=new CnWord(Integer.parseInt((String)cns.elementAt(i)));
str=adjs.elementAt(i)+"."+tcw.word;
cgp.append(str,null);
}
}
else{
CnWord cw=new CnWord(current);
text.setString(cw.word);
Vector ens=cw.enRSId;
currentIds=ens;
EnWord tew=null;
for(int i=0;i<ens.size();i++){
tew=new EnWord(Integer.parseInt((String)ens.elementAt(i)));
cgp.append(tew.word,null);
}
}
}
}
/**
* 顯示單詞的詳細信息方法,該方法只對"英漢查詢"時有效.主要是顯示該單詞的詳細信息.
* 包括單詞,英標,是否生詞,中文解釋.用戶可以在該頁面中對單詞的所有屬性進行修改,
* 然后提交修改后的單詞.
*/
private void showInfo(){
if(isEn&¤t!=-1){
EnWord tew=new EnWord(current);
AddWordScreen aws=AddWordScreen.getInstance();
aws.enWord=tew.word;
aws.rsId=tew.rsId;
aws.groupId=NumGenerator.getInstance().getWordNum(tew.word,true);
aws.senId=tew.senId;
if(tew.senId==-1)aws.sen = false;
else aws.sen=true;
String[]ybs=tew.ybs;
if(ybs!=null&&ybs.length>0){
for(int i=0;i<ybs.length;i++){
aws.ybs.addElement(ybs[i]);
}
}
Vector tcns=tew.cnRSId;
Vector tadjs=tew.cnAdj;
CnWord tcw=null;
if(tcns!=null&&tcns.size()>0){
for(int i=0;i<tcns.size();i++){
tcw=new CnWord(Integer.parseInt((String)tcns.elementAt(i)));
aws.cnWords.addElement(tadjs.elementAt(i)+"."+tcw.word);
}
}
Navigator.show(aws);
}
}
/**
* 偵探text中關鍵字的改變,如果有改變則,清除查詢結果
* @param item Item
*/
public void itemStateChanged(Item item) {
if(item==text){
for(int n=cgp.size()-1;n>=0;n--){
cgp.delete(n);
}
removeCommand(delete);
removeCommand(summary);
removeCommand(info);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -