Search in sources :

Example 56 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.

the class DataSourceAttributePanel method setAttribute.

/**
 * Sets the attribute.
 *
 * @param expression the new attribute
 */
public void setAttribute(Expression expression) {
    String propertyName = null;
    if (expression instanceof PropertyExistsFunction) {
        Expression e = ((PropertyExistsFunction) expression).getParameters().get(0);
        Object value = ((LiteralExpressionImpl) e).getValue();
        propertyName = ((AttributeExpressionImpl) value).getPropertyName();
    } else if (expression instanceof AttributeExpressionImpl) {
        propertyName = ((AttributeExpressionImpl) expression).getPropertyName();
    } else if (expression instanceof LiteralExpressionImpl) {
        propertyName = AttributeUtils.extract((String) ((LiteralExpressionImpl) expression).getValue());
    }
    if (propertyName != null) {
        oldValueObj = propertyName;
        attributeComboBox.setSelectedItem(propertyName);
    } else {
        oldValueObj = propertyName;
        attributeComboBox.setSelectedIndex(-1);
    }
}
Also used : PropertyExistsFunction(org.geotools.filter.function.PropertyExistsFunction) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Example 57 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.

the class FieldConfigMarkerTest method testGetFill.

/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#getFill(org.opengis.style.GraphicFill,
 * com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
 */
@Test
public void testGetFill() {
    // Test it with null values
    boolean valueOnly = true;
    ColourFieldConfig fillConfig = new ColourFieldConfig(GroupIdEnum.FILL, FieldIdEnum.FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_WIDTH);
    ColourFieldConfig strokeConfig = new ColourFieldConfig(GroupIdEnum.STROKE, FieldIdEnum.STROKE_STROKE_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
    FieldConfigMarker field = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly, false), fillConfig, strokeConfig, null);
    assertNull(field.getStringValue());
    GraphicFill graphicFill = null;
    GraphicPanelFieldManager fieldConfigManager = null;
    Fill actualValue = field.getFill(graphicFill, fieldConfigManager);
    assertNull(actualValue);
    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    actualValue = field.getFill(graphicFill, fieldConfigManager);
    assertNotNull(actualValue);
    assertNull(actualValue.getColor());
    assertNull(actualValue.getGraphicFill());
    assertNull(actualValue.getOpacity());
    // Test it with non null values
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    symbolSelectionField.createUI();
    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);
    FieldConfigMarker field2 = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly, false), fillConfig, strokeConfig, symbolSelectionFieldId);
    actualValue = field2.getFill(graphicFill, fieldConfigManager);
    assertNotNull(actualValue);
    LiteralExpressionImpl literalExpressionImpl = (LiteralExpressionImpl) actualValue.getColor();
    String actualColourString = literalExpressionImpl.toString();
    assertTrue(actualColourString.compareTo(expectedColourValue) == 0);
    StyleBuilder styleBuilder = new StyleBuilder();
    graphicFill = styleBuilder.createGraphic();
    actualValue = field2.getFill(graphicFill, fieldConfigManager);
    assertNull(actualValue.getColor());
    assertNull(actualValue.getOpacity());
}
Also used : Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) StyleBuilder(org.geotools.styling.StyleBuilder) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) FieldConfigMarker(com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker) GraphicFill(org.opengis.style.GraphicFill) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) ColourFieldConfig(com.sldeditor.ui.detail.ColourFieldConfig) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) PointFillDetails(com.sldeditor.ui.detail.PointFillDetails) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FieldConfigSymbolType(com.sldeditor.ui.detail.config.FieldConfigSymbolType) Test(org.junit.jupiter.api.Test)

Example 58 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.

the class FieldConfigColourTest method testGenerateExpression.

/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigColour#generateExpression()}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#populateExpression(java.lang.Object,
 * org.opengis.filter.expression.Expression)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigColour#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigColour#getColourExpression()}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourOpacityExpression()}. Test
 * method for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigColour extends FieldConfigColour {

        public TestFieldConfigColour(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigColour field = new TestFieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly, false));
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateExpression(null);
    assertNull(field.getColourExpression());
    assertNull(field.getColourOpacityExpression());
    // Try string values - erroneous
    field.createUI();
    field.populateExpression("");
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo("#000000") == 0);
    String colour1 = "#123456";
    field.populateExpression(colour1);
    actualValue = field.getStringValue();
    assertTrue(colour1.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour1) == 0);
    String colour2 = "#AABBCC";
    field.setTestValue(FieldIdEnum.UNKNOWN, colour2);
    actualValue = field.getStringValue();
    assertTrue(colour2.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour2) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    LiteralExpressionImpl literal = (LiteralExpressionImpl) actualExpression;
    double opacity = (Double) literal.getValue();
    double expectedOpacity = 1.0;
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.0001);
    // Try using FieldConfigBase.populate(colour expression, opacity)
    String colour3 = "#001122";
    expectedOpacity = DefaultSymbols.defaultColourOpacity();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    field.populate(ff.literal(colour3));
    actualValue = field.getStringValue();
    assertTrue(colour3.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour3) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    literal = (LiteralExpressionImpl) actualExpression;
    opacity = (Double) literal.getValue();
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.1);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl("colour");
    field.populate(attributeExpression);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof AttributeExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.jupiter.api.Test)

Aggregations

LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)58 Expression (org.opengis.filter.expression.Expression)33 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)20 AttributeType (ddf.catalog.data.AttributeType)7 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)7 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)6 MarkImpl (org.geotools.styling.MarkImpl)6 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 ConstantExpression (org.geotools.filter.ConstantExpression)4 IsEqualsToImpl (org.geotools.filter.IsEqualsToImpl)4 Literal (org.opengis.filter.expression.Literal)4 XMLFieldLiteralString (com.sldeditor.common.xml.ui.XMLFieldLiteralString)3 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)3 Color (java.awt.Color)3 Geometry (org.locationtech.jts.geom.Geometry)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2