Search in sources :

Example 1 with StylePropertyValue

use of org.polymap.core.style.model.StylePropertyValue in project polymap4-core by Polymap4.

the class StylePropertyEditor method canHandleCurrentValue.

/**
 * Checks if the <b>actual</b> type of the {@link #prop} is compatible with the
 * type parameter of this editor.
 */
public boolean canHandleCurrentValue() {
    Type targetType = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    Class<? extends StylePropertyValue> targetClass = null;
    if (targetType instanceof Class) {
        targetClass = (Class<? extends StylePropertyValue>) targetType;
    } else if (targetType instanceof ParameterizedType) {
        targetClass = (Class<? extends StylePropertyValue>) ((ParameterizedType) targetType).getRawType();
    } else {
        throw new RuntimeException("Target type is not a Class: " + targetType);
    }
    StylePropertyValue current = prop.get();
    if (current != null) {
        if (current.lastEditorHint.get() != null) {
            return current.lastEditorHint.get().equals(hint());
        }
        return targetClass.isAssignableFrom(current.getClass());
    }
    return false;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) FeatureType(org.opengis.feature.type.FeatureType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) StylePropertyValue(org.polymap.core.style.model.StylePropertyValue)

Example 2 with StylePropertyValue

use of org.polymap.core.style.model.StylePropertyValue in project polymap4-core by Polymap4.

the class StyleCompositeSerializer method handle.

protected <V> Iterable<RuleModifier<V, S>> handle(Property<StylePropertyValue<V>> prop) {
    StylePropertyValue<V> styleProp = prop.get();
    // no value -> nothing to modify
    if (styleProp == null || styleProp instanceof NoValue) {
        return singletonList(new NoValueRuleModifier());
    } else // ConstantValue
    if (styleProp instanceof ConstantValue) {
        Expression expr = ff.literal(((ConstantValue) styleProp).value());
        return singletonList(new SimpleRuleModifier(expr));
    } else // AttributeValue
    if (styleProp instanceof AttributeValue) {
        String attributeName = (String) ((AttributeValue) styleProp).attributeName.get();
        Expression expr = ff.property(attributeName);
        return singletonList(new SimpleRuleModifier(expr));
    } else // FilterMappedValues
    if (styleProp instanceof FilterMappedValues) {
        List<Mapped<Filter, Object>> values = ((FilterMappedValues) styleProp).values();
        return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key()));
    } else // ScaleMappedValues
    if (styleProp instanceof ScaleMappedValues) {
        List<Mapped<ScaleRange, Object>> values = ((ScaleMappedValues) styleProp).values();
        return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key().min.get(), mapped.key().max.get()));
    } else {
        throw new RuntimeException("Unhandled StylePropertyValue type: " + styleProp.getClass().getSimpleName());
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) Configurable(org.polymap.core.runtime.config.Configurable) StylePropertyValue(org.polymap.core.style.model.StylePropertyValue) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) Mandatory(org.polymap.core.runtime.config.Mandatory) StyleComposite(org.polymap.core.style.model.StyleComposite) Function(java.util.function.Function) StyleFactory(org.geotools.styling.StyleFactory) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Style(org.polymap.core.style.model.Style) ScaleMappedValues(org.polymap.core.style.model.feature.ScaleMappedValues) Config2(org.polymap.core.runtime.config.Config2) FluentIterable(com.google.common.collect.FluentIterable) FilterFactory2(org.opengis.filter.FilterFactory2) ConstantValue(org.polymap.core.style.model.feature.ConstantValue) FilterMappedValues(org.polymap.core.style.model.feature.FilterMappedValues) ScaleRange(org.polymap.core.style.model.feature.ScaleMappedValues.ScaleRange) Symbolizer(org.geotools.styling.Symbolizer) Cloner(com.rits.cloning.Cloner) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Property(org.polymap.model2.Property) Expression(org.opengis.filter.expression.Expression) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) List(java.util.List) NoValue(org.polymap.core.style.model.feature.NoValue) Rule(org.geotools.styling.Rule) AttributeValue(org.polymap.core.style.model.feature.AttributeValue) Filter(org.opengis.filter.Filter) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) FilterStyleProperty(org.polymap.core.style.model.feature.FilterStyleProperty) AttributeValue(org.polymap.core.style.model.feature.AttributeValue) Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) ScaleMappedValues(org.polymap.core.style.model.feature.ScaleMappedValues) NoValue(org.polymap.core.style.model.feature.NoValue) Expression(org.opengis.filter.expression.Expression) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Filter(org.opengis.filter.Filter) FilterMappedValues(org.polymap.core.style.model.feature.FilterMappedValues) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ConstantValue(org.polymap.core.style.model.feature.ConstantValue)

Example 3 with StylePropertyValue

use of org.polymap.core.style.model.StylePropertyValue in project polymap4-core by Polymap4.

the class StylePropertyEditor method updatePropertyWithHint.

/**
 * Updates the property and sets also the hint for the current editor.
 */
public void updatePropertyWithHint() {
    updateProperty();
    StylePropertyValue current = prop.get();
    if (current != null) {
        current.lastEditorHint.set(hint());
    }
}
Also used : StylePropertyValue(org.polymap.core.style.model.StylePropertyValue)

Aggregations

StylePropertyValue (org.polymap.core.style.model.StylePropertyValue)3 FluentIterable (com.google.common.collect.FluentIterable)1 Cloner (com.rits.cloning.Cloner)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Function (java.util.function.Function)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)1 Rule (org.geotools.styling.Rule)1 StyleFactory (org.geotools.styling.StyleFactory)1 Symbolizer (org.geotools.styling.Symbolizer)1 FeatureType (org.opengis.feature.type.FeatureType)1 Filter (org.opengis.filter.Filter)1 FilterFactory2 (org.opengis.filter.FilterFactory2)1 Expression (org.opengis.filter.expression.Expression)1 Config2 (org.polymap.core.runtime.config.Config2)1