⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faketextfieldcustomitem.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
						} else {							// left layout (default)							g.drawChar( this.caretChar, x, y, Graphics.TOP | Graphics.LEFT );						}					}					//#ifdef polish.css.font-bitmap					}					//#endif					return;				} else { // this is either not focused or no direct input is enabled:					super.paintContent(x, y, leftBorder, rightBorder, g);					}		//#else			super.paintContent(x, y, leftBorder, rightBorder, g);		//#endif		if (this.showCaret && this.isFocused ) {			if (this.text == null) {				// when the text is null the appropriate font and color				// might not have been set, so set them now:				g.setFont( this.font );				//#ifndef polish.css.textfield-caret-color					g.setColor( this.textColor );				//#endif			}			//#ifdef polish.css.textfield-caret-color				g.setColor( this.caretColor );			//#endif						//#ifndef tmp.forceDirectInput				if (this.originalHeight > 0) {					y += this.originalHeight - this.font.getHeight();				}				if (this.isLayoutCenter) {					int centerX = leftBorder 						+ (rightBorder - leftBorder) / 2 						+ this.originalWidth / 2						+ 2;					g.drawChar(this.caretChar, centerX, y, Graphics.TOP | Graphics.LEFT );				} else if (this.isLayoutRight){					g.drawChar(this.caretChar, rightBorder, y, Graphics.TOP | Graphics.RIGHT );				} else {					x += this.originalWidth + 2;					g.drawChar(this.caretChar, x, y, Graphics.TOP | Graphics.LEFT );				}			//#endif		}		// end of non-blackberry block		//#endif	}	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#initItem()	 */	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.caretRow = i;								setCaretRow(line, line.length() - (readCharacters - this.caretPosition) );							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() ) {							setCaretRow( line, this.caretColumn );						} 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 {							setCaretRow( line, line.length() );							//System.out.println(this + ".initContent()/font2: caretX=" + this.caretX);						}					//} else if (updateCaretPosition) {						//					}				} // 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;						String caretRowText = this.realTextLines[ this.caretRow ]; 						setCaretRow( caretRowText, caretRowText.length() );												this.caretPosition = this.caretColumn;						this.caretY = 0; // this.rowHeight * (this.realTextLines.length - 1);						//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.caretY;				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	}		//#if tmp.directInput	/**	 * Sets the caret row.	 * The fields originalRowText, caretColumn, caretRowFirstPart, caretX, caretRowLastPart and caretRowLastPartWidth	 * are being set. Note that the field caretRowLastPartWidth is only set whent the	 * layout is either center or right.	 *  	 * @param line the new caret row text	 * @param column the column position of the caret	 */	private void setCaretRow( String line, int column ) {		//#debug		System.out.println("setCaretRow( line=\"" + line + "\", column=" + column + ")");		this.originalRowText = line;		int length = line.length();		if (column > length )  {			column = length;		}		this.caretColumn = column;		boolean endsInLineBreak = (length >= 1) && (line.charAt(length-1) == '\n'); 		if (column == length || ( endsInLineBreak && column == length -1 )) {			if ( endsInLineBreak ) {				this.caretRowFirstPart = line.substring( 0, length - 1);											} else {				this.caretRowFirstPart = line;							}			this.caretRowLastPartWidth = 0;			this.caretRowLastPart = "";		} else {			this.caretRowFirstPart = line.substring( 0, this.caretColumn );			if ( endsInLineBreak ) {				this.caretRowLastPart = line.substring( column, length - 1);											} else {				this.caretRowLastPart = line.substring( column );							}			if (this.isLayoutRight || this.isLayoutCenter) {				this.caretRowLastPartWidth = this.font.stringWidth(this.caretRowLastPart);			}			//this.caretRowLastPartWidth = this.font.stringWidth(this.caretRowLastPart);;		}		this.caretX = this.font.stringWidth(this.caretRowFirstPart);		//#debug		System.out.println("setCaretRow() result: endsInLineBreak=" + endsInLineBreak + ", firstPart=[" + this.caretRowFirstPart + "], lastPart=[" + this.caretRowLastPart + "].");	}	//#endif			/*	 * Checks the caret position - is only used during debugging.	private void checkCaretPosition() {		int cPos = 0;		for (int i = 0; i < this.realTextLines.length; i++) {			String line = this.realTextLines[i];			if (i == this.caretRow) {				cPos += this.caretColumn;				break;			}			cPos += line.length();		}		if (cPos != this.caretPosition) {			System.out.println("=============================");			System.out.println("Warning: this.caretPosition = " + this.caretPosition);			System.out.println("but it should be: " + cPos );			System.out.println("=============================");		}	}	 */	//#ifdef tmp.directInput	/*	 * Calculates the caret x and y positions.	private void calculateCaretPosition() {		// calculate row, column, x and y position of the caret:		if (this.text == null) {			this.caretX = 0;			this.caretY = 0;			return;		}		//#ifdef polish.css.font-bitmap			if (this.bitMapFontViewer != null) {				// a bitmap-font is used				//TODO calculate caret-position with bitmap-fonts			}		//#endif		// no bitmap-font is used:		int maxPos = this.text.length();		if (this.caretPosition == maxPos) {			int length = this.textLines.length - 1;			this.caretY = length * (this.font.getHeight() + this.paddingVertical);			this.caretX = this.font.stringWidth( this.textLines[ length ] );			return;		}		int pos = 0;		int row = 0;		int y = 0;		int rowHeight = this.font.getHeight() + this.paddingVertical;		for (int i = 0; i < this.textLines.length; i++) {			String line = this.textLines[i];			int lineLength = line.length();			int textIndex = this.text.indexOf(line, pos);			int lastPos = textIndex + lineLength;			if (lastPos < maxPos) {				char lastChar = this.text.charAt( lastPos );				if (lastChar == ' ') {					pos++;					line += " ";				}			}						if (this.caretPosition <= pos + lineLength) {				this.caretColumn = this.caretPosition - pos;				this.caretRow = row;				//TODO respect the layout of the text:				if ( this.caretColumn != 0 ) {					this.caretX = this.font.stringWidth(line.substring(0, this.caretColumn));				} else {					this.caretX = 0;				}				this.caretY = y;				break;			}			pos += lineLength;			y += rowHeight;			row++;		}	}	 */	//#endif		//#if polish.blackberry//	protected void hideNotify() {//		this.editField.onUndisplay();//	}	//#endif	//#ifdef polish.useDynamicStyles	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#getCssSelector()	 */	protected String createCssSelector() {		return "textfield";	}	//#endif	/* (non-Javado

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -