📄 dialog.java
字号:
/********************************************************************
*
* 版权说明,此程序仅供学习参考。不能用于商业
*
********************************************************************/
package org.pook.ui.form;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import org.pook.log.Log;
import org.pook.ui.Command;
import org.pook.ui.SoftButton;
import org.pook.ui.core.Platform;
import org.pook.ui.event.CommandListener;
import org.pook.ui.timer.TimerTaskManager;
/**
* <b>类名:Dialog.java</b> </br> 编写日期: 2006-9-16 <br/>
* 程序功能描述:弹出窗�?,因为足球项目要求很多的弹出窗口的形式不同�?�? 定义�?个抽象的弹出窗口,把基本的功能再这个实�?,以下的�?�么绘制则交给具体的要求
* <br/> Demo: <br/> Bug: <br/>
*
* 程序变更日期 �?<br/> 变更作�?? �?<br/> 变更说明 �?<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public abstract class Dialog extends Canvas implements Runnable {
private static Log log = Log.getLog("Dialog");
protected final int X = 0;
protected final int Y = 1;
protected final int WIDTH = 2;
protected final int HEIGHT = 3;
/** 显示主要部分.比如菜单的Icon,List的数据的位置 */
protected int[] view = new int[4];
/** Preset alternative containing OK */
public static final int DIALOG_OK = 0;
/** Preset alternative containing CANCEL = 1 */
public static final int DIALOG_CANCEL = 2;
/** Preset alternatives containing YES and NO */
public static final int DIALOG_YES_NO = 3;
/** Preset alternatives containing OK and CANCEL */
public static final int DIALOG_OK_CANCEL = 4;
/** Preset alternatives containing YES, NO, and CANCEL */
public static final int DIALOG_YES_NO_CANCEL = 5;
public static final int DIALOG_TEXT = 6;
/**
* 保存当前窗口,主要用�?�是,当前对话筐消失的时�??,要求重绘�?. 永远刷新父类
*/
protected Panel parent;
protected boolean hasFocus;
/**
* 定义超时参数
*/
long timeOut;
/**
* 对话框类�?
*/
int type;
/** 对话框标�? */
protected String title;
/**
* 把单行标题转换为多行以方便显�?
*/
protected String[] rowTitle;
protected int bgColor;
protected int fontColor;
protected Font font = Font.getDefaultFont();
/** 用于执行消失窗口 */
protected TimerTask task;
protected Display display;
protected SoftButton softButton;
/**
* 构�?�一个默认的标题,父类的窗�?
*
* @param title
* @param parent
*/
public Dialog(String title, Panel parent, Display display) {
this(title, parent, display, 3000);
}
/**
* 构�?�一个指定时间的构�?�窗�?
*
* @param title
* @param parent
* @param timeOut
*/
public Dialog(String title, Panel parent, Display display, long timeOut) {
this(title, parent, display, Dialog.DIALOG_OK, timeOut);
}
/**
* 构�?�一个指定窗口类�?,时间的窗�?
*
* @param title
* @param parent
* @param type
* @param timeOut
*/
public Dialog(String title, Panel parent, Display display, int type,
long timeOut) {
setFullScreenMode(true);
this.parent = parent;
checkParent();
this.timeOut = timeOut;
this.type = type;
this.title = title;
this.display = display;
softButton = new SoftButton();
if (timeOut != 0)
task = TimerTaskManager.getInstace().add(this, timeOut);
//设置默认的风�?
setStyle(0x0033FF, 0xFFFFFF);
}
public void setStyle(int bgColor, int fontColor) {
this.bgColor = bgColor;
this.fontColor = fontColor;
}
public void cancel() {
//log.debug("Stop...");
if (parent == null)
throw new NullPointerException("Parent is not Null.");
task.cancel();
if(parent == null)
return;
display.setCurrent(parent);
}
public void addCommand(Command cmd) {
this.softButton.addCommand(cmd);
}
public void setSoftButtonListener(CommandListener cml) {
this.softButton.setCommandListener(cml);
}
public void setSoftButtonStyle(int bgColor, int fontColor){
this.softButton.setStyle(bgColor, fontColor);
}
public void run() {
cancel();
}
/** 绘制透明�? * */
public void drawRGB(Graphics g) {
int ai[] = new int[Platform.WIDTH];
for (int j1 = 0; j1 < ai.length; j1++)
ai[j1] = 0x90000000;
g.drawRGB(ai, 0, 0, 0, 0, Platform.WIDTH, Platform.HEIGHT, true); // 绘制透明景色
}
private void checkParent() {
if (parent == null){
throw new NullPointerException("Parent is not null");
}
}
protected void keyPressed(int keyCode) {
softButton.onClick(keyCode);
}
public void setPanel(Panel panel) {
this.parent = panel;
}
public void setTimeOut(long timeOut) {
this.timeOut = timeOut;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -