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

📄 textfield.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)TextField.java	1.239 02/10/14 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package javax.microedition.lcdui;import com.sun.midp.lcdui.EventHandler;import com.sun.midp.lcdui.Text;import com.sun.midp.lcdui.TextCursor;import com.sun.midp.lcdui.TextPolicy;import com.sun.midp.lcdui.PhoneDial;import com.sun.midp.lcdui.InputMethodHandler;import com.sun.midp.lcdui.InputMethodClient;import com.sun.midp.lcdui.DynamicCharacterArray;/** * A <code>TextField</code> is an editable text component that may be * placed into * a {@link Form Form}. 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 {@link #getMaxSize() getMaxSize()}.  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 {@link TextBox TextBox} 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> * * <TABLE BORDER="2"> * <TR> * <TD ROWSPAN="1" COLSPAN="1"> *     <pre><code> *     (408) 555-1212    </code></pre> * </TD> * </TR> * </TABLE> * * <p>but the actual contents of the object visible to the application * through the APIs would be the string * &quot;<code>4085551212</code>&quot;. * 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 {@link #setConstraints setConstraints()} 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>&amp;</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>&amp;</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 {@link * TextBox TextBox} 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 {@link * #setInitialInputMode setInitialInputMode()} 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 * {@link #setInitialInputMode setInitialInputMode()} method. * String comparison is case sensitive. * * <P>Unicode character blocks can be named by adding the prefix * &quot;<code>UCB</code>_&quot; 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>&quot;Input subsets&quot; as defined by the J2SE class * <code>java.awt.im.InputSubset</code> may be named by adding the prefix * &quot;<code>IS_</code>&quot; 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 &quot;<code>X_</code>&quot;.  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 * &quot;<code>X_</code>&quot; 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 &quot;loaned&quot; 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. * * @since MIDP 1.0 */public class TextField extends Item {    /**     * The user is allowed to enter any text.     * <A HREF="Form.html#linebreak">Line breaks</A> may be entered.     *     * <P>Constant <code>0</code> is assigned to <code>ANY</code>.</P>     */    public final static int ANY = 0;    /**     * The user is allowed to enter an e-mail address.     *     * <P>Constant <code>1</code> is assigned to <code>EMAILADDR</code>.</P>     */    public final static int EMAILADDR = 1;    /**     * The user is allowed to enter only an integer value. The implementation     * must restrict the contents either to be empty or to consist of an     * optional minus sign followed by a string of one or more decimal     * numerals.  Unless the value is empty, it will be successfully parsable     * using {@link java.lang.Integer#parseInt(String)}.     *     * <P>The minus sign consumes space in the text object.  It is thus     * impossible to enter negative numbers into a text object whose maximum     * size is <code>1</code>.</P>     *     * <P>Constant <code>2</code> is assigned to <code>NUMERIC</code>.</P>     */    public final static int NUMERIC = 2;    /**     * The user is allowed to enter a phone number. The phone number is a     * special     * case, since a phone-based implementation may be linked to the     * native phone     * dialing application. The implementation may automatically start a phone     * dialer application that is initialized so that pressing a single key     * would be enough to make a call. The call must not made automatically     * without requiring user's confirmation.  Implementations may also     * provide a feature to look up the phone number in the device's phone or     * address database.     *     * <P>The exact set of characters allowed is specific to the device and to     * the device's network and may include non-numeric characters, such as a     * &quot;+&quot; prefix character.</P>     *     * <P>Some platforms may provide the capability to initiate voice calls     * using the {@link javax.microedition.midlet.MIDlet#platformRequest     * MIDlet.platformRequest} method.</P>     *     * <P>Constant <code>3</code> is assigned to <code>PHONENUMBER</code>.</P>     */    public final static int PHONENUMBER = 3;    /**     * The user is allowed to enter a URL.     *     * <P>Constant <code>4</code> is assigned to <code>URL</code>.</P>     */    public final static int URL = 4;    /**     * The user is allowed to enter numeric values with optional decimal     * fractions, for example &quot;-123&quot;, &quot;0.123&quot;, or     * &quot;.5&quot;.     *

⌨️ 快捷键说明

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