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);
});
}
Aggregations