public void drawLabelComponent(Object nativeGraphics,int cmpX,int cmpY,int cmpHeight,int cmpWidth,Style style,String text,Object icon,Object stateIcon,int preserveSpaceForState,int gap,boolean rtl,boolean isOppositeSide,int textPosition,int stringWidth,boolean isTickerRunning,int tickerShiftText,boolean endsWith3Points,int valign){
  Font font=style.getFont();
  Object nativeFont=font.getNativeFont();
  setNativeFont(nativeGraphics,nativeFont);
  setColor(nativeGraphics,style.getFgColor());
  int iconWidth=0;
  int iconHeight=0;
  if (icon != null) {
    iconWidth=getImageWidth(icon);
    iconHeight=getImageHeight(icon);
  }
  int textDecoration=style.getTextDecoration();
  int stateIconSize=0;
  int stateIconYPosition=0;
  int leftPadding=style.getPaddingLeft(rtl);
  int rightPadding=style.getPaddingRight(rtl);
  int topPadding=style.getPaddingTop();
  int bottomPadding=style.getPaddingBottom();
  int fontHeight=0;
  if (text == null) {
    text="";
  }
  if (text.length() > 0) {
    fontHeight=font.getHeight();
  }
  if (stateIcon != null) {
    stateIconSize=getImageWidth(stateIcon);
    stateIconYPosition=cmpY + topPadding + (cmpHeight - topPadding - bottomPadding) / 2 - stateIconSize / 2;
    int tX=cmpX;
    if (isOppositeSide) {
      if (rtl) {
        tX+=leftPadding;
      }
 else {
        tX=tX + cmpWidth - leftPadding - stateIconSize;
      }
      cmpWidth-=leftPadding - stateIconSize;
    }
 else {
      preserveSpaceForState=stateIconSize + gap;
      if (rtl) {
        tX=tX + cmpWidth - leftPadding - stateIconSize;
      }
 else {
        tX+=leftPadding;
      }
    }
    drawImage(nativeGraphics,stateIcon,tX,stateIconYPosition);
  }
  int x=cmpX + leftPadding + preserveSpaceForState;
  int y=cmpY + topPadding;
  int align=reverseAlignForBidi(rtl,style.getAlignment());
  int textPos=reverseAlignForBidi(rtl,textPosition);
switch (align) {
case Component.LEFT:
switch (textPos) {
case Label.LEFT:
case Label.RIGHT:
      y=y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? iconHeight : 0),fontHeight))) / 2;
    break;
case Label.BOTTOM:
case Label.TOP:
  y=y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? iconHeight + gap : 0)+ fontHeight)) / 2;
