boolean doCenter = this.isLayoutCenter; if ( doCenter) { int itemSpace = rightBorder - leftBorder; if (itemSpace > this.itemWidth) {   x+= (itemSpace - this.itemWidth) / 2; doCenter = false; } } boolean doRightAlign = this.isLayoutRight; if ( doRightAlign ) { int itemSpace = rightBorder - leftBorder; if (itemSpace > this.itemWidth) {  x+= itemSpace - this.itemWidth; }
if ( this.isLayoutCenter  && availableWidth > this.itemWidth) { x += (availableWidth - this.itemWidth) / 2; } else if ( this.isLayoutRight && availableWidth > this.itemWidth) {   x += availableWidth - this.itemWidth;
	public void paint( int x, int y, int leftBorder, int rightBorder, Graphics g ) {		// initialise this item if necessary:		if (!this.isInitialised) {			init( rightBorder - x, rightBorder - leftBorder );		}		// set coordinates of this item:		this.xLeftPos = leftBorder;		this.yTopPos = y;		this.xRightPos = rightBorder; // contentX + this.contentWidth; //x + this.itemWidth; //TODO rob: Item.xRightPos might differ when this item contains line breaks		this.yBottomPos = y + this.itemHeight;		// paint label:		if (this.label != null) {			if (this.useSingleRow) {				this.label.paint( x, y, leftBorder, rightBorder - this.itemWidth, g );				x += this.label.itemWidth;				leftBorder += this.label.itemWidth;			} else {				this.label.paint( x, y, leftBorder, rightBorder, g );				y += this.label.itemHeight;			}		}				leftBorder += (this.marginLeft + this.borderWidth + this.paddingLeft);		//#ifdef polish.useBeforeStyle			leftBorder += this.beforeWidth;		//#endif		//System.out.println( this.style.name + ":  increasing leftBorder by " + (this.marginLeft + this.borderWidth + this.paddingLeft));		rightBorder -= (this.marginRight + this.borderWidth + this.paddingRight);		//#ifdef polish.useAfterStyle			rightBorder -= this.afterWidth;		//#endif				//System.out.println( this.style.name + ":  decreasing rightBorder by " + (this.marginRight + this.borderWidth + this.paddingRight));		boolean doCenter = this.isLayoutCenter;		if ( doCenter) {			int itemSpace = rightBorder - leftBorder;			if (itemSpace > this.itemWidth) {				/*				if (this.isLayoutExpand) {					System.out.println( this.style.name + ": centering item by " + ((itemSpace - this.itemWidth) / 2)+ " pixels, event though LAYOUT_EXPAND is set!");				}				*/				//System.out.println("itemSpace=" + itemSpace + "  itemWidth=" + this.itemWidth + "  x-increase=" + ((itemSpace - this.itemWidth) / 2));				x+= (itemSpace - this.itemWidth) / 2;				doCenter = false;			}		}		boolean doRightAlign = this.isLayoutRight;		if ( doRightAlign ) {			int itemSpace = rightBorder - leftBorder;			if (itemSpace > this.itemWidth) {				/*				if (this.isLayoutExpand) {					System.out.println( this.style.name + ": right aligning item by " + (itemSpace - this.itemWidth)+ " pixels, event though LAYOUT_EXPAND is set!");				}				*/				x+= itemSpace - this.itemWidth;			}		}		// paint background:		x += this.marginLeft;		y += this.marginTop;		if (this.background != null) {			this.background.paint(x, y, this.backgroundWidth, this.backgroundHeight, g);		}				int contX = x + this.borderWidth + this.paddingLeft;		int contY = y + this.borderWidth + this.paddingTop;		int originalContentY = contY;				// paint before element:		//#ifdef polish.useBeforeStyle			if (this.beforeImage != null) {				int beforeY = contY;				if ( this.beforeHeight < this.contentHeight) {					beforeY += (this.contentHeight - this.beforeHeight) / 2;				} else {					contY += (this.beforeHeight - this.contentHeight) / 2;				}				g.drawImage(this.beforeImage, contX, beforeY, Graphics.TOP | Graphics.LEFT );				contX += this.beforeWidth;			}		//#endif				// paint after element:		//#ifdef polish.useAfterStyle			if (this.afterImage != null) {				int afterY = originalContentY;				if ( this.afterHeight < this.contentHeight) {					afterY += (this.contentHeight - this.afterHeight) / 2;				} else {					//#ifdef polish.useBeforeStyle					if (this.afterHeight > this.beforeHeight) {					//#endif						contY = originalContentY + (this.afterHeight - this.contentHeight) / 2;					//#ifdef polish.useBeforeStyle					}					//#endif				}				g.drawImage(this.afterImage, rightBorder, afterY, Graphics.TOP | Graphics.LEFT );			}		//#endif				// align content positions:		if ( doCenter ) {			int contentSpace = rightBorder - this.marginRight - this.borderWidth 					- this.paddingRight - contX;			if (contentSpace > this.contentWidth) {				contX += (contentSpace - this.contentWidth ) / 2;							}		} else if ( doRightAlign ) {			int contentSpace = rightBorder - this.marginRight - this.borderWidth 					- this.paddingRight - contX;			if (contentSpace > this.contentWidth) {				contX += contentSpace - this.contentWidth;							}		}				// paint content:		this.contentX = contX;		this.contentY = contY;		paintContent( contX, contY, leftBorder, rightBorder, g );						// paint border:		if (this.border != null) {			this.border.paint(x, y, this.backgroundWidth, this.backgroundHeight, g);		}	}