use of com.codename1.ui.layouts.TextModeLayout in project CodenameOne by codenameone.
the class TextComponentSample2745 method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", new TextModeLayout(2, 1));
TextComponent cmp1 = new TextComponent().label("label1");
TextComponent cmp2 = new TextComponent().label("label2");
hi.add(cmp1);
hi.add(cmp2);
hi.show();
cmp1.text("text1");
cmp2.text("text2");
hi.revalidateWithAnimationSafety();
hi.repaint();
}
use of com.codename1.ui.layouts.TextModeLayout in project CodenameOne by codenameone.
the class TestTextComponentPassword2976 method start.
public void start() {
if (current != null) {
current.show();
return;
}
TextModeLayout tl = new TextModeLayout(2, 1);
Form f = new Form("Pixel Perfect", tl);
TextComponent user = new TextComponent();
TextComponentPassword pass = new TextComponentPassword();
f.addAll(user, pass);
f.show();
}
use of com.codename1.ui.layouts.TextModeLayout in project CodenameOne by codenameone.
the class Validator method addConstraint.
/**
* Places a constraint on the validator, returns this object so constraint
* additions can be chained. Shows validation errors messages even when the
* TextModeLayout is not {@code onTopMode} (it's possible to disable this
* functionality setting to false the theme constant
* {@code showValidationErrorsIfNotOnTopMode}: basically, the error
* message is shown for two second in place of the label on the left of the
* InputComponent (or on right of the InputComponent for RTL languages);
* this solution never breaks the layout, because the error message is
* trimmed to fit the available space. The error message UIID is
* "ErrorLabel" when it's not onTopMode.
*
* @param cmp the component to validate
* @param c the constraint or constraints
* @return this object so we can write code like v.addConstraint(cmp1,
* cons).addConstraint(cmp2, otherConstraint);
*/
public Validator addConstraint(Component cmp, Constraint... c) {
Constraint constraint = null;
if (c.length == 1) {
constraint = c[0];
constraintList.put(cmp, constraint);
} else if (c.length > 1) {
constraint = new GroupConstraint(c);
constraintList.put(cmp, constraint);
}
if (constraint == null) {
throw new IllegalArgumentException("addConstraint needs at least a Constraint, but the Constraint array in empty");
}
bindDataListener(cmp);
boolean isV = isValid();
for (Component btn : submitButtons) {
btn.setEnabled(isV);
}
// Show validation error on iPhone
if (UIManager.getInstance().isThemeConstant("showValidationErrorsIfNotOnTopMode", true) && cmp instanceof InputComponent) {
final InputComponent inputComponent = (InputComponent) cmp;
if (!inputComponent.isOnTopMode()) {
Label labelForComponent = null;
if (inputComponent instanceof TextComponent) {
labelForComponent = ((TextComponent) inputComponent).getField().getLabelForComponent();
} else if (inputComponent instanceof PickerComponent) {
labelForComponent = ((PickerComponent) inputComponent).getPicker().getLabelForComponent();
}
if (labelForComponent != null) {
final Label myLabel = labelForComponent;
final String originalText = myLabel.getText();
final String originalUIID = myLabel.getUIID();
final Constraint myConstraint = constraint;
final Runnable showError = new Runnable() {
@Override
public void run() {
boolean isValid = false;
if (inputComponent instanceof TextComponent) {
isValid = myConstraint.isValid(((TextComponent) inputComponent).getField().getText());
} else if (inputComponent instanceof PickerComponent) {
isValid = myConstraint.isValid(((PickerComponent) inputComponent).getPicker().getValue());
}
String errorMessage = trimLongString(UIManager.getInstance().localize(myConstraint.getDefaultFailMessage(), myConstraint.getDefaultFailMessage()), "ErrorLabel", myLabel.getWidth());
if (errorMessage != null && errorMessage.length() > 0 && !isValid) {
// show the error in place of the label for component
myLabel.setUIID("ErrorLabel");
myLabel.setText(errorMessage);
UITimer.timer(2000, false, Display.getInstance().getCurrent(), new Runnable() {
@Override
public void run() {
myLabel.setUIID(originalUIID);
myLabel.setText(originalText);
}
});
} else {
// show the label for component without the error
myLabel.setUIID(originalUIID);
myLabel.setText(originalText);
}
}
};
FocusListener myFocusListener = new FocusListener() {
@Override
public void focusLost(Component cmp) {
showError.run();
}
@Override
public void focusGained(Component cmp) {
// no code here
}
};
if (inputComponent instanceof TextComponent) {
((TextComponent) inputComponent).getField().addFocusListener(myFocusListener);
} else if (inputComponent instanceof PickerComponent) {
((PickerComponent) inputComponent).getPicker().addFocusListener(myFocusListener);
}
}
}
}
return this;
}
Aggregations