Search in sources :

Example 1 with InputComponent

use of com.codename1.ui.InputComponent in project CodenameOne by codenameone.

the class Validator method setValid.

void setValid(Component cmp, boolean v) {
    Boolean b = (Boolean) cmp.getClientProperty(VALID_MARKER);
    if (b != null && b.booleanValue() == v) {
        return;
    }
    cmp.putClientProperty(VALID_MARKER, v);
    if (!v) {
        // if one component is invalid... just disable the submit buttons
        for (Component c : submitButtons) {
            c.setEnabled(false);
        }
    } else {
        boolean isV = isValid();
        for (Component c : submitButtons) {
            c.setEnabled(isV);
        }
        if (message != null && cmp.hasFocus()) {
            message.dispose();
        }
    }
    if (cmp instanceof InputComponent && ((InputComponent) cmp).isOnTopMode()) {
        InputComponent tc = (InputComponent) cmp;
        if (v) {
            tc.errorMessage(null);
        } else {
            tc.errorMessage(getErrorMessage(cmp));
        }
    }
    if (validationFailureHighlightMode == HighlightMode.EMBLEM || validationFailureHighlightMode == HighlightMode.UIID_AND_EMBLEM) {
        if (!(cmp.getComponentForm().getGlassPane() instanceof ComponentListener)) {
            cmp.getComponentForm().setGlassPane(new ComponentListener(null));
        }
    }
    if (v) {
        if (validationFailureHighlightMode == HighlightMode.UIID || validationFailureHighlightMode == HighlightMode.UIID_AND_EMBLEM) {
            String uiid = cmp.getUIID();
            if (uiid.endsWith("Invalid")) {
                uiid = uiid.substring(0, uiid.length() - 7);
                cmp.setUIID(uiid);
            }
            return;
        }
        if (validationFailureHighlightMode == HighlightMode.EMBLEM && validationFailedEmblem != null) {
        }
    } else {
        if (validationFailureHighlightMode == HighlightMode.UIID || validationFailureHighlightMode == HighlightMode.UIID_AND_EMBLEM) {
            String uiid = cmp.getUIID();
            if (!uiid.endsWith("Invalid")) {
                cmp.setUIID(uiid + "Invalid");
            }
            return;
        }
    }
}
Also used : InputComponent(com.codename1.ui.InputComponent) TextComponent(com.codename1.ui.TextComponent) Component(com.codename1.ui.Component) InputComponent(com.codename1.ui.InputComponent)

Example 2 with InputComponent

use of com.codename1.ui.InputComponent in project CodenameOne by codenameone.

the class TextModeLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
@Override
public void layoutContainer(Container parent) {
    if (autoGrouping && actual != table && lastComponentCount != parent.getComponentCount()) {
        lastComponentCount = parent.getComponentCount();
        ArrayList<Component> tc = new ArrayList<Component>();
        for (Component c : parent) {
            if (c instanceof InputComponent) {
                tc.add(c);
            }
        }
        if (tc.size() > 0) {
            Component[] tcArr = new Component[tc.size()];
            tc.toArray(tcArr);
            InputComponent.group(tcArr);
        }
    }
    actual.layoutContainer(parent);
}
Also used : InputComponent(com.codename1.ui.InputComponent) ArrayList(java.util.ArrayList) Component(com.codename1.ui.Component) InputComponent(com.codename1.ui.InputComponent)

Example 3 with InputComponent

use of com.codename1.ui.InputComponent in project CodenameOne by codenameone.

the class InputComponent method errorMessage.

/**
 * Sets the text of the error label
 * @param errorMessage the text
 * @return this for chaining calls E.g. {@code TextComponent tc = new TextComponent().text("Text").label("Label"); }
 */
public InputComponent errorMessage(String errorMessage) {
    String col = getUIManager().getThemeConstant("textComponentErrorColor", null);
    if (errorMessage == null || errorMessage.length() == 0) {
        // no need for double showing of error
        if (this.errorMessage.getText().length() == 0) {
            return this;
        }
        // clear the error mode
        this.errorMessage.setText("");
        if (col != null) {
            lbl.setUIID(lbl.getUIID());
            getEditor().setUIID(getEditor().getUIID());
        }
    } else {
        this.errorMessage.setText(errorMessage);
        if (col != null) {
            int val = Integer.parseInt(col, 16);
            lbl.getAllStyles().setFgColor(val);
            Border b = Border.createUnderlineBorder(2, val);
            getEditor().getAllStyles().setBorder(b);
        }
    }
    refreshForGuiBuilder();
    return this;
}
Also used : Border(com.codename1.ui.plaf.Border)

Aggregations

Component (com.codename1.ui.Component)2 InputComponent (com.codename1.ui.InputComponent)2 TextComponent (com.codename1.ui.TextComponent)1 Border (com.codename1.ui.plaf.Border)1 ArrayList (java.util.ArrayList)1