private void layoutItem(MTabBarItem item,IStyleProvider styles){
  int contentX=item.contentBounds.x + item.marginWidth;
  int contentY=item.contentBounds.y + item.marginHeight;
  int contentWidth=item.contentBounds.width - item.marginWidth - item.marginWidth;
  int contentHeight=item.contentBounds.height - item.marginHeight - item.marginHeight;
  if (item.imageVisible && item.textVisible) {
    boolean itemVertical=(item.textPosition & (SWT.TOP | SWT.BOTTOM)) != 0;
    boolean imageLeading=(item.textPosition & (SWT.RIGHT | SWT.BOTTOM)) != 0;
    Point imageSize=item.imageVisible ? computeImageSize(item.getImage()) : new Point(0,0);
    Point textSize=item.textVisible ? computeTextSize(item.getText(),item.font) : new Point(0,0);
    int imageWHint=styles.getWidth(item,MTabBarItem.IMAGE,itemVertical ? contentWidth : SWT.DEFAULT);
    int imageHHint=styles.getHeight(item,MTabBarItem.IMAGE,itemVertical ? SWT.DEFAULT : contentHeight);
    int textWHint=styles.getWidth(item,MTabBarItem.TEXT,itemVertical ? contentWidth : SWT.DEFAULT);
    int textHHint=styles.getHeight(item,MTabBarItem.TEXT,itemVertical ? SWT.DEFAULT : contentHeight);
    Point imageAreaSize=item.imageVisible ? computePreferredSize(imageSize.x,imageSize.y,imageWHint,imageHHint) : new Point(0,0);
    Point textAreaSize=item.textVisible ? computePreferredSize(textSize.x,textSize.y,textWHint,textHHint) : new Point(0,0);
    if (itemVertical) {
      if (imageHHint > 0 && textHHint < 0) {
        textAreaSize.y=Math.max(0,contentHeight - imageAreaSize.y - item.vSpacing);
      }
 else       if (imageHHint < 0 && textHHint > 0) {
        imageAreaSize.y=Math.max(0,contentHeight - textAreaSize.y - item.vSpacing);
      }
    }
 else {
      if (imageWHint > 0 && textWHint < 0) {
        textAreaSize.x=Math.max(0,contentWidth - imageAreaSize.x - item.hSpacing);
      }
 else       if (imageWHint < 0 && textWHint > 0) {
        imageAreaSize.x=Math.max(0,contentWidth - textAreaSize.x - item.hSpacing);
      }
    }
    imageSize=computeConstrainedSize(imageSize.x,imageSize.y,imageAreaSize.x,imageAreaSize.y);
    textSize=computeConstrainedSize(textSize.x,textSize.y,textAreaSize.x,textAreaSize.y);
    if (itemVertical) {
      item.imageBounds.x=contentX + (contentWidth - imageSize.x) / 2;
      item.imageBounds.y=contentY + (imageAreaSize.y - imageSize.y) / 2;
      item.textBounds.x=contentX + (contentWidth - textSize.x) / 2;
      item.textBounds.y=contentY + (textAreaSize.y - textSize.y) / 2;
      if (imageLeading) {
        item.textBounds.y+=imageAreaSize.y + item.vSpacing;
      }
 else {
        item.imageBounds.y+=textAreaSize.y + item.vSpacing;
      }
    }
 else {
      item.imageBounds.x=contentX + (imageAreaSize.x - imageSize.x) / 2;
      item.imageBounds.y=contentY + (contentHeight - imageSize.y) / 2;
      item.textBounds.x=contentX + (textAreaSize.x - textSize.x) / 2;
      item.textBounds.y=contentY + (textAreaSize.y - textSize.y) / 2;
      if (imageLeading) {
        item.textBounds.x+=imageAreaSize.x + item.hSpacing;
      }
 else {
        item.imageBounds.x+=textAreaSize.x + item.hSpacing;
      }
    }
    item.imageBounds.width=imageSize.x;
    item.imageBounds.height=imageSize.y;
    item.textBounds.width=textSize.x;
    item.textBounds.height=textSize.y;
  }
 else   if (item.imageVisible) {
    Point imageSize=computeImageSize(item.getImage());
    Point constrainedSize=computeConstrainedSize(imageSize.x,imageSize.y,contentWidth,contentHeight);
    item.imageBounds.x=contentX + (contentWidth - constrainedSize.x) / 2;
    item.imageBounds.y=contentY + (contentHeight - constrainedSize.y) / 2;
    item.imageBounds.width=constrainedSize.x;
    item.imageBounds.height=constrainedSize.y;
    item.textBounds.x=0;
    item.textBounds.y=0;
    item.textBounds.width=0;
    item.textBounds.height=0;
  }
 else   if (item.textVisible) {
    Point textSize=computeTextSize(item.getText(),item.font);
    Point constrainedSize=computeConstrainedSize(textSize.x,textSize.y,contentWidth,contentHeight);
    item.imageBounds.x=0;
    item.imageBounds.y=0;
    item.imageBounds.width=0;
    item.imageBounds.height=0;
    item.textBounds.x=contentX + (contentWidth - constrainedSize.x) / 2;
    item.textBounds.y=contentY + (contentHeight - constrainedSize.y) / 2;
    item.textBounds.width=constrainedSize.x;
    item.textBounds.height=constrainedSize.y;
  }
 else {
    item.imageBounds.x=0;
    item.imageBounds.y=0;
    item.imageBounds.width=0;
    item.imageBounds.height=0;
    item.textBounds.x=0;
    item.textBounds.y=0;
    item.textBounds.width=0;
    item.textBounds.height=0;
  }
}

