Search in sources :

Example 26 with Symbolizer

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

the class SimpleFillSymbol method convertToFill.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int)
     */
@Override
public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) {
    if (element == null)
        return null;
    JsonObject obj = element.getAsJsonObject();
    List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
    Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR));
    Expression transparencyExpression = getTransparency(transparency);
    Fill fill = null;
    if (fillColour != null) {
        fill = styleFactory.createFill(fillColour, transparencyExpression);
    }
    PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
    polygon.setStroke(null);
    polygon.setFill(fill);
    symbolizerList.add(polygon);
    return symbolizerList;
}
Also used : Fill(org.geotools.styling.Fill) Expression(org.opengis.filter.expression.Expression) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer)

Example 27 with Symbolizer

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

the class RuleRenderVisitor method visit.

/**
 * Visit.
 *
 * @param rule the rule
 */
/*
     * (non-Javadoc)
     *
     * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.Rule)
     */
@SuppressWarnings("deprecation")
@Override
public void visit(Rule rule) {
    Rule copy = null;
    Symbolizer[] symsCopy = null;
    if (!displayOverall && ((symbolizerIndex >= 0) && (symbolizerIndex < rule.getSymbolizers().length))) {
        symsCopy = new Symbolizer[1];
        symsCopy[0] = copy(rule.getSymbolizers()[symbolizerIndex]);
    }
    // As a catch all copy everything
    if (symsCopy == null) {
        symsCopy = rule.getSymbolizers();
        for (int i = 0; i < symsCopy.length; i++) {
            symsCopy[i] = copy(symsCopy[i]);
        }
    }
    Graphic[] legendCopy = rule.getLegendGraphic();
    for (int i = 0; i < legendCopy.length; i++) {
        legendCopy[i] = copy(legendCopy[i]);
    }
    Description descCopy = rule.getDescription();
    descCopy = copy(descCopy);
    copy = sf.createRule();
    copy.setSymbolizers(symsCopy);
    copy.setDescription(descCopy);
    copy.setLegendGraphic(legendCopy);
    copy.setName(rule.getName());
    Filter filterCopy = null;
    copy.setFilter(filterCopy);
    copy.setElseFilter(rule.isElseFilter());
    if (STRICT && !copy.equals(rule)) {
        throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule);
    }
    pages.push(copy);
}
Also used : Description(org.opengis.style.Description) Filter(org.opengis.filter.Filter) Graphic(org.geotools.styling.Graphic) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 28 with Symbolizer

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

the class BatchUpdateFontData method updateFont.

/**
 * Update font.
 *
 * @param sldWriter the sld writer
 * @return true, if successful
 */
public boolean updateFont(SLDWriterInterface sldWriter) {
    boolean refreshUI = false;
    if ((rule != null) && (sldWriter != null)) {
        List<Font> fontList = symbolizer.fonts();
        Font localFont = fontList.get(0);
        if (isFontNameUpdated()) {
            localFont.getFamily().clear();
            localFont.getFamily().addAll(this.font.getFamily());
        }
        if (isFontStyleUpdated()) {
            localFont.setStyle(ff.literal(this.font.getStyle()));
        }
        if (isFontWeightUpdated()) {
            localFont.setWeight(ff.literal(this.font.getWeight()));
        }
        if (isFontSizeUpdated()) {
            localFont.setSize(ff.literal(this.font.getSize()));
        }
        String sldContents = sldWriter.encodeSLD(null, this.sld);
        SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();
        if ((current != null) && (sldData != null)) {
            if (((current.getSLDFile() == null) && (sldData.getSLDFile() == null)) || ((current.getSLDFile() != null) && current.getSLDFile().equals(sldData.getSLDFile())) || ((current.getSLDURL() != null) && current.getSLDURL().equals(sldData.getSLDURL()))) {
                Symbolizer currentSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, SelectedSymbol.getInstance().getSld());
                if (currentSymbolizer instanceof TextSymbolizer) {
                    TextSymbolizer textSymbolizer = (TextSymbolizer) currentSymbolizer;
                    textSymbolizer.fonts().clear();
                    textSymbolizer.fonts().add(localFont);
                    refreshUI = true;
                }
            }
        }
        if (sldData != null) {
            sldData.updateSLDContents(sldContents);
        }
        setOriginalData(localFont);
    }
    return refreshUI;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) TextSymbolizer(org.geotools.styling.TextSymbolizer) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 29 with Symbolizer

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

the class BatchUpdateFontUtils method containsFonts.

