📄 textfield.java
字号:
cursor.option = Text.PAINT_USE_CURSOR_INDEX; keyUsed = true; } break; case Canvas.RIGHT: if (cursor.index < buffer.length()) { cursor.index++; cursor.option = Text.PAINT_USE_CURSOR_INDEX; keyUsed = true; } break; case Canvas.UP: if (multiLine) { cursor.y -= Screen.CONTENT_FONT.getHeight(); if (cursor.y > 0) { cursor.option = Text.PAINT_GET_CURSOR_INDEX; keyUsed = true; } else { cursor.y += Screen.CONTENT_FONT.getHeight(); } } break; case Canvas.DOWN: if (multiLine) { cursor.y += Screen.CONTENT_FONT.getHeight(); height = bounds[HEIGHT]; if (getLabelHeight(bounds[WIDTH]) != height) { height -= getLabelHeight(bounds[WIDTH]); } if (cursor.y < height) { cursor.option = Text.PAINT_GET_CURSOR_INDEX; keyUsed = true; } else { cursor.y -= Screen.CONTENT_FONT.getHeight(); } } break; } return keyUsed; } /** * Called by the system * * <p>The default implementation of the traverse() method always returns * false.</p> * * @param dir the direction of traversal * @param viewportWidth the width of the container's viewport * @param viewportHeight the height of the container's viewport * @param visRect_inout passes the visible rectangle into the method, and * returns the updated traversal rectangle from the method * @return true if internal traversal had occurred, false if traversal * should proceed out * * @see #getInteractionModes * @see #traverseOut * @see #TRAVERSE_HORIZONTAL * @see #TRAVERSE_VERTICAL */ boolean callTraverse(int dir, int viewportWidth, int viewportHeight, int[] visRect_inout) { super.callTraverse(dir, viewportWidth, viewportHeight, visRect_inout); boolean ret = false; usePreferredX = !(dir == Canvas.UP || dir == Canvas.DOWN); if (firstTimeInTraverse || dir == CustomItem.NONE) { if (firstTimeInTraverse) { inputClient.setInputMode(initialInputMode); inputHandler.setInputMethodClient(inputClient); cursor.option = Text.PAINT_USE_CURSOR_INDEX; cursor.visible = editable; firstTimeInTraverse = false; } repaint(); if (owner.currentDisplay != null) { owner.currentDisplay.serviceRepaints(owner); } ret = true; } else { inputHandler.endComposition(false); if (moveCursor(dir)) { repaint(); if (owner.currentDisplay != null) { owner.currentDisplay.serviceRepaints(owner); } ret = true; } } visRect_inout[X] = cursor.x; visRect_inout[Y] = cursor.y - cursor.height; if (!fitsOneLine) { // If we're not on one line, we adjust for any // possible label offset visRect_inout[Y] += getLabelHeight(visRect_inout[WIDTH]); } visRect_inout[WIDTH] = cursor.width; // We include space for the border padding and for the // border so that when we "traverse" to the last line // in the TextField, Form will scroll far enough to include // our border as well as room for the traversal box visRect_inout[HEIGHT] = cursor.height + BORDER_PAD + 2; return ret; } /** * Called by the system to indicate traversal has left this Item * * @see #getInteractionModes * @see #traverse * @see #TRAVERSE_HORIZONTAL * @see #TRAVERSE_VERTICAL */ void callTraverseOut() { super.callTraverseOut(); firstTimeInTraverse = true; inputHandler.clearInputMethodClient(inputClient); // We re-set the Display's input mode indicator try { owner.currentDisplay.setInputMode(0); } catch (Throwable t) { // if owner.currentDisplay is null, we just // quietly catch the error and continue } cursor.option = Text.PAINT_USE_CURSOR_INDEX; cursor.index = buffer.length(); cursor.visible = false; repaint(); } /** * Called when this item is hidden */ void callHideNotify() { firstTimeInTraverse = true; } /** * Turns the border on or off * * @param state true to turn the border on, false to turn it off */ void setBorder(boolean state) { hasBorder = state; } /** * flag indicating if it is the first time that traverse is being * called */ private boolean firstTimeInTraverse = true; /** editable state of the text field */ private boolean editable; /** * An internal flag, True means this TextField prefers to be on one line */ private boolean fitsOneLine; /** * The pixel padding around this TextField to draw the border */ private static int BORDER_PAD = 2; /** buffer to store the text */ DynamicCharacterArray buffer; /** cursor to keep track of where to draw the cursor */ TextCursor cursor; /** current character waiting to be committed */ char currentInputChar; /** previous number of characters in the buffer */ int oldNumChars; /** true if the text field is allowed to have multiple lines */ boolean multiLine; /** true if the text field should draw a border */ boolean hasBorder; /** * true if the preferredX field in TextCursor should be updated with * the latest TextCursor.x coordinate */ boolean usePreferredX = true; /** the initial input mode for when the text field gets focus */ String initialInputMode = null; /** the input handler to use to retreive input */ InputMethodHandler inputHandler = null; /** the input client to receive callbacks from the input handler */ InputMethodClientImpl inputClient = null; /** * will ignore the next key entered. * used if we know input buffer is full */ private boolean ignoreNextKeyEntered; /** * buffer to hold characters that will be inserted when * the user enters text */ private char[] inputChars = new char[2]; /** * Acts as a gateway between this text field and the input handler */ private class InputMethodClientImpl implements InputMethodClient { /** the input handler to use */ private InputMethodHandler imh = null; /** active constraints */ private int constraints = TextField.ANY; /** default input mode */ private String inputMode = null; /** allowed input modes */ private String[] allowedModes = null; /** * Set which input handler to use * * @param imh input handler to use */ public void setInputMethodHandler(InputMethodHandler imh) { this.imh = imh; } /** * Set which input mode to use * * @param inputMode a String identifying the input mode */ public void setInputMode(String inputMode) { this.inputMode = inputMode; } /** * Returns the current input mode * * @return current input mode */ public String getInputMode() { return inputMode; } /** * Sets which modes are allowed * * @param allowedModes array of strings specifying allowed modes */ public void setAllowedModes(String[] allowedModes) { this.allowedModes = new String[allowedModes.length]; System.arraycopy(allowedModes, 0, this.allowedModes, 0, allowedModes.length); } /** * Returns the allowed modes * * @return the allowed modes */ public String[] getAllowedModes() { return allowedModes; } /** * Returns the current input constraints * * @return the current input constraints */ public int getConstraints() { return constraints; } /** * Set the current input constraints * * @param constraints the constraints to set * @return true if the constraints were set correctly */ public boolean setConstraints(int constraints) { this.constraints = constraints; if (imh != null) { return imh.setConstraints(constraints); } else { return true; } } // // call backs from the InputMethodHandler // /** * Call back from the input handler when a key has been committed * * @param keyCode key code of the key committed */ public void keyEntered(int keyCode) { TextField.this.keyEntered(keyCode); } /** * Call back from the input handler to inform the client that * the input mode has changed and that may want to show that * information to the user * * @param mode new input mode */ public void showInputMode(int mode) { if (hasFocus && owner.currentDisplay != null) { owner.currentDisplay.setInputMode(mode); } } /** * Returns the current display * * @return the current display */ public Display getDisplay() { return owner.currentDisplay; } /** * Tell the input client that it should set itself to be * the current display. This is called when returning * from the symbol table * * @param displayable displayable to be used * @param display display to be used */ public void setCurrent(Displayable displayable, Display display) { owner.resetToTop = false; display.setCurrent(displa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -