MultilineArrowControl.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.MOM.ui.control;
- import com.MOM.Constants;
- import com.MOM.resources.Resources;
- import com.framework.DisplayManager;
- import com.framework.GTantra;
- import com.framework.TextControl;
- import com.framework.UIControl;
- import com.framework.Util;
- import javax.microedition.lcdui.Graphics;
- /**
- *
- * @author Swaroop Kumar
- */
- public class MultilineArrowControl extends UIControl{
- TextControl control;
- boolean paintLeftArrow,paintRightArrow;
- int leftArrowColor = 0;
- public MultilineArrowControl(String text,boolean paintLeftArrow,boolean paintRightArrow,GTantra font) {
- setWidth(DisplayManager.getInst().getWidth());
- control = new TextControl(text, width - (Constants.LEFT_PADDING * 3)- Constants.RIGHT_ARROW_PADDING - Constants.LEFT_ARROW_WIDTH - Resources.getInstance().getFontRightArrow().getStringWidth(Constants.RIGHT_ARROW_TEXT), font, GTantra.TEXT_LEFT, false);
- control.setY(Constants.TOP_PADDING);
- setHeight(control.getHeight() + (Constants.TOP_PADDING * 2) );
- control.setX((Constants.LEFT_PADDING * 4) + Constants.LEFT_ARROW_WIDTH);
- control.setSelectionFont(font);
- this.paintLeftArrow = paintLeftArrow;
- this.paintRightArrow = paintRightArrow;
- }
- public void setSelectable(boolean selectable) {
- super.setSelectable(selectable);
- if(!selectable)
- {
- control.setY(0);
- setHeight(control.getHeight());
- if(getParent() != null)
- {
- getParent().resize();
- }
- }
- }
- public void setLeftArrowColor(int leftArrowColor) {
- this.leftArrowColor = leftArrowColor;
- }
- public void showNotify() {
- super.showNotify();
- control.showNotify();
- }
- public void hideNotify() {
- super.hideNotify();
- control.hideNotify();
- }
- public void setSelected(boolean selected) {
- super.setSelected(selected);
- control.setSelected(selected);
- }
- public void paint(Graphics g) {
- if(paintLeftArrow)
- {
- if(isSelected())
- {
- g.setColor(0xffffff);
- }else
- g.setColor(leftArrowColor);
- if(isSelectable())
- {
- Util.fillTriangle(g, Constants.LEFT_PADDING + Constants.LEFT_ARROW_WIDTH , (Constants.TOP_PADDING * 2)+ Constants.LEFT_ARROW_WIDTH , Constants.LEFT_ARROW_WIDTH << 1, 1);
- }else{
- Util.fillTriangle(g, Constants.LEFT_PADDING + Constants.LEFT_ARROW_WIDTH , Constants.TOP_PADDING + Constants.LEFT_ARROW_WIDTH , Constants.LEFT_ARROW_WIDTH << 1, 1);
- }
- }
- control.paintUI(g);
- if(paintRightArrow)
- {
- GTantra font = Resources.getInstance().getFontRightArrow();
- if(isSelected())
- {
- font.setColor(0xffffff);
- }else{
- font.setColor(0);
- }
- font.drawString(g, Constants.RIGHT_ARROW_TEXT, width - Constants.LEFT_PADDING - font.getStringWidth(Constants.RIGHT_ARROW_TEXT), (height - font.getFontHeight()) >> 1, GTantra.TEXT_LEFT);
- }
- if(isSelectable() && !isSelected())
- {
- g.setColor(0x999999);
- g.drawLine(0, 0, width, 0);
- g.drawLine(0, height -1, width , height - 1);
- }
- }
- public void setSelectionFont(GTantra font)
- {
- control.setSelectionFont(font);
- }
- }