📄 textfield.java
字号:
} 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 = Locale.get("polish.command.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 = Locale.get("polish.command.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 = Locale.get("polish.command.entersymbol"); 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.setColor( this.caretColor ); //#endif g.drawChar( this.caretChar, rightBorder - this.caretRowLastPartWidth, y, Graphics.TOP | Graphics.RIGHT ); //#ifdef polish.css.textfield-caret-color g.setColor( this.textColor ); //#endif } g.drawString( this.caretRowFirstPart, rightBorder - this.caretRowLastPartWidth - this.caretWidth, y, Graphics.TOP | Graphics.RIGHT ); } else if (this.isLayoutCenter) { int width = this.caretX + this.caretWidth + this.caretRowLastPartWidth; int leftX = centerX - (width / 2); g.drawString( this.caretRowFirstPart, leftX, y, Graphics.TOP | Graphics.LEFT ); leftX += this.caretX; if (this.showCaret) { //#ifdef polish.css.textfield-caret-color g.setColor( this.caretColor ); //#endif g.drawChar( this.caretChar, leftX, y, Graphics.TOP | Graphics.LEFT ); //#ifdef polish.css.textfield-caret-color g.setColor( this.textColor ); //#endif } leftX += this.caretWidth; g.drawString( this.caretRowLastPart, leftX, y, Graphics.TOP | Graphics.LEFT ); } else { int leftX = x; //#ifdef polish.css.text-wrap //if (this.clipText) { if ( leftX + this.caretX + this.caretWidth > rightBorder) { leftX = rightBorder - (this.caretX + this.caretWidth); } //} //#endif g.drawString( this.caretRowFirstPart, leftX, y, Graphics.TOP | Graphics.LEFT ); leftX += this.caretX; if (this.showCaret) { //#ifdef polish.css.textfield-caret-color g.setColor( this.caretColor ); //#endif g.drawChar( this.caretChar, leftX, y, Graphics.TOP | Graphics.LEFT ); //#ifdef polish.css.textfield-caret-color g.setColor( this.textColor ); //#endif } leftX += this.caretWidth; g.drawString( this.caretRowLastPart, leftX, y, Graphics.TOP | Graphics.LEFT ); } } else { // this a normal row in which no caret is shown: String line = this.textLines[i]; // adjust the painting according to the layout: if (this.isLayoutRight) { g.drawString( line, rightBorder, y, Graphics.TOP | Graphics.RIGHT ); } else if (this.isLayoutCenter) { g.drawString( line, centerX, y, Graphics.TOP | Graphics.HCENTER ); } else { // left layout (default) g.dr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -