Search in sources :

Example 26 with Stroke

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

the class StrokeDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    Stroke stroke = null;
    if (selectedSymbol != null) {
        symbolizer = selectedSymbol.getSymbolizer();
        if (symbolizer instanceof PointSymbolizer) {
            PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
            Graphic graphic = pointSymbolizer.getGraphic();
            List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols();
            if (graphicalSymbols.size() > 0) {
                GraphicalSymbol symbol = graphicalSymbols.get(0);
                if (symbol instanceof MarkImpl) {
                    MarkImpl markerSymbol = (MarkImpl) symbol;
                    stroke = markerSymbol.getStroke();
                }
            }
        } else if (symbolizer instanceof LineSymbolizer) {
            LineSymbolizer lineSymbol = (LineSymbolizer) symbolizer;
            stroke = lineSymbol.getStroke();
        } else if (symbolizer instanceof PolygonSymbolizer) {
            PolygonSymbolizer polygonSymbol = (PolygonSymbolizer) symbolizer;
            stroke = polygonSymbol.getStroke();
        }
    }
    Class<?> symbolizerClass = null;
    if (symbolizer != null) {
        symbolizerClass = symbolizer.getClass();
    }
    populateStroke(symbolizerClass, stroke);
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) LineSymbolizer(org.geotools.styling.LineSymbolizer) MarkImpl(org.geotools.styling.MarkImpl)

Example 27 with Stroke

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

the class StrokeDetails method updateSymbol.

/**
 * Update symbol.
 */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        Stroke stroke = getStroke();
        if (symbolizer instanceof PointSymbolizer) {
            PointSymbolizer pointSymbol = (PointSymbolizer) symbolizer;
            Graphic graphic = pointSymbol.getGraphic();
            GraphicalSymbol symbol = graphic.graphicalSymbols().get(0);
            if (symbol instanceof MarkImpl) {
                MarkImpl markerSymbol = (MarkImpl) symbol;
                markerSymbol.setStroke(stroke);
                SelectedSymbol.getInstance().replaceSymbolizer(pointSymbol);
                this.fireUpdateSymbol();
            }
        } else if (symbolizer instanceof LineSymbolizer) {
            LineSymbolizer lineSymbol = (LineSymbolizer) symbolizer;
            lineSymbol.setStroke(stroke);
            SelectedSymbol.getInstance().replaceSymbolizer(lineSymbol);
            this.fireUpdateSymbol();
        } else if (symbolizer instanceof PolygonSymbolizer) {
            PolygonSymbolizer polygonSymbol = (PolygonSymbolizer) symbolizer;
            polygonSymbol.setStroke(stroke);
            SelectedSymbol.getInstance().replaceSymbolizer(polygonSymbol);
            this.fireUpdateSymbol();
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) LineSymbolizer(org.geotools.styling.LineSymbolizer) MarkImpl(org.geotools.styling.MarkImpl)

Example 28 with Stroke

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

the class StrokeDetails method getStroke.

/**
 * Gets the stroke.
 *
 * @return the stroke
 */
public Stroke getStroke() {
    Expression join = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_LINE_JOIN);
    Expression lineCap = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_LINE_CAP);
    Expression offset = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_OFFSET);
    Expression strokeWidth = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_WIDTH);
    ValueComboBoxData symbolTypeValue = fieldConfigVisitor.getComboBox(FieldIdEnum.STROKE_STYLE);
    Expression symbolType = null;
    if (symbolTypeValue != null) {
        symbolType = getFilterFactory().literal(symbolTypeValue.getKey());
    }
    List<Float> dashList = createDashArray(fieldConfigVisitor.getText(FieldIdEnum.STROKE_DASH_ARRAY));
    float[] dashes = convertDashListToArray(dashList);
    FieldConfigBase fdmFillColour = fieldConfigManager.get(FieldIdEnum.STROKE_FILL_COLOUR);
    FieldConfigColour colourField = (FieldConfigColour) fdmFillColour;
    Expression fillColour = colourField.getColourExpression();
    Expression opacity = fieldConfigVisitor.getExpression(FieldIdEnum.OVERALL_OPACITY);
    boolean isLine = true;
    if (symbolTypeValue != null) {
        isLine = (symbolTypeValue.getKey().compareTo(SOLID_LINE_KEY) == 0);
    }
    boolean fillColourEnabled = isPanelEnabled(GroupIdEnum.FILLCOLOUR);
    boolean strokeColourEnabled = isPanelEnabled(GroupIdEnum.STROKECOLOUR);
    Stroke stroke = null;
    if (isLine) {
        opacity = fieldConfigVisitor.getExpression(FieldIdEnum.LINE_FILL_OPACITY);
        stroke = getStyleFactory().stroke(fillColour, opacity, strokeWidth, join, lineCap, dashes, offset);
    } else {
        stroke = getStyleFactory().getDefaultStroke();
        AnchorPoint anchorPoint = getStyleFactory().anchorPoint(fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H), fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V));
        // default so it doesn't appear in the SLD
        if (DetailsUtilities.isSame(defaultAnchorPoint, anchorPoint)) {
            anchorPoint = null;
        }
        Displacement displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y));
        // so it doesn't appear in the SLD
        if (DetailsUtilities.isSame(defaultDisplacement, displacement)) {
            displacement = null;
        }
        List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(this.fieldConfigManager, symbolType, fillColourEnabled, strokeColourEnabled, selectedFillPanelId);
        Expression initalGap = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP);
        Expression gap = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_GAP);
        Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_ANGLE);
        Expression symbolSize = fieldConfigVisitor.getExpression(FieldIdEnum.STROKE_SYMBOL_SIZE);
        GraphicStroke graphicStroke = getStyleFactory().graphicStroke(symbols, opacity, symbolSize, rotation, anchorPoint, displacement, initalGap, gap);
        boolean overallOpacity = symbolTypeFactory.isOverallOpacity(PointSymbolizer.class, selectedFillPanelId);
        if (overallOpacity) {
            stroke.setOpacity(opacity);
        }
        stroke.setGraphicStroke(graphicStroke);
        stroke.setWidth(strokeWidth);
    }
    return stroke;
}
Also used : GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GraphicStroke(org.opengis.style.GraphicStroke) Displacement(org.geotools.styling.Displacement) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) AnchorPoint(org.geotools.styling.AnchorPoint) ConstantExpression(org.geotools.filter.ConstantExpression) Expression(org.opengis.filter.expression.Expression) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour)

Example 29 with Stroke

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

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

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