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

📄 tabbar.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					//#ifdef polish.midp2
						g.fillTriangle(x, y + halfWidth-1, x + this.scrollArrowHeight, y, x + this.scrollArrowHeight, y + this.scrollArrowHeight );
					//#else
						//# g.drawLine( x, y + halfWidth-1, x + this.scrollArrowHeight, y );
						//# g.drawLine( x + this.scrollArrowHeight, y, x + this.scrollArrowHeight, y + this.scrollArrowHeight);
						//# g.drawLine( x, y + halfWidth-1, x + this.scrollArrowHeight, y  + this.scrollArrowHeight );
					//#endif
			//#ifdef polish.css.tabbar-left-arrow
				//# }
			//#endif
			x += this.scrollArrowHeight + this.scrollArrowPadding;
			//#if polish.css.tabbar-roundtrip
				//# if (this.allowRoundtrip) {
					//# originalX = x;
				//# }
			//#endif
		}
			
		//#if polish.css.tabbar-roundtrip
			//# if ( this.allowRoundtrip || this.activeTabIndex < this.tabs.length - 1 ) {
		//#else
			if ( this.activeTabIndex < this.tabs.length - 1 ) {
		//#endif		
			// draw right scrolling indicator:
			rightBorder -=  (this.scrollArrowHeight + this.scrollArrowPadding);
			//#ifdef polish.css.tabbar-right-arrow
				//# if (this.rightArrow != null) {
					//# g.drawImage(this.rightArrow, rightBorder + this.arrowXOffset, y + this.arrowYOffset, Graphics.LEFT |  Graphics.TOP );
				//# } else {
			//#endif
					int halfWidth = this.scrollArrowHeight / 2;
					//#ifdef polish.midp2
						g.fillTriangle(rightBorder, y, rightBorder, y  + this.scrollArrowHeight, rightBorder + this.scrollArrowHeight, y + halfWidth - 1 );
					//#else
						//# g.drawLine( rightBorder, y, rightBorder, y  + this.scrollArrowHeight );
						//# g.drawLine( rightBorder, y, rightBorder + this.scrollArrowHeight, y + halfWidth - 1);
						//# g.drawLine( rightBorder, y  + this.scrollArrowHeight, rightBorder + this.scrollArrowHeight, y + halfWidth - 1);
					//#endif
			//#ifdef polish.css.tabbar-right-arrow
				//# }
			//#endif
			rightBorder -=  this.scrollArrowPadding;
		}

		// draw the tabs:
		y -= (cHeight - this.scrollArrowHeight) / 2;
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipWidth = g.getClipWidth();
		int clipHeight = g.getClipHeight();
		g.setClip( x, y, rightBorder - x, clipHeight);
		x = originalX + this.xOffset;
		for (int i = 0; i < this.tabs.length; i++) {
			ImageItem tab = this.tabs[i];
			int tabHeight = tab.itemHeight;
			tab.paint( x, y + (cHeight - tabHeight), leftBorder, rightBorder, g );
			x += tab.itemWidth;
		}
		g.setClip( clipX, clipY, clipWidth, clipHeight);		
	}

	//#ifdef polish.useDynamicStyles	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#createCssSelector()
	 */
	protected String createCssSelector() {
		return "tabbar";
	}
	//#endif
	

	public void setStyle(Style style) {
		super.setStyle(style);
		//#ifdef polish.css.tabbar-scrolling-indicator-color
			//# Integer scrollColorInt = style.getIntProperty(47);
			//# if (scrollColorInt != null) {
				//# this.scrollArrowColor = scrollColorInt.intValue();
			//# }
		//#endif
		//#ifdef polish.css.tabbar-left-arrow
			//# String leftArrowUrl = style.getProperty(155);
			//# if (leftArrowUrl != null) {
				//# try {
					//# this.leftArrow = StyleSheet.getImage(leftArrowUrl, this, false);
					//# this.scrollArrowHeight = this.leftArrow.getHeight();
				//# } catch (IOException e) {
					//#debug error
					//# System.out.println("Unable to load tabbar-left-arrow " + leftArrowUrl);
				//# }
			//# }
		//#endif
		//#ifdef polish.css.tabbar-right-arrow
			//# String rightArrowUrl = style.getProperty(156);
			//# if (rightArrowUrl != null) {
				//# try {
					//# this.rightArrow = StyleSheet.getImage(rightArrowUrl, this, false);
					//# this.scrollArrowHeight = this.rightArrow.getHeight();
				//# } catch (IOException e) {
					//#debug error
					//# System.out.println("Unable to load tabbar-right-arrow " + rightArrowUrl);
				//# }
			//# }
		//#endif
		//#ifdef polish.css.tabbar-arrow-y-offset
			//# Integer arrowYOffsetInt = style.getIntProperty(157);
			//# if (arrowYOffsetInt != null) {
				//# this.arrowYOffset = arrowYOffsetInt.intValue();
			//# }
		//#endif
		//#ifdef polish.css.tabbar-arrow-x-offset
			//# Integer arrowXOffsetInt = style.getIntProperty(157);
			//# if (arrowXOffsetInt != null) {
				//# this.arrowXOffset = arrowXOffsetInt.intValue();
			//# }
		//#endif
		//#if polish.css.tabbar-roundtrip
			//# Boolean allowRoundtripBool = style.getBooleanProperty(158);
			//# if (allowRoundtripBool != null) {
				//# this.allowRoundtrip = allowRoundtripBool.booleanValue();
			//# }
		//#endif
	}
	
	
	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#handleKeyPressed(int, int)
	 */
	protected boolean handleKeyPressed(int keyCode, int gameAction) {
		//#if polish.css.tabbar-roundtrip
			//# if (this.allowRoundtrip) {
				//# if (gameAction == Canvas.RIGHT) {
					//# this.nextTabIndex = this.activeTabIndex + 1;
					//# if (this.nextTabIndex >= this.tabs.length) {
						//# this.nextTabIndex = 0;
					//# }
					//# return true;
				//# } else if (gameAction == Canvas.LEFT) {
					//# this.nextTabIndex = this.activeTabIndex - 1;
					//# if (this.nextTabIndex < 0) {
						//# this.nextTabIndex = this.tabs.length - 1;
					//# }		
					//# return true;
				//# }
			//# }
		//#endif
		if (gameAction == Canvas.RIGHT && this.activeTabIndex < this.tabs.length -1 ) {
			this.nextTabIndex = this.activeTabIndex + 1;
			return true;
		} else if (gameAction == Canvas.LEFT && this.activeTabIndex > 0) {
			this.nextTabIndex = this.activeTabIndex - 1;
			return true;
		}
		return super.handleKeyPressed(keyCode, gameAction);
	}

	//#ifdef polish.hasPointerEvents
	//# protected boolean handlePointerPressed(int x, int y) {
		//# if (y < this.yTopPos || y > this.yBottomPos || x < this.xLeftPos || x > this.xRightPos ) {
			//# return false;
		//# }
		//# //System.out.println( "pointer-pressed: " + x + ", " + y);
		//# int scrollerWidth = this.scrollArrowHeight + 2 * this.scrollArrowPadding; 
		//# if ( (this.activeTabIndex > 0 || this.allowRoundtrip) && x <= scrollerWidth ) {
			//# //System.out.println("left: x <= " + scrollerWidth );
			//# int index = this.activeTabIndex - 1;
			//# if (index < 0) {
				//# index = this.tabs.length - 1;
			//# }
			//# this.newActiveTabIndex = index;
		//# } else if ( (this.activeTabIndex < this.tabs.length -1 || this.allowRoundtrip) && x >= this.xRightPos - scrollerWidth) {
			//# //System.out.println("right: x >= " + (this.xRightPos - scrollerWidth) );
			//# this.newActiveTabIndex = (this.activeTabIndex + 1) % this.tabs.length;
		//# } else {
			//# int width = this.xOffset;
			//# if (this.activeTabIndex > 0 || this.allowRoundtrip) {
				//# width += scrollerWidth;
			//# }
			//# for (int i = 0; i < this.tabs.length; i++) {
				//# ImageItem tab = this.tabs[i];
				//# if ( x >= width && x <= width + tab.itemWidth) {
					//# //System.out.println("i-1=" + i + ": x <= " + tab.xLeftPos + ", x <= " + tab.xRightPos );
					//# this.newActiveTabIndex = i;
					//# return true;
				//# }
				//# width += tab.itemWidth;
			//# }
			//# this.newActiveTabIndex = this.tabs.length - 1;
		//# }
//# 		
		//# return true;
	//# }
	//#endif

	/**
	 * Sets the image for the specified tab.
	 * 
	 * @param tabIndex the index of the tab 
	 * @param image the image
	 */
	public void setImage(int tabIndex, Image image) {
		this.tabs[tabIndex].setImage(image);		
	}
	
	/**
	 * Sets the text for the specified tab.
	 * 
	 * @param tabIndex the index of the tab 
	 * @param text the text
	 */
	public void setText(int tabIndex, String text ) {
		this.tabs[tabIndex].setAltText(text);		
	}

	/**
	 * Retrieves the index of the currently selected tab.
	 * 
	 * @return the index of the currently selected tab, 0 is the index of the first tab.
	 */
	public int getNextTab() {
		return this.nextTabIndex;
	}

}

⌨️ 快捷键说明

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