Search in sources :

Example 1 with IconRendererAttribute

use of com.codename1.rad.attributes.IconRendererAttribute in project CodeRAD by shannah.

the class MultiButtonEntityView method update.

@Override
public void update() {
    EntityType type = getEntity().getEntity().getEntityType();
    boolean changed = false;
    if (line1PropDirty) {
        line1PropDirty = false;
        line1Prop = line1Prop == null ? type.findProperty(line1, Thing.name) : line1Prop;
        if (line1Prop != null) {
            String text = type.getText(line1Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine1())) {
                setTextLine1(text);
                changed = true;
            }
        }
    }
    if (line2PropDirty) {
        line2PropDirty = false;
        line2Prop = line2Prop == null ? type.findProperty(line2, Thing.description) : line2Prop;
        if (line2Prop != null) {
            String text = type.getText(line2Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine2())) {
                setTextLine2(text);
                changed = true;
            }
        }
    }
    if (line3PropDirty) {
        line3PropDirty = false;
        line3Prop = line3Prop == null ? type.findProperty(line3) : line3Prop;
        if (line3Prop != null) {
            String text = type.getText(line3Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine3())) {
                setTextLine3(text);
                changed = true;
            }
        }
    }
    if (line4PropDirty) {
        line4PropDirty = false;
        line4Prop = line4Prop == null ? type.findProperty(line4) : line4Prop;
        if (line4Prop != null) {
            String text = type.getText(line4Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine4())) {
                setTextLine4(text);
                changed = true;
            }
        }
    }
    if (iconDirty) {
        iconDirty = false;
        Property iconProp = this.iconProp != null ? this.iconProp : type.findProperty(icon);
        this.iconProp = iconProp;
        if (iconProp != null) {
            Object iconData = iconProp.getValue(getEntity().getEntity());
            if (iconData != null) {
                IconRendererAttribute iconRendererAtt = (IconRendererAttribute) viewNode.findInheritedAttribute(IconRendererAttribute.class);
                EntityImageRenderer iconRenderer = iconRendererAtt == null ? new DefaultEntityImageRenderer() : iconRendererAtt.getValue();
                iconRenderer.createImage(this, iconProp, 0, false, false).ready(im -> {
                    setIcon(im);
                    revalidateLater();
                });
            }
        }
    }
    if (changed) {
        revalidateLater();
    }
}
Also used : EntityType(com.codename1.rad.models.EntityType) EntityImageRenderer(com.codename1.rad.ui.image.EntityImageRenderer) DefaultEntityImageRenderer(com.codename1.rad.ui.image.DefaultEntityImageRenderer) IconRendererAttribute(com.codename1.rad.attributes.IconRendererAttribute) ViewProperty(com.codename1.rad.ui.ViewProperty) Property(com.codename1.rad.models.Property) DefaultEntityImageRenderer(com.codename1.rad.ui.image.DefaultEntityImageRenderer)

Aggregations

IconRendererAttribute (com.codename1.rad.attributes.IconRendererAttribute)1 EntityType (com.codename1.rad.models.EntityType)1 Property (com.codename1.rad.models.Property)1 ViewProperty (com.codename1.rad.ui.ViewProperty)1 DefaultEntityImageRenderer (com.codename1.rad.ui.image.DefaultEntityImageRenderer)1 EntityImageRenderer (com.codename1.rad.ui.image.EntityImageRenderer)1