this.subTitle.yBottomPos = topHeight;
	public void paint(Graphics g) {		//System.out.println("Painting screen "+ this + ", background == null: " + (this.background == null));		synchronized (this.paintLock ) {			//#if polish.Bugs.losesFullScreen				//# super.setFullScreenMode( true );			//#endif			//#if tmp.fullScreenInPaint				if (!this.isInFullScreenMode) {					//# super.setFullScreenMode( true );					this.isInFullScreenMode = true;					//#if tmp.menuFullScreen						//#ifdef polish.FullCanvasHeight:defined							//#= this.fullScreenHeight = ${polish.FullCanvasHeight};						//#else							this.fullScreenHeight = getHeight();						//#endif						this.screenHeight = this.fullScreenHeight - this.menuBarHeight;						this.originalScreenHeight = this.screenHeight;						this.scrollIndicatorY = this.screenHeight + 1; //- this.scrollIndicatorWidth - 1 - this.menuBarHeight;					//#endif				}			//#endif			//#if !tmp.menuFullScreen				int translateY = g.getTranslateY();				if (translateY != 0 && this.screenHeight == this.originalScreenHeight) {					this.screenHeight -= translateY;					//#if !tmp.useScrollBar 						this.scrollIndicatorY -= translateY;					//#endif					//#debug					System.out.println("Adjusting screenheight from " + this.originalScreenHeight + " to " + this.screenHeight );					if (this.container != null) {						int y = translateY;						calculateContentArea( 0, y, this.screenWidth, this.screenHeight - y );					}				}			//#endif			//#if tmp.fullScreen && polish.FullCanvasSize:defined && polish.Bugs.setClipForFullScreenNeeded				g.translate( -g.getTranslateX(), -g.getTranslateY() );				//#= g.setClip( 0, 0, ${polish.FullCanvasWidth}, ${polish.FullCanvasHeight} );			//#endif			//#if polish.debug.error			try {			//#endif				//#if polish.css.repaint-previous-screen					//#if polish.Screen.dontBufferPreviousScreen						if (this.repaintPreviousScreen && this.previousScreen != null) {							this.previousScreen.paint(g);							//#if !polish.Bugs.noTranslucencyWithDrawRgb								this.previousScreenOverlayBackground.paint(0, 0, this.screenWidth, this.screenHeight, g);							//#endif						}					//#else						if (this.repaintPreviousScreen && this.previousScreenImage != null) {							g.drawImage(this.previousScreenImage, 0, 0, Graphics.TOP | Graphics.LEFT );							//#if !polish.Bugs.noTranslucencyWithDrawRgb								this.previousScreenOverlayBackground.paint(0, 0, this.screenWidth, this.screenHeight, g);							//#endif						}					//#endif				//#endif				int sWidth = this.screenWidth - this.marginLeft - this.marginRight;				int leftBorder = this.marginLeft;				int rightBorder = leftBorder + sWidth;				if (this.isLayoutHorizontalShrink) {					int contWidth = this.contentWidth;					if (this.container != null) {						contWidth = this.container.getItemWidth(sWidth, sWidth); 					}					sWidth = contWidth;					//System.out.println("is horizontal shrink - from sWidth=" + (this.screenWidth - this.marginLeft - this.marginRight) + ", to=" + sWidth );										if (this.isLayoutRight) {						leftBorder = rightBorder - sWidth;					} else if (this.isLayoutCenter) {						leftBorder = (this.screenWidth - sWidth) / 2;						rightBorder = this.screenWidth - leftBorder;					} else {						rightBorder = this.screenWidth - sWidth;					}					//System.out.println("leftBorder=" + leftBorder + ", rightBorder=" + rightBorder );				}								//#ifdef tmp.menuFullScreen					int sHeight = this.fullScreenHeight - this.marginTop - this.marginBottom;				//#else					//# int sHeight = this.screenHeight - this.marginTop - this.marginBottom;				//#endif				int topBorder = this.marginTop;				if (this.isLayoutVerticalShrink) {					int contHeight = this.contentHeight;					if (this.container != null) {						contHeight = this.container.getItemHeight(sWidth, sWidth); 					}//					//#if tmp.menuFullScreen//						sHeight = contHeight + this.titleHeight + this.menuBarHeight;//					//#else						sHeight = contHeight + this.titleHeight;//					//#endif					//System.out.println("isLayoutVerticalShrink - sHeight: from=" + (this.fullScreenHeight - this.marginTop - this.marginBottom) + ", to=" + sHeight + ", contentHeight=" + this.contentHeight + ", topBorder=" + topBorder );					if (this.isLayoutBottom) {//						//#ifdef tmp.menuFullScreen//							topBorder = this.fullScreenHeight - (this.marginBottom + sHeight + 1);//						//#else							topBorder = this.screenHeight - (this.marginBottom + sHeight + 1);//						//#endif						//System.out.println("bottom -> topBorder=" + topBorder + ", contY=>" + (topBorder + this.titleHeight) );					} else if (this.isLayoutVCenter) {//						//#ifdef tmp.menuFullScreen//							topBorder = (this.fullScreenHeight - (this.marginBottom + this.marginBottom))/2 - sHeight/2;//						//#else							topBorder = (this.screenHeight - (this.marginBottom + this.marginTop + sHeight))/2;//						//#endif						 						//System.out.println("vcenter -> topBorder=" + topBorder + ", contY=>" + (topBorder + this.titleHeight) );					}				}				// paint background:				if (this.background != null) {					int backgroundHeight = sHeight;					int backgroundY = topBorder;					//#ifdef tmp.menuFullScreen						if (this.excludeMenuBarForBackground) {							backgroundHeight = this.screenHeight - this.marginTop - this.marginBottom;						}					//#endif					//#ifdef tmp.usingTitle						if (this.excludeTitleForBackground) {							backgroundHeight -= this.titleHeight;							backgroundY += this.titleHeight;						}					//#endif					// System.out.println("Screen (" + this + ": painting background at leftBorder=" + leftBorder + ", backgroundY=" + backgroundY);					this.background.paint(leftBorder, backgroundY, sWidth, backgroundHeight, g);				} else {					//System.out.println("Screen (" + this + ": clearing area...");					int backgroundHeight = sHeight;					int backgroundY = topBorder;					//#ifdef tmp.menuFullScreen						if (this.excludeMenuBarForBackground) {							backgroundHeight = this.screenHeight - this.marginTop - this.marginBottom;						}					//#endif					//#ifdef tmp.usingTitle						if (this.excludeTitleForBackground) {							backgroundHeight -= this.titleHeight;							backgroundY += this.titleHeight;						}					//#endif					g.setColor( 0xFFFFFF );					g.fillRect( leftBorder, backgroundY, sWidth, backgroundHeight );				}								int topHeight = topBorder;				//#ifdef tmp.usingTitle					//#if polish.css.title-position						if (this.paintTitleAtTop) {					//#endif							// paint title:							if (this.title != null && this.showTitleOrMenu) {								this.title.paint( leftBorder, topBorder, leftBorder, rightBorder, g);								topHeight += this.titleHeight;							}					//#if polish.css.title-position						}					//#endif				//#endif				if (this.subTitle != null) {					this.subTitle.paint( leftBorder, topHeight, leftBorder, rightBorder, g );					topHeight += this.subTitleHeight;				}				//#ifndef polish.skipTicker								//#if tmp.paintTickerAtTop						if (this.ticker != null) {							this.ticker.paint( leftBorder, topHeight, leftBorder, rightBorder, g);							topHeight += this.ticker.itemHeight;						}					//#elif polish.css.ticker-position && !polish.TickerPosition:defined						if (this.paintTickerAtTop && this.ticker != null) {							this.ticker.paint( leftBorder, topHeight, leftBorder, rightBorder, g);							topHeight += this.ticker.itemHeight;						}					//#endif				//#endif					int infoItemY = topHeight;				//#if polish.clip-screen-info					if (this.showInfoItem && this.clipScreenInfo) {									topHeight += this.infoHeight;					}				//#endif				//System.out.println("topHeight=" + topHeight + ", contentY=" + contentY);								// protect the title, ticker and the full-screen-menu area:	//			int clipHeight = this.screenHeight - topHeight;	//			//#if tmp.menuFullScreen	//				int cHeight = this.fullScreenHeight - topHeight - this.marginBottom;	//				if (cHeight < clipHeight) {	//					clipHeight = cHeight;	//				}	//			//#endif				g.setClip(leftBorder, topHeight, sWidth, this.screenHeight - topHeight  );					// paint content:				//System.out.println("starting to paint content of screen");				paintScreen( g );				//System.out.println("done painting content of screen");								//#if tmp.useScrollBar					if (this.container != null && this.container.itemHeight > this.contentHeight) {						// paint scroll bar: - this.container.yOffset						//#debug						System.out.println("Screen/ScrollBar: container.contentY=" + this.container.contentY + ", container.internalY=" +  this.container.internalY + ", container.yOffset=" + this.container.yOffset + ", container.yTop=" + this.container.yTop + ", container.yTopPos=" + this.container.yTopPos);												int scrollX = sWidth + this.marginLeft 									- this.scrollBar.initScrollBar(sWidth, this.contentHeight, this.container.itemHeight, this.container.yOffset, this.container.internalY, this.container.internalHeight, this.container.focusedIndex, this.container.size() );						//TODO allow scroll bar on the left side						this.scrollBar.paint( scrollX, this.contentY, scrollX, rightBorder, g);					}				//#endif								// allow painting outside of the screen again:				//#ifdef tmp.menuFullScreen				 	g.setClip(0, 0, this.screenWidth, this.fullScreenHeight );				//#else				 	g.setClip(0, 0, this.screenWidth, this.originalScreenHeight );				//#endif				 				// paint info element:				if (this.showInfoItem) {								this.infoItem.paint( this.marginLeft, infoItemY, this.marginLeft, rightBorder, g );				}	 					int bottomY = this.contentY + this.contentHeight;				//#ifndef polish.skipTicker								//#if tmp.paintTickerAtBottom						if (this.ticker != null) {							this.ticker.paint( this.marginLeft, bottomY, this.marginLeft, rightBorder, g);							bottomY += this.ticker.itemHeight;						}					//#elif polish.css.ticker-position && !polish.TickerPosition:defined						if (!this.paintTickerAtTop && this.ticker != null) {							this.ticker.paint( this.marginLeft, bottomY, this.marginLeft, rightBorder, g);							bottomY += this.ticker.itemHeight;						}					//#endif				//#endif				//#if tmp.usingTitle && polish.css.title-position						if (!this.paintTitleAtTop) {							// paint title:							if (this.title != null && this.showTitleOrMenu) {								this.title.paint( leftBorder, bottomY, leftBorder, rightBorder, g);								//bottomY += this.titleHeight;							}						}				//#endif								// paint border:				if (this.border != null) {	//				//#ifdef tmp.menuFullScreen	//					this.border.paint(this.marginLeft, this.marginTop, sWidth, this.screenHeight - this.marginBottom - this.marginTop, g);	//				//#else						this.border.paint(leftBorder, this.marginTop, sWidth, sHeight, g);	//				//#endif				}								//#if polish.ScreenInfo.enable == true					ScreenInfo.paint( g, topHeight, this.screenWidth );				//#endif									// paint menu in full-screen mode:				int menuLeftX = 0;				int menuRightX = this.screenWidth;				int menuY = this.screenHeight; // + this.marginBottom;				//#if polish.css.separate-menubar					if (!this.separateMenubar) {						menuLeftX = leftBorder;						menuRightX = rightBorder;						menuY = this.screenHeight - this.marginBottom;					}				//#endif				//#ifdef tmp.menuFullScreen					//#ifdef tmp.useExternalMenuBar						this.menuBar.paint(menuLeftX, menuY, menuLeftX, menuRightX, g);						//#if !tmp.useScrollBar							if (this.menuBar.isOpened) {								this.paintScrollIndicator = this.menuBar.paintScrollIndicator;								this.paintScrollIndicatorUp = this.menuBar.canScrollUpwards;								this.paintScrollIndicatorDown = this.menuBar.canScrollDownwards;							}						//#endif					//#else						if (this.menuOpened) {							topHeight -= this.infoHeight;							int menuHeight = this.menuContainer.getItemHeight(this.screenWidth, this.screenWidth);							int y = this.originalScreenHeight - (menuHeight + 1);							if (y < topHeight) {								//#if !tmp.useScrollBar								this.paintScrollIndicator = true;								this.paintScrollIndicatorUp = (this.menuContainer.yOffset != 0);								this.paintScrollIndicatorDown = ( (this.menuContainer.focusedIndex != this.menuContainer.size() - 1)										&& (this.menuContainer.yOffset + menuHeight > this.originalScreenHeight - topHeight)) ;								//#endif								y = topHeight; 								this.menuContainer.setVerticalDimensions(y, this.originalScreenHeight);							//#if !tmp.useScrollBar							} else {								this.paintScrollIndicator = false;							//#endif							}							g.setClip(0, topHeight, this.screenWidth, this.originalScreenHeight - topHeight );							this.menuContainer.paint(menuLeftX, y, menuLeftX, menuLeftX + this.screenWidth, g);						 	g.setClip(0, 0, this.screenWidth, this.fullScreenHeight );						} 						if (this.showTitleOrMenu || this.menuOpened) {							// clear menu-bar:							if (this.menuBarColor != Item.TRANSPARENT) {								g.setColor( this.menuBarColor );								//TODO check use menuY instead of this.originalScreenHeight?								g.fillRect(menuLeftX, this.originalScreenHeight, menuRightX,  this.menuBarHeight );							}							if (this.menuContainer != null && this.menuContainer.size() > 0) {								String menuText = null;								if (this.menuOpened) {									//#ifdef polish.i18n.useDynamicTranslations										menuText = Locale.get( "polish.command.select" ); 									//#elifdef polish.command.select:defined										//#= menuText = "${polish.command.select}";									//#else										menuText = "Select";									//#endif								} else {									if (this.menuSingleLeftCommand != null) {										menuText = this.menuSingleLeftCommand.getLabel();									} else {										//#ifdef polish.i18n.useDynamicTranslations											menuText = Locale.get( "polish.command.options" ); 										//#elifdef polish.command.options:defined											//#= menuText = "${polish.command.options}";										//#else											menuText = "Options";														//#endif									}								}								//#ifdef polish.Menu.MarginLeft:defined									//#= int menuLeftX += ${polish.Menu.MarginLeft};								//#else									menuLeftX += 2;								//#endif								//#ifdef polish.hasPointerEvents									this.menuLeftCommandX = menuLeftX + this.menuFont.stringWidth( menuText );								//#endif								g.setColor( this.menuFontColor );								g.setFont( this.menuFont );								//#ifdef polish.Menu.MarginTop:defined									//#= g.drawString(menuLeftX, menuX, this.originalScreenHeight + ${polish.Menu.MarginTop}, Graphics.TOP | Graphics.LEFT );								//#else									g.drawString(menuText, menuLeftX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.LEFT );								//#endif								if ( this.menuOpened ) {									// draw cancel string:									//#ifdef polish.i18n.useDynamicTranslations										menuText = Locale.get( "polish.command.cancel" ); 									//#elifdef polish.command.cancel:defined										//#= menuText = "${polish.command.cancel}";									//#else										menuText = "Cancel";									//#endif									//#ifdef polish.Menu.MarginRight:defined										//#= menuRightX -= ${polish.Menu.MarginRight};									//#elifdef polish.Menu.MarginLeft:defined										menuRightX -= 2;									//#endif									//#ifdef polish.Menu.MarginTop:defined										//#= g.drawString(menuText, menuRightX, this.originalScreenHeight + ${polish.Menu.MarginTop}, Graphics.TOP | Graphics.RIGHT );									//#else										g.drawString(menuText, menuRightX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.RIGHT );									//#endif									//#ifdef polish.hasPointerEvents										this.menuRightCommandX = menuRightX - this.menuFont.stringWidth( menuText );									//#endif								}							}							if (this.menuSingleRightCommand != null && !this.menuOpened) {								g.setColor( this.menuFontColor );								g.setFont( this.menuFont );								String menuText = this.menuSingleRightCommand.getLabel();								//#ifdef polish.Menu.MarginRight:defined									//#= menuRightX -= ${polish.Menu.MarginRight};								//#elifdef polish.Menu.MarginLeft:defined									menuRightX -= 2;								//#endif								//#ifdef polish.Menu.MarginTop:defined									//#= g.drawString(menuText, menuRightX, this.originalScreenHeight + ${polish.Menu.MarginTop}, Graphics.TOP | Graphics.RIGHT );								//#else									g.drawString(menuText, menuRightX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.RIGHT );								//#endif								//#ifdef polish.hasPointerEvents									this.menuRightCommandX = menuRightX - this.menuFont.stringWidth( menuText );								//#endif							}						} // if this.showTitleOrMenu || this.menuOpened					//#endif				//#endif										//#if !tmp.useScrollBar					// paint scroll-indicator in the middle of the menu:										if (this.paintScrollIndicator) {						g.setColor( this.scrollIndicatorColor );						int x = this.scrollIndicatorX;						int y = this.scrollIndicatorY;						//System.out.println("paint: this.scrollIndicatorY=" + this.scrollIndicatorY);						int width = this.scrollIndicatorWidth;						int halfWidth = width / 2;						if (this.paintScrollIndicatorUp) {							//#if polish.css.scrollindicator-up-image								if (this.scrollIndicatorUpImage != null) {									g.drawImage(this.scrollIndicatorUpImage, x, y, Graphics.LEFT | Graphics.TOP );								} else {							//#endif														//#ifdef polish.midp2									g.fillTriangle(x, y + halfWidth-1, x + width, y + halfWidth-1, x + halfWidth, y );								//#else									g.drawLine( x, y + halfWidth-1, x + width, y + halfWidth-1 );									g.drawLine( x, y + halfWidth-1, x + halfWidth, y );									g.drawLine( x + width, y + halfWidth-1, x + halfWidth, y );								//#endif							//#if polish.css.scrollindicator-up-image								}							//#endif						}						if (this.paintScrollIndicatorDown) {							//#if polish.css.scrollindicator-down-image								if (this.scrollIndicatorDownImage != null) {									//#if polish.css.scrollindicator-down-image										if (this.scrollIndicatorUpImage != null) {											y += this.scrollIndicatorUpImage.getHeight() + 1;										} else {											y += halfWidth;										}									//#else										y += halfWidth;									//#endif									g.drawImage(this.scrollIndicatorDownImage, x, y, Graphics.LEFT | Graphics.TOP );								} else {							//#endif														//#ifdef polish.midp2									g.fillTriangle(x, y + halfWidth+1, x + width, y + halfWidth+1, x + halfWidth, y + width );								//#else									g.drawLine( x, y + halfWidth+1, x + width, y + halfWidth+1 );									g.drawLine( x, y + halfWidth+1, x + halfWidth, y + width );									g.drawLine(x + width, y + halfWidth+1, x + halfWidth, y + width );								//#endif							//#if polish.css.scrollindicator-down-image								}							//#endif						}					}				//#endif				//#ifdef polish.css.foreground-image					if (this.foregroundImage != null) {						g.drawImage( this.foregroundImage, this.foregroundX, this.foregroundY, Graphics.TOP | Graphics.LEFT  );					}				//#endif						//#if polish.debug.error			} catch (RuntimeException e) {				//#debug error				System.out.println( "unable to paint screen (" + getClass().getName() + "):" + e );			}			//#endif		}	}