📄 textfield.java
字号:
//#condition polish.usePolishGui/* * Copyright (c) 2004-2005 Robert Virkus / Enough Software * * This file is part of J2ME Polish. * * J2ME Polish is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * J2ME Polish is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with J2ME Polish; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Commercial licenses are also available, please * refer to the accompanying LICENSE.txt or visit * http://www.j2mepolish.org for details. */package de.enough.polish.ui;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;import de.enough.polish.util.BitMapFontViewer;import de.enough.polish.util.Locale;//#if polish.blackberryimport de.enough.polish.blackberry.ui.PolishEditField;import net.rim.device.api.ui.Field;import net.rim.device.api.ui.FieldChangeListener;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.XYRect;import net.rim.device.api.ui.component.BasicEditField;//#endif/** * A <code>TextField</code> is an editable text component that may be * placed into * a <A HREF="../../../javax/microedition/lcdui/Form.html"><CODE>Form</CODE></A>. It can be * given a piece of text that is used as the initial value. * * <P>A <code>TextField</code> has a maximum size, which is the * maximum number of characters * that can be stored in the object at any time (its capacity). This limit is * enforced when the <code>TextField</code> instance is constructed, * when the user is editing text within the <code>TextField</code>, as well as * when the application program calls methods on the * <code>TextField</code> that modify its * contents. The maximum size is the maximum stored capacity and is unrelated * to the number of characters that may be displayed at any given time. * The number of characters displayed and their arrangement into rows and * columns are determined by the device. </p> * * <p>The implementation may place a boundary on the maximum size, and the * maximum size actually assigned may be smaller than the application had * requested. The value actually assigned will be reflected in the value * returned by <A HREF="../../../javax/microedition/lcdui/TextField.html#getMaxSize()"><CODE>getMaxSize()</CODE></A>. A defensively-written * application should compare this value to the maximum size requested and be * prepared to handle cases where they differ.</p> * * <a name="constraints"></a> * <h3>Input Constraints</h3> * * <P>The <code>TextField</code> shares the concept of <em>input * constraints</em> with the <A HREF="../../../javax/microedition/lcdui/TextBox.html"><CODE>TextBox</CODE></A> class. The different * constraints allow the application to request that the user's input be * restricted in a variety of ways. The implementation is required to * restrict the user's input as requested by the application. For example, if * the application requests the <code>NUMERIC</code> constraint on a * <code>TextField</code>, the * implementation must allow only numeric characters to be entered. </p> * * <p>The <em>actual contents</em> of the text object are set and modified by * and are * reported to the application through the <code>TextBox</code> and * <code>TextField</code> APIs. The <em>displayed contents</em> may differ * from the actual contents if the implementation has chosen to provide * special formatting suitable for the text object's constraint setting. * For example, a <code>PHONENUMBER</code> field might be displayed with * digit separators and punctuation as * appropriate for the phone number conventions in use, grouping the digits * into country code, area code, prefix, etc. Any spaces or punctuation * provided are not considered part of the text object's actual contents. For * example, a text object with the <code>PHONENUMBER</code> * constraint might display as * follows:</p> * * <pre><code> * (408) 555-1212 * </code></pre> * * <p>but the actual contents of the object visible to the application * through the APIs would be the string * "<code>4085551212</code>". * The <code>size</code> method reflects the number of characters in the * actual contents, not the number of characters that are displayed, so for * this example the <code>size</code> method would return <code>10</code>.</p> * * <p>Some constraints, such as <code>DECIMAL</code>, require the * implementation to perform syntactic validation of the contents of the text * object. The syntax checking is performed on the actual contents of the * text object, which may differ from the displayed contents as described * above. Syntax checking is performed on the initial contents passed to the * constructors, and it is also enforced for all method calls that affect the * contents of the text object. The methods and constructors throw * <code>IllegalArgumentException</code> if they would result in the contents * of the text object not conforming to the required syntax.</p> * * <p>The value passed to the <A HREF="../../../javax/microedition/lcdui/TextField.html#setConstraints(int)"><CODE>setConstraints()</CODE></A> method * consists of a restrictive constraint setting described above, as well as a * variety of flag bits that modify the behavior of text entry and display. * The value of the restrictive constraint setting is in the low order * <code>16</code> bits * of the value, and it may be extracted by combining the constraint value * with the <code>CONSTRAINT_MASK</code> constant using the bit-wise * <code>AND</code> (<code>&</code>) operator. * The restrictive constraint settings are as follows: * * <blockquote><code> * ANY<br> * EMAILADDR<br> * NUMERIC<br> * PHONENUMBER<br> * URL<br> * DECIMAL<br> * </code></blockquote> * * <p>The modifier flags reside in the high order <code>16</code> bits * of the constraint * value, that is, those in the complement of the * <code>CONSTRAINT_MASK</code> constant. * The modifier flags may be tested individually by combining the constraint * value with a modifier flag using the bit-wise <code>AND</code> * (<code>&</code>) operator. The * modifier flags are as follows: * * <blockquote><code> * PASSWORD<br> * UNEDITABLE<br> * SENSITIVE<br> * NON_PREDICTIVE<br> * INITIAL_CAPS_WORD<br> * INITIAL_CAPS_SENTENCE<br> * </code></blockquote> * * <a name="modes"></a> * <h3>Input Modes</h3> * * <p>The <code>TextField</code> shares the concept of <em>input * modes</em> with the <A HREF="../../../javax/microedition/lcdui/TextBox.html"><CODE>TextBox</CODE></A> class. The application can request that the * implementation use a particular input mode when the user initiates editing * of a <code>TextField</code> or <code>TextBox</code>. The input * mode is a concept that exists within * the user interface for text entry on a particular device. The application * does not request an input mode directly, since the user interface for text * entry is not standardized across devices. Instead, the application can * request that the entry of certain characters be made convenient. It can do * this by passing the name of a Unicode character subset to the <A HREF="../../../javax/microedition/lcdui/TextField.html#setInitialInputMode(java.lang.String)"><CODE>setInitialInputMode()</CODE></A> method. Calling this method * requests that the implementation set the mode of the text entry user * interface so that it is convenient for the user to enter characters in this * subset. The application can also request that the input mode have certain * behavioral characteristics by setting modifier flags in the constraints * value. * * <p>The requested input mode should be used whenever the user initiates the * editing of a <code>TextBox</code> or <code>TextField</code> object. * If the user had changed input * modes in a previous editing session, the application's requested input mode * should take precedence over the previous input mode set by the user. * However, the input mode is not restrictive, and the user is allowed to * change the input mode at any time during editing. If editing is already in * progress, calls to the <code>setInitialInputMode</code> method do not * affect the current input mode, but instead take effect at the next time the * user initiates editing of this text object. * * <p>The initial input mode is a hint to the implementation. If the * implementation cannot provide an input mode that satisfies the * application's request, it should use a default input mode. * * <P>The input mode that results from the application's request is not a * restriction on the set of characters the user is allowed to enter. The * user MUST be allowed to switch input modes to enter any character that is * allowed within the current constraint setting. The constraint * setting takes precedence over an input mode request, and the implementation * may refuse to supply a particular input mode if it is inconsistent with the * current constraint setting. * * <P>For example, if the current constraint is <code>ANY</code>, the call</P> * * <TABLE BORDER="2"> * <TR> * <TD ROWSPAN="1" COLSPAN="1"> * <pre><code> * setInitialInputMode("MIDP_UPPERCASE_LATIN"); </code></pre> * </TD> * </TR> * </TABLE> * * <p>should set the initial input mode to allow entry of uppercase Latin * characters. This does not restrict input to these characters, and the user * will be able to enter other characters by switching the input mode to allow * entry of numerals or lowercase Latin letters. However, if the current * constraint is <code>NUMERIC</code>, the implementation may ignore * the request to set an * initial input mode allowing <code>MIDP_UPPERCASE_LATIN</code> * characters because these * characters are not allowed in a <code>TextField</code> whose * constraint is <code>NUMERIC</code>. In * this case, the implementation may instead use an input mode that allows * entry of numerals, since such an input mode is most appropriate for entry * of data under the <code>NUMERIC</code> constraint. * * <P>A string is used to name the Unicode character subset passed as a * parameter to the * <A HREF="../../../javax/microedition/lcdui/TextField.html#setInitialInputMode(java.lang.String)"><CODE>setInitialInputMode()</CODE></A> method. * String comparison is case sensitive. * * <P>Unicode character blocks can be named by adding the prefix * "<code>UCB</code>_" to the * the string names of fields representing Unicode character blocks as defined * in the J2SE class <code>java.lang.Character.UnicodeBlock</code>. Any * Unicode character block may be named in this fashion. For convenience, the * most common Unicode character blocks are listed below. * * <blockquote><code> * UCB_BASIC_LATIN<br> * UCB_GREEK<br> * UCB_CYRILLIC<br> * UCB_ARMENIAN<br> * UCB_HEBREW<br> * UCB_ARABIC<br> * UCB_DEVANAGARI<br> * UCB_BENGALI<br> * UCB_THAI<br> * UCB_HIRAGANA<br> * UCB_KATAKANA<br> * UCB_HANGUL_SYLLABLES<br> * </code></blockquote> * * <P>"Input subsets" as defined by the J2SE class * <code>java.awt.im.InputSubset</code> may be named by adding the prefix * "<code>IS_</code>" to the string names of fields * representing input subsets as defined * in that class. Any defined input subset may be used. For convenience, the * names of the currently defined input subsets are listed below. * * <blockquote><code> * IS_FULLWIDTH_DIGITS<br> * IS_FULLWIDTH_LATIN<br> * IS_HALFWIDTH_KATAKANA<br> * IS_HANJA<br> * IS_KANJI<br> * IS_LATIN<br> * IS_LATIN_DIGITS<br> * IS_SIMPLIFIED_HANZI<br> * IS_TRADITIONAL_HANZI<br> * </code></blockquote> * * <P>MIDP has also defined the following character subsets: * * <blockquote> * <code>MIDP_UPPERCASE_LATIN</code> - the subset of * <code>IS_LATIN</code> that corresponds to * uppercase Latin letters * </blockquote> * <blockquote> * <code>MIDP_LOWERCASE_LATIN</code> - the subset of * <code>IS_LATIN</code> that corresponds to * lowercase Latin letters * </blockquote> * * <p> * Finally, implementation-specific character subsets may be named with * strings that have a prefix of "<code>X_</code>". In * order to avoid namespace conflicts, * it is recommended that implementation-specific names include the name of * the defining company or organization after the initial * "<code>X_</code>" prefix. * * <p> For example, a Japanese language application might have a particular * <code>TextField</code> that the application intends to be used * primarily for input of * words that are "loaned" from languages other than Japanese. The * application might request an input mode facilitating Hiragana input by * issuing the following method call:</p> * * <TABLE BORDER="2"> * <TR> * <TD ROWSPAN="1" COLSPAN="1"> * <pre><code> * textfield.setInitialInputMode("UCB_HIRAGANA"); </code></pre> * </TD> * </TR> * </TABLE> * <h3>Implementation Note</h3> * * <p>Implementations need not compile in all the strings listed above. * Instead, they need only to compile in the strings that name Unicode * character subsets that they support. If the subset name passed by the * application does not match a known subset name, the request should simply * be ignored without error, and a default input mode should be used. This * lets implementations support this feature reasonably inexpensively. * However, it has the consequence that the application cannot tell whether * its request has been accepted, nor whether the Unicode character subset it * has requested is actually a valid subset. * <HR> * * @author Robert Virkus, robert@enough.de * @author Andrew Barnes, <andy@geni.com.au> basic implementation of direct input * @since MIDP 1.0 */public class TextField extends StringItem//#if polish.TextField.useDirectInput && !polish.blackberry //#define tmp.forceDirectInput //#define tmp.directInput//#elif polish.css.textfield-direct-input && !polish.blackberry //#define tmp.directInput //#define tmp.allowDirectInput//#endif//#if polish.TextField.supportSymbolsEntry && tmp.directInput //#define tmp.supportsSymbolEntry //#if !polish.css.style.textFieldSymbolTable && !polish.css.style.textFieldSymbolList //#abort You need to define the ".textFieldSymbolList" CSS style when enabling the polish.TextField.supportSymbolsEntry option. //#endif//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -