📄 popup.java
字号:
/**
* Index into <code>charOptionCounter</code> for the last character used.
volatile protected int charOptionCounter = 0;*/
/**
* The characters, mapped to the number keys
final static protected char[][] CHAR_OPTIONS = {
{'0', '+'},
{'1', '.', '-', '\'', '+', '!', '\"', '*', '#', '$', '%', '(', ')', '@', '&', '_',
'~', '`', '^', '=', '\\', '|', ',', '/', '?', '<', '>', ':', ';', '[', ']'},
{'A', 'B', 'C', 'a', 'b', 'c', '2'},
{'D', 'E', 'F', 'd', 'e', 'f', '3'},
{'G', 'H', 'I', 'g', 'h', 'i', '4'},
{'J', 'K', 'L', 'j', 'k', 'l', '5'},
{'M', 'N', 'O', 'm', 'n', 'o', '6'},
{'P', 'Q', 'R', 'S', 'p', 'q', 'r', 's', '7'},
{'T', 'U', 'V', 't', 'u', 'v', '8'},
{'W', 'X', 'Y', 'Z', 'w', 'x', 'y', 'z', '9'},
{' '}
};*/
/**
* Phone keys used for data input.
final static protected int[] KEY_OPTIONS = {
PlatformCanvas.KEY_NUM0, PlatformCanvas.KEY_NUM1, PlatformCanvas.KEY_NUM2, PlatformCanvas.KEY_NUM3,
PlatformCanvas.KEY_NUM4, PlatformCanvas.KEY_NUM5, PlatformCanvas.KEY_NUM6, PlatformCanvas.KEY_NUM7,
PlatformCanvas.KEY_NUM8, PlatformCanvas.KEY_NUM9, PlatformCanvas.KEY_POUND
};
protected boolean preProcessKeyCode(int keyCode) {
if (keyCode != lastKeyCode) {
insertMode = true;
charOptionCounter = 0;
return true;
}
return false;
}
protected char processKeyCode(int keyCode) {
System.out.println("processKeyCode>>" + keyCode);
final int keyIndex = getKeyOption(keyCode);
if (keyIndex == -1) {
insertMode = true;
charOptionCounter = 0;
return (char) keyCode;
}
int rc = charOptionCounter;
final int len = CHAR_OPTIONS[keyIndex].length;
if (rc >= len) rc %= len;
char ch, rslt = 0;
for (int p = 0; p < len; p++) {
ch = CHAR_OPTIONS[keyIndex][rc];
System.out.println("processKeyCode CHAR_OPTIONS>>" + ch);
if (isCharValid(ch)) {
if (rslt == 0) {
charOptionCounter = rc + 1;
rslt = ch;
} else {
insertMode = false;
return rslt;
}
}
rc = (rc + 1) % len;
}
insertMode = true;
charOptionCounter = 0;
return rslt;
}*/
/**
* Numeric characters
protected static final String NUMERIC_CHARS = "0123456789";*/
/**
* Uppercase characters
protected static final String UC_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";*/
/**
* Lowercase characters
protected static final String LC_CHARS = "abcdefghijklmnopqrstuvwxyz";*/
/**
* Email special characters
protected static final String EMAIL_SPEC_CHARS = "~_.@";*/
/**
* Space character
protected static final String SPACE_CHARS = " ";*/
/**
* All special character
protected static final String ALL_SPEC_CHARS = " ~`!@#$%^&*()_-+=\\|'\".,/?<>:;[]";*/
/**
* Do not allows any chars
public static final int C_NO_CHARS = 0x00; */
/**
* Allows numbers in the document
* @see #NUMERIC_CHARS
public static final int C_NUMERIC = 0x01; */
/**
* Allows lowercase letters in the document
* @see #LC_CHARS
public static final int C_LOWER_CASE = 0x02;*/
/**
* Allows uppercase letters in the document
* @see #UC_CHARS
public static final int C_UPPER_CASE = 0x04;*/
/**
* Allows email special letters in the document
* @see #EMAIL_SPEC_CHARS
public static final int C_EMAIL_SPEC_CHARS = 0x08;*/
/**
* Allows spaces in the document
* @see #SPACE_CHARS
public static final int C_SPACE = 0x10;*/
/**
* Allows all special characters in the document
* @see #ALL_SPEC_CHARS
public static final int C_ALL_SPEC_CHARS = 0x80;*/
/**
* Allows all alphabet characters and space in the document
public static final int C_ALPHA = C_LOWER_CASE | C_UPPER_CASE | C_SPACE;*/
/**
* Allows alphanumeric characters in the document
public static final int C_ALPHA_NUMERIC = C_ALPHA | C_NUMERIC;*/
/**
* Allows all email characters in the document
public static final int C_EMAIL =
C_ALPHA_NUMERIC | C_EMAIL_SPEC_CHARS ^ C_SPACE;*/
/**
* Allows any characters in the document
public static final int C_ANY = 0xFF;*/
/**
* Constraints for the document
protected int constraint = C_NO_CHARS;*/
/**
* The array of allowed characted
protected char[] validChars = null;*/
/**
* Creates a new <code>TextComponent</code> instance.
* @param constr Constraints for this document
public void initValidChars(int constr) {
this.constraint = constr;
int vc = 0;
if ((constr & C_NUMERIC) > 0) {
vc += NUMERIC_CHARS.length();
}
if ((constr & C_LOWER_CASE) > 0) {
vc += UC_CHARS.length();
}
if ((constr & C_UPPER_CASE) > 0) {
vc += LC_CHARS.length();
}
if ((constr & C_ALL_SPEC_CHARS) > 0) {
vc += ALL_SPEC_CHARS.length();
} else {
if ((constr & C_EMAIL_SPEC_CHARS) > 0) {
vc += EMAIL_SPEC_CHARS.length();
}
if ((constr & C_SPACE) > 0) {
vc += SPACE_CHARS.length();
}
}
validChars = new char[vc];
int i, len;
vc = 0;
if ((constr & C_NUMERIC) > 0) {
len = NUMERIC_CHARS.length();
for (i = 0; i < len; i++)
validChars[vc++] = NUMERIC_CHARS.charAt(i);
}
if ((constr & C_LOWER_CASE) > 0) {
len = LC_CHARS.length();
for (i = 0; i < len; i++)
validChars[vc++] = LC_CHARS.charAt(i);
}
if ((constr & C_UPPER_CASE) > 0) {
len = UC_CHARS.length();
for (i = 0; i < len; i++)
validChars[vc++] = UC_CHARS.charAt(i);
}
if ((constr & C_ALL_SPEC_CHARS) > 0) {
len = ALL_SPEC_CHARS.length();
for (i = 0; i < len; i++)
validChars[vc++] = ALL_SPEC_CHARS.charAt(i);
} else {
if ((constr & C_EMAIL_SPEC_CHARS) > 0) {
len = EMAIL_SPEC_CHARS.length();
for (i = 0; i < len; i++)
validChars[vc++] = EMAIL_SPEC_CHARS.charAt(i);
}
if ((constr & C_SPACE) > 0) {
len = SPACE_CHARS.length();
for (i = 0; i < len; i++)
validChars[vc++] = SPACE_CHARS.charAt(i);
}
}
}*/
/**
* Checks if the character is allows symbol
* @param ch test character
* @return <code>true</code> if the characted is allwed symbol
* for the component, <code>false</code> otherwise
protected boolean isCharValid(char ch) {
System.out.println("isCharValid>>" + ch);
int vcl = validChars.length;
for (int i = 0; i < vcl; i++) {
if (validChars[i] == ch) return true;
}
return false;
}
protected int getKeyOption(int keyCode) {
System.out.println("getKeyOption>>" + keyCode);
int l = KEY_OPTIONS.length;
for (int keyIndex = 0; keyIndex < l; keyIndex++) {
if (KEY_OPTIONS[keyIndex] == keyCode) return keyIndex;
}
return -1;
}
protected int calculatedCaretPosition;
protected int calculatedCursorOffset;
protected int currentLength;*/
/**
* The echo character, which is used when
* the user wishes to disguise the characters
* typed into the text field.
* The disguises are removed if echoChar = <code>0</code>.
public char echoChar = 0;
public int adjustment = 0;
protected static final boolean SCROLLABLE = false;
protected char[] getFormattedText(boolean calcCursorOffset) {
char[] formattedText;
currentLength = composer.getCurrentLength();
if (echoChar != 0) {
formattedText = new char[currentLength];
for (int i = 0; i < currentLength; i++) {
formattedText[i] = echoChar;
}
} else {
formattedText = composer.getChars();
}
if (calcCursorOffset) {
calculatedCaretPosition = composer.getCaretPosition();
}
return formattedText;
}
*/
/////////////////////////////////////////////////////////////////////////
/**
* Disposes all resources held by this popup and closes it.
*/
public void dispose()
{
m_active = false;
m_text = null;
m_altTexts = null;
m_listener = null;
m_breakTextData = null;
System.gc();
}
/**
* Returns whether this popup is active or not.
*
* @return true if active, false otherwise.
*/
public boolean isActive()
{
return m_active;
}
/**
* Returns alternative index on timeout
*
* @return timeout alternative
*/
public byte getTimeOutChoice()
{
return m_timeOutAlt;
}
/**
* Called by framework to check if popup reached its' timeout.
*
* @return true if timeout, false otherwise.
*/
protected boolean pollTimeout()
{
if (m_active)
{
if (m_endTime > 0 && System.currentTimeMillis() > m_endTime)
{
m_active = false;
if (m_listener != null)
{
m_listener.selectedChoice(m_timeOutAlt, true);
return true;
}
}
}
return false;
}
// Runnable impl to poll this popup
public void run()
{
while (isActive())
{
// Poll popup timeout
try
{
Thread.sleep(1000);
pollTimeout();
} catch (InterruptedException e) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -