Search in sources :

Example 36 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class FieldConfigWindBarbs method getValue.

/**
 * Gets the value.
 *
 * @param fieldConfigManager the field config manager
 * @param symbolType the symbol type
 * @param fillEnabled the fill enabled
 * @param strokeEnabled the stroke enabled
 * @return the value
 */
@Override
public List<GraphicalSymbol> getValue(GraphicPanelFieldManager fieldConfigManager, Expression symbolType, boolean fillEnabled, boolean strokeEnabled) {
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    Expression wellKnownName = null;
    if ((getConfigField() != null) && (fieldConfigManager != null)) {
        wellKnownName = getConfigField().getExpression();
        if (wellKnownName != null) {
            Expression expFillColour = null;
            Expression expFillColourOpacity = null;
            FieldConfigBase field = fieldConfigManager.get(FieldIdEnum.FILL_COLOUR);
            if (field != null) {
                FieldConfigColour colourField = (FieldConfigColour) field;
                expFillColour = colourField.getColourExpression();
            }
            Stroke stroke = null;
            Fill fill = getStyleFactory().createFill(expFillColour, expFillColourOpacity);
            Expression size = null;
            Expression rotation = null;
            Mark mark = getStyleFactory().createMark(wellKnownName, stroke, fill, size, rotation);
            symbolList.add(mark);
        }
    }
    return symbolList;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) Expression(org.opengis.filter.expression.Expression) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Mark(org.geotools.styling.Mark) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour)

Example 37 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class FieldConfigArrow method getValue.

/**
 * Gets the value.
 *
 * @param fieldConfigManager the field config manager
 * @param symbolType the symbol type
 * @param fillEnabled the fill enabled
 * @param strokeEnabled the stroke enabled
 * @return the value
 */
@Override
public List<GraphicalSymbol> getValue(GraphicPanelFieldManager fieldConfigManager, Expression symbolType, boolean fillEnabled, boolean strokeEnabled) {
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    if (fieldConfigManager != null) {
        Expression wellKnownName = null;
        if (getConfigField() != null) {
            wellKnownName = getConfigField().getExpression();
            if (wellKnownName != null) {
                // Stroke colour
                FieldConfigBase field = null;
                Stroke stroke = null;
                if (strokeEnabled && (strokeFieldConfig != null)) {
                    Expression expStrokeColour = null;
                    Expression expStrokeColourOpacity = null;
                    field = fieldConfigManager.get(strokeFieldConfig.getColour());
                    if (field != null) {
                        if (field instanceof FieldConfigColour) {
                            FieldConfigColour colourField = (FieldConfigColour) field;
                            expStrokeColour = colourField.getColourExpression();
                        }
                    }
                    field = fieldConfigManager.get(strokeFieldConfig.getOpacity());
                    if (field != null) {
                        expStrokeColourOpacity = field.getExpression();
                    }
                    stroke = getStyleFactory().createStroke(expStrokeColour, expStrokeColourOpacity);
                }
                // Fill colour
                Fill fill = null;
                if (fillEnabled && (fillFieldConfig != null)) {
                    Expression expFillColour = null;
                    Expression expFillColourOpacity = null;
                    field = fieldConfigManager.get(fillFieldConfig.getColour());
                    if (field != null) {
                        if (field instanceof FieldConfigColour) {
                            FieldConfigColour colourField = (FieldConfigColour) field;
                            expFillColour = colourField.getColourExpression();
                        }
                    }
                    field = fieldConfigManager.get(fillFieldConfig.getOpacity());
                    if (field != null) {
                        expFillColourOpacity = field.getExpression();
                    }
                    fill = getStyleFactory().createFill(expFillColour, expFillColourOpacity);
                }
                field = fieldConfigManager.get(FieldIdEnum.STROKE_WIDTH);
                if (field != null) {
                    Expression strokeWidth = field.getExpression();
                    stroke.setWidth(strokeWidth);
                }
                Expression symbolSize = null;
                field = fieldConfigManager.get(FieldIdEnum.STROKE_SYMBOL_SIZE);
                if (field != null) {
                    symbolSize = field.getExpression();
                }
                Expression rotation = null;
                Mark mark = getStyleFactory().createMark(wellKnownName, stroke, fill, symbolSize, rotation);
                symbolList.add(mark);
            }
        }
    }
    return symbolList;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) Expression(org.opengis.filter.expression.Expression) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Mark(org.geotools.styling.Mark) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour)

Example 38 with Fill

use of org.geotools.styling.Fill 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), 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));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", 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), 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.Test)

Example 39 with Fill

use of org.geotools.styling.Fill in project sldeditor by robward-scisys.

the class FieldConfigFilenameTest method testGetFill.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename#getFill(org.opengis.style.GraphicFill, com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
 */
@Test
public void testGetFill() {
    boolean valueOnly = true;
    FieldConfigFilename field = new FieldConfigFilename(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    GraphicFill graphicFill = null;
    GraphicPanelFieldManager fieldConfigManager = null;
    assertNull(field.getFill(graphicFill, fieldConfigManager));
    Class<?> panelId = PointFillDetails.class;
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(FieldIdEnum.UNKNOWN, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    symbolSelectionField.createUI();
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);
    field.createUI();
    StyleBuilder styleBuilder = new StyleBuilder();
    graphicFill = styleBuilder.createGraphic();
    Fill actualValue = field.getFill(graphicFill, fieldConfigManager);
    assertTrue(actualValue.getOpacity().toString().compareTo(String.valueOf(expectedOpacityValue)) == 0);
}
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) FieldConfigFilename(com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename) GraphicFill(org.opengis.style.GraphicFill) 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.Test)

Aggregations

Fill (org.geotools.styling.Fill)39 Expression (org.opengis.filter.expression.Expression)23 Stroke (org.geotools.styling.Stroke)18 GraphicFill (org.opengis.style.GraphicFill)17 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 Graphic (org.geotools.styling.Graphic)13 ArrayList (java.util.ArrayList)11 Mark (org.geotools.styling.Mark)11 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)10 JsonObject (com.google.gson.JsonObject)9 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)8 AnchorPoint (org.geotools.styling.AnchorPoint)7 Displacement (org.geotools.styling.Displacement)7 PointSymbolizer (org.geotools.styling.PointSymbolizer)6 Test (org.junit.Test)6 ExternalGraphic (org.geotools.styling.ExternalGraphic)5 JsonElement (com.google.gson.JsonElement)4 MarkImpl (org.geotools.styling.MarkImpl)4 Symbolizer (org.geotools.styling.Symbolizer)4