日期:2014-05-20 浏览次数:20774 次
public abstract class Part { protected final int X = 0; protected final int Y = 1; protected final int WIDTH = 2; protected final int HEIGHT = 3; /** * 位置的显示位置(相对手机屏幕的位置) */ protected int view[] = new int[4]; /** * 背景色 */ protected int bgColor = 0x000000; /** * 字体颜色 */ protected int fontColor = 0xFFFFFF; protected int selectIndex; protected Canvas container; protected String label; /** 每个Item都有自己的焦点 **/ protected boolean hasFocus; protected PartChangeListener partChangeListener; public Part(int x, int y, int widht, int height) { view[X] = x; view[Y] = y; view[WIDTH] = widht; view[HEIGHT] = height; } public void setStyle(int bgColor, int fontColor) { this.bgColor = bgColor; this.fontColor = fontColor; } /** * 默认字体 */ protected Font font = Font.getDefaultFont(); /** * 资料实现绘制方法 * * @param g */ public abstract void paint(Graphics g); /** * 事件 * * @param keyCode */ public abstract void onClick(int keyCode); public int getSelectIndex() { return selectIndex; } public void setSelectIndex(int selectIndex) { this.selectIndex = selectIndex; } /** * 改变部件的位置 */ public void changePosition(int x, int y, int width, int height){ view[X] = x; view[Y] = y; view[WIDTH] = width; view[HEIGHT] = height; } public void setContainer(Canvas container) { this.container = container; } /** * 聚焦,主要用户当前使用的Part。 * @param hasFocus */ public void setHasFocus(boolean hasFocus){ this.hasFocus = hasFocus; } public void setPartChangeListener(PartChangeListener partChangeListener) { this.partChangeListener = partChangeListener; } public int[] getView() { return view; }
public abstract class Panel extends Canvas { private static Log log = Log.getLog("Panel"); final int X = 0; final int Y = 1; final int WIDTH = 2; final int HEIGHT = 3; /** 显示主要部分.比如菜单的Icon,List的数据的位置 */ int[] viewContent = new int[4]; Image icon; Part part; SoftButton softButton; Part timer; public Panel(){ init(); } public Panel(Image icon) { init(); this.icon = icon; //此方法是让所以的Panel都添加一个TimerPart //以后重构的时候应该???虑要不要这么做 //this.setTimer(null); } private void init() { setFullScreenMode(true); initViewContent(); this.softButton = new SoftButton(); } public void addCommand(Command cmd) { if (cmd == null) return; softButton.addCommand(cmd); } public Part getPart() { return part; } public void append(Part part){ this.part = part; } public void setPartChangeListener(PartChangeListener partChangeListener) { this.part.setPartChangeListener(partChangeListener); } public void removeCommand(int type) { softButton.removeCommand(type); } public void setSoftButtonListener(CommandListener cmdListener) { if (softButton != null) softButton.setCommandListener(cmdListener); } public void setSoftButtonStyle(int bgColor, int fontColor){ this.softButton.setStyle(bgColor, fontColor); } public abstract void paint(Graphics g); protected abstract void keyPressed(int keyCode); /** * 长按事件 */ protected void keyRepeated(int keyCode) { keyPressed(keyCode); } private void initViewContent() { viewContent[X] = 0; viewContent[Y] = 45; viewContent[WIDTH] = Platform.WIDTH; viewContent[HEIGHT] = Platform.HEIGHT; } public SoftButton getSoftButton() { return softButton; } public void setSoftButton(SoftButton softButton) { this.softButton = softButton; } /** * 增加时间显示 */ public void setTimer(Part timer){ this.timer = timer; } void paintTimerImpl(Graphics g){ if(timer != null) timer.paint(g); } public void repaintTimer(){ if(timer != null){ int [] view = timer.getView(); repaint(view[X],view[Y],view[WIDTH], view[HEIGHT] ); } } }