layoutButtons();
if (area.width == 0 || area.height == 0 || items.length == 0) return false;  shortenedTabs = false; int[] widths = new int[items.length]; GC gc = new GC(this); for (int i = 0; i < items.length; i++) { widths[i] = items[i].preferredWidth(gc); } gc.dispose();  int oldAverageWidth = 0; int averageWidth = (area.width - borderLeft - borderRight) / items.length; while (averageWidth > oldAverageWidth) { int width = area.width - borderLeft - borderRight; int count = items.length; for (int i = 0; i < items.length; i++) { if (widths[i] < averageWidth) { width -= widths[i]; count--; } } oldAverageWidth = averageWidth; if (count > 0) { averageWidth = width / count; } } if (averageWidth > MIN_TAB_WIDTH * tabHeight) { for (int i = 0; i < items.length; i++) { if (widths[i] > averageWidth) { widths[i] = averageWidth; } } topTabIndex = 0; shortenedTabs = true; }  boolean changed = false; int totalWidth = 0; for (int i = 0; i < items.length; i++) { CTabItem tab = items[i]; if (tab.height != tabHeight || tab.width != widths[i]) changed = true; tab.height = tabHeight; tab.width = widths[i]; totalWidth += widths[i]; }  if (setItemsLocation()) changed = true;  int areaWidth = area.x + area.width - borderRight; if (totalWidth <= areaWidth) {  if (topTabIndex != 0) { topTabIndex = 0; setItemsLocation(); changed = true; } } else {  CTabItem lastItem = items[items.length -1]; if (lastItem.x + lastItem.width < areaWidth) { int scrollWidth = arrowBar.getSize().x; int maxWidth = areaWidth; if (scroll_leftVisible() || scroll_rightVisible()) { maxWidth -=  scrollWidth; } while (topTabIndex > 0 && maxWidth - lastItem.x - lastItem.width > items[topTabIndex - 1].width) { topTabIndex--; setItemsLocation(); changed = true; maxWidth = areaWidth; if (scroll_leftVisible() || scroll_rightVisible()) { maxWidth -=  scrollWidth; } } } } return changed;
 void layoutItems() {	if (isDisposed()) return;	Rectangle area = super.getClientArea();	int tabHeight = getTabHeight();	shortenedTabs = false;	if (items.length > 0) {		int[] widths = new int[items.length];		int totalWidth = 0;		GC gc = new GC(this);		for (int i = 0; i < items.length; i++) {			widths[i] = items[i].preferredWidth(gc);			totalWidth += widths[i];		}		gc.dispose();		if (totalWidth < (area.width - borderLeft - borderRight) ) {			topTabIndex = 0;		} else {						int oldAverageWidth = 0;			int averageWidth = (area.width - borderLeft - borderRight) / items.length;			while (averageWidth > oldAverageWidth) {				int width = area.width - borderLeft - borderRight;				int count = items.length;				for (int i = 0; i < items.length; i++) {					if (widths[i] < averageWidth) {						width -= widths[i];						count--;					}				}				oldAverageWidth = averageWidth;				if (count > 0) {					averageWidth = width / count;				}			}			if (averageWidth > MIN_TAB_WIDTH * tabHeight) {				for (int i = 0; i < items.length; i++) {					if (widths[i] > averageWidth) {						widths[i] = averageWidth;					}				}				topTabIndex = 0;				shortenedTabs = true;			}		}		int x = area.x;		int y = area.y + borderTop;		if (onBottom) {			y = Math.max(0, area.y + area.height - borderBottom - tabHeight);		}		for (int i = topTabIndex - 1; i>=0; i--) { 			// if the first visible tab is not the first tab			CTabItem tab = items[i];			tab.width = widths[i];			tab.height = getTabHeight();			x -= tab.width; 			// layout tab items from right to left thus making them invisible			tab.x = x;			tab.y = y;		}				x = area.x + borderLeft;		for (int i=topTabIndex; i<items.length; i++) {			// continue laying out remaining, visible items left to right 			CTabItem tab = items[i];			tab.x = x;			tab.y = y;			tab.height = tabHeight;			tab.width = widths[i];			x = x + tab.width;		}	}		xClient = area.x + borderLeft + marginWidth;	if (onBottom) {		yClient = area.y + borderTop + marginHeight; 	} else {		yClient = area.y + borderTop + tabHeight + 1 + marginHeight; 		// +1 is for the line at the bottom of the tabs	}		// resize the scrollbar and close butotns	layoutButtons();}