Search in sources :

Example 21 with Constraint

use of com.codename1.ui.validation.Constraint in project CodenameOne by codenameone.

the class GameCanvasImplementation method editString.

/**
 * @inheritDoc
 */
public void editString(Component cmp, int maxSize, int constraint, String text, int keyCode) {
    UIManager m = UIManager.getInstance();
    CONFIRM_COMMAND = new Command(m.localize("ok", "OK"), Command.OK, 1);
    CANCEL_COMMAND = new Command(m.localize("cancel", "Cancel"), Command.CANCEL, 2);
    if (mid.getAppProperty("forceBackCommand") != null) {
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    currentTextBox = new TextBox("", "", maxSize, TextArea.ANY);
    currentTextBox.setCommandListener((CommandListener) canvas);
    currentTextBox.addCommand(CONFIRM_COMMAND);
    currentTextBox.addCommand(CANCEL_COMMAND);
    currentTextComponent = cmp;
    currentTextBox.setMaxSize(maxSize);
    currentTextBox.setString(text);
    currentTextBox.setConstraints(constraint);
    display.setCurrent(currentTextBox);
    ((C) canvas).setDone(false);
    Display.getInstance().invokeAndBlock(((C) canvas));
}
Also used : Command(javax.microedition.lcdui.Command) UIManager(com.codename1.ui.plaf.UIManager) TextBox(javax.microedition.lcdui.TextBox)

Example 22 with Constraint

use of com.codename1.ui.validation.Constraint in project CodenameOne by codenameone.

the class GridBagLayoutInfo method addLayoutComponent.

public void addLayoutComponent(Object constraints, Component comp, Container c) {
    GridBagConstraints cons;
    if (constraints != null) {
        if (!(constraints instanceof GridBagConstraints)) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("AddLayoutComponent: constraint object must be GridBagConstraints");
        }
        cons = (GridBagConstraints) constraints;
    } else {
        if (comptable.containsKey(comp)) {
            // don't replace constraints with default ones
            return;
        }
        cons = defaultConstraints;
    }
    /*try {
            //cons.verify();
        } catch (IllegalArgumentException e) {
            // awt.81=AddLayoutComponent: {0}
            throw new IllegalArgumentException("AddLayoutComponent: " + e.getMessage()); //$NON-NLS-1$
        }*/
    GridBagConstraints consClone = (GridBagConstraints) cons.clone();
    comptable.put(comp, consClone);
    Container parent = comp.getParent();
    updateParentInfo(parent, consClone);
}
Also used : Container(com.codename1.ui.Container)

Example 23 with Constraint

use of com.codename1.ui.validation.Constraint in project CodenameOne by codenameone.

the class LayeredLayout method calcPreferredValues.

private void calcPreferredValues(Component cmp) {
    if (tmpLaidOut.contains(cmp)) {
        return;
    }
    tmpLaidOut.add(cmp);
    LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
    if (constraint != null) {
        constraint.fixDependencies(cmp.getParent());
        for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
            if (inset.referenceComponent != null && inset.referenceComponent.getParent() == cmp.getParent()) {
                calcPreferredValues(inset.referenceComponent);
            }
            inset.calcPreferredValue(cmp.getParent(), cmp);
        }
    }
}
Also used : Inset(com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)

Example 24 with Constraint

use of com.codename1.ui.validation.Constraint in project CodenameOne by codenameone.

the class MigLayout method setComponentConstraintsImpl.

/**
 * Sets the component constraint for the component that already must be
 * handled by this layout manager.
 * <p>
 * See the class JavaDocs for information on how this string is formatted.
 *
 * @param constr The component constraints as a String or
 * {@link net.miginfocom.layout.CC}. <code>null</code> is ok.
 * @param comp The component to set the constraints for.
 * @param noCheck Doe not check if the component is handled if true
 * @throws RuntimeException if the constraint was not valid.
 * @throws IllegalArgumentException If the component is not handling the
 * component.
 */
private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck) {
    Container parent = comp.getParent();
    if (noCheck == false && scrConstrMap.containsKey(comp) == false) {
        throw new IllegalArgumentException("Component must already be added to parent!");
    }
    ComponentWrapper cw = new CodenameOneMiGComponentWrapper(comp);
    if (constr == null || constr instanceof String) {
        String cStr = ConstraintParser.prepare((String) constr);
        scrConstrMap.put(comp, constr);
        ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr));
    } else if (constr instanceof CC) {
        scrConstrMap.put(comp, constr);
        ccMap.put(cw, (CC) constr);
    } else {
        throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString());
    }
    dirty = true;
}
Also used : CC(com.codename1.ui.layouts.mig.CC) Container(com.codename1.ui.Container) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 25 with Constraint

use of com.codename1.ui.validation.Constraint in project CodenameOne by codenameone.

the class CodenameOneView method setInputType.

public void setInputType(EditorInfo editorInfo) {
    /**
     * do not use the enter key to fire some kind of action!
     */
    // editorInfo.imeOptions |= EditorInfo.IME_ACTION_NONE;
    Component txtCmp = Display.getInstance().getCurrent().getFocused();
    if (txtCmp != null && txtCmp instanceof TextArea) {
        TextArea txt = (TextArea) txtCmp;
        if (txt.isSingleLineTextArea()) {
            editorInfo.imeOptions |= EditorInfo.IME_ACTION_DONE;
        } else {
            editorInfo.imeOptions |= EditorInfo.IME_ACTION_NONE;
        }
        int inputType = 0;
        int constraint = txt.getConstraint();
        if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
            constraint = constraint ^ TextArea.PASSWORD;
        }
        switch(constraint) {
            case TextArea.NUMERIC:
                inputType = EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_FLAG_SIGNED;
                break;
            case TextArea.DECIMAL:
                inputType = EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_FLAG_DECIMAL;
                break;
            case TextArea.PHONENUMBER:
                inputType = EditorInfo.TYPE_CLASS_PHONE;
                break;
            case TextArea.EMAILADDR:
                inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
                break;
            case TextArea.URL:
                inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_URI;
                break;
            default:
                inputType = EditorInfo.TYPE_CLASS_TEXT;
                break;
        }
        editorInfo.inputType = inputType;
    }
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Aggregations

Component (com.codename1.ui.Component)7 TextArea (com.codename1.ui.TextArea)7 Container (com.codename1.ui.Container)5 Style (com.codename1.ui.plaf.Style)5 PeerComponent (com.codename1.ui.PeerComponent)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Inset (com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)3 Point (java.awt.Point)3 java.util (java.util)3 Button (com.codename1.ui.Button)2 Form (com.codename1.ui.Form)2 Label (com.codename1.ui.Label)2 TextField (com.codename1.ui.TextField)2 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)2 Dimension (com.codename1.ui.geom.Dimension)2 BoxLayout (com.codename1.ui.layouts.BoxLayout)2 UITimer (com.codename1.ui.util.UITimer)2 java.awt (java.awt)2 AttributedString (java.text.AttributedString)2 Timer (java.util.Timer)2