use of com.codename1.ui.TextArea in project CodenameOne by codenameone.
the class GenericListCellRenderer method findComponentsOfInterest.
private void findComponentsOfInterest(Component cmp, ArrayList dest) {
if (cmp instanceof Container) {
Container c = (Container) cmp;
int count = c.getComponentCount();
for (int iter = 0; iter < count; iter++) {
findComponentsOfInterest(c.getComponentAt(iter), dest);
}
return;
}
// performance optimization for fixed images in lists
if (cmp.getName() != null) {
if (cmp instanceof Label) {
Label l = (Label) cmp;
if (l.getName().toLowerCase().endsWith("fixed") && l.getIcon() != null) {
l.getIcon().lock();
}
dest.add(cmp);
return;
}
if (cmp instanceof TextArea) {
dest.add(cmp);
return;
}
}
}
use of com.codename1.ui.TextArea in project CodenameOne by codenameone.
the class GenericListCellRenderer method setComponentValue.
/**
* Initializes the given component with the given value
*
* @param cmp one of the components that is or is a part of the renderer
* @param value the value to install into the component
*/
private void setComponentValue(Component cmp, Object value, Component parent, Component rootRenderer) {
// process so renderer selected/unselected styles are applied
if (cmp.getName().toLowerCase().endsWith("fixed")) {
return;
}
if (cmp instanceof Label) {
if (value instanceof Image) {
Image i = (Image) value;
if (i.isAnimation()) {
if (pendingAnimations == null) {
pendingAnimations = new ArrayList<Image>();
}
if (!pendingAnimations.contains(i)) {
pendingAnimations.add(i);
if (parentList == null) {
parentList = parent;
}
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
} else {
waitingForRegisterAnimation = true;
}
}
} else {
if (waitingForRegisterAnimation) {
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
}
}
}
}
}
Image oldImage = ((Label) cmp).getIcon();
((Label) cmp).setIcon(i);
((Label) cmp).setText("");
if (oldImage == null || oldImage.getWidth() != i.getWidth() || oldImage.getHeight() != i.getHeight()) {
((Container) rootRenderer).revalidate();
}
return;
} else {
((Label) cmp).setIcon(null);
}
if (cmp instanceof CheckBox) {
((CheckBox) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof RadioButton) {
((RadioButton) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof Slider) {
((Slider) cmp).setProgress(((Integer) value).intValue());
return;
}
Label l = (Label) cmp;
if (value == null) {
l.setText("");
} else {
if (value instanceof Label) {
l.setText(((Label) value).getText());
l.setIcon(((Label) value).getIcon());
} else {
l.setText(value.toString());
}
}
if (firstCharacterRTL) {
String t = l.getText();
if (t.length() > 0) {
l.setRTL(Display.getInstance().isRTL(t.charAt(0)));
}
}
return;
}
if (cmp instanceof TextArea) {
if (value == null) {
((TextArea) cmp).setText("");
} else {
((TextArea) cmp).setText(value.toString());
}
}
}
use of com.codename1.ui.TextArea in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawTextArea.
/**
* {@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();
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);
// 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;
}
}
}
}
use of com.codename1.ui.TextArea in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawTextFieldCursor.
/**
* {@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);
}
use of com.codename1.ui.TextArea in project CodenameOne by codenameone.
the class DefaultLookAndFeel method getTextAreaSize.
/**
* {@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);
}
Aggregations