Search in sources :

Example 11 with MarkImpl

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

the class SLDUtilsTest method testReadSLDFile.

@Test
public void testReadSLDFile() {
    try {
        File tmpFile = File.createTempFile(getClass().getSimpleName(), ".sld");
        FileWriter fileWriter = new FileWriter(tmpFile);
        fileWriter.write(expectedSld);
        fileWriter.flush();
        fileWriter.close();
        StyledLayerDescriptor sld = SLDUtils.readSLDFile(null);
        assertNull(sld);
        sld = SLDUtils.readSLDFile(tmpFile);
        StyledLayer[] styledLayers = sld.getStyledLayers();
        NamedLayer namedLayer = (NamedLayer) styledLayers[0];
        Style[] actualStyles = namedLayer.getStyles();
        PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
        MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
        assertEquals("circle", mark.getWellKnownName().toString());
        tmpFile.delete();
    } catch (IOException e) {
        e.printStackTrace();
        fail("Failed to create test file");
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) FileWriter(java.io.FileWriter) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) MarkImpl(org.geotools.styling.MarkImpl) IOException(java.io.IOException) File(java.io.File) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 12 with MarkImpl

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

the class SLDTreeLeafPointTest method testGetFill.

/**
 * Test method for
 * {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPoint#getFill(org.opengis.style.Symbolizer)}.
 */
@Test
public void testGetFill() {
    SLDTreeLeafPoint leaf = new SLDTreeLeafPoint();
    assertNull(leaf.getFill(null));
    assertNull(leaf.getFill(DefaultSymbols.createDefaultPolygonSymbolizer()));
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    Fill expectedFill = null;
    Graphic graphic = pointSymbolizer.getGraphic();
    if (graphic != null) {
        List<GraphicalSymbol> symbolList = graphic.graphicalSymbols();
        if ((symbolList != null) && !symbolList.isEmpty()) {
            GraphicalSymbol obj = symbolList.get(0);
            if (obj != null) {
                if (obj instanceof MarkImpl) {
                    MarkImpl mark = (MarkImpl) obj;
                    expectedFill = mark.getFill();
                }
            }
        }
    }
    assertEquals(expectedFill, leaf.getFill(pointSymbolizer));
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Fill(org.geotools.styling.Fill) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) SLDTreeLeafPoint(com.sldeditor.common.tree.leaf.SLDTreeLeafPoint) MarkImpl(org.geotools.styling.MarkImpl) Test(org.junit.Test)

Example 13 with MarkImpl

use of org.geotools.styling.MarkImpl 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 14 with MarkImpl

use of org.geotools.styling.MarkImpl 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 15 with MarkImpl

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

Aggregations

MarkImpl (org.geotools.styling.MarkImpl)19 Expression (org.opengis.filter.expression.Expression)12 PointSymbolizer (org.geotools.styling.PointSymbolizer)8 GraphicalSymbol (org.opengis.style.GraphicalSymbol)7 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)6 Graphic (org.geotools.styling.Graphic)6 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)4 Fill (org.geotools.styling.Fill)4 Stroke (org.geotools.styling.Stroke)4 Test (org.junit.Test)4 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)3 AnchorPoint (org.geotools.styling.AnchorPoint)3 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)3 FillImpl (org.geotools.styling.FillImpl)3 Mark (org.geotools.styling.Mark)3 NamedLayer (org.geotools.styling.NamedLayer)3 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)3 Style (org.geotools.styling.Style)3 StyledLayer (org.geotools.styling.StyledLayer)3 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)3