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

📄 exclusivesinglelineview.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		//#ifdef polish.css.exclusiveview-arrow-position			Integer positionInt = style.getIntProperty("exclusiveview-arrow-position");			if ( positionInt != null ) {				this.arrowPosition = positionInt.intValue();			}			//#ifdef polish.css.exclusiveview-arrow-padding				Integer arrowPaddingInt = style.getIntProperty("exclusiveview-arrow-padding");				if (arrowPaddingInt != null) {					this.arrowPadding = arrowPaddingInt.intValue();//				} else {//					this.arrowPadding = style.paddingHorizontal;				}			//#endif		//#endif		//#ifdef polish.css.exclusiveview-roundtrip			Boolean allowRoundTripBool = style.getBooleanProperty("exclusiveview-roundtrip");			if (allowRoundTripBool != null) {				this.allowRoundTrip = allowRoundTripBool.booleanValue();			}		//#endif	}			/* (non-Javadoc)	 * @see de.enough.polish.ui.ContainerView#paintContent(int, int, int, int, javax.microedition.lcdui.Graphics)	 */	protected void paintContent(int x, int y, int leftBorder, int rightBorder,			Graphics g) 	{		//#debug		System.out.println("ExclusiveView.start: x=" + x + ", y=" + y + ", leftBorder=" + leftBorder + ", rightBorder=" + rightBorder );		this.xStart = x;		int modifiedX = x;		//#ifdef polish.css.exclusiveview-expand-background			if (this.expandBackground && this.background != null) {				this.currentItem.background = null;				this.background.paint(x, y, this.contentWidth, this.contentHeight, g);			}		//#endif		//#ifdef polish.css.exclusiveview-arrow-position			if (this.arrowPosition == POSITION_BOTH_SIDES ) {		//#endif				modifiedX += this.arrowWidth + this.paddingHorizontal;				leftBorder += this.arrowWidth + this.paddingHorizontal;		//#ifdef polish.css.exclusiveview-arrow-position			} else if (this.arrowPosition == POSITION_LEFT ) {				modifiedX += (this.arrowWidth + this.paddingHorizontal) << 1;				leftBorder += (this.arrowWidth + this.paddingHorizontal) << 1;			}		//#endif							//#ifdef polish.css.exclusiveview-arrow-position			if (this.arrowPosition == POSITION_BOTH_SIDES ) {		//#endif				rightBorder -= this.arrowWidth + this.paddingHorizontal;		//#ifdef polish.css.exclusiveview-arrow-position			} else if (this.arrowPosition == POSITION_RIGHT ) {				rightBorder -= (this.arrowWidth + this.paddingHorizontal) << 1;			}		//#endif				//#debug		System.out.println("ExclusiveView.item: x=" + modifiedX + ", y=" + y + ", leftBorder=" + leftBorder + ", rightBorder=" + rightBorder + ", availableWidth=" + (rightBorder - leftBorder) + ", itemWidth=" + this.currentItem.itemWidth  );		if (this.currentItem != null) {			this.currentItem.paint(modifiedX, y, leftBorder, rightBorder, g);		}		g.setColor( this.arrowColor );		//draw left arrow:		//#ifdef polish.css.exclusiveview-roundtrip			if (this.allowRoundTrip || this.currentItemIndex > 0) {		//#else			//# if (this.currentItemIndex > 0) {		//#endif			// draw left arrow			int startX = x + this.leftArrowStartX;				//#ifdef polish.css.exclusiveview-left-arrow				if (this.leftArrow != null) {					//System.out.println("Drawing left IMAGE arrow at " + startX );					g.drawImage( this.leftArrow, startX, y + this.leftYOffset, Graphics.LEFT | Graphics.TOP );				} else {			//#endif				//#if polish.midp2					//System.out.println("Drawing left triangle arrow at " + startX );					g.fillTriangle( 							startX, y + this.contentHeight/2, 							startX + this.arrowWidth, y,							startX + this.arrowWidth, y + this.contentHeight );				//#else					int y1 = y + this.contentHeight / 2;					int x2 = startX + this.arrowWidth;					int y3 = y + this.contentHeight;					g.drawLine( startX, y1, x2, y );					g.drawLine( startX, y1, x2, y3 );					g.drawLine( x2, y, x2, y3 );				//#endif			//#ifdef polish.css.exclusiveview-left-arrow				}			//#endif		}				// draw right arrow:		//#ifdef polish.css.exclusiveview-roundtrip			if (this.allowRoundTrip ||  (this.currentItemIndex < this.parentContainer.size() - 1) ) {		//#else			//# if (this.currentItemIndex < this.parentContainer.size() - 1) {		//#endif			// draw right arrow			int startX = x + this.rightArrowStartX;				//#ifdef polish.css.exclusiveview-right-arrow				if (this.rightArrow != null) {					g.drawImage( this.rightArrow, startX, y + this.rightYOffset, Graphics.LEFT | Graphics.TOP );				} else {			//#endif				//#if polish.midp2					g.fillTriangle( 							startX + this.arrowWidth, y + this.contentHeight/2, 							startX, y,							startX, y + this.contentHeight );				//#else					int y1 = y + this.contentHeight / 2;					int x2 = startX + this.arrowWidth;					int y3 = y + this.contentHeight;					g.drawLine( x2, y1, startX, y );					g.drawLine( x2, y1, startX, y3 );					g.drawLine( startX, y, startX, y3 );				//#endif			//#ifdef polish.css.exclusiveview-right-arrow				}			//#endif		}	}	/* (non-Javadoc)	 * @see de.enough.polish.ui.ContainerView#getNextItem(int, int)	 */	protected Item getNextItem(int keyCode, int gameAction) {		//#debug		System.out.println("ExclusiveSingleLineView: getNextItem()");		ChoiceGroup choiceGroup = (ChoiceGroup) this.parentContainer;		Item[] items = this.parentContainer.getItems();		if (this.currentItem == null) {			//#debug warn			System.out.println("ExclusiveSingleLineView: getNextItem(): no current item defined, it seems the initContent() has been skipped.");			this.currentItemIndex = choiceGroup.getSelectedIndex();			this.currentItem = (ChoiceItem) items[ this.currentItemIndex ];		}		Item lastItem = this.currentItem;		//ChoiceItem currentItem = (ChoiceItem) items[ this.currentItemIndex ];			//#ifdef polish.css.exclusiveview-roundtrip			if ( gameAction == Canvas.LEFT && (this.allowRoundTrip || this.currentItemIndex > 0 )) {		//#else			//# if ( gameAction == Canvas.LEFT && this.currentItemIndex > 0 ) {		//#endif			this.currentItem.select( false );			this.currentItemIndex--;			//#ifdef polish.css.exclusiveview-roundtrip				if (this.currentItemIndex < 0) {					this.currentItemIndex = items.length - 1;				}			//#endif			this.currentItem = (ChoiceItem) items[ this.currentItemIndex ];			this.currentItem.adjustProperties( lastItem );			//this.currentItem.select( true );			choiceGroup.setSelectedIndex( this.currentItemIndex, true );			choiceGroup.notifyStateChanged();						return this.currentItem;		//#ifdef polish.css.exclusiveview-roundtrip			} else if ( gameAction == Canvas.RIGHT && (this.allowRoundTrip || this.currentItemIndex < items.length - 1  )) {		//#else			} else if ( gameAction == Canvas.RIGHT && this.currentItemIndex < items.length - 1 ) {		//#endif			this.currentItem.select( false );			this.currentItemIndex++;			//#ifdef polish.css.exclusiveview-roundtrip				if (this.currentItemIndex >= items.length) {					this.currentItemIndex = 0;				}			//#endif			this.currentItem = (ChoiceItem) items[ this.currentItemIndex ];			this.currentItem.adjustProperties( lastItem );			choiceGroup.setSelectedIndex( this.currentItemIndex, true );			choiceGroup.notifyStateChanged();			//this.currentItem.select( true );						return this.currentItem;		}		// in all other cases there is no next item:		return null;	}	//#ifdef polish.hasPointerEvents	/**	 * Handles pointer pressed events.	 * This is an optional feature that doesn't need to be implemented by subclasses.	 * 	 * @param x the x position of the event	 * @param y the y position of the event	 * @return true when the event has been handled. When false is returned the parent container	 *         will forward the event to the affected item.	 */	public boolean handlePointerPressed(int x, int y) {		if (y < 0 || y > this.contentHeight ) {			return false;		}		Item[] items = this.parentContainer.getItems();		this.currentItem.select( false );		x -= this.xStart;		int index = this.currentItemIndex;		if ( (index > 0 || this.allowRoundTrip) && x >= this.leftArrowStartX  && x <= this.leftArrowEndX ) {			index--;			if (index < 0) {				index = items.length - 1;			}		} else if (! (x >= this.leftArrowStartX  && x <= this.leftArrowEndX && index > 0)) {			index = ( index + 1) % items.length;		}		this.currentItemIndex = index;		this.currentItem = (ChoiceItem) items[ index ];		//this.currentItem.select( true );		((ChoiceGroup) this.parentContainer).setSelectedIndex( this.currentItemIndex, true );		this.parentContainer.focus(this.currentItemIndex, this.currentItem, 0);		this.parentContainer.notifyStateChanged();		return true;	}	//#endif	/* (non-Javadoc)	 * @see de.enough.polish.ui.ContainerView#defocus(de.enough.polish.ui.Style)	 */	protected void defocus(Style originalStyle) {		if (this.parentBackground != null ) {			this.parentContainer.background = this.parentBackground;			this.parentBackground = null;		}		super.defocus(originalStyle);		//System.out.println("EXCLUSIVE:   DEFOCUS!");	}	/* (non-Javadoc)	 * @see de.enough.polish.ui.ContainerView#focus(de.enough.polish.ui.Style, int)	 */	public void focus(Style focusstyle, int direction) {		Background bg = this.parentContainer.background;		if (bg != null) {			this.parentBackground = bg; 			this.parentContainer.background = null;		}		//System.out.println("EXCLUSIVE:   FOCUS, parentBackround != null: " + (this.parentBackground != null));		super.focus(focusstyle, direction);	}		}

⌨️ 快捷键说明

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