www.pudn.com > WordTip.zip > ViewAll.java
/*
* Created on 2005-1-27
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.hyweb.ui;
import java.io.IOException;
import javax.microedition.lcdui.*;
import net.hyweb.wordmodel.*;
/**
* @author user
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ViewAll extends List implements CommandListener{
private UIController uicontroller;
private Model model;
private Image image;
private Command exitCommand;
private Command deleteCommand;
private Command detailCommand;
private Word[] word = null;
/**
* @param arg0
* @param arg1
* @throws IllegalArgumentException
*/
public ViewAll(UIController uicontroller) throws IllegalArgumentException {
super("ViewAll", List.IMPLICIT);
this.uicontroller = uicontroller;
model = new Model();
image = this.createImage("/icon1.png");
this.detailCommand = new Command("Detail", Command.ITEM, 1);
this.deleteCommand = new Command("Delete", Command.ITEM, 2);
this.exitCommand = new Command("Back", Command.BACK, 3);
this.addCommand(this.detailCommand);
this.addCommand(this.deleteCommand);
this.addCommand(this.exitCommand);
setCommandListener(this);
}
/**
* 刷新浏览单词列表
* 在刷新的清空步骤中,要首先 “反向” 删除List中的内容
* 如果正向删除,会导致列表在删到后一半的时候出现外溢
*/
public void refresh(){
Word[] words = model.ViewAll();
//首先删除所有信息
int iCount = this.size();
for(int j = iCount - 1; j >= 0; j --){
this.delete(j);
}
if(words == null){
return;
}
//列出所有单词信息
for(int i = 0; i < words.length; i++){
this.append(words[i].getEnWord(), image);
}
}
public void refresh_Search(){
if(this.word == null){
return;
}else{
int iCount = this.size();
for(int j = iCount - 1; j >= 0; j --){
this.delete(j);
}
//列出所有单词信息
for(int i = 0; i < this.word.length; i++){
this.append(word[i].getEnWord(), image);
}
}
}
public Image createImage(String name){
Image image = null;
try {
image = Image.createImage(name);
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
public void commandAction(Command command, Displayable display) {
if(command.equals(this.detailCommand)){
int i = this.getSelectedIndex();
if(i < 0){
uicontroller.EventController(EventID.ALERT_EMPTY);
}else{
uicontroller.EventController(EventID.DETAILED_WORD, new Object[]{this.getString(i)});
}
}else if(command.equals(this.deleteCommand)){
int i = this.getSelectedIndex();
if(i < 0){
uicontroller.EventController(EventID.ALERT_EMPTY);
}else{
uicontroller.EventController(EventID.DELETE_WORD, new Object[]{this.getString(i), new Integer(i)});
}
}else{
uicontroller.EventController(EventID.UI_MAIN);
}
}
/**
* @return Returns the word.
*/
public Word[] getWord() {
return word;
}
/**
* @param word The word to set.
*/
public void setWord(Word[] word) {
this.word = word;
}
}