Search in sources :

Example 26 with Fill

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

the class DefaultSymbols method createDefaultTextSymbolizer.

/**
 * Creates the default text symbolizer.
 *
 * @return the text symbolizer
 */
public static TextSymbolizer createDefaultTextSymbolizer() {
    Expression fontFamily = ff.literal("Serif");
    Expression fontSize = ff.literal(10.0);
    Expression fontStyle = ff.literal("normal");
    Expression fontWeight = ff.literal("normal");
    Expression rotation = ff.literal(0.0);
    Expression label = ff.literal("Test");
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);
    String name = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
    AnchorPoint anchor = null;
    Displacement displacement = null;
    PointPlacement pointPlacement = (PointPlacement) styleFactory.pointPlacement(anchor, displacement, rotation);
    Expression fillColour = ff.literal(DEFAULT_COLOUR);
    Expression fillColourOpacity = ff.literal(1.0);
    Fill fill = styleFactory.fill(null, fillColour, fillColourOpacity);
    Halo halo = null;
    List<Expression> fontFamilyList = new ArrayList<Expression>();
    fontFamilyList.add(fontFamily);
    Font font = (Font) styleFactory.font(fontFamilyList, fontStyle, fontWeight, fontSize);
    Description description = null;
    Unit<Length> unit = null;
    TextSymbolizer newTextSymbolizer = (TextSymbolizer) styleFactory.textSymbolizer(name, geometryField, description, unit, label, font, pointPlacement, halo, fill);
    return newTextSymbolizer;
}
Also used : PointPlacement(org.geotools.styling.PointPlacement) Fill(org.geotools.styling.Fill) Description(org.geotools.styling.Description) ArrayList(java.util.ArrayList) Displacement(org.opengis.style.Displacement) Font(org.geotools.styling.Font) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Length(javax.measure.quantity.Length) TextSymbolizer(org.geotools.styling.TextSymbolizer) Halo(org.geotools.styling.Halo)

Example 27 with Fill

use of org.geotools.styling.Fill 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 28 with Fill

use of org.geotools.styling.Fill 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)

Example 29 with Fill

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

the class FieldConfigMarker 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) {
    if ((symbolType == null) || (fieldConfigManager == null)) {
        return null;
    }
    Expression symbolTypeExpression = null;
    String symbolTypeName = symbolType.toString();
    if (symbolTypeName.compareTo(SOLID_SYMBOL_KEY) != 0) {
        symbolTypeExpression = symbolType;
    }
    Fill fill = null;
    Stroke stroke = null;
    if (symbolTypeName.startsWith(GEOSERVER_MARKER_PREFIX)) {
        Expression strokeColour = null;
        FieldConfigBase field = fieldConfigManager.get(fillFieldConfig.getColour());
        if (field != null) {
            strokeColour = ((FieldConfigColour) field).getColourExpression();
        }
        Expression strokeColourOpacity = null;
        field = fieldConfigManager.get(fillFieldConfig.getOpacity());
        if (field != null) {
            strokeColourOpacity = field.getExpression();
        }
        Expression strokeWidth = null;
        field = fieldConfigManager.get(fillFieldConfig.getWidth());
        if (field != null) {
            strokeWidth = field.getExpression();
        }
        stroke = getStyleFactory().createStroke(strokeColour, strokeWidth, strokeColourOpacity);
    } else {
        Expression fillColour = null;
        FieldConfigBase field = fieldConfigManager.get(fillFieldConfig.getColour());
        if (field != null) {
            fillColour = ((FieldConfigColour) field).getColourExpression();
        }
        Expression fillColourOpacity = null;
        field = fieldConfigManager.get(fillFieldConfig.getOpacity());
        if (field != null) {
            fillColourOpacity = field.getExpression();
        }
        if (fillEnabled) {
            fill = getStyleFactory().fill(null, fillColour, fillColourOpacity);
        }
        if (strokeEnabled) {
            Expression strokeColour = null;
            field = fieldConfigManager.get(strokeFieldConfig.getColour());
            if (field != null) {
                strokeColour = ((FieldConfigColour) field).getColourExpression();
            }
            Expression strokeColourOpacity = null;
            field = fieldConfigManager.get(strokeFieldConfig.getOpacity());
            if (field != null) {
                strokeColourOpacity = field.getExpression();
            }
            Expression strokeWidth = null;
            field = fieldConfigManager.get(strokeFieldConfig.getWidth());
            if (field != null) {
                strokeWidth = field.getExpression();
            }
            stroke = getStyleFactory().createStroke(strokeColour, strokeWidth, strokeColourOpacity);
        }
    }
    Mark markerSymbol = getStyleFactory().mark(symbolTypeExpression, fill, stroke);
    return SelectedSymbol.getInstance().getSymbolList(markerSymbol);
}
Also used : Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) Stroke(org.geotools.styling.Stroke) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) Expression(org.opengis.filter.expression.Expression) Mark(org.geotools.styling.Mark)

