this.contentHeight = myContentHeight; this.contentWidth = myContentWidth; return;  }     boolean isNormalWidthColumns = (this.columnsSetting == NORMAL_WIDTH_COLUMNS); if (this.columnsSetting != STATIC_WIDTH_COLUMNS) { int availableColumnWidth; if (isNormalWidthColumns) {     availableColumnWidth = lineWidth - ((this.numberOfColumns -1) * this.paddingHorizontal); } else {  availableColumnWidth = (lineWidth - ((this.numberOfColumns -1) * this.paddingHorizontal)) / this.numberOfColumns; }  this.columnsWidths = new int[ this.numberOfColumns ]; for (int i = 0; i < this.numberOfColumns; i++) { this.columnsWidths[i] = availableColumnWidth; } } else { int restWidth = 0; int dynamicColumnIndex = -1; for (int i = 0; i < this.numberOfColumns; i++) { int w = this.columnsWidths[i]; if (w == -1) { dynamicColumnIndex = i; } else { restWidth += w; } } if (dynamicColumnIndex != -1) { this.columnsWidths[ dynamicColumnIndex ] = lineWidth - restWidth; } }  ArrayList rowHeightsList = new ArrayList( (myItems.length / this.numberOfColumns) + (myItems.length % 2) + 1 );  this.numberOfRows = (myItems.length / this.numberOfColumns) + (myItems.length % 2); this.rowsHeights = new int[ this.numberOfRows ];  int maxRowHeight = 0; int columnIndex = 0; int rowIndex = 0; int[] maxColumnWidths = null; if (isNormalWidthColumns) { maxColumnWidths = new int[ this.numberOfColumns ]; } int maxWidth = 0; int myContentHeight = 0;  for (int i=0; i< myItems.length; i++) { Item item = myItems[i]; int availableWidth = this.columnsWidths[columnIndex];  int itemColSpan = item.colSpan; if (item.style != null) { Integer colSpanInt = item.style.getIntProperty("colspan"); if ( colSpanInt != null ) { itemColSpan = colSpanInt.intValue();  } } if (itemColSpan > 1) {    int maxColSpan = this.numberOfColumns - columnIndex; if (itemColSpan > maxColSpan) {  System.err.println("Warning: colspan " + itemColSpan + " is invalid at column " + columnIndex + " of a table with " + this.numberOfColumns + " columns, now using maximum possible value " + maxColSpan + "."); itemColSpan = maxColSpan; } if (item.colSpan != itemColSpan) {  item.colSpan = itemColSpan; item.isInitialised = false; }      if (!isNormalWidthColumns) { for (int j = columnIndex + 1; j < columnIndex + itemColSpan; j++) { availableWidth += this.paddingHorizontal + this.columnsWidths[j]; } } }   int width = item.getItemWidth( availableWidth, availableWidth );  int height = item.getItemHeight( availableWidth, availableWidth );    if (this.autoFocusEnabled  && (i >= this.autoFocusIndex ) && (item.appearanceMode != Item.PLAIN)) {  System.out.println("Container: Autofocusing item " + i ); this.autoFocusEnabled = false; focus( i, item, 0 ); height = item.getItemHeight( availableWidth, availableWidth ); width = item.getItemWidth( availableWidth, availableWidth ); }  if (height > maxRowHeight) { maxRowHeight = height; }  if (itemColSpan == 1) {  if (isNormalWidthColumns && width > maxColumnWidths[columnIndex ]) { maxColumnWidths[ columnIndex ] = width; } if (width > maxWidth ) { maxWidth = width; }  }   columnIndex += itemColSpan;  columnIndex++;  if (columnIndex == this.numberOfColumns) {  columnIndex = 0;  rowHeightsList.add( new Integer( maxRowHeight ) );  this.rowsHeights[rowIndex] = maxRowHeight;  myContentHeight += maxRowHeight + this.paddingVertical; maxRowHeight = 0; rowIndex++; } }  this.numberOfRows = rowHeightsList.size(); this.rowsHeights = new int[ this.numberOfRows ]; for (int i = 0; i < this.numberOfRows; i++) { this.rowsHeights[i] = ((Integer) rowHeightsList.get(i)).intValue(); }   if (isNormalWidthColumns) {         int availableRowWidth = lineWidth - ((this.numberOfColumns -1) * this.paddingHorizontal); int availableColumnWidth = availableRowWidth / this.numberOfColumns; int usedUpWidth = 0; int leftColumns = this.numberOfColumns; int completeWidth = 0; for (int i = 0; i < maxColumnWidths.length; i++) { int maxColumnWidth = maxColumnWidths[i]; if (maxColumnWidth <= availableColumnWidth) { usedUpWidth += maxColumnWidth; leftColumns--; } completeWidth += maxColumnWidth; } if (completeWidth <= availableRowWidth) {  this.columnsWidths = maxColumnWidths; } else {   int leftAvailableColumnWidth = (availableRowWidth - usedUpWidth) / leftColumns; int[] newMaxColumnWidths = new int[ this.numberOfColumns ]; myContentHeight = 0; columnIndex = 0; rowIndex = 0; maxRowHeight = 0; maxWidth = 0;  for (int i = 0; i < myItems.length; i++) { Item item = myItems[i]; int width = item.itemWidth; int height = item.itemHeight; if (maxColumnWidths[ columnIndex ] <= availableColumnWidth) { newMaxColumnWidths[ columnIndex ] = maxColumnWidths[ columnIndex ]; } else {   if ( width > leftAvailableColumnWidth ) { item.isInitialised = false; width = item.getItemWidth( leftAvailableColumnWidth, leftAvailableColumnWidth ); height = item.getItemHeight( leftAvailableColumnWidth, leftAvailableColumnWidth ); } if (width > newMaxColumnWidths[ columnIndex ]) { newMaxColumnWidths[ columnIndex ] = width; } } if (height > maxRowHeight) { maxRowHeight = height; }  columnIndex += item.colSpan;  columnIndex++;   if (columnIndex == this.numberOfColumns) {  columnIndex = 0; this.rowsHeights[rowIndex] = maxRowHeight; myContentHeight += maxRowHeight + this.paddingVertical; maxRowHeight = 0; rowIndex++; } } this.columnsWidths = newMaxColumnWidths; } } else if (this.columnsSetting == EQUAL_WIDTH_COLUMNS) {    if (!this.isLayoutExpand) { for (int i = 0; i < this.columnsWidths.length; i++) { this.columnsWidths[i] = maxWidth; } } }  int myContentWidth = 0; for (int i = 0; i < this.columnsWidths.length; i++) { myContentWidth += this.columnsWidths[i] + this.paddingHorizontal; } this.contentWidth = myContentWidth; this.contentHeight = myContentHeight;
	protected void initContent(int firstLineWidth, int lineWidth) {		//#debug		System.out.println("Container: intialising content for " + this + ": autofocus=" + this.autoFocusEnabled);		Item[] myItems = (Item[]) this.itemsList.toArray( new Item[ this.itemsList.size() ]);		this.items = myItems;		if (this.autoFocusEnabled && this.autoFocusIndex >= myItems.length ) {			this.autoFocusIndex = 0;		}		//#ifdef tmp.supportViewType			if (this.view != null) {				if (this.autoFocusEnabled) {					//#debug					System.out.println("Container/View: autofocusing element " + this.autoFocusIndex);					this.autoFocusEnabled = false;					if (this.autoFocusIndex < myItems.length ) {						Item item = myItems [ this.autoFocusIndex ];						if (item.appearanceMode != Item.PLAIN) {							// make sure that the item has applied it's own style first:							item.getItemHeight( firstLineWidth, lineWidth );							// now focus the item:							focus( this.autoFocusIndex, item, 0 );							this.view.focusedIndex = this.autoFocusIndex;							this.view.focusedItem = this.focusedItem;						}					}				}				this.view.initContent(this, firstLineWidth, lineWidth);				this.contentWidth = this.view.contentWidth;				this.contentHeight = this.view.contentHeight;				this.appearanceMode = this.view.appearanceMode;				return;			}		//#endif					//#ifdef tmp.useTable		if (this.columnsSetting == NO_COLUMNS || myItems.length <= 1) {		//#endif			int myContentWidth = 0;			int myContentHeight = 0;			boolean hasFocusableItem = false;			for (int i = 0; i < myItems.length; i++) {				Item item = myItems[i];				//System.out.println("initalising " + item.getClass().getName() + ":" + i);				int width = item.getItemWidth( firstLineWidth, lineWidth );				int height = item.getItemHeight( firstLineWidth, lineWidth );				// now the item should have a style, so it can be safely focused				// without loosing the style information:				if (item.appearanceMode != PLAIN) {					hasFocusableItem = true;				}				if (this.autoFocusEnabled  && (i >= this.autoFocusIndex ) && (item.appearanceMode != Item.PLAIN)) {					//#debug					System.out.println("Container: autofocusing element " + i);					this.autoFocusEnabled = false;					focus( i, item, 0 );					height = item.getItemHeight( firstLineWidth, lineWidth );					width = item.getItemWidth( firstLineWidth, lineWidth );				}				if (width > myContentWidth) {					myContentWidth = width; 				}				myContentHeight += height + this.paddingVertical;			}			if (!hasFocusableItem) {				this.appearanceMode = PLAIN;			} else {				this.appearanceMode = INTERACTIVE;			}					this.contentHeight = myContentHeight;			this.contentWidth = myContentWidth;			return;		//#ifdef tmp.useTable		}		//#endif				//#ifdef tmp.useTable			// columns are used			boolean isNormalWidthColumns = (this.columnsSetting == NORMAL_WIDTH_COLUMNS);			if (this.columnsSetting != STATIC_WIDTH_COLUMNS) {				int availableColumnWidth;				if (isNormalWidthColumns) {					// this.columnsSetting == NORMAL_WIDTH_COLUMNS					// each column should use as much space as it can use					// without ousting the other columns					// (the calculation will be finished below)					availableColumnWidth = lineWidth - ((this.numberOfColumns -1) * this.paddingHorizontal);				} else {					// each column should take an equal share					availableColumnWidth = 						(lineWidth - ((this.numberOfColumns -1) * this.paddingHorizontal))						/ this.numberOfColumns;				}				//System.out.println("available column width: " + availableColumnWidth );				this.columnsWidths = new int[ this.numberOfColumns ];				for (int i = 0; i < this.numberOfColumns; i++) {					this.columnsWidths[i] = availableColumnWidth;				}			} else {				int restWidth = 0;				int dynamicColumnIndex = -1;				for (int i = 0; i < this.numberOfColumns; i++) {					int w = this.columnsWidths[i];					if (w == -1) {						dynamicColumnIndex = i;					} else {						restWidth += w;					}				}				if (dynamicColumnIndex != -1) {					this.columnsWidths[ dynamicColumnIndex ] = lineWidth - restWidth;				}			}			//#if polish.css.colspan				ArrayList rowHeightsList = new ArrayList( (myItems.length / this.numberOfColumns) + (myItems.length % 2) + 1 );			//#else				this.numberOfRows = (myItems.length / this.numberOfColumns) + (myItems.length % 2);				this.rowsHeights = new int[ this.numberOfRows ];			//#endif			int maxRowHeight = 0;			int columnIndex = 0;			int rowIndex = 0;			int[] maxColumnWidths = null;			if (isNormalWidthColumns) {				maxColumnWidths = new int[ this.numberOfColumns ];			}			int maxWidth = 0; // important for "equal" columns-width			int myContentHeight = 0;			//System.out.println("starting init of " + myItems.length + " container items.");			for (int i=0; i< myItems.length; i++) {				Item item = myItems[i];				int availableWidth = this.columnsWidths[columnIndex];				//#if polish.css.colspan					int itemColSpan = item.colSpan;					if (item.style != null) {						Integer colSpanInt = item.style.getIntProperty("colspan");						if ( colSpanInt != null ) {							itemColSpan = colSpanInt.intValue();							//System.out.println("colspan of item " + i + "/" + item + ", column " + columnIndex + ": " + itemColSpan);						}					}					if (itemColSpan > 1) {						// okay, this item stretched beyond one column,						// so let's calculate the correct available cell width						// and switch to the right column index:						int maxColSpan = this.numberOfColumns - columnIndex;						if (itemColSpan > maxColSpan) {							//#debug error							System.err.println("Warning: colspan " + itemColSpan + " is invalid at column " + columnIndex + " of a table with " + this.numberOfColumns + " columns, now using maximum possible value " + maxColSpan + ".");							itemColSpan = maxColSpan;						}						if (item.colSpan != itemColSpan) { 							//System.out.println("initializing new colspan of item " + i + "/" + item + ", column " + columnIndex + ": " + itemColSpan);							item.colSpan = itemColSpan;							item.isInitialised = false;						}						// adjust the available width only when						// each column has an equal size or when						// the column widths are static,						// otherwise the complete row width						// is available anyhow:						if (!isNormalWidthColumns) {							for (int j = columnIndex + 1; j < columnIndex + itemColSpan; j++) {								availableWidth += this.paddingHorizontal + this.columnsWidths[j];							}						}					}				//#endif				//System.out.println("available with: " + availableWidth);				int width = item.getItemWidth( availableWidth, availableWidth );				//System.out.println("got item width");				int height = item.getItemHeight( availableWidth, availableWidth );								// now the item should have a style, so it can be safely focused				// without loosing the style information:				if (this.autoFocusEnabled  && (i >= this.autoFocusIndex ) && (item.appearanceMode != Item.PLAIN)) {					//#debug					System.out.println("Container: Autofocusing item " + i );					this.autoFocusEnabled = false;					focus( i, item, 0 );					height = item.getItemHeight( availableWidth, availableWidth );					width = item.getItemWidth( availableWidth, availableWidth );				}								if (height > maxRowHeight) {					maxRowHeight = height;				}				//#if polish.css.colspan					if (itemColSpan == 1) {				//#endif						if (isNormalWidthColumns && width > maxColumnWidths[columnIndex ]) {							maxColumnWidths[ columnIndex ] = width;						}						if (width > maxWidth ) {							maxWidth = width;						}				//#if polish.css.colspan					}				//#endif				//#if polish.css.colspan					columnIndex += itemColSpan;				//#else					columnIndex++;				//#endif				if (columnIndex == this.numberOfColumns) {					//System.out.println("starting new row: rowIndex=" + rowIndex + "  numberOfRows: " + numberOfRows);					columnIndex = 0;					//#if polish.css.colspan						rowHeightsList.add( new Integer( maxRowHeight ) );					//#else						this.rowsHeights[rowIndex] = maxRowHeight;											//#endif					myContentHeight += maxRowHeight + this.paddingVertical;					maxRowHeight = 0;					rowIndex++;				}			} // for each item			//#if polish.css.colspan				this.numberOfRows = rowHeightsList.size();				this.rowsHeights = new int[ this.numberOfRows ];				for (int i = 0; i < this.numberOfRows; i++) {					this.rowsHeights[i] = ((Integer) rowHeightsList.get(i)).intValue();				}			//#endif			// now save the worked out dimensions:			if (isNormalWidthColumns) {				// Each column should use up as much space as 				// needed in the "normal" columns-width mode.				// Each column which takes less than available 				// the available-row-width / number-of-columns				// can keep, but the others might need to be adjusted,				// in case the complete width of the table is wider				// than the allowed width.								int availableRowWidth = lineWidth - ((this.numberOfColumns -1) * this.paddingHorizontal);				int availableColumnWidth = availableRowWidth / this.numberOfColumns;				int usedUpWidth = 0;				int leftColumns = this.numberOfColumns;				int completeWidth = 0;				for (int i = 0; i < maxColumnWidths.length; i++) {					int maxColumnWidth = maxColumnWidths[i];					if (maxColumnWidth <= availableColumnWidth) {						usedUpWidth += maxColumnWidth;						leftColumns--;					}					completeWidth += maxColumnWidth;				}				if (completeWidth <= availableRowWidth) {					// okay, the table is fine just how it is					this.columnsWidths = maxColumnWidths;				} else {					// okay, some columns need to be adjusted:					// re-initialise the table:					int leftAvailableColumnWidth = (availableRowWidth - usedUpWidth) / leftColumns;					int[] newMaxColumnWidths = new int[ this.numberOfColumns ];					myContentHeight = 0;					columnIndex = 0;					rowIndex = 0;					maxRowHeight = 0;					maxWidth = 0;					//System.out.println("starting init of " + myItems.length + " container items.");					for (int i = 0; i < myItems.length; i++) {						Item item = myItems[i];						int width = item.itemWidth;						int height = item.itemHeight;						if (maxColumnWidths[ columnIndex ] <= availableColumnWidth) {							newMaxColumnWidths[ columnIndex ] = maxColumnWidths[ columnIndex ];						} else {							// re-initialise this item,							// if it is wider than the left-available-column-width							if ( width > leftAvailableColumnWidth ) {								item.isInitialised = false;								width = item.getItemWidth( leftAvailableColumnWidth, leftAvailableColumnWidth );								height = item.getItemHeight( leftAvailableColumnWidth, leftAvailableColumnWidth );							}							if (width > newMaxColumnWidths[ columnIndex ]) {								newMaxColumnWidths[ columnIndex ] = width;							}						}						if (height > maxRowHeight) {							maxRowHeight = height;						}						//#if polish.css.colspan							columnIndex += item.colSpan;						//#else							columnIndex++;						//#endif												if (columnIndex == this.numberOfColumns) {							//System.out.println("starting new row: rowIndex=" + rowIndex + "  numberOfRows: " + numberOfRows);							columnIndex = 0;							this.rowsHeights[rowIndex] = maxRowHeight;							myContentHeight += maxRowHeight + this.paddingVertical;							maxRowHeight = 0;							rowIndex++;						}					} // for each item							this.columnsWidths = newMaxColumnWidths;				}			} else if (this.columnsSetting == EQUAL_WIDTH_COLUMNS) {				// Use the maximum used column-width for each column,				// unless this table should be expanded, in which				// case the above set widths  will be used instead.				if (!this.isLayoutExpand) {					for (int i = 0; i < this.columnsWidths.length; i++) {						this.columnsWidths[i] = maxWidth;					}				}			} // otherwise the column widths are defined statically.			// set content height & width:			int myContentWidth = 0;			for (int i = 0; i < this.columnsWidths.length; i++) {				myContentWidth += this.columnsWidths[i] + this.paddingHorizontal;			}			this.contentWidth = myContentWidth;			this.contentHeight = myContentHeight;		//#endif	}