Java Code Examples for com.codename1.ui.TextArea#getX()
The following examples show how to use
com.codename1.ui.TextArea#getX() .
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 |
@Override public Spans calculateTextAreaSpan(TextSelection sel, TextArea ta) { Spans out = sel.newSpans(); //setFG(g, ta); //Span out = sel.newSpan(ta); int line = ta.getLines(); //int oX = g.getClipX(); //int oY = g.getClipY(); //int oWidth = g.getClipWidth(); //int oHeight = g.getClipHeight(); Font f = ta.getStyle().getFont(); int fontHeight = f.getHeight(); int align = reverseAlignForBidi(ta); int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL()); int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL()); int topPadding = ta.getStyle().getPaddingTop(); switch (ta.getVerticalAlignment()) { case Component.CENTER : topPadding += Math.max(0, (ta.getInnerHeight() - (ta.getRowsGap() + fontHeight) * line)/2); break; case Component.BOTTOM : topPadding += Math.max(0, (ta.getInnerHeight() - (ta.getRowsGap() + fontHeight) * line)); } //boolean shouldBreak = false; int posOffset = 0; int lastRowBottom = 0; for (int i = 0; i < line; i++) { Span rowSpan = sel.newSpan(ta); int x = ta.getX() + leftPadding; int y = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * i; int adjustedY = Math.max(y, lastRowBottom); int yDiff = adjustedY - y; y = adjustedY; //if(Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) { String rowText = (String) ta.getTextAt(i); //display ******** if it is a password field String displayText = ""; if ((ta.getConstraint() & TextArea.PASSWORD) != 0) { int rlen = rowText.length(); for (int j = 0; j < rlen; j++) { displayText += passwordChar; } } else { displayText = rowText; } posOffset = ta.getText().indexOf(rowText, posOffset); switch(align) { case Component.RIGHT: x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText); break; case Component.CENTER: x+= (ta.getWidth()-leftPadding-rightPadding-f.stringWidth(displayText))/2; break; } //int nextY = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * (i + 2); //if this is the last line to display and there is more content and isEndsWith3Points() is true //add "..." at the last row if(ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line){ if(displayText.length() > 3){ displayText = displayText.substring(0, displayText.length() - 3); } //g.drawString(displayText + "...", x, y ,ta.getStyle().getTextDecoration()); append(sel, ta, rowSpan, displayText + "...", f, posOffset, x, y, getSelectionHeight(f) - yDiff); lastRowBottom = rowSpan.getBounds().getY() + rowSpan.getBounds().getHeight(); rowSpan = rowSpan.translate(ta.getAbsoluteX() - sel.getSelectionRoot().getAbsoluteX() - ta.getX(), ta.getAbsoluteY() - sel.getSelectionRoot().getAbsoluteY() - ta.getY()); out.add(rowSpan); return out; }else{ //g.drawString(displayText, x, y ,ta.getStyle().getTextDecoration()); append(sel, ta, rowSpan, displayText, f, posOffset, x, y, getSelectionHeight(f) - yDiff); lastRowBottom = rowSpan.getBounds().getY() + rowSpan.getBounds().getHeight(); rowSpan = rowSpan.translate(ta.getAbsoluteX() - sel.getSelectionRoot().getAbsoluteX() - ta.getX(), ta.getAbsoluteY() - sel.getSelectionRoot().getAbsoluteY() - ta.getY()); out.add(rowSpan); } posOffset += displayText.length(); //shouldBreak = true; //}else{ // if(shouldBreak){ // break; // } //} } return out; }
Example 2
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public void drawTextArea(Graphics g, TextArea ta) { setFG(g, ta); int line = ta.getLines(); int oX = g.getClipX(); int oY = g.getClipY(); int oWidth = g.getClipWidth(); int oHeight = g.getClipHeight(); Font f = ta.getStyle().getFont(); int fontHeight = f.getHeight(); int align = reverseAlignForBidi(ta); int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL()); int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL()); int topPadding = ta.getStyle().getPaddingTop(); switch (ta.getVerticalAlignment()) { case Component.CENTER : topPadding += Math.max(0, (ta.getInnerHeight() - ta.getRowsGap()*(line-1) - fontHeight* line)/2); break; case Component.BOTTOM : topPadding += Math.max(0, (ta.getInnerHeight() - ta.getRowsGap()*(line-1) - fontHeight* line)); } boolean shouldBreak = false; for (int i = 0; i < line; i++) { int x = ta.getX() + leftPadding; int y = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * i; if(Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) { String rowText = (String) ta.getTextAt(i); //display ******** if it is a password field String displayText = ""; if ((ta.getConstraint() & TextArea.PASSWORD) != 0) { int rlen = rowText.length(); for (int j = 0; j < rlen; j++) { displayText += passwordChar; } } else { displayText = rowText; } switch(align) { case Component.RIGHT: x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText); break; case Component.CENTER: x+= (ta.getWidth()-leftPadding-rightPadding-f.stringWidth(displayText))/2; break; } int nextY = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * (i + 2); //if this is the last line to display and there is more content and isEndsWith3Points() is true //add "..." at the last row if(ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line){ if(displayText.length() > 3){ displayText = displayText.substring(0, displayText.length() - 3); } g.drawString(displayText + "...", x, y ,ta.getStyle().getTextDecoration()); return; }else{ g.drawString(displayText, x, y ,ta.getStyle().getTextDecoration()); } shouldBreak = true; }else{ if(shouldBreak){ break; } } } }
Example 3
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 4
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); }