Java Code Examples for com.codename1.ui.TextArea#getStyle()
The following examples show how to use
com.codename1.ui.TextArea#getStyle() .
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: InPlaceEditView.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
TextAreaData(TextArea ta) { absoluteX = ta.getAbsoluteX(); absoluteY = ta.getAbsoluteY(); scrollX = ta.getScrollX(); scrollY = ta.getScrollY(); Style s = ta.getStyle(); paddingTop = s.getPaddingTop(); paddingLeft = s.getPaddingLeft(ta.isRTL()); paddingRight = s.getPaddingRight(ta.isRTL()); paddingBottom = s.getPaddingBottom(); isTextField = (ta instanceof TextField); verticalAlignment = ta.getVerticalAlignment(); height = ta.getHeight(); width = ta.getWidth(); fontHeight = s.getFont().getHeight(); textArea = ta; isRTL = ta.isRTL(); nextDown = textArea.getComponentForm().getNextComponent(textArea); isSingleLineTextArea = textArea.isSingleLineTextArea(); hint = ta.getHint(); nativeHintBool = textArea.getUIManager().isThemeConstant("nativeHintBool", false); nativeFont = s.getFont().getNativeFont(); fgColor = s.getFgColor(); maxSize = ta.getMaxSize(); }
Example 2
Source File: DefaultLookAndFeel.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public Dimension getTextAreaSize(TextArea ta, boolean pref) { int prefW = 0; int prefH = 0; Style style = ta.getStyle(); Font f = style.getFont(); //if this is a text field the preferred size should be the text width if (ta.getRows() == 1) { prefW = f.stringWidth(ta.getText()); } else { prefW = f.charWidth(TextArea.getWidestChar()) * ta.getColumns(); } int rows; if(pref) { rows = ta.getActualRows(); } else { rows = ta.getLines(); } prefH = (f.getHeight() + ta.getRowsGap()) * rows; if(!ta.isActAsLabel()) { int columns = ta.getColumns(); String str = ""; for (int iter = 0; iter < columns; iter++) { str += TextArea.getWidestChar(); } if(columns > 0) { prefW = Math.max(prefW, f.stringWidth(str)); } } prefH = Math.max(prefH, rows * f.getHeight()); prefW += style.getPaddingRightNoRTL() + style.getPaddingLeftNoRTL(); prefH += style.getPaddingTop() + style.getPaddingBottom(); if(style.getBorder() != null) { prefW = Math.max(style.getBorder().getMinimumWidth(), prefW); prefH = Math.max(style.getBorder().getMinimumHeight(), prefH); } if(isBackgroundImageDetermineSize() && style.getBgImage() != null) { prefW = Math.max(style.getBgImage().getWidth(), prefW); prefH = Math.max(style.getBgImage().getHeight(), prefH); } return new Dimension(prefW, prefH); }
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); }