SoftkeyBar.java
资源名称:src.zip [点击查看]
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:4k
源码类别:
J2ME
开发平台:
Java
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.framework;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- /**
- *
- * @author Swaroop Kumar
- */
- public class SoftkeyBar {
- GTantra font;
- private int height,width;
- private Image bgImage;
- private UiDisplayble parentScreen;
- private TickerTextControl left;
- private TickerTextControl right;
- private EventManager eventManager;
- private int bgColor = -1;
- protected SoftkeyBar(UiDisplayble screen) {
- this.parentScreen = screen;
- resize();
- }
- public void setFont(GTantra font) {
- this.font = font;
- }
- public String getSoftKeyText(int position)
- {
- if(position == Graphics.LEFT && left != null)
- {
- return left.getText();
- }else if(position == Graphics.RIGHT && right != null)
- {
- return right.getText();
- }else
- return "";
- }
- protected boolean pointerReleased(int x, int y) {
- if(eventManager != null)
- {
- if(left != null)
- {
- if(Util.isInRect(left, x, y))
- {
- eventManager.event(EventManager.LEFT_SOFT_KEY_PRESSED, this,null);
- return true;
- }
- }if(right != null)
- {
- if(Util.isInRect(right, x, y))
- {
- eventManager.event(EventManager.RIGHT_SOFT_KEY_PRESSED, this,null);
- return true;
- }
- }
- }
- return false;
- }
- public boolean keyPressed(int keyCode)
- {
- if(eventManager != null)
- {
- if(left != null && keyCode == KeyEvent.KEY_SOFT_LEFT)
- {
- eventManager.event(EventManager.LEFT_SOFT_KEY_PRESSED, this,null);
- return true;
- }else if(right != null && keyCode == KeyEvent.KEY_SOFT_RIGHT)
- {
- eventManager.event(EventManager.RIGHT_SOFT_KEY_PRESSED, this,null);
- return true;
- }
- }
- return false;
- }
- public void setEventManager(EventManager manager)
- {
- eventManager = manager;
- }
- public void resize()
- {
- width = DisplayManager.getInst().getWidth();
- if(font != null)
- {
- height = font.getFontHeight() + (Theme.DEFAULT_PADDING << 1);
- }
- if(left != null)
- {
- height = Math.max(height, left.getHeight());
- }if(right != null)
- {
- height = Math.max(height, right.getHeight());
- }
- if(bgImage != null)
- {
- height = Math.max(height, bgImage.getHeight());
- }
- }
- public void setBgImage(Image bgImage) {
- this.bgImage = bgImage;
- }
- public void paintUi(Graphics g)
- {
- if(bgColor != -1)
- {
- g.setColor(bgColor);
- g.fillRect( 0, DisplayManager.getInst().getHeight() - height , width , height);
- }
- if(bgImage != null)
- {
- g.drawImage(bgImage, 0, DisplayManager.getInst().getHeight() - height, 0);
- }
- if(left != null)
- {
- left.paintUI(g);
- }if(right != null)
- {
- right.paintUI(g);
- }
- }
- public void setSetSoftkey(int position,String text)
- {
- if(position == Graphics.LEFT)
- {
- left = new TickerTextControl(text, font);
- left.setPoistion(0, DisplayManager.getInst().getHeight() - left.getHeight());
- }else if(position == Graphics.RIGHT)
- {
- right = new TickerTextControl(text, font);
- right.setPoistion(DisplayManager.getInst().getWidth() - right.getWidth(), DisplayManager.getInst().getHeight() - right.getHeight());
- }
- invalidate();
- }
- public void invalidate()
- {
- resize();
- parentScreen.invalidate();
- }
- public int getHeight() {
- return height;
- }
- public void setBgColor(int bgColor) {
- this.bgColor = bgColor;
- }
- public int getWidth() {
- return width;
- }
- }