Search in sources :

Example 1 with Mark

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

the class FieldConfigWindBarbsTest method testGetValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#getValue(com.sldeditor.ui.detail.GraphicPanelFieldManager, org.opengis.filter.expression.Expression, boolean, boolean)}.
 */
@Test
public void testGetValue() {
    // Test it with null values
    boolean valueOnly = true;
    FieldConfigWindBarbs field = new FieldConfigWindBarbs(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    field.createUI();
    assertNull(field.getStringValue());
    GraphicPanelFieldManager fieldConfigManager = null;
    Expression symbolType = null;
    List<GraphicalSymbol> actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
    assertTrue(actualValue.isEmpty());
    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    String actualMarkerSymbol = "solid";
    StyleBuilder styleBuilder = new StyleBuilder();
    symbolType = styleBuilder.literalExpression(actualMarkerSymbol);
    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);
    // Try without setting any fields
    actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
    assertNotNull(actualValue);
    assertEquals(1, actualValue.size());
    Mark actualSymbol = (Mark) actualValue.get(0);
    assertTrue(actualSymbol.getWellKnownName().toString().compareTo("windbarbs://default(0)[m/s]") == 0);
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) GraphicalSymbol(org.opengis.style.GraphicalSymbol) StyleBuilder(org.geotools.styling.StyleBuilder) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) Mark(org.geotools.styling.Mark) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigWindBarbs(com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs) 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 2 with Mark

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

the class CharacterMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the marker graphic
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markerList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT);
    if (fontElement != null) {
        JsonObject fontObj = fontElement.getAsJsonObject();
        String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
        int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX);
        Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code));
        // Create colour
        Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR));
        Fill fill = styleFactory.createFill(colour);
        Stroke stroke = null;
        Mark mark = styleFactory.mark(wellKnownName, fill, stroke);
        ExternalGraphic[] externalGraphics = null;
        Mark[] marks = new Mark[1];
        marks[0] = mark;
        Symbol[] symbols = null;
        Expression opacity = null;
        Expression rotation = ff.literal(angle);
        Expression size = ff.literal(symbolSize);
        Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation);
        // Displacement (offsets)
        if ((xOffset > 0.0) && (yOffset > 0.0)) {
            Expression expressionX = ff.literal(xOffset);
            Expression expressionY = ff.literal(yOffset);
            Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY);
            graphic.setDisplacement(displacement);
        }
        markerList.add(graphic);
    }
    return markerList;
}
Also used : Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression) JsonElement(com.google.gson.JsonElement)

Example 3 with Mark

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

the class SimpleMarkerSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the graphic marker list
 */
@Override
public List<Graphic> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Graphic> markList = new ArrayList<Graphic>();
    double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
    double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE);
    double size = getDouble(obj, CommonSymbolKeys.SIZE);
    int style = getInt(obj, CommonSymbolKeys.STYLE);
    double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
    double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
    Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
    Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR));
    Expression wellKnownName = ff.literal(styleMap.get(style));
    Stroke stroke = null;
    if (outlineSize > 0.0) {
        stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize));
    }
    Fill fill = styleFactory.createFill(markerColour);
    Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle));
    Expression expressionOpacity = null;
    ExternalGraphic[] externalGraphics = null;
    Symbol[] symbols = null;
    Mark[] marks = new Mark[1];
    marks[0] = mark;
    Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle));
    // Set offset
    if ((xOffset > 0.0) && (yOffset > 0.0)) {
        Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
        graphic.setDisplacement(displacement);
    }
    markList.add(graphic);
    return markList;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) Symbol(org.geotools.styling.Symbol) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Mark(org.geotools.styling.Mark) ExternalGraphic(org.geotools.styling.ExternalGraphic) Displacement(org.geotools.styling.Displacement) Expression(org.opengis.filter.expression.Expression)

Example 4 with Mark

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

