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

📄 textfield.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	/**
	 * Sets the maximum size (number of characters) that can be contained
	 * in this
	 * <code>TextField</code>. If the current contents of the
	 * <code>TextField</code> are larger than
	 * <code>maxSize</code>, the contents are truncated to fit.
	 * 
	 * @param maxSize the new maximum size
	 * @return assigned maximum capacity may be smaller than requested.
	 * @throws IllegalArgumentException if maxSize is zero or less.
	 *									or if the contents after truncation would be illegal for the current input constraints
	 * @see #getMaxSize()
	 */
	public int setMaxSize(int maxSize)
	{
		if ((this.text != null && maxSize < this.text.length()) || (maxSize < 1)) {
			throw new IllegalArgumentException();
		}
		//#if ! tmp.forceDirectInput && !polish.blackberry
			if (this.midpTextBox != null) {
				this.maxSize = this.midpTextBox.setMaxSize(maxSize);
				return this.maxSize;
			} else {
		//#endif
				this.maxSize = maxSize;
				return maxSize;
		//#if ! tmp.forceDirectInput  && !polish.blackberry
			}
		//#endif
	}

	/**
	 * Gets the number of characters that are currently stored in this
	 * <code>TextField</code>.
	 * 
	 * @return number of characters in the TextField
	 */
	public int size()
	{
		if (this.text == null) {
			return 0;
		} else {
			return this.text.length();
		}
	}

	/**
	 * Gets the current input position.  For some UIs this may block and ask
	 * the user for the intended caret position, and on other UIs this may
	 * simply return the current caret position.
	 * When the direct input mode is used, this method simply returns the current cursor position (= non blocking).
	 * 
	 * @return the current caret position, 0 if at the beginning
	 */
	public int getCaretPosition()
	{
		//#ifdef tmp.allowDirectInput
			//# if (this.enableDirectInput) {
				//# return this.caretPosition;
			//#if !tmp.forceDirectInput
			//# } else if (this.midpTextBox != null) {
				//# return this.midpTextBox.getCaretPosition();
			//#endif
			//# }
			//# return 0;
		//#elif polish.blackberry
			//# return this.editField.getInsertPositionOffset();
		//#elif tmp.forceDirectInput
			//# return this.caretPosition;
		//#else
			if (this.midpTextBox != null) {
				return this.midpTextBox.getCaretPosition();
			}
			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.isInitialized ) {
				//# 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;
		int fieldType = constraints & 0xffff;
		this.isUneditable = (constraints & UNEDITABLE) == UNEDITABLE;
		//#if polish.blackberry
//# 			
			//# long bbStyle = Field.FOCUSABLE;
			//# if (!this.isUneditable) {
				//# bbStyle |= Field.EDITABLE;
			//# }
//# 			
			//# if ( fieldType == DECIMAL) {
				//# bbStyle |= BasicEditField.FILTER_REAL_NUMERIC;
			//# } else if (fieldType == NUMERIC) {
				//# bbStyle |= BasicEditField.FILTER_INTEGER;
			//# } else if (fieldType == PHONENUMBER) {
				//# bbStyle |= BasicEditField.FILTER_PHONE;
			//# } else if (fieldType == EMAILADDR ) {
				//# bbStyle |= BasicEditField.FILTER_EMAIL;
			//# } else if ( fieldType == 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 );
				//# }
			//# }
			//# if ((constraints & PASSWORD) == PASSWORD) {
				//# this.editField = new PolishPasswordEditField( null, getString(), this.maxSize, bbStyle );
			//# } else {
				//# this.editField = new PolishEditField( null, getString(), this.maxSize, bbStyle );
			//# }
			//# this.editField.setChangeListener( this );
			//# this._bbField = (Field) this.editField;
		//#elif !tmp.forceDirectInput
			if (this.midpTextBox != null) {
				this.midpTextBox.setConstraints(constraints);
			}
		//#endif
		//#ifdef tmp.directInput
			//# this.characters = CHARACTERS;
			//# if ((constraints & PASSWORD) == PASSWORD) {
				//# this.isPassword = true;
			//# }
			//# if (fieldType == NUMERIC) {
				//# this.isNumeric = true;
				//# this.inputMode = MODE_NUMBERS;
				//#ifndef polish.hasPointerEvents
					//# this.enableDirectInput = true;
				//#endif
			//# } else {
				//# this.isNumeric = false;
			//# }
			//# if (fieldType == DECIMAL) {
				//# this.isNumeric = true;
				//# this.isDecimal = true;
				//# this.inputMode = MODE_NUMBERS;
			//# } else {
				//# this.isDecimal = false;
			//# }
			//# if (fieldType == EMAILADDR) {
				//# this.isEmail = true;
				//# this.characters = EMAIL_CHARACTERS;
			//# }
			//# 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.midpTex

⌨️ 快捷键说明

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