Search in sources :

Example 26 with Graphic

use of org.geotools.styling.Graphic 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 27 with Graphic

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

the class SymbolTypeFactory method getMinimumVersion.

/**
 * Gets the minimum version for the SLD symbol.
 *
 * @param parentObj the parent obj
 * @param sldObj the sld obj
 * @param vendorOptionsPresentList the vendor options present list
 */
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
    GraphicalSymbol symbol = null;
    Graphic graphic = null;
    if (sldObj instanceof Graphic) {
        graphic = (Graphic) sldObj;
    } else if (sldObj instanceof Fill) {
        Fill fill = (Fill) sldObj;
        graphic = fill.getGraphicFill();
    } else if (sldObj instanceof Stroke) {
        Stroke stroke = (Stroke) sldObj;
        graphic = stroke.getGraphicStroke();
    }
    if (graphic != null) {
        List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
        if ((graphicalSymbolList != null) && !graphicalSymbolList.isEmpty()) {
            symbol = graphicalSymbolList.get(0);
        }
    }
    if (symbol != null) {
        for (FieldState panel : symbolTypeFieldList) {
            if (panel.accept(symbol)) {
                panel.getMinimumVersion(parentObj, sldObj, vendorOptionsPresentList);
            }
        }
    }
}
Also used : Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) Stroke(org.geotools.styling.Stroke) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol)

Example 28 with Graphic

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

the class SLDTreeLeafPoint method createFill.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.leaf.SLDTreeLeafInterface#createFill(org.opengis.style.Symbolizer)
     */
@Override
public void createFill(Symbolizer symbolizer) {
    if (symbolizer instanceof PointSymbolizer) {
        PointSymbolizer point = (PointSymbolizer) symbolizer;
        if (point != null) {
            Graphic graphic = point.getGraphic();
            if (graphic == null) {
                graphic = styleFactory.createDefaultGraphic();
                point.setGraphic(graphic);
            }
            if (graphic != null) {
                if (graphic.graphicalSymbols().isEmpty()) {
                    Mark mark = styleFactory.getDefaultMark();
                    graphic.graphicalSymbols().add(mark);
                }
            }
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Graphic(org.geotools.styling.Graphic) Mark(org.geotools.styling.Mark)

Example 29 with Graphic

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

the class VOGeoServerTextSymbolizer2 method populate.

/**
 * Populate.
 *
 * @param textSymbolizer the text symbolizer
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface#populate(org.geotools.styling.TextSymbolizer)
     */
@Override
public void populate(TextSymbolizer textSymbolizer) {
    if (textSymbolizer instanceof TextSymbolizer2) {
        TextSymbolizer2 textSymbol2 = (TextSymbolizer2) textSymbolizer;
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_FEATURE_DESCRIPTION, textSymbol2.getFeatureDescription());
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SNIPPET, textSymbol2.getSnippet());
        OtherText otherText = textSymbol2.getOtherText();
        String target = null;
        Expression text = null;
        if (otherText != null) {
            target = otherText.getTarget();
            text = otherText.getText();
        }
        GroupConfigInterface group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT);
        if (group != null) {
            group.enable(otherText != null);
        }
        fieldConfigVisitor.populateTextField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TARGET, target);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TEXT, text);
        Graphic graphic = textSymbol2.getGraphic();
        boolean enableFill = false;
        boolean enableStroke = false;
        if (graphic == null) {
            graphic = getStyleFactory().createDefaultGraphic();
            graphic.setSize(getFilterFactory().literal(10.0));
            Mark mark = getStyleFactory().createMark();
            graphic.graphicalSymbols().add(mark);
        }
        Expression fillColour = getFilterFactory().literal(DefaultSymbols.defaultColour());
        Expression fillOpacity = getFilterFactory().literal(DefaultSymbols.defaultColourOpacity());
        Expression strokeColour = getFilterFactory().literal(DefaultSymbols.defaultColour());
        Expression strokeOpacity = getFilterFactory().literal(DefaultSymbols.defaultColourOpacity());
        Expression strokeLineWidth = null;
        List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
        if (!graphicalSymbolList.isEmpty()) {
            GraphicalSymbol symbol = graphicalSymbolList.get(0);
            symbolTypeFactory.setValue(TextSymbolizer2.class, this.fieldConfigManager, graphic, symbol);
            if (symbol instanceof Mark) {
                Mark mark = (Mark) symbol;
                Fill fill = mark.getFill();
                if (fill != null) {
                    enableFill = true;
                    fillColour = fill.getColor();
                    fillOpacity = fill.getOpacity();
                }
                Stroke stroke = mark.getStroke();
                if (stroke != null) {
                    enableStroke = true;
                    strokeColour = stroke.getColor();
                    strokeOpacity = stroke.getOpacity();
                    strokeLineWidth = stroke.getWidth();
                }
            }
        }
        Expression expSize = graphic.getSize();
        Expression expRotation = graphic.getRotation();
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SIZE, expSize);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_ANGLE, expRotation);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_FILL_COLOUR, fillColour);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_FILL_OPACITY, fillOpacity);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_STROKE_FILL_COLOUR, strokeColour);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_STROKE_OPACITY, strokeOpacity);
        fieldConfigVisitor.populateField(FieldIdEnum.VO_TEXTSYMBOLIZER_2_STROKE_FILL_WIDTH, strokeLineWidth);
        GroupConfigInterface fillGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_FILL);
        if (fillGroup != null) {
            fillGroup.enable(enableFill);
        }
        GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_STROKE);
        if (strokeGroup != null) {
            group.enable(enableStroke);
        }
        group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_GRAPHIC);
        if (group != null) {
            group.enable(textSymbol2.getGraphic() != null);
        }
    }
}
Also used : Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) TextSymbolizer2(org.geotools.styling.TextSymbolizer2) Expression(org.opengis.filter.expression.Expression) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) OtherText(org.geotools.styling.OtherText) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface)