break;
}
break;
case Component.CENTER:
switch (textPos) {
case Label.LEFT:
case Label.RIGHT:
x=x + (cmpWidth - (preserveSpaceForState + leftPadding + rightPadding+ ((icon != null) ? iconWidth + gap : 0)+ stringWidth)) / 2;
x=Math.max(x,cmpX + leftPadding + preserveSpaceForState);
y=y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? iconHeight : 0),fontHeight))) / 2;
break;
case Label.BOTTOM:
case Label.TOP:
x=x + (cmpWidth - (preserveSpaceForState + leftPadding + rightPadding+ Math.max(((icon != null) ? iconWidth + gap : 0),stringWidth))) / 2;
x=Math.max(x,cmpX + leftPadding + preserveSpaceForState);
y=y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? iconHeight + gap : 0)+ fontHeight)) / 2;
break;
}
break;
case Component.RIGHT:
switch (textPos) {
case Label.LEFT:
case Label.RIGHT:
x=cmpX + cmpWidth - rightPadding - (((icon != null) ? (iconWidth + gap) : 0) + stringWidth);
if (rtl) {
x=Math.max(x - preserveSpaceForState,cmpX + leftPadding);
}
 else {
x=Math.max(x,cmpX + leftPadding + preserveSpaceForState);
}
y=y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? iconHeight : 0),fontHeight))) / 2;
break;
case Label.BOTTOM:
case Label.TOP:
x=cmpX + cmpWidth - rightPadding - (Math.max(((icon != null) ? (iconWidth) : 0),stringWidth));
x=Math.max(x,cmpX + leftPadding + preserveSpaceForState);
y=y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? iconHeight + gap : 0)+ fontHeight)) / 2;
break;
}
break;
default :
break;
}
int textSpaceW=cmpWidth - rightPadding - leftPadding;
if (icon != null && (textPos == Label.RIGHT || textPos == Label.LEFT)) {
textSpaceW=textSpaceW - iconWidth;
}
if (stateIcon != null) {
textSpaceW=textSpaceW - stateIconSize;
}
 else {
textSpaceW=textSpaceW - preserveSpaceForState;
}
if (icon == null) {
drawLabelString(nativeGraphics,nativeFont,text,x,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,fontHeight);
}
 else {
int strWidth=stringWidth;
int iconStringWGap;
int iconStringHGap;
switch (textPos) {
case Label.LEFT:
if (iconHeight > fontHeight) {
iconStringHGap=(iconHeight - fontHeight) / 2;
strWidth=drawLabelStringValign(nativeGraphics,nativeFont,text,x,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,strWidth,iconStringHGap,iconHeight,fontHeight,valign);
drawImage(nativeGraphics,icon,x + strWidth + gap,y);
}
 else {
iconStringHGap=(fontHeight - iconHeight) / 2;
strWidth=drawLabelString(nativeGraphics,nativeFont,text,x,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,strWidth,fontHeight);
drawImage(nativeGraphics,icon,x + strWidth + gap,y + iconStringHGap);
}
break;
case Label.RIGHT:
if (iconHeight > fontHeight) {
iconStringHGap=(iconHeight - fontHeight) / 2;
drawImage(nativeGraphics,icon,x,y);
drawLabelStringValign(nativeGraphics,nativeFont,text,x + iconWidth + gap,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,iconStringHGap,iconHeight,fontHeight,valign);
}
 else {
iconStringHGap=(fontHeight - iconHeight) / 2;
drawImage(nativeGraphics,icon,x,y + iconStringHGap);
drawLabelString(nativeGraphics,nativeFont,text,x + iconWidth + gap,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,fontHeight);
}
break;
case Label.BOTTOM:
if (iconWidth > strWidth) {
iconStringWGap=(iconWidth - strWidth) / 2;
drawImage(nativeGraphics,icon,x,y);
drawLabelString(nativeGraphics,nativeFont,text,x + iconStringWGap,y + iconHeight + gap,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,fontHeight);
}
 else {
iconStringWGap=(Math.min(strWidth,textSpaceW) - iconWidth) / 2;
drawImage(nativeGraphics,icon,x + iconStringWGap,y);
drawLabelString(nativeGraphics,nativeFont,text,x,y + iconHeight + gap,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,fontHeight);
}
break;
case Label.TOP:
if (iconWidth > strWidth) {
iconStringWGap=(iconWidth - strWidth) / 2;
drawLabelString(nativeGraphics,nativeFont,text,x + iconStringWGap,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,fontHeight);
drawImage(nativeGraphics,icon,x,y + fontHeight + gap);
}
 else {
iconStringWGap=(Math.min(strWidth,textSpaceW) - iconWidth) / 2;
drawLabelString(nativeGraphics,nativeFont,text,x,y,textSpaceW,isTickerRunning,tickerShiftText,textDecoration,rtl,endsWith3Points,stringWidth,fontHeight);
drawImage(nativeGraphics,icon,x + iconStringWGap,y + fontHeight + gap);
}
break;
}
}
}

