📄 textfield.java
字号:
* <p>The implementation may display a period "." or a * comma "," for the decimal fraction separator, depending on * the conventions in use on the device. Similarly, the implementation * may display other device-specific characters as part of a decimal * string, such as spaces or commas for digit separators. However, the * only characters allowed in the actual contents of the text object are * period ".", minus sign "-", and the decimal * digits.</p> * * <p>The actual contents of a <code>DECIMAL</code> text object may be * empty. If the actual contents are not empty, they must conform to a * subset of the syntax for a <code>FloatingPointLiteral</code> as defined * by the <em>Java Language Specification</em>, section 3.10.2. This * subset syntax is defined as follows: the actual contents * must consist of an optional minus sign * "-", followed by one or more whole-number decimal digits, * followed by an optional fraction separator, followed by zero or more * decimal fraction digits. The whole-number decimal digits may be * omitted if the fraction separator and one or more decimal fraction * digits are present.</p> * * <p>The syntax defined above is also enforced whenever the application * attempts to set or modify the contents of the text object by calling * a constructor or a method.</p> * * <p>Parsing this string value into a numeric value suitable for * computation is the responsibility of the application. If the contents * are not empty, the result can be parsed successfully by * <code>Double.valueOf</code> and related methods if they are present * in the runtime environment. </p> * * <p>The sign and the fraction separator consume space in the text * object. Applications should account for this when assigning a maximum * size for the text object.</p> * * <P>Constant <code>5</code> is assigned to <code>DECIMAL</code>.</P> * * @since MIDP 2.0 */ public static final int DECIMAL = 5; /** * Indicates that the text entered is confidential data that should be * obscured whenever possible. The contents may be visible while the * user is entering data. However, the contents must never be divulged * to the user. In particular, the existing contents must not be shown * when the user edits the contents. The means by which the contents * are obscured is implementation-dependent. For example, each * character of the data might be masked with a * "<code>*</code>" character. The * <code>PASSWORD</code> modifier is useful for entering * confidential information * such as passwords or personal identification numbers (PINs). * * <p>Data entered into a <code>PASSWORD</code> field is treated * similarly to <code>SENSITIVE</code> * in that the implementation must never store the contents into a * dictionary or table for use in predictive, auto-completing, or other * accelerated input schemes. If the <code>PASSWORD</code> bit is * set in a constraint * value, the <code>SENSITIVE</code> and * <code>NON_PREDICTIVE</code> bits are also considered to be * set, regardless of their actual values. In addition, the * <code>INITIAL_CAPS_WORD</code> and * <code>INITIAL_CAPS_SENTENCE</code> flag bits should be ignored * even if they are set.</p> * * <p>The <code>PASSWORD</code> modifier can be combined with * other input constraints * by using the bit-wise <code>OR</code> operator (<code>|</code>). * The <code>PASSWORD</code> modifier is not * useful with some constraint values such as * <code>EMAILADDR</code>, <code>PHONENUMBER</code>, * and <code>URL</code>. These combinations are legal, however, * and no exception is * thrown if such a constraint is specified.</p> * * <p>Constant <code>0x10000</code> is assigned to * <code>PASSWORD</code>.</p> */ public static final int PASSWORD = 0x10000; /** * Indicates that editing is currently disallowed. When this flag is set, * the implementation must prevent the user from changing the text * contents of this object. The implementation should also provide a * visual indication that the object's text cannot be edited. The intent * of this flag is that this text object has the potential to be edited, * and that there are circumstances where the application will clear this * flag and allow the user to edit the contents. * * <p>The <code>UNEDITABLE</code> modifier can be combined with * other input constraints * by using the bit-wise <code>OR</code> operator (<code>|</code>). * * <p>Constant <code>0x20000</code> is assigned to <code>UNEDITABLE</code>. * * @since MIDP 2.0 */ public static final int UNEDITABLE = 0x20000; /** * Indicates that the text entered is sensitive data that the * implementation must never store into a dictionary or table for use in * predictive, auto-completing, or other accelerated input schemes. A * credit card number is an example of sensitive data. * * <p>The <code>SENSITIVE</code> modifier can be combined with other input * constraints by using the bit-wise <code>OR</code> operator * (<code>|</code>).</p> * * <p>Constant <code>0x40000</code> is assigned to * <code>SENSITIVE</code>.</p> * * @since MIDP 2.0 */ public static final int SENSITIVE = 0x40000; /** * Indicates that the text entered does not consist of words that are * likely to be found in dictionaries typically used by predictive input * schemes. If this bit is clear, the implementation is allowed to (but * is not required to) use predictive input facilities. If this bit is * set, the implementation should not use any predictive input facilities, * but it instead should allow character-by-character text entry. * * <p>The <code>NON_PREDICTIVE</code> modifier can be combined * with other input * constraints by using the bit-wise <code>OR</code> operator * (<code>|</code>). * * <P>Constant <code>0x80000</code> is assigned to * <code>NON_PREDICTIVE</code>.</P> * * @since MIDP 2.0 */ public static final int NON_PREDICTIVE = 0x80000; /** * This flag is a hint to the implementation that during text editing, the * initial letter of each word should be capitalized. This hint should be * honored only on devices for which automatic capitalization is * appropriate and when the character set of the text being edited has the * notion of upper case and lower case letters. The definition of * word boundaries is implementation-specific. * * <p>If the application specifies both the * <code>INITIAL_CAPS_WORD</code> and the * <code>INITIAL_CAPS_SENTENCE</code> flags, * <code>INITIAL_CAPS_WORD</code> behavior should be used. * * <p>The <code>INITIAL_CAPS_WORD</code> modifier can be combined * with other input * constraints by using the bit-wise <code>OR</code> operator * (<code>|</code>). * * <p>Constant <code>0x100000</code> is assigned to * <code>INITIAL_CAPS_WORD</code>. * * @since MIDP 2.0 */ public static final int INITIAL_CAPS_WORD = 0x100000; /** * This flag is a hint to the implementation that during text editing, the * initial letter of each sentence should be capitalized. This hint * should be honored only on devices for which automatic capitalization is * appropriate and when the character set of the text being edited has the * notion of upper case and lower case letters. The definition of * sentence boundaries is implementation-specific. * * <p>If the application specifies both the * <code>INITIAL_CAPS_WORD</code> and the * <code>INITIAL_CAPS_SENTENCE</code> flags, * <code>INITIAL_CAPS_WORD</code> behavior should be used. * * <p>The <code>INITIAL_CAPS_SENTENCE</code> modifier can be * combined with other input * constraints by using the bit-wise <code>OR</code> operator * (<code>|</code>). * * <p>Constant <code>0x200000</code> is assigned to * <code>INITIAL_CAPS_SENTENCE</code>. * * @since MIDP 2.0 */ public static final int INITIAL_CAPS_SENTENCE = 0x200000; /** * The mask value for determining the constraint mode. The application * should * use the bit-wise <code>AND</code> operation with a value returned by * <code>getConstraints()</code> and * <code>CONSTRAINT_MASK</code> in order to retrieve the current * constraint mode, * in order to remove any modifier flags such as the * <code>PASSWORD</code> flag. * * <P>Constant <code>0xFFFF</code> is assigned to * <code>CONSTRAINT_MASK</code>.</P> */ public final static int CONSTRAINT_MASK = 0xFFFF; /** * Creates a new <code>TextField</code> object with the given label, initial * contents, maximum size in characters, and constraints. * If the text parameter is <code>null</code>, the * <code>TextField</code> is created empty. * The <code>maxSize</code> parameter must be greater than zero. * An <code>IllegalArgumentException</code> is thrown if the * length of the initial contents string exceeds <code>maxSize</code>. * However, * the implementation may assign a maximum size smaller than the * application had requested. If this occurs, and if the length of the * contents exceeds the newly assigned maximum size, the contents are * truncated from the end in order to fit, and no exception is thrown. * * @param label item label * @param text the initial contents, or <code>null</code> if the * <code>TextField</code> is to be empty * @param maxSize the maximum capacity in characters * @param constraints see <a href="#constraints">input constraints</a> * * @throws IllegalArgumentException if <code>maxSize</code> is zero or less * @throws IllegalArgumentException if the value of the constraints * parameter * is invalid * @throws IllegalArgumentException if <code>text</code> is illegal * for the specified constraints * @throws IllegalArgumentException if the length of the string exceeds * the requested maximum capacity */ public TextField(String label, String text, int maxSize, int constraints) { super(label); synchronized (Display.LCDUILock) { // IllegalArgumentException thrown here buffer = new DynamicCharacterArray(maxSize); cursor = new TextCursor(0); cursor.visible = false; hasBorder = true; inputHandler = InputMethodHandler.getInputMethodHandler(); inputClient = new InputMethodClientImpl(); // // we need to set the constraints before we tell the // handler about the client // setConstraints(constraints); inputClient.setInputMethodHandler(inputHandler); inputHandler.setInputMethodClient(inputClient); // // this will use inputClient // setString(text); } } /** * Gets the contents of the <code>TextField</code> as a string value. * * @return the current contents * @see #setString */ public String getString() { synchronized (Display.LCDUILock) { return buffer.toString(); } } /** * Sets the contents of the <code>TextField</code> as a string * value, replacing the * previous contents. * * @param text the new value of the <code>TextField</code>, or * <code>null</code> if the TextField is to be made empty * @throws IllegalArgumentException if <code>text</code> * is illegal for the current * <a href="TextField.html#constraints">input constraints</a> * @throws IllegalArgumentException if the text would exceed the current * maximum capacity * @see #getString */ public void setString(String text) { if (text == null) { setChars(null, 0, 0); } else { setChars(text.toCharArray(), 0, text.length()); } } /** * Copies the contents of the <code>TextField</code> into a * character array starting at * index zero. Array elements beyond the characters copied are left * unchanged. * * @param data the character array to receive the value * @return the number of characters copied * @throws ArrayIndexOutOfBoundsException if the array is too short for the * contents * @throws NullPointerException if <code>data</code> is <code>null</code> * @see #setChars */ public int getChars(char[] data) { synchronized (Display.LCDUILock) { try { buffer.getChars(0, buffer.length(), data, 0); } catch (IndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } return buffer.length(); } } /** * Sets the contents of the <code>TextField</code> from a * character array, replacing the * previous contents. Characters are copied from the region of the * <code>data</code> array * starting at array index <code>offset</code> and running for * <code>length</code> characters. * If the data array is <code>null</code>, the <code>TextField</code> * is set to be empty and the other parameters are ignored. * * <p>The <code>offset</code> and <code>length</code> parameters must * specify a valid range of characters within * the character array <code>data</code>. * The <code>offset</code> parameter must be within the * range <code>[0..(data.length)]</code>, inclusive. * The <code>length</code> parameter * must be a non-negative integer such that * <code>(offset + length) <= data.length</code>.</p> * * @param data the source of the character data * @param offset the beginning of the region of characters to copy * @param length the number of characters to copy * @throws ArrayIndexOutOfBoundsException if <code>offset</code> * and <code>length</code> do not specify * a valid range within the data array * @throws IllegalArgumentException if <code>data</code> * is illegal for the current * <a href="TextField.html#constraints">input constraints</a> * @throws IllegalArgumentException if the text would exceed the current * maximum capacity * @see #getChars */ public void setChars(char[] data, int offset, int length) { synchronized (Display.LCDUILock) { if (data == null) { buffer.delete(0, buffer.length()); cursor.index = 0; cursor.option = Text.PAINT_USE_CURSOR_INDEX;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -