this.menuRightCommandX = this.screenWidth - 2 - this.menuFont.stringWidth( menuText );
this.menuRightCommandX = menuRightX - this.menuFont.stringWidth( menuText );
	public void paint(Graphics g) {		//System.out.println("Painting screen "+ this + ", background == null: " + (this.background == null));		//#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;				this.scrollIndicatorY -= translateY;				//#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		//#ifdef polish.debug.error		try {		//#endif			//#if polish.css.repaint-previous-screen				if (this.repaintPreviousScreen && this.previousScreenImage != null) {					g.drawImage(this.previousScreenImage, 0, 0, Graphics.TOP | Graphics.LEFT );				}			//#endif			int sWidth = this.screenWidth - this.marginLeft - this.marginRight;			int rightBorder = this.marginLeft + sWidth;			//#ifdef tmp.menuFullScreen				int sHeight = this.fullScreenHeight - this.marginTop - this.marginBottom;			//#else				//# int sHeight = this.screenHeight - this.marginTop - this.marginBottom;			//#endif			//int sHeight = this.screenHeight - this.marginTop - this.marginBottom;			// paint background:			if (this.background != null) {				//System.out.println("Screen (" + this + ": using background...");				this.background.paint(this.marginLeft, this.marginTop, sWidth, sHeight, g);			} else {				//System.out.println("Screen (" + this + ": clearing area...");				g.setColor( 0xFFFFFF );				g.fillRect( this.marginLeft, this.marginTop, sWidth, sHeight );			}						int topHeight = this.marginTop;			//#ifdef tmp.usingTitle				//#if polish.css.title-position					if (this.paintTitleAtTop) {				//#endif						// paint title:						if (this.title != null && this.showTitleOrMenu) {							this.title.paint( this.marginLeft, this.marginTop, this.marginLeft, rightBorder, g);							topHeight = this.titleHeight;						}				//#if polish.css.title-position					}				//#endif			//#endif			if (this.subTitle != null) {				this.subTitle.paint( this.marginLeft, topHeight, this.marginLeft, rightBorder, g );				topHeight += this.subTitleHeight;			}			//#ifndef polish.skipTicker							//#if tmp.paintTickerAtTop					if (this.ticker != null) {						this.ticker.paint( this.marginLeft, topHeight, this.marginLeft, rightBorder, g);						topHeight += this.ticker.itemHeight;					}				//#elif polish.css.ticker-position && !polish.TickerPosition:defined					if (this.paintTickerAtTop && this.ticker != null) {						this.ticker.paint( this.marginLeft, topHeight, this.marginLeft, 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			// protect the title, ticker and the full-screen-menu area:			g.setClip(this.marginLeft, topHeight, sWidth, this.screenHeight - topHeight - this.marginBottom );			// 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					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.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( this.marginLeft, bottomY, this.marginLeft, 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(this.marginLeft, 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 = this.marginLeft;					menuRightX = rightBorder;					menuY = this.screenHeight - this.marginBottom;				}			//#endif			//#ifdef tmp.menuFullScreen				//#ifdef tmp.useExternalMenuBar					this.menuBar.paint(menuLeftX, menuY, menuLeftX, menuRightX, g);					if (this.menuBar.isOpened) {						this.paintScrollIndicator = this.menuBar.paintScrollIndicator;						this.paintScrollIndicatorUp = this.menuBar.canScrollUpwards;						this.paintScrollIndicatorDown = this.menuBar.canScrollDownwards;					}				//#else					if (this.menuOpened) {						topHeight -= this.infoHeight;						int menuHeight = this.menuContainer.getItemHeight(this.menuMaxWidth, this.menuMaxWidth);						int y = this.originalScreenHeight - menuHeight;						if (y < topHeight) {							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)) ;							y = topHeight; 							this.menuContainer.setVerticalDimensions(y, this.originalScreenHeight);						} else {							this.paintScrollIndicator = false;						}						g.setClip(0, topHeight, this.screenWidth, this.originalScreenHeight - topHeight );						this.menuContainer.paint(this.marginLeft, y, this.marginLeft, this.menuMaxWidth, 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 );							g.fillRect(this.marginLeft, this.originalScreenHeight, sWidth,  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.hasPointerEvents								this.menuLeftCommandX = 2 + this.menuFont.stringWidth( menuText );							//#endif							g.setColor( this.menuFontColor );							g.setFont( this.menuFont );							//#ifdef polish.Menu.MarginLeft:defined								//#= int menuX = ${polish.Menu.MarginLeft} + this.marginLeft;							//#else								int menuX = 2 + this.marginLeft;							//#endif							//#ifdef polish.Menu.MarginTop:defined								//#= g.drawString(menuText, menuX, this.originalScreenHeight + ${polish.Menu.MarginTop}, Graphics.TOP | Graphics.LEFT );							//#else								g.drawString(menuText, menuX, 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									//#= menuX = ${polish.Menu.MarginRight}  + this.marginRight;								//#elifdef polish.Menu.MarginLeft:defined									menuX = 2 + this.marginRight;								//#endif								//#ifdef polish.Menu.MarginTop:defined									//#= g.drawString(menuText, this.screenWidth - menuX, this.originalScreenHeight + ${polish.Menu.MarginTop}, Graphics.TOP | Graphics.RIGHT );								//#else									g.drawString(menuText, this.screenWidth - menuX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.RIGHT );								//#endif								//#ifdef polish.hasPointerEvents									this.menuRightCommandX = this.screenWidth - 2 - 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								//#= int menuX = ${polish.Menu.MarginRight} + this.marginRight;							//#else								int menuX = 2 + this.marginRight;							//#endif							//#ifdef polish.Menu.MarginTop:defined								//#= g.drawString(menuText, this.screenWidth - menuX, this.originalScreenHeight + ${polish.Menu.MarginTop}, Graphics.TOP | Graphics.RIGHT );							//#else								g.drawString(menuText, this.screenWidth - menuX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.RIGHT );							//#endif							//#ifdef polish.hasPointerEvents								this.menuRightCommandX = this.screenWidth - menuX 									- this.menuFont.stringWidth( menuText );							//#endif						}					} // if this.showTitleOrMenu || this.menuOpened				//#endif			//#endif			// 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.TOP | Graphics.LEFT );						} 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 (this.scrollIndicatorUpImage != null) {								y += this.scrollIndicatorUpImage.getHeight() + 1;							}							g.drawImage(this.scrollIndicatorDownImage, x, y, Graphics.TOP | Graphics.LEFT );						} 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				}			}			//#ifdef polish.css.foreground-image				if (this.foregroundImage != null) {					g.drawImage( this.foregroundImage, this.foregroundX, this.foregroundY, Graphics.TOP | Graphics.LEFT  );				}			//#endif				//#ifdef polish.debug.error		} catch (RuntimeException e) {			//#debug error			System.out.println( "unable to paint screen (" + getClass().getName() + "):" + e );		}		//#endif	}