📄 textfield.java
字号:
// the delete command is a Command.ITEM type when the extended menubar is used in conjunction with a defined return-key,
// because CANCEL will be mapped on special keys like the return key on Sony Ericsson devices.
//#if polish.MenuBar.useExtendedMenuBar && polish.key.ReturnKey:defined
//#ifdef polish.i18n.useDynamicTranslations
//# protected static Command DELETE_CMD = new Command( "Delete", Command.ITEM, 1 );
//#elifdef polish.command.delete:defined
//#= protected static final Command DELETE_CMD = new Command( "${polish.command.delete}", Command.ITEM, 1 );
//#else
//# protected static final Command DELETE_CMD = new Command( "Delete", Command.ITEM, 1 );
//#endif
//#else
//#ifdef polish.i18n.useDynamicTranslations
//# protected static Command DELETE_CMD = new Command( "Delete", Command.CANCEL, 1 );
//#elifdef polish.command.delete:defined
protected static final Command DELETE_CMD = new Command( "Delete", Command.CANCEL, 1 );
//#else
//# protected static final Command DELETE_CMD = new Command( "Delete", Command.CANCEL, 1 );
//#endif
//#endif
//#endif
//#ifdef polish.i18n.useDynamicTranslations
//# protected static Command CLEAR_CMD = new Command( "Clear", Command.ITEM, 2 );
//#elifdef polish.command.clear:defined
protected static final Command CLEAR_CMD = new Command( "Clear", Command.ITEM, 2 );
//#else
//# protected static final Command CLEAR_CMD = new Command( "Clear", Command.ITEM, 2 );
//#endif
/** valid input characters for local parts of email addresses, apart from 0..9 and a..z. */
private static final String VALID_LOCAL_EMAIL_ADDRESS_CHARACTERS = ".-_@!#$%&'*+/=?^`{|}~";
/** valid input characters for domain names, apart from 0..9 and a..z. */
private static final String VALID_DOMAIN_CHARACTERS = "._-";
private int maxSize;
private int constraints;
//#ifdef polish.css.textfield-caret-color
//# private int caretColor = -1;
//#endif
private char editingCaretChar = '|';
protected char caretChar = '|';
//#ifdef polish.css.font-bitmap
//# private BitMapFontViewer editingCaretViewer;
//# private BitMapFontViewer caretViewer;
//#endif
protected boolean showCaret;
private long lastCaretSwitch;
private int originalWidth; // the content width according to the text
private int originalHeight; // the content height according to the text
protected String title;
private String passwordText;
private boolean isPassword;
private boolean enableDirectInput;
//#if (!tmp.suppressCommands && !tmp.supportsSymbolEntry) || tmp.supportsSymbolEntry
private ItemCommandListener additionalItemCommandListener;
//#endif
// this is outside of the tmp.directInput block, so that it can be referenced from the UiAccess class
int inputMode; // the current input mode
//#if tmp.directInput
//#if tmp.supportsSymbolEntry
//# private static List symbolsList;
//#if polish.TextField.Symbols:defined
//#= private static String definedSymbols = "${ escape(polish.TextField.Symbols)}";
//#else
//# private static String definedSymbols = "@/\\<>(){}.,+-*:_\"#$%";
//#endif
//#ifdef polish.i18n.useDynamicTranslations
//# private static Command ENTER_SYMBOL_CMD = new Command( "Add Symbol", Command.ITEM, 3 );
//#elifdef polish.command.entersymbol:defined
//#= private static final Command ENTER_SYMBOL_CMD = new Command( "${polish.command.entersymbol}", Command.ITEM, 3 );
//#else
//# private static final Command ENTER_SYMBOL_CMD = new Command( "Add Symbol", Command.ITEM, 3 );
//#endif
//#endif
//#ifdef polish.css.text-wrap
//# private int currentXOffset; // used for scrolling to the correct position when text-wrapping is deactivated
//#endif
//# private boolean isKeyDown;
//#ifdef polish.TextField.InputTimeout:defined
//#= private static final int INPUT_TIMEOUT = ${polish.TextField.InputTimeout};
//#else
//# private static final int INPUT_TIMEOUT = 1000;
//#endif
//# private static final int MODE_LOWERCASE = 0;
//# private static final int MODE_FIRST_UPPERCASE = 1; // only the first character should be written in uppercase
//# private static final int MODE_UPPERCASE = 2;
//# static final int MODE_NUMBERS = 3;
//# private static final int MODE_NATIVE = 4;
//#ifdef polish.key.ChangeInputModeKey:defined
//#= private static final int KEY_CHANGE_MODE = ${polish.key.ChangeInputModeKey};
//#else
//# private static final int KEY_CHANGE_MODE = Canvas.KEY_POUND;
//#endif
//# private boolean nextCharUppercase; // is needed for the FIRST_UPPERCASE-mode
//#
//# private String[] realTextLines; // the displayed lines with spaces (which are otherwise removed)
//#
//# private int caretPosition; // the position of the caret in the text
//# private int caretColumn; // the current column of the caret, 0 is the first column
//# private int caretRow; // the current row of the caret, 0 is the first row
//# private int caretX;
//# private int caretY;
//# private int caretWidth;
//# private String originalRowText;
//#
//#ifdef polish.css.textfield-show-length
//# private boolean showLength;
//#endif
//#
//# private int lastKey; // the last key which has been pressed
//# long lastInputTime; // the last time a key has been pressed
//# private int characterIndex; // the index within the available characters of the current key
//# // the characters for each key:
//#ifdef polish.TextField.charactersKey1:defined
//#= private static final String charactersKey1 = "${polish.TextField.charactersKey1}";
//#else
//# private static final String charactersKey1 = ".,!?:/@_-+1";
//#endif
//#ifdef polish.TextField.charactersKey2:defined
//#= private static final String charactersKey2 = "${polish.TextField.charactersKey2}";
//#else
//# private static final String charactersKey2 = "abc2";
//#endif
//#ifdef polish.TextField.charactersKey3:defined
//#= private static final String charactersKey3 = "${polish.TextField.charactersKey3}";
//#else
//# private static final String charactersKey3 = "def3";
//#endif
//#ifdef polish.TextField.charactersKey4:defined
//#= private static final String charactersKey4 = "${polish.TextField.charactersKey4}";
//#else
//# private static final String charactersKey4 = "ghi4";
//#endif
//#ifdef polish.TextField.charactersKey5:defined
//#= private static final String charactersKey5 = "${polish.TextField.charactersKey5}";
//#else
//# private static final String charactersKey5 = "jkl5";
//#endif
//#ifdef polish.TextField.charactersKey6:defined
//#= private static final String charactersKey6 = "${polish.TextField.charactersKey6}";
//#else
//# private static final String charactersKey6 = "mno6";
//#endif
//#ifdef polish.TextField.charactersKey7:defined
//#= private static final String charactersKey7 = "${polish.TextField.charactersKey7}";
//#else
//# private static final String charactersKey7 = "pqrs7";
//#endif
//#ifdef polish.TextField.charactersKey8:defined
//#= private static final String charactersKey8 = "${polish.TextField.charactersKey8}";
//#else
//# private static final String charactersKey8 = "tuv8";
//#endif
//#ifdef polish.TextField.charactersKey9:defined
//#= private static final String charactersKey9 = "${polish.TextField.charactersKey9}";
//#else
//# private static final String charactersKey9 = "wxyz9";
//#endif
//#ifdef polish.TextField.charactersKey0:defined
//#= private static final String charactersKey0 = "${polish.TextField.charactersKey0}";
//#else
//# private static final String charactersKey0 = " 0";
//#endif
//#ifdef polish.TextField.charactersKeyStar:defined
//#= private static final String charactersKeyStar = "${polish.TextField.charactersKeyStar}";
//#else
//# private static final String charactersKeyStar = ".,!?:/@_-+";
//#endif
//#ifdef polish.TextField.charactersKeyPound:defined
//#= private static final String charactersKeyPound = "${polish.TextField.charactersKeyPound}";
//#else
//# private static final String charactersKeyPound = null;
//#endif
//# private static final String[] CHARACTERS = new String[]{ charactersKey0, charactersKey1, charactersKey2, charactersKey3, charactersKey4, charactersKey5, charactersKey6, charactersKey7, charactersKey8, charactersKey9 };
//# private static final String[] EMAIL_CHARACTERS = new String[]{ VALID_LOCAL_EMAIL_ADDRESS_CHARACTERS + "0", VALID_LOCAL_EMAIL_ADDRESS_CHARACTERS + "1", "abc2", "def3", "ghi4", "jkl5", "mno6", "pqrs7", "tuv8", "wxyz9" };
//# private String[] characters;
//# private boolean caretPositionHasBeenSet;
//# private boolean isNumeric;
//# private boolean isDecimal;
//# private boolean isEmail;
//#
//# private String caretRowFirstPart;
//# private String caretRowLastPart;
//# private int caretRowLastPartWidth;
//#
//# private int rowHeight;
//#
//# protected final Object lock;
//#endif
protected char emailSeparatorChar = ';';
//#if polish.blackberry
//# private PolishTextField editField;
//#if polish.Bugs.ItemStateListenerCalledTooEarly
//# private long lastFieldChangedEvent;
//#endif
//#endif
//#if !polish.blackberry && !polish.doja
//#define tmp.useNativeTextBox
private javax.microedition.lcdui.TextBox midpTextBox;
//#endif
protected boolean flashCaret = true;
protected boolean isUneditable;
private boolean doSetCaretPosition;
/**
* 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 null if the TextField is to be empty
* @param maxSize the maximum capacity in characters
* @param constraints see input constraints
* @throws IllegalArgumentException if maxSize is zero or less
* or if the value of the constraints parameter is invalid
* or if text is illegal for the specified constraints
* or if the length of the string exceeds the requested maximum capacity
*/
public TextField( String label, String text, int maxSize, int constraints)
{
this( label, text, maxSize, constraints, null );
}
/**
* 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 null if the TextField is to be empty
* @param maxSize the maximum capacity in characters
* @param constraints see input constraints
* @param style the CSS style for this field
* @throws IllegalArgumentException if maxSize is zero or less
* or if the value of the constraints parameter is invalid
* or if text is illegal for the specified constraints
* or if the length of the string exceeds the requested maximum capacity
*/
public TextField( String label, String text, int maxSize, int constraints, Style style)
{
super( label, text, INTERACTIVE, style );
//#if tmp.directInput
//# this.lock = new Object();
//#endif
this.constraints = constraints;
this.maxSize = maxSize;
if (label != null) {
this.title = label;
} else {
//#ifdef polish.title.input:defined
this.title = "Input";
//#else
//# this.title = "Input";
//#endif
}
if ((constraints & PASSWORD) == PASSWORD) {
this.isPassword = true;
setString( text );
}
//#ifndef polish.hasPointerEvents
if ((constraints & NUMERIC) == NUMERIC && (constraints & DECIMAL) != DECIMAL) {
this.enableDirectInput = true;
}
//#endif
setConstraints(constraints);
}
//#if tmp.useNativeTextBox
/**
* Creates the TextBox used for the actual input mode.
*/
private void createTextBox() {
String currentText = this.isPassword ? this.passwordText : this.text;
this.midpTextBox = new javax.microedition.lcdui.TextBox( this.title, currentText, this.maxSize, this.constraints );
//TODO add i18n support
this.midpTextBox.addCommand(StyleSheet.OK_CMD);
if (!this.isUneditable) {
this.midpTextBox.addCommand(StyleSheet.CANCEL_CMD);
}
this.midpTextBox.setCommandListener( this );
}
//#endif
/**
* Gets the contents of the <code>TextField</code> as a string value.
*
* @return the current contents, an empty string when the current value is null.
* @see #setString(java.lang.String)
*/
public String getString()
{
//#if tmp.directInput
//# if (this.caretChar != this.editingCaretChar) {
//# insertCharacter();
//# }
//#endif
//#if polish.blackberry
//# if ( this.editField != null ) {
//# return this.editField.getText();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -