this.contentX = contX; this.contentY = contY; paintContent( contX, contY, leftBorder, rightBorder, g );
this.contentX = x; this.contentY = y; paintContent( x, y, leftBorder, rightBorder, g );
	public void paint( int x, int y, int leftBorder, int rightBorder, Graphics g ) {		// initialise this item if necessary:		int availableWidth = rightBorder - leftBorder;		if (!this.isInitialised ) { // || availableWidth < this.itemWidth || availableWidth < this.backgroundWidth			init( rightBorder - x, availableWidth );		}		boolean isLayoutShrink = (this.layout & LAYOUT_SHRINK) == LAYOUT_SHRINK;		// 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 background and border when the label should be included in this:		//#if polish.css.include-label			if (this.includeLabel) {				int width = this.itemWidth - this.marginLeft - this.marginRight;				int height = this.itemHeight - this.marginTop - this.marginBottom;				int bX = x + this.marginLeft;				int bY = y + this.marginTop;				if ( this.background != null ) {					this.background.paint(bX, bY, width, height, g);				}				if ( this.border != null ) {					this.border.paint(bX, bY, width, height, g);				}			}		//#endif				// 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));		if ( this.isLayoutCenter  && availableWidth > this.itemWidth) {			int difference = (availableWidth - this.itemWidth) / 2; 			x += difference;			if (isLayoutShrink) {				leftBorder += difference;				rightBorder -= difference;				//System.out.println("item " + this + ": (center) shrinking left border to " + leftBorder + ", right border to " + rightBorder);			}		} else if ( this.isLayoutRight && availableWidth > this.itemWidth) {			// adjust the x-position so that the item is painted up to			// the right border (when it starts at x):			x += availableWidth - this.itemWidth;			if (isLayoutShrink) {				leftBorder += availableWidth - this.itemWidth;				//System.out.println("item " + this + ": (right) shrinking left border to " + leftBorder);			}		} else if (isLayoutShrink && availableWidth > this.itemWidth) {			rightBorder -= availableWidth - this.itemWidth;			//System.out.println("item " + this + ": (left) shrinking right border to " + rightBorder);		}				// paint background:		x += this.marginLeft;		y += this.marginTop;		//#if polish.css.include-label			if (!this.includeLabel) {		//#endif				if (this.background != null) {					this.background.paint(x, y, this.backgroundWidth, this.backgroundHeight, g);				}				// paint border:				if (this.border != null) {					this.border.paint(x, y, this.backgroundWidth, this.backgroundHeight, g);				}		//#if polish.css.include-label			}		//#endif				int contX = x + this.borderWidth + this.paddingLeft;		int contY = y + this.borderWidth + this.paddingTop;		int originalContentY = contY;				// paint before element:		//#if polish.useBeforeStyle || polish.useAfterStyle || polish.css.min-height  || polish.css.max-height			boolean isVerticalCenter = (this.layout & LAYOUT_VCENTER) == LAYOUT_VCENTER; 			boolean isTop = !isVerticalCenter && (this.layout & LAYOUT_TOP) == LAYOUT_TOP; 			boolean isBottom = !isVerticalCenter && (this.layout & LAYOUT_BOTTOM) == LAYOUT_BOTTOM; 		//#endif		//#if polish.css.min-height			if (this.minimumHeight != 0) {				int minHeight = this.minimumHeight - ( 2 * this.borderWidth + this.marginTop + this.marginBottom + this.paddingTop + this.paddingBottom);				if ( isVerticalCenter ) {//					System.out.println("vertical: adjusting contY by " + ((this.minimumHeight - this.contentHeight) / 2)//							+ ", contentHeight=" + this.contentHeight + ", minHeight=" + this.minimumHeight );					contY += (minHeight - this.contentHeight) / 2; 				} else if ( isBottom ) {					//System.out.println("bottom: adjusting contY by " + (this.minimumHeight - this.contentHeight) );					contY += (minHeight - this.contentHeight);				}			}		//#endif		//#ifdef polish.useBeforeStyle			if (this.beforeImage != null) {				int beforeY = contY;				int yAdjustment = this.beforeHeight - this.contentHeight;				if ( this.beforeHeight < this.contentHeight) {					if (isTop) {						beforeY -= yAdjustment;					} else if (isBottom) {						beforeY += yAdjustment;					} else {						beforeY -= yAdjustment / 2;					}				} else {					if (isTop) {						// keep contY					} else if (isBottom) {						contY += yAdjustment;					} else {						contY += yAdjustment / 2;					}					//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;				int yAdjustment = this.afterHeight - this.contentHeight;				if ( this.afterHeight < this.contentHeight) {					if (isTop) {						afterY -= yAdjustment;					} else if (isBottom) {						afterY += yAdjustment;					} else {						afterY -= yAdjustment / 2;					}					//afterY += (this.contentHeight - this.afterHeight) / 2;				} else {					//#ifdef polish.useBeforeStyle					if (this.afterHeight > this.beforeHeight) {					//#endif						if (isTop) {							// keep contY						} else if (isBottom) {							contY = originalContentY + yAdjustment;						} else {							contY = originalContentY + yAdjustment / 2;						}						//contY = originalContentY + (this.afterHeight - this.contentHeight) / 2;					//#ifdef polish.useBeforeStyle					}					//#endif				}				g.drawImage(this.afterImage, rightBorder, afterY, Graphics.TOP | Graphics.LEFT );			}		//#endif				// paint content:		this.contentX = contX;		this.contentY = contY;		paintContent( contX, contY, leftBorder, rightBorder, g );					}