Search in sources :

Example 1 with GraphicStroke

use of org.opengis.style.GraphicStroke 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 2 with GraphicStroke

use of org.opengis.style.GraphicStroke 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 3 with GraphicStroke

use of org.opengis.style.GraphicStroke in project sldeditor by robward-scisys.

the class StrokeDetailsTest method testStrokeDetailsLine.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@SuppressWarnings("deprecation")
@Test
public void testStrokeDetailsLine() {
    StrokeDetails panel = new StrokeDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Stroke stroke = styleFactory.getDefaultStroke();
    SymbolTypeFactory fillFactory = new SymbolTypeFactory(StrokeDetails.class, new ColourFieldConfig(GroupIdEnum.FILLCOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH), new ColourFieldConfig(GroupIdEnum.STROKECOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH), FieldIdEnum.STROKE_STYLE);
    fillFactory.populate(panel, panel.getFieldDataManager());
    Expression symbolType = ff.literal("star");
    List<GraphicalSymbol> symbols = fillFactory.getValue(panel.getFieldDataManager(), symbolType, true, true, FieldConfigMarker.class);
    Expression initalGap = ff.literal(0);
    Expression gap = ff.literal(0);
    GraphicStroke graphicStroke = styleFactory.graphicStroke(symbols, null, ff.literal(10), ff.literal(0), styleFactory.createAnchorPoint(ff.literal(0.5), ff.literal(0.75)), styleFactory.createDisplacement(ff.literal(0.35), ff.literal(0.12)), initalGap, gap);
    stroke.setDashArray(new float[] { 1.0f, 2.0f, 3.0f });
    stroke.setGraphicStroke(graphicStroke);
    LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    symbolizer.setStroke(stroke);
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    double expectedAngle = 14.5;
    FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
    angleField.populateField(expectedAngle);
    FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);
    panel.dataChanged(null);
    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertTrue(panel.isDataPresent());
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);
    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
Also used : GraphicStroke(org.opengis.style.GraphicStroke) Stroke(org.geotools.styling.Stroke) StrokeDetails(com.sldeditor.ui.detail.StrokeDetails) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GraphicStroke(org.opengis.style.GraphicStroke) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FilterFactory(org.opengis.filter.FilterFactory) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) Expression(org.opengis.filter.expression.Expression) ColourFieldConfig(com.sldeditor.ui.detail.ColourFieldConfig) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) SymbolTypeFactory(com.sldeditor.ui.detail.config.symboltype.SymbolTypeFactory) Test(org.junit.Test)

Aggregations

Stroke (org.geotools.styling.Stroke)3 Expression (org.opengis.filter.expression.Expression)3 GraphicStroke (org.opengis.style.GraphicStroke)3 GraphicalSymbol (org.opengis.style.GraphicalSymbol)3 ConstantExpression (org.geotools.filter.ConstantExpression)2 AnchorPoint (org.geotools.styling.AnchorPoint)2 Displacement (org.geotools.styling.Displacement)2 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 StrokeDetails (com.sldeditor.ui.detail.StrokeDetails)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)1 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)1 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)1 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)1 SymbolTypeFactory (com.sldeditor.ui.detail.config.symboltype.SymbolTypeFactory)1 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)1 ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)1 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)1