Search in sources :

Example 21 with Stroke

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

the class SymbolManager method getStrokeList.

/**
 * Gets the stroke.
 *
 * @param jsonElementSymbol the json element symbol
 * @return the stroke list
 */
public List<Stroke> getStrokeList(JsonElement jsonElementSymbol) {
    List<Stroke> strokeList = null;
    if (jsonElementSymbol != null) {
        JsonObject jsonSymbol = jsonElementSymbol.getAsJsonObject();
        for (String lineSymbolType : lineSymbolMap.keySet()) {
            JsonElement obj = jsonSymbol.get(lineSymbolType);
            if (obj != null) {
                EsriLineSymbolInterface esriLineSymbol = lineSymbolMap.get(lineSymbolType);
                strokeList = esriLineSymbol.convert(obj);
                break;
            }
        }
    }
    return strokeList;
}
Also used : Stroke(org.geotools.styling.Stroke) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 22 with Stroke

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

the class CartographicLineSymbol method convert.

/**
 * Convert.
 *
 * @param element the element
 * @return the list of strokes
 */
@SuppressWarnings("deprecation")
@Override
public List<Stroke> convert(JsonElement element) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Stroke> strokeList = new ArrayList<Stroke>();
    double width = getDouble(obj, CommonSymbolKeys.WIDTH);
    Stroke stroke = styleFactory.createStroke(getColour(obj.get(CommonSymbolKeys.COLOUR)), ff.literal(width));
    // Line dash pattern
    JsonElement templateElement = obj.get(CartographicLineSymbolKeys.TEMPLATE);
    if (templateElement != null) {
        JsonArray templateArray = templateElement.getAsJsonArray();
        List<Float> patternList = new ArrayList<Float>();
        for (int index = 0; index < templateArray.size(); index++) {
            JsonObject patternElement = templateArray.get(index).getAsJsonObject();
            float mark = 0.0f;
            JsonElement markElement = patternElement.get(CartographicLineSymbolKeys.MARK);
            if (markElement != null) {
                mark = markElement.getAsFloat();
            }
            patternList.add(mark);
            float gap = 0.0f;
            JsonElement gapElement = patternElement.get(CartographicLineSymbolKeys.GAP);
            if (gapElement != null) {
                gap = gapElement.getAsFloat();
            }
            patternList.add(gap);
        }
        float[] dashArray = new float[patternList.size()];
        int index = 0;
        for (Float value : patternList) {
            dashArray[index] = value;
            index++;
        }
        stroke.setDashArray(dashArray);
        // Start of line offset
        JsonElement lineStartOffsetElement = obj.get(CartographicLineSymbolKeys.LINE_START_OFFSET);
        if (lineStartOffsetElement != null) {
            stroke.setDashOffset(ff.literal(lineStartOffsetElement.getAsDouble()));
        }
    }
    strokeList.add(stroke);
    return strokeList;
}
Also used : JsonArray(com.google.gson.JsonArray) Stroke(org.geotools.styling.Stroke) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 23 with Stroke

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

the class StrokeTreeItemTest method testGetTreeString.

/**
 * Test method for {@link com.sldeditor.ui.tree.item.StrokeTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    StrokeTreeItem item = new StrokeTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.stroke");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Stroke stroke = DefaultSymbols.createDefaultStroke();
    actualValue = item.getTreeString(null, stroke);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    actualValue = item.getTreeString(null, stroke);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Also used : Stroke(org.geotools.styling.Stroke) StrokeTreeItem(com.sldeditor.ui.tree.item.StrokeTreeItem) Test(org.junit.Test)

Example 24 with Stroke

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

the class DefaultSymbols method createDefaultPointSymbolizer.

/**
 * Creates the default point symbolizer.
 *
 * @return the point symbolizer
 */
