Search in sources :

Example 1 with Bindable

use of com.codename1.rad.models.Bindable in project CodeRAD by shannah.

the class ComponentBinder method bindFocus.

public static void bindFocus(Bindable bindable, PropertySelector property, Component cmp) {
    cmp.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(Component cmp) {
            if (property.isFalsey()) {
                property.setBoolean(true);
            }
        }

        @Override
        public void focusLost(Component cmp) {
            if (!property.isFalsey()) {
                property.setBoolean(false);
            }
        }
    });
    ActionListener<PropertyChangeEvent> pcl = evt -> {
        boolean isFocused = !property.isFalsey();
        if (isFocused && !cmp.hasFocus()) {
            cmp.requestFocus();
        }
    };
    bindable.addBindListener(() -> {
        property.addPropertyChangeListener(pcl);
    });
    bindable.addUnbindListener(() -> {
        property.removePropertyChangeListener(pcl);
    });
}
Also used : FocusListener(com.codename1.ui.events.FocusListener) PropertyChangeEvent(com.codename1.rad.models.PropertyChangeEvent) Component(com.codename1.ui.Component) Bindable(com.codename1.rad.models.Bindable) ActionListener(com.codename1.ui.events.ActionListener) PropertySelector(com.codename1.rad.models.PropertySelector) PropertyChangeEvent(com.codename1.rad.models.PropertyChangeEvent) Component(com.codename1.ui.Component) FocusListener(com.codename1.ui.events.FocusListener)

Aggregations

Bindable (com.codename1.rad.models.Bindable)1 PropertyChangeEvent (com.codename1.rad.models.PropertyChangeEvent)1 PropertySelector (com.codename1.rad.models.PropertySelector)1 Component (com.codename1.ui.Component)1 ActionListener (com.codename1.ui.events.ActionListener)1 FocusListener (com.codename1.ui.events.FocusListener)1