if (index == this.focusedIndex && item.isFocused) {  System.out.println("Container: ignoring focusing of item " + index );  return;
Item item = (Item) this.itemsList.get(index ); if (item.appearanceMode != Item.PLAIN) { int direction = 0; if (this.isFocused) { if (this.focusedIndex == -1) {  } else if (this.focusedIndex < index ) { direction = Canvas.DOWN; } else if (this.focusedIndex > index) { direction = Canvas.UP; }  } focus( index, item, direction ); return true;
	public void focus( int index, Item item, int direction ) {		//#debug		System.out.println("Container (" + getClass().getName() + "): Focusing item " + index );				//#if polish.blackberry			//# getScreen().setFocus( item );		//#endif						if (this.autoFocusEnabled  && !this.isInitialised) {			// setting the index for automatically focusing the appropriate item			// during the initialisation:			//#debug			System.out.println("Container: Setting autofocus-index to " + index );			this.autoFocusIndex = index;			//this.isFirstPaint = true;			return;		}				if (index == this.focusedIndex && item.isFocused) {			//#debug			System.out.println("Container: ignoring focusing of item " + index );			// ignore the focusing of the same element:			return;		}		// first defocus the last focused item:		if (this.focusedItem != null) {			if (this.itemStyle != null) {				this.focusedItem.defocus(this.itemStyle);			} else {				//#debug error				System.out.println("Container: Unable to defocus item - no previous style found.");				this.focusedItem.defocus( StyleSheet.defaultStyle );			}		}				this.itemStyle = item.focus( this.focusedStyle, direction );		//#ifdef polish.debug.error			if (this.itemStyle == null) {				//#debug error 				System.out.println("Container: Unable to retrieve style of item " + item.getClass().getName() );			}		//#endif		boolean isDownwards = (direction == Canvas.DOWN) || (direction == Canvas.RIGHT) || (direction == 0 &&  index > this.focusedIndex);		this.focusedIndex = index;		this.focusedItem = item;		//#if tmp.supportViewType			if ( this.view != null ) {				this.view.focusedIndex = index;				this.view.focusedItem = item;			}		//#endif		if  (this.isInitialised) { // (this.yTopPos != this.yBottomPos) {			// this container has been initialised already,			// so the dimensions are known.			if (item.internalX != -9999) {				this.internalX =  item.contentX - this.contentX + item.internalX;				this.internalWidth = item.internalWidth;				this.internalY = item.contentY - this.contentY + item.internalY;				this.internalHeight = item.internalHeight;				//#debug				System.out.println("Container (" + getClass().getName() + "): setting internalY=" + this.internalY + ", item.contentY=" + item.contentY + ", this.contentY=" + this.contentY + ", item.internalY=" + item.internalY+ ", this.yOffset=" + this.yOffset + ", item.internalHeight=" + item.internalHeight);			} else {				this.internalX = item.xLeftPos - this.contentX;				this.internalWidth = item.itemWidth;				this.internalY = item.yTopPos + this.yOffset; // (item.yTopPos - this.yOffset) - this.contentY;				this.internalHeight = item.itemHeight;				//#debug				System.out.println("Container (" + getClass().getName() + "): setting internalY=" + this.internalY + ", item.yTopPos=" + item.yTopPos + ", this.contentY=" + this.contentY + ", this.yOffset=" + this.yOffset + ", item.itemHeight=" + item.itemHeight);			}			if (this.enableScrolling) {					// Now adjust the scrolling:								Item nextItem;				if ( isDownwards && index < this.itemsList.size() - 1 ) {					nextItem = (Item) this.itemsList.get( index + 1 );					//#debug					System.out.println("Focusing downwards, nextItem.y = [" + nextItem.yTopPos + "-" + nextItem.yBottomPos + "], focusedItem.y=[" + item.yTopPos + "-" + item.yBottomPos + "], this.yOffset=" + this.yOffset + ", this.targetYOffset=" + this.targetYOffset);				} else if ( !isDownwards && index > 0 ) {					nextItem = (Item) this.itemsList.get( index - 1 );					//#debug					System.out.println("Focusing upwards, nextItem.yTopPos = " + nextItem.yTopPos + ", focusedItem.yTopPos=" + item.yTopPos );				} else {					//#debug					System.out.println("Focusing last or first item.");					nextItem = item;				}								int itemYTop = isDownwards ? item.yTopPos : nextItem.yTopPos;				int itemYBottom = isDownwards ? nextItem.yBottomPos : item.yBottomPos;				//				if (itemYBottom - itemYTop > this.yTop - this.yBottom) {//					if ( isDownwards ) {//						itemYBottom = this.internalY + this.internalHeight;//					} else {//						itemYTop = this.internalY;//					}//				}//				int difference = 0;				scroll( isDownwards, this.xLeftPos, itemYTop, item.internalWidth, itemYBottom - itemYTop );//				if (itemYTop == itemYBottom) {//					//#debug//					System.out.println("Container: unable to auto-scroll, item.yBottomPos == item.yTopPos");//				} else if (itemYBottom > this.yBottom) {//					// this item is too low://					difference = this.yBottom - itemYBottom;//					// #debug//					//System.out.println("item too low: difference: " + difference + "  itemYBottom=" + itemYBottom + "  container.yBottom=" + this.yBottom );//					//if ( itemYTop + difference < this.yTop) {//					if ( isDownwards && itemYTop + difference < this.yTop) {//						// #debug//						//System.out.println("correcting: difference: " + difference + "  itemYTop=" + itemYTop + "  <  this.yTop=" +  this.yTop + "  to new difference=" + (this.yTop - itemYTop + 10) );//						difference = this.yTop - itemYTop + 10; // additional pixels for adjusting the focused style above://					}//					/*//					if ( itemYTop + difference < this.internalY) {//						//#debug//						System.out.println("correcting: difference: " + difference + "  itemYTop=" + itemYTop + "  <  this.internalY=" +  this.internalY + "  to new difference=" + (this.internalY - itemYTop + 10) );//						difference = this.internalY - itemYTop + 10; // additional pixels for adjusting the focused style above://					}//					*///				} else if (itemYTop < this.yTop) {//					// this item is too high://					//#if tmp.supportViewType//						//TODO when colpan is used, the index might need to be higher than anticipated//						if ((index == 0) || ( this.view != null && (index < this.view.numberOfColumns) ) ) {//					//#else//						//# if (index == 0) {//					//#endif//						// scroll to the very top://						difference = -1 * this.yOffset;//					} else {//						difference = this.yTop - itemYTop + this.focusedTopMargin;//					}//					// re-adjust the scrolling in case we scroll up and the previous//					// item is very large://					if ( !isDownwards && itemYBottom + difference > this.yBottom  ) {//						difference = this.yBottom - itemYBottom;//					}//						//					// #debug//					//System.out.println("item too high: difference: " + difference + "  itemYTop=" + itemYTop + "  container.yTop=" + this.yTop  );//				}//				//#debug//				System.out.println("Container (" + getClass().getName() + "): difference: " + difference + "  container.yOffset=" + this.yOffset + ", itemY=[" + itemYTop + "-" + itemYBottom + "],  item.internalY: " + (item.internalY) + " bis " + (item.internalY + item.internalHeight ) + "  contentY:" + this.contentY + "  top:" + this.yTop + " bottom:" + this.yBottom  + "   ---- , this.internalY=" +  this.internalY);//						//				//#if polish.css.scroll-mode//					if (!this.scrollSmooth) {//						this.yOffset += difference;//					} else {//				//#endif//						this.targetYOffset = this.yOffset + difference;//				//#if polish.css.scroll-mode//					}//				//#endif			}		} else if (this.enableScrolling) {			//#debug			System.out.println("focus: postpone scrolling to initContent()");			this.isScrollRequired = true;			//		} else if (this.enableScrolling) {//			this.isFirstPaint = true;		}		this.isInitialised = false;	}