public static PointSymbolizer createDefaultPointSymbolizer() {
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);
    List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
    Stroke stroke = null;
    AnchorPoint anchorPoint = null;
    Displacement displacement = null;
    Fill fill = styleFactory.createFill(ff.literal(DEFAULT_MARKER_COLOUR));
    GraphicalSymbol symbol = styleFactory.mark(ff.literal(DEFAULT_MARKER_SYMBOL), fill, stroke);
    symbolList.add(symbol);
    Graphic graphic = styleFactory.graphic(symbolList, ff.literal(DEFAULT_COLOUR_OPACITY), ff.literal(DEFAULT_MARKER_SYMBOL_SIZE), ff.literal(0.0), anchorPoint, displacement);
    PointSymbolizer newPointSymbolizer = (PointSymbolizer) styleFactory.pointSymbolizer(Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker"), geometryField, null, null, graphic);
    return newPointSymbolizer;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Displacement(org.opengis.style.Displacement)

Example 25 with Stroke

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

the class StrokeDetails method populateStroke.

/**
 * Populate stroke.
 *
 * @param symbolizerType the symbolizer type
 * @param stroke the stroke
 */
private void populateStroke(Class<?> symbolizerType, Stroke stroke) {
    Expression expColour = null;
    Expression expStrokeColour = null;
    Expression expOpacity = null;
    Expression expStrokeWidth = null;
    Expression expStrokeOffset = null;
    Expression expStrokeLineCap = null;
    Expression expStrokeLineJoin = null;
    Expression expStrokeDashArray = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    Expression expSymbolSize = null;
    Expression expSymbolRotation = null;
    if (stroke == null) {
        expColour = getFilterFactory().literal("#000000");
        expOpacity = getFilterFactory().literal(1.0);
        symbolTypeFactory.setSolidFill(fieldConfigManager, expColour, expOpacity);
        expStrokeWidth = getFilterFactory().literal(1.0);
        expStrokeOffset = getFilterFactory().literal(0.0);
        expStrokeLineCap = getFilterFactory().literal("round");
        expStrokeLineJoin = getFilterFactory().literal("round");
        expStrokeDashArray = getFilterFactory().literal("");
    } else {
        Graphic graphicFill = stroke.getGraphicFill();
        Graphic graphicStroke = stroke.getGraphicStroke();
        if ((graphicFill == null) && (graphicStroke == null)) {
            expOpacity = stroke.getOpacity();
            symbolTypeFactory.setSolidFill(fieldConfigManager, stroke.getColor(), stroke.getOpacity());
        }
        expOpacity = stroke.getOpacity();
        expStrokeWidth = stroke.getWidth();
        expStrokeOffset = stroke.getDashOffset();
        expStrokeLineCap = stroke.getLineCap();
        expStrokeLineJoin = stroke.getLineJoin();
        expColour = stroke.getColor();
        List<Float> dashesArray = getStrokeDashArray(stroke);
        expStrokeDashArray = getFilterFactory().literal(createDashArrayString(dashesArray));
        if (graphicStroke != null) {
            // Anchor points
            AnchorPoint anchorPoint = graphicStroke.getAnchorPoint();
            if (anchorPoint != null) {
                expAnchorPointX = anchorPoint.getAnchorPointX();
                expAnchorPointY = anchorPoint.getAnchorPointY();
            } else {
                expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
                expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
            }
            // Displacement
            Displacement displacement = graphicStroke.getDisplacement();
            if (displacement != null) {
                expDisplacementX = displacement.getDisplacementX();
                expDisplacementY = displacement.getDisplacementY();
            } else {
                expDisplacementX = defaultDisplacement.getDisplacementX();
                expDisplacementY = defaultDisplacement.getDisplacementY();
            }
            expGap = graphicStroke.getGap();
            expInitialGap = graphicStroke.getInitialGap();
            expSymbolSize = graphicStroke.getSize();
            expSymbolRotation = graphicStroke.getRotation();
            List<GraphicalSymbol> graphicSymbolList = graphicStroke.graphicalSymbols();
            for (GraphicalSymbol graphicSymbol : graphicSymbolList) {
                if (graphicSymbol instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) graphicSymbol;
                    Mark defaultMark = getStyleFactory().getDefaultMark();
                    Fill markFill = mark.getFill();
                    if (markFill != null) {
                        expColour = markFill.getColor();
                    }
                    expStrokeColour = defaultMark.getStroke().getColor();
                    Stroke markStroke = mark.getStroke();
                    if (markStroke != null) {
                        expStrokeColour = markStroke.getColor();
                    }
                } else if (graphicSymbol instanceof ExternalGraphicImpl) {
                    @SuppressWarnings("unused") ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) graphicSymbol;
                }
                symbolTypeFactory.setValue(symbolizerType, this.fieldConfigManager, graphicStroke, graphicSymbol);
            }
        }
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_WIDTH, expStrokeWidth);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_OFFSET, expStrokeOffset);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_CAP, expStrokeLineCap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_JOIN, expStrokeLineJoin);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_DASH_ARRAY, expStrokeDashArray);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_GAP, expGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP, expInitialGap);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_SIZE, expSymbolSize);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANGLE, expSymbolRotation);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H, expAnchorPointX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V, expAnchorPointY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X, expDisplacementX);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y, expDisplacementY);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_FILL_COLOUR, expColour);
        fieldConfigVisitor.populateField(FieldIdEnum.STROKE_STROKE_COLOUR, expStrokeColour);
        if ((graphicFill == null) && (graphicStroke == null)) {
            GroupConfigInterface fillColourGroup = getGroup(GroupIdEnum.FILLCOLOUR);
            if (fillColourGroup != null) {
                fillColourGroup.enable(true);
            }
        }
    // 
    // GroupConfigInterface strokeColourGroup = getGroup(GroupIdEnum.STROKECOLOUR);
    // if (strokeColourGroup != null) {
    // strokeColourGroup.enable(strokeColourEnabled);
    // }
    }
}
Also used : Fill(org.geotools.styling.Fill) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) MarkImpl(org.geotools.styling.MarkImpl) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Aggregations

Stroke (org.geotools.styling.Stroke)36 Fill (org.geotools.styling.Fill)18 Expression (org.opengis.filter.expression.Expression)16 JsonObject (com.google.gson.JsonObject)13 GraphicalSymbol (org.opengis.style.GraphicalSymbol)13 LineSymbolizer (org.geotools.styling.LineSymbolizer)12 ArrayList (java.util.ArrayList)11 Graphic (org.geotools.styling.Graphic)10 Mark (org.geotools.styling.Mark)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)10 GraphicFill (org.opengis.style.GraphicFill)8 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)7 JsonElement (com.google.gson.JsonElement)6 Symbolizer (org.geotools.styling.Symbolizer)6 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)5 Displacement (org.geotools.styling.Displacement)5 ExternalGraphic (org.geotools.styling.ExternalGraphic)5 GraphicStroke (org.opengis.style.GraphicStroke)5 JsonArray (com.google.gson.JsonArray)4 AnchorPoint (org.geotools.styling.AnchorPoint)4