the class FieldConfigWKT 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 stroke = null;
                Fill fill = null;
                // Stroke colour
                FieldConfigBase field = null;
                if (strokeEnabled) {
                    Expression expStrokeColour = null;
                    Expression expStrokeColourOpacity = null;
                    field = fieldConfigManager.get(this.strokeFieldConfig.getColour());
                    if (field != null) {
                        if (field instanceof FieldConfigColour) {
                            FieldConfigColour colourField = (FieldConfigColour) field;
                            expStrokeColour = colourField.getColourExpression();
                        }
                    }
                    // Stroke width
                    Expression strokeWidth = null;
                    field = fieldConfigManager.get(this.strokeFieldConfig.getWidth());
                    if (field != null) {
                        strokeWidth = field.getExpression();
                    }
                    // Opacity
                    field = fieldConfigManager.get(this.strokeFieldConfig.getOpacity());
                    if (field != null) {
                        expStrokeColourOpacity = field.getExpression();
                    }
                    stroke = getStyleFactory().createStroke(expStrokeColour, strokeWidth, expStrokeColourOpacity);
                }
                // Fill colour
                if (fillEnabled) {
                    Expression expFillColour = null;
                    Expression expFillColourOpacity = null;
                    field = fieldConfigManager.get(this.fillFieldConfig.getColour());
                    if (field != null) {
                        if (field instanceof FieldConfigColour) {
                            FieldConfigColour colourField = (FieldConfigColour) field;
                            expFillColour = colourField.getColourExpression();
                        }
                    }
                    // Opacity
                    field = fieldConfigManager.get(this.fillFieldConfig.getOpacity());
                    if (field != null) {
                        expFillColourOpacity = field.getExpression();
                    }
                    fill = getStyleFactory().createFill(expFillColour, expFillColourOpacity);
                }
                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 5 with Mark

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

the class FieldConfigWKT method setValue.

/**
 * Sets the value.
 *
 * @param symbolizerType the symbolizer type
 * @param fieldConfigManager the field config manager
 * @param multiOptionPanel the multi option panel
 * @param graphic the graphic
 * @param symbol the symbol
 */
@Override
public void setValue(Class<?> symbolizerType, GraphicPanelFieldManager fieldConfigManager, FieldConfigSymbolType multiOptionPanel, Graphic graphic, GraphicalSymbol symbol) {
    if ((symbol != null) && (fieldConfigManager != null)) {
        if (symbol instanceof Mark) {
            MarkImpl markerSymbol = (MarkImpl) symbol;
            // Fill
            FillImpl fill = markerSymbol.getFill();
            if (fill != null) {
                populateColour(fieldConfigManager, fillFieldConfig, fill.getColor(), fill.getOpacity());
            }
            GroupConfigInterface fillGroup = fieldConfigManager.getGroup(fieldConfigManager.getComponentId(), fillFieldConfig.getGroup());
            if (fillGroup != null) {
                fillGroup.enable(fill != null);
            }
            // Stroke
            StrokeImpl stroke = markerSymbol.getStroke();
            if (stroke != null) {
                populateColour(fieldConfigManager, strokeFieldConfig, stroke.getColor(), stroke.getOpacity());
            }
            GroupConfigInterface strokeGroup = fieldConfigManager.getGroup(fieldConfigManager.getComponentId(), strokeFieldConfig.getGroup());
            if (strokeGroup != null) {
                strokeGroup.enable(stroke != null);
            }
            if (wktPanel != null) {
                wktPanel.populateExpression(markerSymbol.getWellKnownName().toString());
            }
            if (multiOptionPanel != null) {
                multiOptionPanel.setSelectedItem(WKT_SYMBOL_KEY);
            }
        }
    }
}
Also used : FillImpl(org.geotools.styling.FillImpl) Mark(org.geotools.styling.Mark) MarkImpl(org.geotools.styling.MarkImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) StrokeImpl(org.geotools.styling.StrokeImpl)

Aggregations

Mark (org.geotools.styling.Mark)34 Test (org.junit.Test)17 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)16 StyleBuilder (org.geotools.styling.StyleBuilder)16 Expression (org.opengis.filter.expression.Expression)16 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)14 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)13 Fill (org.geotools.styling.Fill)11 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)10 ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)10 Stroke (org.geotools.styling.Stroke)10 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)9 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)8 ArrayList (java.util.ArrayList)8 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)7 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)7 Graphic (org.geotools.styling.Graphic)7 GraphicFill (org.opengis.style.GraphicFill)7 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)6