Search in sources :

Example 1 with PropertyChangeEvent

use of com.codename1.rad.models.PropertyChangeEvent 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)

Example 2 with PropertyChangeEvent

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

the class PropertySelector method addPropertyChangeListener.

/**
 * Adds a change listener on property.
 * @param l The listener to add.
 */
public void addPropertyChangeListener(ActionListener<PropertyChangeEvent> l) {
    if (root != null) {
        Property prop = property;
        if (prop == null && tags != null) {
            prop = root.getEntity().findProperty(tags);
        }
        if (prop != null) {
            root.getEntity().addPropertyChangeListener(prop, pcl());
        }
    } else {
        Entity leafEntity = getLeafEntity();
        Property leafProperty = getLeafProperty();
        if (leafEntity != null && leafProperty != null) {
            leafEntity.getEntity().addPropertyChangeListener(leafProperty, pcl());
        }
        parent.addVetoablePropertyChangeListener(vpcl());
        parent.addListChangeListener(listChangeListener());
    }
    if (listeners == null) {
        listeners = new EventDispatcher();
    }
    listeners.addListener(l);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

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 EventDispatcher (com.codename1.ui.util.EventDispatcher)1