/**
 * Contains font details.
 *
 * @param sldData the sld data
 * @return the scale sld data, returns null if invalid SLD string supplied.
 */
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
    List<BatchUpdateFontData> dataList = null;
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        for (StyledLayer styledLayer : styledLayerList) {
            if (styledLayer instanceof NamedLayerImpl) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                for (Style style : namedLayerImpl.styles()) {
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        for (Rule rule : fts.rules()) {
                            for (Symbolizer symbolizer : rule.symbolizers()) {
                                if (symbolizer instanceof TextSymbolizer) {
                                    TextSymbolizer textSymbol = (TextSymbolizer) symbolizer;
                                    Font font = textSymbol.getFont();
                                    if (font != null) {
                                        if (dataList == null) {
                                            dataList = new ArrayList<>();
                                        }
                                        BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData);
                                        fontSLDData.setNamedLayer(namedLayerImpl.getName());
                                        fontSLDData.setFeatureTypeStyle(fts.getName());
                                        fontSLDData.setStyle(style.getName());
                                        fontSLDData.setRule(rule);
                                        fontSLDData.setSymbolizer(textSymbol);
                                        fontSLDData.setFont(font);
                                        dataList.add(fontSLDData);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return dataList;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 30 with Symbolizer

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

the class SelectedSymbolTest method testRemove.

/**
 * Test method for {@link
 * com.sldeditor.common.data.SelectedSymbol#removeFeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)}.
 */
@Test
public void testRemove() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    Rule rule1 = DefaultSymbols.createNewRule();
    Rule rule2 = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts1 = DefaultSymbols.createNewFeatureTypeStyle();
    FeatureTypeStyle fts2 = DefaultSymbols.createNewFeatureTypeStyle();
    Style style1 = DefaultSymbols.createNewStyle();
    Style style2 = DefaultSymbols.createNewStyle();
    Style style3 = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer polygonSymbolizer1 = DefaultSymbols.createDefaultPolygonSymbolizer();
    PolygonSymbolizer polygonSymbolizer2 = DefaultSymbols.createDefaultPolygonSymbolizer();
    PolygonSymbolizer polygonSymbolizer3 = DefaultSymbols.createDefaultPolygonSymbolizer();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyledLayer(namedLayer);
    instance.addNewStyle(style1);
    instance.addNewStyle(style2);
    instance.addNewStyle(style3);
    instance.setStyle(style1);
    instance.addNewFeatureTypeStyle(fts1);
    instance.addNewFeatureTypeStyle(fts2);
    instance.setFeatureTypeStyle(fts1);
    instance.addNewRule(rule1);
    instance.setRule(rule1);
    instance.addSymbolizerToRule(polygonSymbolizer1);
    instance.addSymbolizerToRule(polygonSymbolizer2);
    instance.addSymbolizerToRule(polygonSymbolizer3);
    instance.addNewRule(rule2);
    Rule ruleToTest = instance.getRule();
    List<Symbolizer> symbolizerList = ruleToTest.symbolizers();
    assertEquals(3, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer3);
    assertEquals(2, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer3);
    assertEquals(2, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer2);
    assertEquals(1, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer1);
    assertEquals(0, symbolizerList.size());
    List<Rule> ruleList = instance.getFeatureTypeStyle().rules();
    assertEquals(2, ruleList.size());
    instance.removeRule(rule2);
    assertEquals(1, ruleList.size());
    instance.removeRule(rule1);
    assertEquals(0, ruleList.size());
    instance.removeRule(rule2);
    assertEquals(0, ruleList.size());
    List<FeatureTypeStyle> ftsList = instance.getStyle().featureTypeStyles();
    assertEquals(2, ftsList.size());
    instance.removeFeatureTypeStyle(fts2);
    assertEquals(1, ftsList.size());
    instance.removeFeatureTypeStyle(fts2);
    assertEquals(1, ftsList.size());
    instance.removeFeatureTypeStyle(fts1);
    assertEquals(0, ftsList.size());
    List<Style> styleList = ((NamedLayer) instance.getStyledLayer()).styles();
    assertEquals(3, styleList.size());
    instance.removeStyle(style3);
    assertEquals(2, styleList.size());
    instance.removeStyle(style2);
    assertEquals(1, styleList.size());
    instance.removeStyle(style2);
    assertEquals(1, styleList.size());
    instance.removeStyle(style1);
    assertEquals(0, styleList.size());
    instance.removeStyledLayerDescriptor(sld);
    assertEquals(sld, instance.getSld());
    instance.removeUserNamedLayer(namedLayer);
    assertEquals(1, instance.getSld().layers().size());
    instance.removeUserNamedLayer(namedLayer);
    assertEquals(0, instance.getSld().layers().size());
    instance.removeUserNamedLayer(namedLayer);
    assertEquals(0, instance.getSld().layers().size());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) 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) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Test(org.junit.jupiter.api.Test)

Aggregations

Symbolizer (org.geotools.styling.Symbolizer)65 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)29 LineSymbolizer (org.geotools.styling.LineSymbolizer)28 PointSymbolizer (org.geotools.styling.PointSymbolizer)27 Rule (org.geotools.styling.Rule)21 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)20 Style (org.geotools.styling.Style)18 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)15 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 Test (org.junit.jupiter.api.Test)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 JsonObject (com.google.gson.JsonObject)11 StyledLayer (org.geotools.styling.StyledLayer)11 NamedLayer (org.geotools.styling.NamedLayer)10 ArrayList (java.util.ArrayList)8 JsonElement (com.google.gson.JsonElement)7 Stroke (org.geotools.styling.Stroke)6 JsonArray (com.google.gson.JsonArray)5 Expression (org.opengis.filter.expression.Expression)5