📄 textbox.java
字号:
*/ void paintContent(Graphics g) { g.setColor(Display.ERASE_COLOR); g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight()); sD.policy.paint(g, sD.buffer, sD.numChars, cursorEnabled, sD.curPos, false); } /** * Notify this TextBox that its height has changed * * @param vpY * @param vpH * @param deltaHeight The change in height * @return int */ int heightChanged(int vpY, int vpH, int deltaHeight) { vpY = super.heightChanged(vpY, vpH, deltaHeight); // adjust the vpY so that the cursor postion // is always in the viewport return initHilight(vpY, vpH); } /** * Layout the content of this TextBox * * @param w The new width for this TextBox * @param h The allowable height for this TextBox * @return int The new height of this TextBox based on the new width */ int layoutContent(int w, int h) { return sD.setWidth(w); } /** * Initialize the highlight of this TextBox * * @param vpY * @param vpH * @return int */ int initHilight(int vpY, int vpH) { int cursorY1 = sD.policy.cursorY; int cursorY2 = cursorY1 + sD.policy.lineHeight; if (vpY > cursorY1 || vpY + vpH < cursorY2) { int t1 = cursorY2 - vpY - vpH; int t2 = vpY - cursorY1; vpY += (t1 >= t2 ? t1 : t2); } return vpY; } /** * Handle a key released event * * @param keyCode The code of the key that was released */ void keyReleased(int keyCode) { synchronized (Display.LCDUILock) { if (imHandler.keyReleased(keyCode)) { return; } } } /** * Handle a key pressed event * * @param keyCode The code of the key that was pressed */ void keyPressed(int keyCode) { synchronized (Display.LCDUILock) { keyPressedImpl(keyCode); } } /** * Traverse this TextBox * * @param dir The direction of traversal * @param top * @param bottom * @return int */ int traverse(int dir, int top, int bottom) { return sD.traverse(dir, top, bottom); } /** * Get the minimum content height of this TextBox * * @param width The width of this TextBox * @param height The allowable height of this TextBox * @return int The minimum height of this TextBox given the width */ int getMinimumContentHeight(int width, int height) { return sD.policy.getMinimumHeight(height) + 8; } /** * Notify this TextBox it is being shown on the Display * * @param d The Display showing this TextBox */ void showNotifyImpl(Display d) { super.showNotifyImpl(d); imHandler.setInputMethodClient(imi); } /** * Notify this TextBox it is being hidden * * @param d The Display which is hiding this TextBox */ void hideNotifyImpl(Display d) { super.hideNotifyImpl(d); imHandler.endComposition(); imHandler.clearInputMethodClient(imi); } /** * This method allows text to be entered from a (QWERTY) keyboard * * @param c The character entered from the keyboard */ void keyTyped(char c) { synchronized (Display.LCDUILock) { keyTypedImpl(c); } } /** * Get the client object of this TextBox * * @return Object Always returns 'this' */ Object getClientObject() { return this; } /** * Handle a key entered from the keyboard * * @param c The character entered from the keyboard */ void keyTypedImpl(char c) { int curPos = getCaretPosition(); // backspace and delete if ((c == 8) || (c == 127)) { if (curPos > 0) { imi.replace(null, 0, 1, curPos - 1, curPos); repaintContent(); } } else { if (sD.numChars < sD.buffer.length) { keyBoardChar[0] = c; try { imi.insert(keyBoardChar, 0, 1, curPos); repaintContent(); } catch (IllegalArgumentException ex) { // invalid character entered } } } } /** * Handle a key pressed event * * @param keyCode The key indentifier which was pressed */ void keyPressedImpl(int keyCode) { if (Display.getSystemKey(keyCode) == EventHandler.SYSTEM_KEY_SEND) { if (sD.policy instanceof PhonePolicy) { PhoneDial.call(getString()); } return; } if (imHandler.keyPressed(keyCode)) { return; } super.keyPressedImpl(keyCode); } /* * Handling InputMethod */ /** Input method, instance of InputMethodClient */ InputMethodImpl imi = new InputMethodImpl(); /** Input method handler */ static InputMethodHandler imHandler = InputMethodHandler.getInputMethodHandler(); /** * An InputMethodClient for this TextBox */ class InputMethodImpl implements InputMethodClient { /** * Get the Display of this InputMethodClient * * @return Display The TextBox's Display */ public Display getDisplay() { return TextBox.this.currentDisplay; } /** * Get the size of the target of this InputMethodClient * * @return int Returns the size() of the TextBox */ public int getSize() { return TextBox.this.size(); } /** * Get the maximum size of this InputMethodClient * * @return int Returns getMaxSize() of the TextBox */ public int getMaxSize() { return TextBox.this.getMaxSize(); } /** * Get the constraints of this InputMethodClient * * @return int Returns getConstraints() of the TextBox */ public int getConstraints() { return TextBox.this.getConstraints(); } /** * Get the character array of this InputMethodClient * * @param data A character array to fill with the character * data stored in this TextBox * @return int Returns the result of getChars(data) of the * TextBox */ public int getChars(char[] data) { return TextBox.this.getChars(data); } /** * Set the character array of this InputMethodClient * * @param data The character array * @param offset The offset into the buffer of the TextBox * @param length The number of characters to set */ public void setChars(char[] data, int offset, int length) { TextBox.this.setChars(data, offset, length); } /** * Get the caret position of this InputMethodClient * * @return int Returns getCaretPosition() of the TextBox */ public int getCaretPosition() { return TextBox.this.getCaretPosition(); } /** * Set the caret position of this InputMethodClient * * @param pos The position to set the caret to */ public void setCaretPosition(int pos) { TextBox.this.sD.curPos = pos; } /** * Toggle the visibility of the caret * * @param t A boolean visiblity value for the caret */ public void setCaretVisible(boolean t) { if (TextBox.this.cursorEnabled != t) { TextBox.this.cursorEnabled = t; TextBox.this.repaintContent(); } } /** * Insert characters into this InputMethodClient * * @param data The array of characters to insert * @param offset The index into the buffer to insert the characters * @param length The number of characters to insert * @param pos */ public void insert(char[] data, int offset, int length, int pos) { TextBox.this.insert(data, offset, length, pos); } /** * Replace characters in this InputMethodClient * * @param data The character array to replace characters from * @param offset * @param length * @param start * @param end */ public void replace(char[] data, int offset, int length, int start, int end) { TextBox.this.delete(start, end-start); if (data != null) { TextBox.this.insert(data, offset, length, start); } } /** * Repaint this InputMethodClient */ public void repaint() { TextBox.this.repaintContent(); if (isShown()) { currentDisplay.updateCommandSet(); } } /** * Repaint the content of this TextBox */ public void repaintContent() { TextBox.this.repaintContent(); } /** * Get the font of this InputMethodClient * * @return Font Returns Screen.CONTENT_FONT */ public Font getFont() { return Screen.CONTENT_FONT; } /** * Get the title of this InputMethodClient * * @return String Returns the result of TextBox.getTitle() */ public String getTitle() { return TextBox.this.getTitle(); } /** * Get the location of this InputMethodClient * * @param rect A four element array holding the location * coordinates (x, y, width, height) */ public void getLocation(int rect[]) { TextBox.this.getContentRect(rect); } /** * Set the input mode of this InputMethodClient * * @param mode The new input mode */ public void setInputMode(int mode) { currentDisplay.setInputMode(mode); } /** * Get the client object of this InputMethodClient * * @return Object Returns the result of TextBox.getClientObject() */ public Object getClientObject() { return TextBox.this.getClientObject(); } } // class InputMethodImpl} // class TextBox
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -