this.originalRowText = line; String firstPart; if (this.caretColumn < line.length()) { firstPart = line.substring(0, this.caretColumn); this.caretRowLastPart = line.substring( this.caretColumn ); this.caretRowLastPartWidth = this.font.stringWidth( this.caretRowLastPart ); } else { firstPart = line; this.caretRowLastPart = ""; this.caretRowLastPartWidth =  0; } this.caretRowFirstPart = firstPart; this.caretX = this.font.stringWidth( firstPart );
setCaretRow(line, line.length() - (readCharacters - this.caretPosition) );
	protected void initContent(int firstLineWidth, int lineWidth) {		super.initContent(firstLineWidth, lineWidth);		if (this.font == null) {			this.font = Font.getDefaultFont();		}		this.originalWidth = this.contentWidth;		this.originalHeight = this.contentHeight;		if (this.contentWidth < this.minimumWidth) {			this.contentWidth = this.minimumWidth;		} 		if (this.contentHeight < this.minimumHeight) {			this.contentHeight = this.minimumHeight;		} else  if (this.contentHeight < this.font.getHeight()) {			this.contentHeight = this.font.getHeight();			this.originalHeight = this.contentHeight;		}		//#if polish.blackberry			if (!this.isFocused) {				return;			}			this.editField.layout( lineWidth, this.contentHeight );			//System.out.println("TextField: editField.getText()="+ this.editField.getText() );			XYRect rect = this.editField.getExtent();			this.contentWidth = rect.width;			this.contentHeight = rect.height;		//#elif tmp.directInput			//#ifdef polish.css.font-bitmap				if (this.bitMapFontViewer != null) {					this.rowHeight = this.bitMapFontViewer.getFontHeight() + this.paddingVertical;				} else {					this.rowHeight = this.font.getHeight() + this.paddingVertical;				}			//#else				this.rowHeight = this.font.getHeight() + this.paddingVertical;			//#endif						if (this.textLines != null) {				// init the original text-lines with spaces and line-breaks:				boolean updateCaretPosition = false;				int length = this.textLines.length;				String[] realLines = new String[ length ];				boolean hasBeenInitedBefore = (this.realTextLines != null);				int endOfLinePos = 0;				int maxPos = this.text.length();				int readCharacters = 0;				for (int i = 0; i < length; i++) {					String line = this.textLines[i];					endOfLinePos += line.length();					if (endOfLinePos < maxPos) {						char c = this.text.charAt( endOfLinePos );						if (c == ' ' || c == '\n') {							line += c;							endOfLinePos++;						}					}					realLines[i] = line;					if (hasBeenInitedBefore 							&& (this.caretRow == i + 1) 							&&  (i < this.realTextLines.length) ) 					{						String prevLine = this.realTextLines[i];						if (prevLine.length() < line.length() ) {							int diff = line.length() - prevLine.length();							if ( this.caretColumn <= diff) {								//System.out.println("Adjusting caret row to previous line");								this.caretRow--;								this.caretColumn += prevLine.length();								this.caretX += this.font.stringWidth(prevLine);							}						}					}					if (this.doSetCaretPosition) {						readCharacters += line.length();						if (readCharacters >= this.caretPosition) {							this.doSetCaretPosition = false;							this.caretColumn = line.length() - (readCharacters - this.caretPosition);							this.caretRow = i;								this.originalRowText = line;							String firstPart;							if (this.caretColumn < line.length()) {								firstPart = line.substring(0, this.caretColumn);								this.caretRowLastPart = line.substring( this.caretColumn );								this.caretRowLastPartWidth = this.font.stringWidth( this.caretRowLastPart );							} else {								firstPart = line;								this.caretRowLastPart = "";								this.caretRowLastPartWidth =  0;							}							this.caretRowFirstPart = firstPart;							this.caretX = this.font.stringWidth( firstPart );							this.internalY = this.caretRow * this.rowHeight;							this.caretY = this.internalY;						}					} else if (i == this.caretRow) {						this.originalRowText = line;						if (this.caretColumn < 0 ) {							this.caretColumn = 0;						}						if (this.caretColumn <= line.length() ) {							this.caretRowFirstPart = line.substring( 0, this.caretColumn );							this.caretRowLastPart = line.substring( this.caretColumn );							if (this.isLayoutRight || this.isLayoutCenter) {								this.caretRowLastPartWidth = this.font.stringWidth(this.caretRowLastPart);							}							if (updateCaretPosition) {								this.caretX = this.font.stringWidth(this.caretRowFirstPart);								//System.out.println(this + ".initContent()/font1: caretX=" + this.caretX);							}						} else if (i < this.textLines.length -1){							// the caret-position has been shifted to the next row:							updateCaretPosition = true;							this.caretColumn -= line.length();							this.caretRow++;							this.caretY += this.rowHeight;							// (the textLine will be updated in the next loop)						} else {							this.caretRowFirstPart = line;							this.caretRowLastPart = "";							this.caretColumn = line.length();							this.caretX = this.font.stringWidth(line);							//System.out.println(this + ".initContent()/font2: caretX=" + this.caretX);						}					}				} // for each line				this.realTextLines = realLines;			}			int textLength = (this.text == null ? 0 : this.text.length());			if (!this.caretPositionHasBeenSet || this.caretPosition > textLength ) {				this.caretPositionHasBeenSet = true;				if (this.text != null) {					//#ifdef polish.css.font-bitmap					//if (this.textLines != null) {					if (this.bitMapFontViewer == null) {					//#endif						//this.caretPosition = this.text.length();						this.caretRow = 0; //this.realTextLines.length - 1;						this.originalRowText = this.realTextLines[ this.caretRow ];						this.caretPosition = this.originalRowText.length();						this.caretColumn = this.originalRowText.length();						this.caretY = 0; // this.rowHeight * (this.realTextLines.length - 1);						this.caretX = this.font.stringWidth( this.originalRowText );						//System.out.println(this + ".initContent()/font3: caretX=" + this.caretX);						//this.textLines[ this.textLines.length -1 ] += " "; 						this.textLines[ 0 ] += " ";					//#ifdef polish.css.font-bitmap					} else {						// a bitmap-font is used:						this.caretPosition = this.text.length();						this.caretX = this.bitMapFontViewer.getWidth();						//System.out.println(this + ".initContent(): caretX=bitMapFontViewer.getWidth()=" + this.caretX);						this.caretY = this.bitMapFontViewer.getHeight() - this.bitMapFontViewer.getFontHeight();					}					//#endif				} else {					this.caretPosition = 0;					this.caretRow = 0;					this.caretColumn = 0;					this.caretX = 0;					//System.out.println(this + ".initContent()/reset1: caretX=" + this.caretX);					this.caretY = 0;					this.originalRowText = null;				}					}			// set the internal information so that big TextBoxes can still be scrolled			// correctly:			if (this.textLines != null && this.textLines.length > 0) {				this.internalX = 0;				this.internalY = this.caretRow * this.rowHeight;				this.internalWidth = this.contentWidth;				this.internalHeight = this.rowHeight;			}			/*			System.out.println("init content");			checkCaretPosition();			*/			this.screen = getScreen();			//System.out.println(this + "" + this + ".initContent():leave: caretX=" + this.caretX);			//System.out.println("firstpart=" + this.caretRowFirstPart + "   lastPart=" + this.caretRowLastPart);		//#endif	}