Example 30 with Graphic

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

the class VOGeoServerTextSpacingTest method testVOGeoServerTextSpacingTest.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSpacingTest#VOGeoServerTextSpacingTest(java.lang.Class, com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSpacingTest() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();
    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSpacing testObj = new VOGeoServerTextSpacing(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);
    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);
    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);
    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols().add(styleFactory.createExternalGraphic(new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);
    textSymbolizer.getOptions().put("wordSpacing", String.valueOf(42));
    textSymbolizer.getOptions().put("charSpacing", String.valueOf(21));
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);
    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(2, vendorOptionsPresentList.size());
    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());
    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());
    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);
    FeatureTypeStyle fts = null;
    testObj.populate(fts);
    testObj.updateSymbol(fts);
    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
Also used : VendorOptionPresent(com.sldeditor.common.vendoroption.minversion.VendorOptionPresent) MalformedURLException(java.net.MalformedURLException) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) ArrayList(java.util.ArrayList) OtherText(org.geotools.styling.OtherText) FilterFactory(org.opengis.filter.FilterFactory) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) OtherTextImpl(org.geotools.styling.OtherTextImpl) TextSymbolizer2(org.geotools.styling.TextSymbolizer2) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) Literal(org.opengis.filter.expression.Literal) VOGeoServerTextSpacing(com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSpacing) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) File(java.io.File) TextSymbolizerDetails(com.sldeditor.ui.detail.TextSymbolizerDetails) Test(org.junit.Test)

Aggregations

Graphic (org.geotools.styling.Graphic)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicalSymbol (org.opengis.style.GraphicalSymbol)16 Fill (org.geotools.styling.Fill)13 Expression (org.opengis.filter.expression.Expression)12 ExternalGraphic (org.geotools.styling.ExternalGraphic)11 Stroke (org.geotools.styling.Stroke)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)9 AnchorPoint (org.geotools.styling.AnchorPoint)8 Displacement (org.geotools.styling.Displacement)8 ArrayList (java.util.ArrayList)7 Mark (org.geotools.styling.Mark)7 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)6 MarkImpl (org.geotools.styling.MarkImpl)6 Rule (org.geotools.styling.Rule)6 JsonObject (com.google.gson.JsonObject)5 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 JsonElement (com.google.gson.JsonElement)4 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)4 NamedLayer (org.geotools.styling.NamedLayer)4