⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uibase.java

📁 j2me开发框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				if( isLetter(ch) ){
					continue;
				}
				else if( ch == 32){
					index -= i; 
					break;
				}
				else {
					break;
				}
			}
		}
		return index;
	}
	
	private boolean isLetter(char a){
		int ascii = (int)a;
		if( ascii >=65 && ascii <= 90 ){
			return true;
		}
		else if(ascii >=97 && ascii <= 122){
		    return true;
		}
		else 
			return false;
	}
		
	/**
	 * 通知容器,自己的尺寸发生变化
	 */
	protected void sizeChange(){
	    if(owner != null){
	    	owner.notifySizeChange(this);
	    }
	}
	
	/**
	 * 设置相对坐标X轴值(相对于容器)
	 */
	protected void setX(int x){
		this.bonds[0][0] = x;
	}
	
	/**
	 * 设置相对坐标Y轴值(相对于容器)
	 */
	protected void setY(int y){
		this.bonds[0][1] = y;

	}
	
	/**
	 * 获取在屏幕上的X坐标值
	 * @return
	 */
	public int getX(){
		if(owner == null)
		    return this.bonds[0][0];
		else
			return owner.getX()+ this.bonds[0][0] + owner.xOffset;
	}
	
	/**
	 * 获取在屏幕上的Y坐标值
	 * @return
	 */
	public int getY(){
		if(owner == null)
		    return this.bonds[0][1];
		else
			return owner.getY()+ this.bonds[0][1] + owner.yOffset;
	}
	
	/**
	 * 设置行高
	 * @param h
	 */
	public void setLineHeight(int h){
		this.lineHeight = h;
	}
	
	public int getLineHeight(){
		if( this.lineHeight > 0 ){
			return this.lineHeight;
		}
		else{
			Style s = this.getStyle();
			return s.dfont.getHeight() + s.paddingTop + s.paddingBottom;
		}
	}
	
	/**
	 * 设置对象的样式 
	 * @param style
	 */
	public void setStyle(Style style){
		if( this.getStyle() != style){
		    this.style = style;
		    //样式变化,通知容器
		    this.sizeChange();
		}
	}
	
	/**
	 * 获取对象的有效样式
	 */
	public Style getStyle(){
		if( this.style != null){
			return this.style;
		}
		else if( owner != null){
			return owner.getStyle();
		}
		else{
			return Style.getDefaultStyle();
		}
	}
	
	/**
     * 把空间自身画在屏幕上
     */
	public void paint(Graphics g) {
		//Logger.info("Painting:" + this.getString());
		//画单行
		if( this.lineNum == 1 && !this.overflow ){
			this.paintOneLine(g);
		}
		else if(this.lineNum == 1 && this.overflow ){
			this.paintScrollLine(g);
		}
		else if( this.autoLineWrap && this.lineNum > 1){
			this.paintMutiLine(g);
		}	    
	}
	/**
	 * 画单行
	 * @param g
	 */
	private void paintOneLine(Graphics g){	
		//Logger.debug(this.getString());
		Style s = this.getStyle();
		int x = this.getX();
		int y = this.getY();
		int w = bonds[1][0]-bonds[0][0];
		int h = bonds[1][1]-bonds[0][1];	    	
	    Image offImage = Image.createImage(w,h);	    	
	    Graphics offGraphics = offImage.getGraphics();
	    //设置背景颜色	       
	    offGraphics.setColor(this.hasFocus()?s.bColorFocus:s.bColorNormal);
	    offGraphics.fillRoundRect(0, 0, w, h, s.rountWidth, s.roundHeight);	        		
        if(!this.hasFocus()){
        	if( s.bImageLeftTop != null){
        	    offGraphics.drawRegion(s.bImageLeftTop, x, y<0?0:y, w, h, Sprite.TRANS_NONE, 0, y<0?-y:0, Graphics.LEFT|Graphics.TOP);
        	}
        }
        //设置文字颜色
        offGraphics.setColor(this.hasFocus()?s.fColorFocus:s.fColorNormal);
        offGraphics.setFont(s.dfont);
        offGraphics.drawString(this.string, s.paddingLeft, s.paddingTop, Graphics.LEFT | Graphics.TOP);
	   
	    //设置可见区域	  
        if( y + h > owner.vHeight){
        	h = owner.vHeight - y;
        }
        g.setClip(x, y, w, h);
        g.drawImage(offImage, x, y, Graphics.TOP | Graphics.LEFT);
	}
       
	
	
	/**
	 * 画跑马灯单行
	 * @param g
	 */
	private void paintScrollLine(Graphics g){
		Style s = getStyle(); 
		//画背景颜色
		g.setColor(this.hasFocus()?s.bColorFocus:s.bColorNormal);
		g.setFont(s.dfont);
		int x = getX();
		int y = getY();
		int w = bonds[1][0]-bonds[0][0];
		int h = bonds[1][1]-bonds[0][1];
		if( y + h > owner.vHeight){
			h = owner.vHeight - h;
		}
		//设置文字的可视区域
		g.setClip(x, y, w, h);
		g.fillRoundRect(x, y, w, h, s.rountWidth, s.roundHeight);
		x += s.paddingLeft;
		y += s.paddingTop;
		//设置可视区域
		g.setClip(x, y, w -s.paddingLeft-s.paddingRight, h );
		g.setColor(this.hasFocus()?s.fColorFocus:s.fColorNormal);
		x += this.offset;
		g.drawString(this.string, x, y, Graphics.LEFT | Graphics.TOP);
	}
	
	/**
	 * 画多行
	 * @param g
	 */
	private void paintMutiLine(Graphics g){
		Logger.debug("paintMutiLine");
		boolean paintNext = true;
		int charOffset = 0;
		Style s = getStyle(); 
		//画背景颜色
		g.setColor(this.hasFocus()?s.bColorFocus:s.bColorNormal);
		g.setFont(s.dfont);
		int x = getX();
		int y = getY();
		int h = this.lineHeight;
		int w = owner.getWidth() - x - owner.getStyle().paddingRight;
		if( y + h > owner.vHeight){
			h = owner.vHeight - h;
			paintNext = false;
		}
		//设置文字的可视区域
		g.setClip(x, y, w, h);
		g.fillRoundRect(x, y, w-5,h, s.rountWidth, s.roundHeight);
		
		x += s.paddingLeft;
		y += s.paddingTop;
		w = w - s.paddingLeft - s.paddingRight;
		//设置可视区域
		g.setClip(x, y, w , h );
		g.setColor(this.hasFocus()?s.fColorFocus:s.fColorNormal);
		g.drawSubstring(this.string, charOffset, this.lineCharNum[0], x, y,Graphics.LEFT | Graphics.TOP);

		charOffset += this.lineCharNum[0];
		int line = 1;
		w = owner.getWidth() - owner.getStyle().paddingLeft - owner.getStyle().paddingRight;
		while(paintNext && line < this.lineNum ){
			x = owner.getStyle().paddingLeft;
		    y = y + this.lineHeight + s.marginBottom - s.paddingTop;
		    if( y + this.lineHeight > owner.vHeight){
				h = owner.vHeight - this.lineHeight;
				paintNext = false;
			}
		    //如果是最后一行
		    if( line == this.lineNum -1 ){
		    	w = this.bonds[1][0];
		    }
		    
		    //设置文字的可视区域
		    g.setClip(x, y, w, h);
		    g.setColor(this.hasFocus()?s.bColorFocus:s.bColorNormal);			
			g.fillRoundRect(x, y, w-5,h, s.rountWidth, s.roundHeight);
			x = owner.getStyle().paddingLeft + s.paddingLeft;
			y += s.paddingTop;
			
			//设置可视区域
			g.setClip(x, y, w-s.paddingLeft-s.paddingRight, h );			
			g.setColor(this.hasFocus()?s.fColorFocus:s.fColorNormal);
			g.drawSubstring(this.string, charOffset, this.lineCharNum[line], x, y,Graphics.LEFT | Graphics.TOP);
			charOffset += this.lineCharNum[line];			
			line++;
		}
	}
	
	/**
	 * 溢出部分的移动
	 */
	public void move() {
	    if(!this.hasFocus() || !this.overflow || !this.enable ) return;
        if(this.offset == 0){
        	this.firstStopCnt--;
    		if(this.firstStopCnt >= 0){
    			return;
    		}
        }
        if(this.lastStopCnt > 0 &&  this.offset + this.overflowWidth > 0){
        	this.offset -= Config.CHARMOVE_OFFSET;        	
        }
        else if( this.lastStopCnt > 0){
        	this.lastStopCnt--;
        	return;
        }
        else{
        	this.offset = 0;
        	firstStopCnt = Config.FIRST_STOPCOUNT;
        	lastStopCnt  = Config.LAST_STOPCOUNT;
        }
        //画元素本身
        Stage.getInstance().notifyRepaint(this);
	}
	
	/**
	 * 判断该容器是否位于可见视窗中
	 * @return
	 */
	public boolean isInViewer(){
		int firstH = getY();
		int lastH  = firstH + this.bonds[1][1]-this.bonds[0][1];
		if( firstH >= 0 && lastH <= owner.vHeight ){
			return true;
		}
		else if(firstH >=0 && firstH + this.lineHeight <= owner.vHeight){
			return true;
		}
		else if( firstH <= 0 && lastH >= 5 ){
			return true;
		}
		else if( firstH <= 0 && lastH >= owner.vHeight){
		    return true;
		}
		else{
		    return false;	
		}
	}
	
	public abstract String getTypeName();
	
	public void setLayout(int l){
		this.layout = l;
	}
	
	public int getLayout(){
		return this.layout;
	}
	
	public void debug(){
	    String debugStr = "[" + this.getString() + "]\r\n" +
	                      "     X=" + this.getX() + ",Y=" + this.getY() +
	                      "     Line=" + this.lineNum + ",Line Height:" + this.lineHeight + "\r\n" +
	                      "     POS[0]= [" + this.bonds[0][0] + "," + this.bonds[0][1] + "]" +  
	                      "     POS[1]= [" + this.bonds[1][0] + "," + this.bonds[1][1] + "]" +
	                      "     Container X=" + owner.getX() + ",Y=" + owner.getY()+",W=" + owner.getWidth();
	    Logger.info(debugStr);
	    //Logger.info(this.lineCharNum);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -