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

📄 textfield.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			}
			return 0;
		//#endif
	}
	
	/**
	 * Sets the caret position.
	 * Please note that this operation requires the direct input mode to work.
	 * 
	 * @param position the new caret position,  0 puts the caret at the start of the line, getString().length moves the caret to the end of the input.
	 */
	public void setCaretPosition(int position) {
		//#if polish.blackberry
			//# this.editField.setCursorPosition(position);
		//#elif tmp.allowDirectInput || tmp.forceDirectInput
			//# if ( ! this.isInitialised ) {
				//# this.doSetCaretPosition = true;
				//# this.caretPosition = position;
			//# } else if (this.realTextLines == null ){
				//# // ignore position when there is not text present
			//# } else {
				//# int row = 0;
				//# int col = 0;
				//# int passedCharacters = 0;
				//# String textLine = null;
				//# for (int i = 0; i < this.realTextLines.length; i++) {
					//# textLine = this.realTextLines[i];
					//# passedCharacters += textLine.length();
					//# //System.out.println("passedCharacters=" + passedCharacters + ", line=" + textLine );
					//# if (passedCharacters >= position ) {
						//# row = i;
						//# col = textLine.length() - (passedCharacters - position);
						//# break;
					//# }
				//# }
				//#debug
				//# System.out.println("setCaretPosition, position=" + position + ", row=" + row + ", col=" + col );
				//# this.caretRow = row;	
				//# this.caretColumn = col;
//# 				
				//# textLine = this.textLines[ row ];
				//# this.originalRowText = textLine;
				//# String firstPart;
				//# if (this.caretColumn < textLine.length()) {
					//# firstPart = textLine.substring(0, this.caretColumn);
					//# if ( textLine.length() > 1 && textLine.charAt( textLine.length()-1) == '\n') {
						//# if ( textLine.length() - 1> this.caretColumn) {
							//# this.caretRowLastPart = textLine.substring( this.caretColumn, textLine.length() - 1 );
						//# } else {
							//# this.caretRowLastPart = "";
						//# }
					//# } else {
						//# this.caretRowLastPart = textLine.substring( this.caretColumn );
					//# }
					//# this.caretRowLastPartWidth = this.font.stringWidth( this.caretRowLastPart );
				//# } else {
					//# firstPart = textLine;
					//# this.caretRowLastPart = "";
					//# this.caretRowLastPartWidth =  0;
				//# }
				//# this.caretRowFirstPart = firstPart;
				//# this.caretX = this.font.stringWidth( firstPart );
				//# this.internalY = this.caretRow * this.rowHeight;
				//# this.caretY = this.internalY;
				//# repaint();
			//# }
		//#endif
	}



	/**
	 * Sets the input constraints of the <code>TextField</code>. If
	 * the the current contents
	 * of the <code>TextField</code> do not match the new
	 * <code>constraints</code>, the contents are
	 * set to empty.
	 * 
	 * @param constraints see input constraints
	 * @throws IllegalArgumentException if constraints is not any of the ones specified in input constraints
	 * @see #getConstraints()
	 */
	public void setConstraints(int constraints)
	{
		this.constraints = constraints;
		this.isUneditable = (constraints & UNEDITABLE) == UNEDITABLE;
		//#if polish.blackberry
//# 			
			//# long bbStyle = Field.FOCUSABLE;
			//# if (!this.isUneditable) {
				//# bbStyle |= Field.EDITABLE;
			//# }
			//# if ( (constraints & DECIMAL) == DECIMAL) {
				//# bbStyle |= BasicEditField.FILTER_REAL_NUMERIC;
			//# } else if ((constraints & NUMERIC) == NUMERIC) {
				//# bbStyle |= BasicEditField.FILTER_INTEGER;
			//# } else if ((constraints & PHONENUMBER) == PHONENUMBER) {
				//# bbStyle |= BasicEditField.FILTER_PHONE;
			//# } else if ( (constraints & EMAILADDR) == EMAILADDR ) {
				//# bbStyle |= BasicEditField.FILTER_EMAIL;
			//# } else if ( (constraints & URL) == URL ) {
				//# bbStyle |= BasicEditField.FILTER_URL;
			//# }
			//# if (this.editField != null) {
				//# // remove the old edit field from the blackberry screen:
				//# this._bbFieldAdded = false;
				//# if (this.isFocused) {
					//# getScreen().setFocus( this );
				//# }
			//# }
			//# this.editField = new PolishEditField( null, getString(), this.maxSize, bbStyle );
			//# this.editField.setChangeListener( this );
			//# this._bbField = this.editField;
		//#elif !tmp.forceDirectInput
			if (this.midpTextBox != null) {
				this.midpTextBox.setConstraints(constraints);
			}
		//#endif
		//#ifdef tmp.directInput
			//# if ((constraints & PASSWORD) == PASSWORD) {
				//# this.isPassword = true;
			//# }
			//# if ((constraints & NUMERIC) == NUMERIC) {
				//# this.isNumeric = true;
				//# this.inputMode = MODE_NUMBERS;
				//#ifndef polish.hasPointerEvents
					//# this.enableDirectInput = true;
				//#endif
			//# } else {
				//# this.isNumeric = false;
			//# }
			//# if ((constraints & DECIMAL) == DECIMAL) {
				//# this.isNumeric = true;
				//# this.isDecimal = true;
				//# this.inputMode = MODE_NUMBERS;
			//# } else {
				//# this.isDecimal = false;
			//# }
			//# if ((constraints & EMAILADDR) == EMAILADDR) {
				//# this.isEmail = true;
			//# }
			//# if ((constraints & INITIAL_CAPS_WORD) == INITIAL_CAPS_WORD) {
				//# this.inputMode = MODE_FIRST_UPPERCASE;
				//# this.nextCharUppercase = true;
			//# } 
			//#if polish.TextField.showInputInfo != false
				//# updateInfo();
			//#endif
		//#endif
		
		// set item commands:
		//#if !tmp.suppressCommands
			if (this.isFocused) {
				getScreen().removeItemCommands( this );
			}
			removeCommand( DELETE_CMD );
			// add default text field item-commands:
			//#if (polish.TextField.suppressDeleteCommand != true) && !polish.blackberry
				if (!this.isUneditable) {
					//#ifdef polish.i18n.useDynamicTranslations
						//# String delLabel = "Delete";
						//# if ( delLabel != DELETE_CMD.getLabel()) {
							//# DELETE_CMD = new Command( delLabel, Command.CANCEL, 1 );
						//# }
					//#endif
					this.addCommand(DELETE_CMD);
				}
			//#endif
			//#if polish.TextField.suppressClearCommand != true
				removeCommand( CLEAR_CMD );
				if (!this.isUneditable) {
					//#ifdef polish.i18n.useDynamicTranslations
						//# String clearLabel = "Clear";
						//# if ( clearLabel != CLEAR_CMD.getLabel()) {
							//# CLEAR_CMD = new Command( clearLabel, Command.ITEM, 2 );
						//# }
					//#endif
					this.addCommand(CLEAR_CMD);
				}
			//#endif
			this.itemCommandListener = this;
			if (this.isFocused) {
				getScreen().setItemCommands( this );
			}

		//#endif
			
		//#if tmp.directInput && tmp.supportsSymbolEntry && polish.TextField.suppressAddSymbolCommand != true
			//# if (!this.isNumeric) {
				//# removeCommand( ENTER_SYMBOL_CMD );
				//# if (!this.isUneditable) {
					//#ifdef polish.i18n.useDynamicTranslations
						//# String enterSymbolLabel = "Add Symbol";
						//# if ( enterSymbolLabel != ENTER_SYMBOL_CMD.getLabel()) {
							//# ENTER_SYMBOL_CMD = new Command( enterSymbolLabel, Command.ITEM, 3 );
						//# }
					//#endif
					//# this.addCommand(ENTER_SYMBOL_CMD);
				//# }
			//# }
		//#endif	
			
			
//		if ( (constraints & UNEDITABLE) == UNEDITABLE) {
//			// deactivate this field:
//			super.setAppearanceMode( Item.PLAIN );
//			if (this.isInitialised && this.isFocused && this.parent instanceof Container) {
//				((Container)this.parent).requestDefocus( this );
//			}
//		} else {
//			super.setAppearanceMode( Item.INTERACTIVE );
//		}
	}

	/**
	 * Gets the current input constraints of the <code>TextField</code>.
	 * 
	 * @return the current constraints value (see input constraints)
	 * @see #setConstraints(int)
	 */
	public int getConstraints()
	{
		return this.constraints;
	}

	/**
	 * Sets a hint to the implementation as to the input mode that should be
	 * used when the user initiates editing of this <code>TextField</code>.  The
	 * <code>characterSubset</code> parameter names a subset of Unicode
	 * characters that is used by the implementation to choose an initial
	 * input mode.  If <code>null</code> is passed, the implementation should
	 * choose a default input mode.
	 * 
	 * 
	 * <p>When the direct input mode is used, J2ME Polish will ignore this call completely.</p>
	 * 
	 * @param characterSubset a string naming a Unicode character subset, or null
	 * @since  MIDP 2.0
	 */
	public void setInitialInputMode( String characterSubset)
	{
		//#if !(tmp.forceDirectInput || polish.blackberry) && polish.midp2
			if (this.midpTextBox == null) {
				createTextBox();
			}
			this.midpTextBox.setInitialInputMode( characterSubset );
		//#endif
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#paint(int, int, javax.microedition.lcdui.Graphics)
	 */
	public void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
		//#if polish.blackberry
        	//# if (this.isFocused && !StyleSheet.currentScreen.isMenuOpened() ) {
				//# this.editField.setPaintPosition( x, y );
			//# } else {
				//# super.paintContent(x, y, leftBorder, rightBorder, g);
			//# }
		//#else
		if (!this.isFocused || this.isUneditable) {
			super.paintContent(x, y, leftBorder, rightBorder, g);
			return;
		}
		//#ifdef tmp.directInput
			//# //System.out.println("rightPart=[" + this.caretRowLastPart + "]");
			//#ifdef tmp.allowDirectInput
				//# if (this.isFocused && this.enableDirectInput) {
			//#else
				//# if (this.isFocused ) {
			//#endif
					//#ifdef polish.css.font-bitmap
					//# if (this.bitMapFont != null) {
						//# //System.out.println("Using bitmap-font");
						//# if (this.isLayoutRight) {
							//# super.paintContent(x, y, leftBorder, rightBorder - this.caretWidth, g);
						//# } else {
							//# super.paintContent(x, y, leftBorder, rightBorder, g);
						//# }
						//# if (this.showCaret) {
							//# //System.out.println(this + "" + this + ".paintContent(): caretX=" + this.caretX);
							//# if (this.isLayoutCenter) {
								//# int centerX = leftBorder + ( rightBorder - leftBorder ) / 2;
								//#ifdef polish.css.text-horizontal-adjustment
									//# centerX += this.textHorizontalAdjustment;
								//#endif
//# 
								//# this.caretViewer.paint( centerX + this.caretX/2 , y + this.caretY, g);
							//# } else if (this.isLayoutRight) {
								//# this.caretViewer.paint( rightBorder - this.caretWidth, y + this.caretY, g);
							//# } else {
								//# this.caretViewer.paint( x + this.caretX, y + this.caretY, g);
							//# }
						//# }
					//# } else {
						//# //System.out.println("bitmapfont is NULL!");
					//#endif
					//# g.setFont( this.font );
					//# g.setColor( this.textColor );
					//# int centerX = 0;
					//# if (this.isLayoutCenter) {
						//# centerX = leftBorder + (rightBorder - leftBorder) / 2;
					//# }
					//# if (this.text != null) {
				  		//#ifdef polish.css.text-wrap
							//# int clipX = 0;
							//# int clipY = 0;
							//# int clipWidth = 0;
							//# int clipHeight = 0;
							//# if (this.useSingleLine && this.clipText ) {
								//# clipX = g.getClipX();
								//# clipY = g.getClipY();
								//# clipWidth = g.getClipWidth();
								//# clipHeight = g.getClipHeight();
								//# g.clipRect( x, y, this.contentWidth, this.contentHeight );
							//# }
						//#endif
						//# for (int i = 0; i < this.textLines.length; i++) {
							//# if (i == this.caretRow) {
								//# if (this.isLayoutRight) {
									//# g.drawString( this.caretRowLastPart, rightBorder, y, Graphics.TOP | Graphics.RIGHT );
									//# if (this.showCaret) {
										//#ifdef polish.css.textfield-caret-color
											//# g.setCo

⌨️ 快捷键说明

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