Example 30 with Fill

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

the class FieldConfigMarker 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)) {
        MarkImpl markerSymbol = (MarkImpl) symbol;
        Expression wellKnownNameExpression = markerSymbol.getWellKnownName();
        if (wellKnownNameExpression instanceof LiteralExpressionImpl) {
            LiteralExpressionImpl literal = (LiteralExpressionImpl) wellKnownNameExpression;
            FieldConfigBase field = fieldConfigManager.get(symbolSelectionField);
            if (field != null) {
                field.populate(literal);
            }
            Expression expFillColour = null;
            Expression expFillOpacity = null;
            Expression expStrokeColour = null;
            Expression expStrokeOpacity = null;
            Expression expStrokeWidth = null;
            // Which opacity attribute do we use?
            if (symbol instanceof MarkImpl) {
                MarkImpl markSymbol = (MarkImpl) symbol;
                Fill fill = markSymbol.getFill();
                if (fill != null) {
                    expFillColour = fill.getColor();
                    if (!isOverallOpacity(symbolizerType)) {
                        expFillOpacity = fill.getOpacity();
                    }
                }
                Stroke stroke = markSymbol.getStroke();
                if (stroke != null) {
                    expStrokeColour = stroke.getColor();
                    if (!isOverallOpacity(symbolizerType)) {
                        expStrokeOpacity = stroke.getOpacity();
                    }
                    expStrokeWidth = stroke.getWidth();
                }
            }
            if (isOverallOpacity(symbolizerType)) {
                FieldConfigBase opacity = fieldConfigManager.get(FieldIdEnum.OVERALL_OPACITY);
                if (opacity != null) {
                    opacity.populate(graphic.getOpacity());
                }
            }
            FieldConfigBase opacity = fieldConfigManager.get(fillFieldConfig.getOpacity());
            if (opacity != null) {
                opacity.populate(expFillOpacity);
            }
            opacity = fieldConfigManager.get(strokeFieldConfig.getOpacity());
            if (opacity != null) {
                opacity.populate(expStrokeOpacity);
            }
            Class<?> panelId = getCommonData().getPanelId();
            GroupConfigInterface fillGroup = fieldConfigManager.getGroup(panelId, fillFieldConfig.getGroup());
            GroupConfigInterface strokeGroup = fieldConfigManager.getGroup(panelId, strokeFieldConfig.getGroup());
            if ((fillGroup == null) || (strokeGroup == null)) {
                return;
            }
            if (literal.toString().startsWith(GEOSERVER_MARKER_PREFIX)) {
                fillGroup.enable(expStrokeColour != null);
                FieldConfigBase fillColour = fieldConfigManager.get(fillFieldConfig.getColour());
                if (fillColour != null) {
                    fillColour.populate(expStrokeColour);
                }
                opacity = fieldConfigManager.get(fillFieldConfig.getOpacity());
                if (opacity != null) {
                    opacity.populate(expStrokeOpacity);
                }
                strokeGroup.enable(false);
            } else {
                fillGroup.enable(expFillColour != null);
                FieldConfigBase fillColour = fieldConfigManager.get(fillFieldConfig.getColour());
                if (fillColour != null) {
                    fillColour.populate(expFillColour);
                }
                strokeGroup.enable(expStrokeColour != null);
                FieldConfigBase strokeColour = fieldConfigManager.get(strokeFieldConfig.getColour());
                if (strokeColour != null) {
                    strokeColour.populate(expStrokeColour);
                }
                FieldConfigBase strokeWidth = fieldConfigManager.get(FieldIdEnum.STROKE_FILL_WIDTH);
                if (strokeWidth != null) {
                    strokeWidth.populate(expStrokeWidth);
                }
            }
        }
    }
}
Also used : Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) Stroke(org.geotools.styling.Stroke) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) Expression(org.opengis.filter.expression.Expression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) MarkImpl(org.geotools.styling.MarkImpl) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

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