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

📄 notemanagerui.java

📁 手机记事本程序
💻 JAVA
字号:
/*
 * Created on 2005-3-3
 *
 * Note Project
 */
package com.favo.note;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDletStateChangeException;

import com.favo.ui.BaseController;
import com.favo.ui.BaseView;

/**
 * @author Favo
 * 
 * NoteListUI <<boundary>>
 */
public class NoteManagerUI extends BaseView implements CommandListener {

	List list;//screen object

	NoteManagerWorkflow noteListWorkflow;

	Command exitCommand;

	Command openCommand;

	Command deleteCommand;

	Command editCommand;

	/**
	 * 构造函数
	 * 
	 * @param noteListWorkflow
	 *            控制器
	 */
	public NoteManagerUI(NoteManagerWorkflow noteListWorkflow) {
		super();
		this.noteListWorkflow = noteListWorkflow;
		noteListWorkflow.setView(this);
	}

	public Display getDisplay() {
		return NoteMidlet.getDisplay();
	}

	public Displayable getScreen() {
		return list;
	}

	protected void createView() throws Exception {
		String[] noteTitleArray = ((NoteManagerWorkflow) getController())
				.getNoteTitleList();
		list = new List("Welcome to Note", Choice.IMPLICIT, noteTitleArray,
				null);
		list.insert(0, "New Note", null);
		exitCommand = new Command("Exit", Command.EXIT, 3);
		openCommand = new Command("Open", Command.ITEM, 1);
		deleteCommand = new Command("Delete", Command.ITEM, 3);
		editCommand = new Command("Edit", Command.ITEM, 2);
		list.addCommand(exitCommand);
		list.addCommand(openCommand);
		list.addCommand(deleteCommand);
		list.addCommand(editCommand);
		list.setSelectCommand(openCommand);
		list.setCommandListener(this);
	}

	public void updateView() throws Exception {
		list.deleteAll();
		list.insert(0, "New Note", null);
		String[] noteTitleArray = ((NoteManagerWorkflow) getController())
				.getNoteTitleList();
		for (int i = 0; i < noteTitleArray.length; i++) {
			list.append(noteTitleArray[i], null);
		}
	}

	public BaseController getController() {
		return noteListWorkflow;
	}

	/**
	 * 显示所选则的笔记
	 * 
	 * @param index
	 *            索引
	 */
	public void showNote(int index) {
		((NoteManagerWorkflow) getController()).showNoteDispose(index);
	}

	/**
	 * 删除所选则的笔记
	 * 
	 * @param index
	 *            索引
	 */
	public void deleteNote(int index) {
		((NoteManagerWorkflow) getController()).deleteNoteDispose(index);
	}

	/**
	 * new Note
	 */
	public void newNote() {
		((NoteManagerWorkflow) getController()).newNoteDispose();
	}

	public void editNote(int index) {
		((NoteManagerWorkflow) getController()).editNoteDispose(index);
	}

	public void commandAction(Command arg0, Displayable arg1) {
		List l = (List) arg1;
		if (arg0 == openCommand) {
			int selectedNum = l.getSelectedIndex();
			if (selectedNum == 0) {//if new note
				newNote();
			} else {
				showNote(selectedNum - 1);
			}
		} else if (arg0 == deleteCommand) {
			int selectedNum = l.getSelectedIndex();
			if (selectedNum == 0) {//if new note just Test
				Alert al = new Alert("Sorry", "please choose a note first",
						null, AlertType.ALARM);
				getDisplay().setCurrent(al);
			} else {
				deleteNote(selectedNum - 1);
			}
		} else if (arg0 == editCommand) {
			int selectedNum = l.getSelectedIndex();
			if (selectedNum == 0) {//if new note just Test
				Alert al = new Alert("Sorry", "please choose a note first",
						null, AlertType.ALARM);
				getDisplay().setCurrent(al);
			} else {
				editNote(selectedNum - 1);
			}
		} else if (arg0 == exitCommand) {
			try {
				NoteMidlet.getMidlet().destroyApp(false);
			} catch (MIDletStateChangeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			NoteMidlet.getMidlet().notifyDestroyed();
		}
	}

}

⌨️ 快捷键说明

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