public void drawLabelComponent ( Object nativeGraphics , int cmpX , int cmpY , int cmpHeight , int cmpWidth , Style style , String text , Object icon , Object stateIcon , int preserveSpaceForState , int gap , boolean rtl , boolean isOppositeSide , int textPosition , int stringWidth , boolean isTickerRunning , int tickerShiftText , boolean endsWith3Points , int valign ) { Font font = style . getFont ( ) ; Object nativeFont = font . getNativeFont ( ) ; setNativeFont ( nativeGraphics , nativeFont ) ; setColor ( nativeGraphics , style . getFgColor ( ) ) ; int iconWidth = 0 ; int iconHeight = 0 ; if ( icon != null ) { iconWidth = getImageWidth ( icon ) ; iconHeight = getImageHeight ( icon ) ; } int textDecoration = style . getTextDecoration ( ) ; int stateIconSize = 0 ; int stateIconYPosition = 0 ; int leftPadding = style . getPaddingLeft ( rtl ) ; int rightPadding = style . getPaddingRight ( rtl ) ; int topPadding = style . getPaddingTop ( ) ; int bottomPadding = style . getPaddingBottom ( ) ; int fontHeight = 0 ; if ( text == null ) { text = "" ; } if ( text . length ( ) > 0 ) { fontHeight = font . getHeight ( ) ; } if ( stateIcon != null ) { stateIconSize = getImageWidth ( stateIcon ) ; stateIconYPosition = cmpY + topPadding + ( cmpHeight - topPadding - bottomPadding ) / 2 - stateIconSize / 2 ; int tX = cmpX ; if ( isOppositeSide ) { if ( rtl ) { tX += leftPadding ; } else { tX = tX + cmpWidth - leftPadding - stateIconSize ; } cmpWidth -= leftPadding - stateIconSize ; } else { preserveSpaceForState = stateIconSize + gap ; if ( rtl ) { tX = tX + cmpWidth - leftPadding - stateIconSize ; } else { tX += leftPadding ; } } drawImage ( nativeGraphics , stateIcon , tX , stateIconYPosition ) ; } int x = cmpX + leftPadding + preserveSpaceForState ; int y = cmpY + topPadding ; int align = reverseAlignForBidi ( rtl , style . getAlignment ( ) ) ; int textPos = reverseAlignForBidi ( rtl , textPosition ) ; switch ( align ) { case Component . LEFT : switch ( textPos ) { case Label . LEFT : case Label . RIGHT : y = y + ( cmpHeight - ( topPadding + bottomPadding + Math . max ( ( ( icon != null ) ? iconHeight : 0 ) , fontHeight ) ) ) / 2 ; break ; case Label . BOTTOM : case Label . TOP : y = y + ( cmpHeight - ( topPadding + bottomPadding + ( ( icon != null ) ? iconHeight + gap : 0 ) + fontHeight ) ) / 2 ; break ; } break ; case Component . CENTER : switch ( textPos ) { case Label . LEFT : case Label . RIGHT : x = x + ( cmpWidth - ( preserveSpaceForState + leftPadding + rightPadding + ( ( icon != null ) ? iconWidth + gap : 0 ) + stringWidth ) ) / 2 ; x = Math . max ( x , cmpX + leftPadding + preserveSpaceForState ) ; y = y + ( cmpHeight - ( topPadding + bottomPadding + Math . max ( ( ( icon != null ) ? iconHeight : 0 ) , fontHeight ) ) ) / 2 ; break ; case Label . BOTTOM : case Label . TOP : x = x + ( cmpWidth - ( preserveSpaceForState + leftPadding + rightPadding + Math . max ( ( ( icon != null ) ? iconWidth + gap : 0 ) , stringWidth ) ) ) / 2 ; x = Math . max ( x , cmpX + leftPadding + preserveSpaceForState ) ; y = y + ( cmpHeight - ( topPadding + bottomPadding + ( ( icon != null ) ? iconHeight + gap : 0 ) + fontHeight ) ) / 2 ; break ; } break ; case Component . RIGHT : switch ( textPos ) { case Label . LEFT : case Label . RIGHT : x = cmpX + cmpWidth - rightPadding - ( ( ( icon != null ) ? ( iconWidth + gap ) : 0 ) + stringWidth ) ; if ( rtl ) { x = Math . max ( x - preserveSpaceForState , cmpX + leftPadding ) ; } else { x = Math . max ( x , cmpX + leftPadding + preserveSpaceForState ) ; } y = y + ( cmpHeight - ( topPadding + bottomPadding + Math . max ( ( ( icon != null ) ? iconHeight : 0 ) , fontHeight ) ) ) / 2 ; break ; case Label . BOTTOM : case Label . TOP : x = cmpX + cmpWidth - rightPadding - ( Math . max ( ( ( icon != null ) ? ( iconWidth ) : 0 ) , stringWidth ) ) ; x = Math . max ( x , cmpX + leftPadding + preserveSpaceForState ) ; y = y + ( cmpHeight - ( topPadding + bottomPadding + ( ( icon != null ) ? iconHeight + gap : 0 ) + fontHeight ) ) / 2 ; break ; } break ; default : break ; } int textSpaceW = cmpWidth - rightPadding - leftPadding ; if ( icon != null && ( textPos == Label . RIGHT || textPos == Label . LEFT ) ) { textSpaceW = textSpaceW - iconWidth ; } if ( stateIcon != null ) { textSpaceW = textSpaceW - stateIconSize ; } else { textSpaceW = textSpaceW - preserveSpaceForState ; } if ( icon == null ) { drawLabelString ( nativeGraphics , nativeFont , text , x , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , fontHeight ) ; } else { int strWidth = stringWidth ; int iconStringWGap ; int iconStringHGap ; switch ( textPos ) { case Label . LEFT : if ( iconHeight > fontHeight ) { iconStringHGap = ( iconHeight - fontHeight ) / 2 ; strWidth = drawLabelStringValign ( nativeGraphics , nativeFont , text , x , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , strWidth , iconStringHGap , iconHeight , fontHeight , valign ) ; drawImage ( nativeGraphics , icon , x + strWidth + gap , y ) ; } else { iconStringHGap = ( fontHeight - iconHeight ) / 2 ; strWidth = drawLabelString ( nativeGraphics , nativeFont , text , x , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , strWidth , fontHeight ) ; drawImage ( nativeGraphics , icon , x + strWidth + gap , y + iconStringHGap ) ; } break ; case Label . RIGHT : if ( iconHeight > fontHeight ) { iconStringHGap = ( iconHeight - fontHeight ) / 2 ; drawImage ( nativeGraphics , icon , x , y ) ; drawLabelStringValign ( nativeGraphics , nativeFont , text , x + iconWidth + gap , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , iconStringHGap , iconHeight , fontHeight , valign ) ; } else { iconStringHGap = ( fontHeight - iconHeight ) / 2 ; drawImage ( nativeGraphics , icon , x , y + iconStringHGap ) ; drawLabelString ( nativeGraphics , nativeFont , text , x + iconWidth + gap , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , fontHeight ) ; } break ; case Label . BOTTOM : if ( iconWidth > strWidth ) { iconStringWGap = ( iconWidth - strWidth ) / 2 ; drawImage ( nativeGraphics , icon , x , y ) ; drawLabelString ( nativeGraphics , nativeFont , text , x + iconStringWGap , y + iconHeight + gap , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , fontHeight ) ; } else { iconStringWGap = ( Math . min ( strWidth , textSpaceW ) - iconWidth ) / 2 ; drawImage ( nativeGraphics , icon , x + iconStringWGap , y ) ; drawLabelString ( nativeGraphics , nativeFont , text , x , y + iconHeight + gap , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , fontHeight ) ; } break ; case Label . TOP : if ( iconWidth > strWidth ) { iconStringWGap = ( iconWidth - strWidth ) / 2 ; drawLabelString ( nativeGraphics , nativeFont , text , x + iconStringWGap , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , fontHeight ) ; drawImage ( nativeGraphics , icon , x , y + fontHeight + gap ) ; } else { iconStringWGap = ( Math . min ( strWidth , textSpaceW ) - iconWidth ) / 2 ; drawLabelString ( nativeGraphics , nativeFont , text , x , y , textSpaceW , isTickerRunning , tickerShiftText , textDecoration , rtl , endsWith3Points , stringWidth , fontHeight ) ; drawImage ( nativeGraphics , icon , x + iconStringWGap , y + fontHeight + gap ) ; } break ; } } }
draws a label on the given graphics context , this method allows optimizing the very common drawing operation using platform native code
