📄 defaultinputmethodhandler.java
字号:
if (constraints == TextField.NUMERIC || constraints == TextField.DECIMAL || constraints == TextField.PHONENUMBER) { defaultMode = IM_NUMERIC; allowedModesNum = 1; allowedModes[0] = IM_NUMERIC; } else if (constraints == TextField.EMAILADDR || constraints == TextField.URL) { defaultMode = IM_ROMAN_SMALL; allowedModesNum = 4; allowedModes[0] = IM_ROMAN_SMALL; allowedModes[1] = IM_ROMAN_CAPS; allowedModes[2] = IM_NUMERIC; allowedModes[3] = IM_SYMBOL; } else { if (constraints != TextField.ANY) { dMode = null; aMode = null; } /* * The mappings from character subsets to input modes are not * unique. So, we use this vector to make sure we do not end up * with the same input mode multiple times. */ Vector uniqueModes = new Vector(NUM_INPUT_MODES); if (dMode == null && aMode == null) { allowedModesNum = supportedInputModes.length; System.arraycopy(supportedInputModes, 0, allowedModes, 0, allowedModesNum); defaultMode = allowedModes[0]; } else { if (dMode == null && aMode != null) { dMode = aMode[0]; } if (dMode != null && aMode == null) { aMode = new String[supportedCharSubset.length]; System.arraycopy(supportedCharSubset, 0, aMode, 0, supportedCharSubset.length); } /* get the default initial mode based on the character subset */ for (int i = 0; i < inputModeConvTable.length; i++) { if (((String)inputModeConvTable[i][0]). equals(dMode)) { defaultMode = ((Integer)inputModeConvTable[i][1]).intValue(); break; } } /* * get all the allowed input modes based on the character * subset */ for (int j = 0; j < inputModeConvTable.length; j++) { for (int i = 0; i < aMode.length; i++) { Integer imode = (Integer)inputModeConvTable[i][1]; if (((String)inputModeConvTable[j][0]).equals(aMode[i]) && uniqueModes.indexOf(imode) == -1) { uniqueModes.addElement(imode); } } } allowedModesNum = uniqueModes.size(); for (int i = 0; i < allowedModesNum; i++) { allowedModes[i] = ((Integer)uniqueModes.elementAt(i)).intValue(); } if (defaultMode == IM_NONE) { defaultMode = allowedModes[0]; } /* temp comment out this code. Not sure the purpose of this code. We do not want to swap the input mode sequence. -tylee 060302 } else { if (defaultMode != allowedModes[0]) { for (i = 0; i < allowedModesNum; i++) { if (defaultMode == allowedModes[i]) { break; } } int t = allowedModes[0]; allowedModes[i] = t; allowedModes[0] = defaultMode; } } */ } capWord = (modifiers & TextField.INITIAL_CAPS_WORD) == TextField.INITIAL_CAPS_WORD; capSentence = (modifiers & TextField.INITIAL_CAPS_SENTENCE) == TextField.INITIAL_CAPS_SENTENCE; if (capWord || capSentence) { defaultMode = IM_ROMAN_CAPS; } } oldInputMode = defaultMode; inputMode = defaultMode; return ret; } /** * Determine if the given character is considered a symbol * * @param c character to check * @return true if the character is a symbol, false otherwise */ public boolean isSymbol(char c) { for (int i = 0; i < symbolTableChars.length; i++) { if (symbolTableChars[i] == c) { return true; } } return false; } /** * A special Canvas to display a symbol table. */ protected class SymbolTable extends Canvas { /** The margin size */ private final int MARGIN = 1; /** The margin size */ private final int DMARGIN = 2; /** Cell size */ private int cc; /** Height margin */ private int hmargin; /** Width margin */ private int wmargin; /** Margin for the cursor */ private int margin; /** Window x position */ private int wx; /** Window y position */ private int wy; /** Window width */ private int ww; /** Window height */ private int wh; /** Number of columns */ private int cols; /** Number of rows */ private int rows; /** Current cursor position */ private int pos; /** New cursor position */ private int newpos; /** Font */ private Font font; /** Flag */ private boolean firstTime = true; /** The current Display object */ private Display currentDisplay; /** The previous Displayable */ private Displayable previousScreen; /** default location to start the cursor */ protected int defaultSymbolCursorPos = 12; /** temporary holder of the imc that was being used */ InputMethodClient tmpimc; /** * Initialize the symbol table */ void init() { if (symbolTableChars.length <= 25) { rows = cols = 5; } else { rows = 6; cols = 6; } int w = getWidth() / cols; int h = getHeight() / rows; cc = (w > h) ? h : w; int cw = 0, ch = 0; int[] fs = {Font.SIZE_LARGE, Font.SIZE_MEDIUM, Font.SIZE_SMALL}; for (int i = 0; i < fs.length; i++) { font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, fs[i]); cw = font.charWidth('M'); ch = font.getHeight(); if (cw <= cc && ch <= cc) { break; } } ww = cols * cc; wh = rows * cc; wx = (getWidth() - ww) / 2; wy = getHeight() - wh; hmargin = (cc - ch) / 2; wmargin = cc / 2; margin = hmargin + 2; } /** * Invoke this symbol table. */ public void invokeSYM() { if (font == null) { init(); } tmpimc = imc; currentDisplay = imc.getDisplay(); previousScreen = currentDisplay.getCurrent(); currentDisplay.setCurrent(this); } /** * Notify this symbol table its being shown on the screen. * Overrides Canvas.showNotify. */ protected void showNotify() { pos = newpos = defaultSymbolCursorPos; } /** * Notify this symbol table its being hidden. * Overrides Canvas.hideNotify. */ protected void hideNotify() { firstTime = true; } /** * Paint this symbol table. * Overrides Canvas.paint. * * @param g The Graphics object to paint to */ protected void paint(Graphics g) { if (firstTime) { paintPanel(g); firstTime = false; } showCursor(g, pos, false); showCursor(g, pos = newpos, true); } /** * Paint the symbol table panel * * @param g The Graphics object to paint to */ void paintPanel(Graphics g) { g.setFont(font); g.setGrayScale(255); g.setClip(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight()); g.setGrayScale(0); g.drawRect(wx+1, wy+1, ww-2, wh-2); for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int i = r * cols + c; if (i == symbolTableChars.length) { break; } drawChar(g, symbolTableChars[i], r, c, false); } } } /** * Draw a character * * @param g The Graphics object to paint to * @param c The character to draw * @param row The row the character is in * @param col The column the character is in * @param reverse A flag to draw the character in inverse */ void drawChar(Graphics g, char c, int row, int col, boolean reverse) { int h = font.charWidth(c); int y = wy + row * cc + hmargin; int x = wx + col * cc + wmargin; g.setFont(font); if (reverse) { g.setGrayScale(255); } else { g.setGrayScale(0); } g.drawChar(c, x, y, Graphics.HCENTER | Graphics.TOP); } /** * Show the cursor of this symbol table * * @param g The Graphics object to paint to * @param pos The position of the cursor * @param show A flag indicating the visibility of the cursor */ void showCursor(Graphics g, int pos, boolean show) { int row = pos / cols; int col = pos % cols; int y = wy + row * cc; int x = wx + col * cc; if (show) { g.setGrayScale(0); } else { g.setGrayScale(255); } g.fillRect(x+margin, y+margin, cc-margin-1, cc-margin-1); drawChar(g, symbolTableChars[pos], row, col, show); } /** * Handle a key press event on this symbol table. * Overrides Canvas.keyPressed. * * @param keyCode The key that was pressed */ protected void keyPressed(int keyCode) { if ((keyCode > 0) && (((char)keyCode) == '*')) { tmpimc.setCurrent(previousScreen, currentDisplay); currentDisplay.callSerially( new Runnable() { public void run() { endComposition(true); ignoreNextKeyRelease = true; switchToNextInputMode(true); } }); } else { switch (getGameAction(keyCode)) { case Canvas.RIGHT: if ((pos + 1) < symbolTableChars.length) { newpos = pos + 1; repaint(); } break; case Canvas.LEFT: if (pos > 0) { newpos = pos - 1; repaint(); } break; case Canvas.UP: { int p = pos - cols; if (p >= 0) { newpos = p; repaint(); } break; } case Canvas.DOWN: { int p = pos + cols; if (p < symbolTableChars.length) { newpos = p; repaint(); } break; } case Canvas.FIRE: tmpimc.setCurrent(previousScreen, currentDisplay); currentDisplay.callSerially( new Runnable() { public void run() { lastKey = symbolTableChars[pos]; endComposition(false); ignoreNextKeyRelease = true; switchToNextInputMode(true); } }); break; } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -