📄 panel.java
字号:
package org.gggeye.easymf.ui;
import java.util.Hashtable;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import org.gggeye.easymf.log.Logger;
import org.gggeye.easymf.midlet.MIDletManager;
public class Panel extends Canvas{
/**
* 行距
*/
public static byte ROW_SPACE = 0;
public static byte SCROLL_SPACE = 6;
public static int width;
public static int height;
public static int viewWidth;
public static int viewStartY;
public static int viewHeight ;
public static int labelHeight ;
public static Font defaultFont = Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_PLAIN, Font.SIZE_SMALL);
/**
* 菜单
*/
Menu menu;
/**
* 事件监听器
*/
/**
* UI 容器
*/
Container container;
HtmlDocument document;
protected ViewBuilder viewBuilder;
ProcessView process;
/**
* 浏览控制的构造体
* @param xWeb
*/
public Panel(String _title) {
initScreenParameter();
container = new Container(this);
document = new HtmlDocument();
document.title = _title;
viewBuilder = new ViewBuilder(document);
this.container.htmlDocument = document;
}
protected void paint(Graphics g) {
long start = System.currentTimeMillis();
Pen tPen = new Pen(g);
doPaint(tPen);
container.doDrawTitle(tPen);
container.doDrawMenu(tPen);
if(menu != null)
menu.doPaint(g);
if(process != null)
process.doPaint(tPen, this.document);
long end = System.currentTimeMillis();
Logger.info("绘制消耗时间==>" + (end-start));
}
/**
* 子类实现这个东西的时候
* 绘制的是一个实体
* @param _pen
*/
protected void doPaint(Pen _pen){
this.container.doPaintViews(_pen);
}
private void initScreenParameter() {
this.setFullScreenMode(true);
width = this.getWidth();
height = this.getHeight();
labelHeight = defaultFont.getHeight();
viewStartY = labelHeight;
viewWidth = width - SCROLL_SPACE - 4;
viewHeight = height - labelHeight*2;
}
protected void keyRepeated(int _keyCode) {
// _keyCode = this.converKey(_keyCode);
// doClick(_keyCode);
}
protected void keyReleased(int _keyCode) {
}
protected void pointerPressed(int x, int y) {
}
protected void pointerReleased(int x, int y) {
}
protected void pointerDragged(int x, int y) {
}
protected void keyPressed(int _keyCode) {
_keyCode = this.converKey(_keyCode);
doClick(_keyCode);
}
private void doClick(int _keyCode) {
if(this.menu != null){
menu.doClick(_keyCode);
}
if(menu != null && menu.isOpen){
if(_keyCode == 8){
menu.isOpen = false;
}
return;
}
this.container.doClick(_keyCode);
this.repaint();
}
/**
* 物理键值转换成自定义键值
* @param _keyCode -- 物理键值
* @return
*/
private int converKey(int _keyCode){
try{
if(_keyCode == -6 || _keyCode == -7)
return _keyCode;
int gameKey = this.getGameAction(_keyCode);
return gameKey;
}catch(Exception e){
Logger.debug(e);
return _keyCode;
}
}
public final void setMenu(Menu _menu){
this.menu = _menu;
}
public final void setEventListener(EventListener _eventListener){
this.container.setEventListener(_eventListener);
//if(this.menu == )
}
public final void show(){
MIDletManager.show(this);
}
public final int size(){
return this.document.size();
}
public ViewBuilder getViewBuilder(){
return this.viewBuilder;
}
public void clearViews(){
this.viewBuilder.reset();
}
public View getFocusView(){
try{
return (View)this.document.getFocusView();
}catch(Exception e){
Logger.debug(e);
}
return null;
}
public void insert(View _view, int _index){
}
public void append(View _view){
this.viewBuilder.addView(_view);
this.repaint();
}
public void delete(int _index){
this.viewBuilder.delete(_index);
this.repaint();
}
public void delete(View _item){
this.viewBuilder.delete(_item);
this.repaint();
}
public Hashtable getKeyValues(HtmlForm _htmlForm) {
return this.document.getKeyValues(_htmlForm);
}
public void setProcess(ProcessView _process){
this.process = _process;
}
/**
* 特殊的View
* @param _process
*/
public void activeProcess(){
if(process != null)
process.active();
}
public void cancelProcess(){
if(process != null)
process.cancel();
this.repaint();
}
public View findViewByName(String _name){
return this.document.findViewByName(_name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -