📄 softbutton.java
字号:
/********************************************************************
*
* 版权说明,此程序仅供学习参考。不能用于商业
*
********************************************************************/
package org.pook.ui;
import javax.microedition.lcdui.Graphics;
import org.pook.ui.core.Platform;
import org.pook.ui.event.CommandListener;
/**
* <b>类名:SoftButton.java</b> </br> 编写日期: 2006-9-14 <br/> 程序功能描述�? <br/> Demo:
* <br/> Bug: <br/>
*
* 程序变更日期 �?<br/> 变更作�?? �?<br/> 变更说明 �?<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public class SoftButton extends Part {
/** 软键 * */
private CommandListener commandListener;
private Command left;
private Command right;
private Command middle;
/**
* 构�?�固定位置的软键�?
*
*/
public SoftButton() {
super(0, Platform.HEIGHT - 20, Platform.WIDTH, Platform.HEIGHT);
}
/**
* 添加�?�?
*
* @param item
*/
public void addCommand(Command cmd) {
if (cmd.type == Command.LEFT)
this.left = cmd;
else if (cmd.type == Command.RIGHT) {
this.right = cmd;
} else if (cmd.type == Command.MIDDLE) {
this.middle = cmd;
}
}
/** 删除相应的Command */
public void removeCommand(int type) {
if (type == Command.LEFT)
left = null;
else if (type == Command.MIDDLE)
middle = null;
else if (type == Command.RIGHT)
right = null;
}
/**
* 注册监视�?
*/
public void setCommandListener(
CommandListener commandListener) {
this.commandListener = commandListener;
}
public void paint(Graphics g) {
paintCmdsImpl(g);
}
/**
* 绘制cmds
*/
private void paintCmdsImpl(Graphics g) {
fillCmdsClip(g);
paintCmdNames(g);
}
// 填充cmds区域
private void fillCmdsClip(Graphics g) {
if (Platform.HEIGHT - 20 > this.view[HEIGHT]) {
view[Y] = Platform.HEIGHT - 20;
view[HEIGHT] = Platform.HEIGHT;
}
g.setColor(bgColor);
g.fillRect(view[X], view[Y], view[WIDTH], view[HEIGHT]);
g.setColor(0x000000);
//画条白线
g.drawLine(view[X],view[Y],view[WIDTH],view[Y]);
}
private void paintCmdNames(Graphics g) {
g.setFont(this.font);
g.setColor(fontColor);
if (left != null) {
g.drawString(left.name, 2, view[Y] + 2, Graphics.TOP
| Graphics.LEFT);
}
if (middle != null) {
g.drawString(middle.name, view[WIDTH] / 2, view[Y] + 2,
Graphics.HCENTER | Graphics.TOP);
}
if (right != null) {
g.drawString(right.name, view[WIDTH] - 2, view[Y] + 2, Graphics.TOP
| Graphics.RIGHT);
}
}
/**
* 按钮的动�?
*/
public void onClick(int keyCode) {
if (this.commandListener == null)
return;
if (keyCode == Platform.KEY_SOFT_LEFT && cmdIsExist(left)) {
commandListener.commandAction(left);
} else if (keyCode == Platform.KEY_SOFT_RIGHT && cmdIsExist(right)) {
commandListener.commandAction(right);
} else if (keyCode == Platform.KEY_ENTER) {
if (cmdIsExist(left) && left.priority == Command.FIRST_PRIORITY) {
commandListener.commandAction(left);
return;
}
if (cmdIsExist(right) && right.priority == Command.FIRST_PRIORITY) {
commandListener.commandAction(right);
}
}
}
// 判断是否存在这个命令,如果为空,或�?�标题为""则表示不存在
private boolean cmdIsExist(Command cmd) {
if (cmd == null || cmd.equals(""))
return false;
else
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -