Java Code Examples for com.codename1.ui.TextArea#getInputMode()
The following examples show how to use
com.codename1.ui.TextArea#getInputMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * Calculates the position of the text field cursor within the string */ private int getTextFieldCursorX(TextArea ta) { Style style = ta.getStyle(); Font f = style.getFont(); // display ******** if it is a password field String displayText = getTextFieldString(ta); String inputMode = ta.getInputMode(); int inputModeWidth = f.stringWidth(inputMode); // QWERTY devices don't quite have an input mode hide it also when we have a VK if(ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) { inputMode = ""; inputModeWidth = 0; } int xPos = 0; int cursorCharPosition = ta.getCursorX(); int cursorX=0; int x = 0; if (reverseAlignForBidi(ta) == Component.RIGHT) { if (Display.getInstance().isBidiAlgorithm()) { //char[] dest = displayText.toCharArray(); cursorCharPosition = Display.getInstance().getCharLocation(displayText, cursorCharPosition-1); if (cursorCharPosition==-1) { xPos = f.stringWidth(displayText); } else { displayText = Display.getInstance().convertBidiLogicalToVisual(displayText); if (!isRTLOrWhitespace((displayText.charAt(cursorCharPosition)))) { cursorCharPosition++; } xPos = f.stringWidth(displayText.substring(0, cursorCharPosition)); } } int displayX = ta.getX() + ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - f.stringWidth(displayText); cursorX = displayX + xPos; x=0; } else { if (cursorCharPosition > 0) { cursorCharPosition = Math.min(displayText.length(), cursorCharPosition); xPos = f.stringWidth(displayText.substring(0, cursorCharPosition)); } cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos; if (ta.isSingleLineTextArea() && ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth -style.getPaddingLeft(ta.isRTL())) { if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL()) { x = ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL() - xPos -1; } } } return cursorX+x; }
Example 2
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public void drawTextFieldCursor(Graphics g, TextArea ta) { Style style = ta.getStyle(); Font f = style.getFont(); int cursorY; if(ta.isSingleLineTextArea()) { switch(ta.getVerticalAlignment()) { case Component.BOTTOM: cursorY = ta.getY() + ta.getHeight() - f.getHeight(); break; case Component.CENTER: cursorY = ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2; break; default: cursorY = ta.getY() + style.getPaddingTop(); break; } } else { cursorY = ta.getY() + style.getPaddingTop() + ta.getCursorY() * (ta.getRowsGap() + f.getHeight()); } int cursorX = getTextFieldCursorX(ta); int align = reverseAlignForBidi(ta); int x=0; if (align==Component.RIGHT) { String inputMode = ta.getInputMode(); int inputModeWidth = f.stringWidth(inputMode); int baseX=ta.getX()+style.getPaddingLeftNoRTL()+inputModeWidth; if (cursorX<baseX) { x=baseX-cursorX; } } int oldColor = g.getColor(); if(getTextFieldCursorColor() == 0) { g.setColor(style.getFgColor()); } else { g.setColor(getTextFieldCursorColor()); } g.drawLine(cursorX + x, cursorY, cursorX + x, cursorY + f.getHeight()); g.setColor(oldColor); }