private void layoutItem ( MTabBarItem item , IStyleProvider styles ) { int contentX = item . contentBounds . x + item . marginWidth ; int contentY = item . contentBounds . y + item . marginHeight ; int contentWidth = item . contentBounds . width - item . marginWidth - item . marginWidth ; int contentHeight = item . contentBounds . height - item . marginHeight - item . marginHeight ; if ( item . imageVisible && item . textVisible ) { boolean itemVertical = ( item . textPosition & ( SWT . TOP | SWT . BOTTOM ) ) != 0 ; boolean imageLeading = ( item . textPosition & ( SWT . RIGHT | SWT . BOTTOM ) ) != 0 ; Point imageSize = item . imageVisible ? computeImageSize ( item . getImage ( ) ) : new Point ( 0 , 0 ) ; Point textSize = item . textVisible ? computeTextSize ( item . getText ( ) , item . font ) : new Point ( 0 , 0 ) ; int imageWHint = styles . getWidth ( item , MTabBarItem . IMAGE , itemVertical ? contentWidth : SWT . DEFAULT ) ; int imageHHint = styles . getHeight ( item , MTabBarItem . IMAGE , itemVertical ? SWT . DEFAULT : contentHeight ) ; int textWHint = styles . getWidth ( item , MTabBarItem . TEXT , itemVertical ? contentWidth : SWT . DEFAULT ) ; int textHHint = styles . getHeight ( item , MTabBarItem . TEXT , itemVertical ? SWT . DEFAULT : contentHeight ) ; Point imageAreaSize = item . imageVisible ? computePreferredSize ( imageSize . x , imageSize . y , imageWHint , imageHHint ) : new Point ( 0 , 0 ) ; Point textAreaSize = item . textVisible ? computePreferredSize ( textSize . x , textSize . y , textWHint , textHHint ) : new Point ( 0 , 0 ) ; if ( itemVertical ) { if ( imageHHint > 0 && textHHint < 0 ) { textAreaSize . y = Math . max ( 0 , contentHeight - imageAreaSize . y - item . vSpacing ) ; } else if ( imageHHint < 0 && textHHint > 0 ) { imageAreaSize . y = Math . max ( 0 , contentHeight - textAreaSize . y - item . vSpacing ) ; } } else { if ( imageWHint > 0 && textWHint < 0 ) { textAreaSize . x = Math . max ( 0 , contentWidth - imageAreaSize . x - item . hSpacing ) ; } else if ( imageWHint < 0 && textWHint > 0 ) { imageAreaSize . x = Math . max ( 0 , contentWidth - textAreaSize . x - item . hSpacing ) ; } } imageSize = computeConstrainedSize ( imageSize . x , imageSize . y , imageAreaSize . x , imageAreaSize . y ) ; textSize = computeConstrainedSize ( textSize . x , textSize . y , textAreaSize . x , textAreaSize . y ) ; if ( itemVertical ) { item . imageBounds . x = contentX + ( contentWidth - imageSize . x ) / 2 ; item . imageBounds . y = contentY + ( imageAreaSize . y - imageSize . y ) / 2 ; item . textBounds . x = contentX + ( contentWidth - textSize . x ) / 2 ; item . textBounds . y = contentY + ( textAreaSize . y - textSize . y ) / 2 ; if ( imageLeading ) { item . textBounds . y += imageAreaSize . y + item . vSpacing ; } else { item . imageBounds . y += textAreaSize . y + item . vSpacing ; } } else { item . imageBounds . x = contentX + ( imageAreaSize . x - imageSize . x ) / 2 ; item . imageBounds . y = contentY + ( contentHeight - imageSize . y ) / 2 ; item . textBounds . x = contentX + ( textAreaSize . x - textSize . x ) / 2 ; item . textBounds . y = contentY + ( textAreaSize . y - textSize . y ) / 2 ; if ( imageLeading ) { item . textBounds . x += imageAreaSize . x + item . hSpacing ; } else { item . imageBounds . x += textAreaSize . x + item . hSpacing ; } } item . imageBounds . width = imageSize . x ; item . imageBounds . height = imageSize . y ; item . textBounds . width = textSize . x ; item . textBounds . height = textSize . y ; } else if ( item . imageVisible ) { Point imageSize = computeImageSize ( item . getImage ( ) ) ; Point constrainedSize = computeConstrainedSize ( imageSize . x , imageSize . y , contentWidth , contentHeight ) ; item . imageBounds . x = contentX + ( contentWidth - constrainedSize . x ) / 2 ; item . imageBounds . y = contentY + ( contentHeight - constrainedSize . y ) / 2 ; item . imageBounds . width = constrainedSize . x ; item . imageBounds . height = constrainedSize . y ; item . textBounds . x = 0 ; item . textBounds . y = 0 ; item . textBounds . width = 0 ; item . textBounds . height = 0 ; } else if ( item . textVisible ) { Point textSize = computeTextSize ( item . getText ( ) , item . font ) ; Point constrainedSize = computeConstrainedSize ( textSize . x , textSize . y , contentWidth , contentHeight ) ; item . imageBounds . x = 0 ; item . imageBounds . y = 0 ; item . imageBounds . width = 0 ; item . imageBounds . height = 0 ; item . textBounds . x = contentX + ( contentWidth - constrainedSize . x ) / 2 ; item . textBounds . y = contentY + ( contentHeight - constrainedSize . y ) / 2 ; item . textBounds . width = constrainedSize . x ; item . textBounds . height = constrainedSize . y ; } else { item . imageBounds . x = 0 ; item . imageBounds . y = 0 ; item . imageBounds . width = 0 ; item . imageBounds . height = 0 ; item . textBounds . x = 0 ; item . textBounds . y = 0 ; item . textBounds . width = 0 ; item . textBounds . height = 0 ; } }
validates bounds of item image and text .
