Search in sources :

Example 1 with TextSymbolizer

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

the class LabelEngineLayerProperties method convert.

/* (non-Javadoc)
     * @see com.sldeditor.extension.convert.esri.label.EsriLabelRendererInterface#convert(java.util.List, org.geotools.styling.Rule, com.google.gson.JsonElement, int)
     */
@Override
public void convert(List<Rule> labelRuleList, Rule rule, JsonElement json, int transparency) {
    if ((json != null) && (rule != null) && (labelRuleList != null)) {
        JsonObject jsonObj = json.getAsJsonObject();
        TextSymbolizer textSymbolizer = styleFactory.createTextSymbolizer();
        textSymbolizer.setUnitOfMeasure(NonSI.PIXEL);
        textSymbolizer.setLabel(extractExpression(jsonObj));
        JsonElement jsonElement = jsonObj.get(LabelEngineLayerPropertiesKey.SYMBOL);
        SymbolManager.getInstance().convertTextSymbols(textSymbolizer, transparency, jsonElement);
        // Yes, this really is round the wrong way
        double maxScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MINIMUM_SCALE);
        double minScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MAXIMUM_SCALE);
        if ((minScale > 0.0) || (maxScale > 0.0)) {
            Rule labelRule = styleFactory.createRule();
            labelRule.setName(extractString(jsonObj, LabelEngineLayerPropertiesKey.CLASS));
            if (minScale > 0.0) {
                labelRule.setMinScaleDenominator(minScale);
            }
            if (maxScale > 0.0) {
                labelRule.setMaxScaleDenominator(maxScale);
            }
            labelRule.symbolizers().add(textSymbolizer);
            labelRuleList.add(labelRule);
        } else {
            rule.symbolizers().add(textSymbolizer);
        }
    }
}
Also used : TextSymbolizer(org.geotools.styling.TextSymbolizer) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Rule(org.geotools.styling.Rule)

Example 2 with TextSymbolizer

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

the class TextSymbolizerDetailsTest method testTextSymbolizerDetails.

/**
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#TextSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#isDataPresent()}.
 * Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#preLoadSymbol()}.
 */
@Test
public void testTextSymbolizerDetails() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();
    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 expectedRuleValue = "rule test value";
    rule.setName(expectedRuleValue);
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    String expectedNameValue = "symbolizer test value";
    symbolizer.setName(expectedNameValue);
    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);
    panel.dataChanged(null);
    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    assertNull(nameField);
    assertTrue(panel.isDataPresent());
    // Reset to default value
    panel.preLoadSymbol();
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) TextSymbolizer(org.geotools.styling.TextSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) TextSymbolizerDetails(com.sldeditor.ui.detail.TextSymbolizerDetails) Test(org.junit.Test)

Example 3 with TextSymbolizer

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

the class RuleRenderVisitor method visit.

/**
 * (non-Javadoc)
 *
 * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.TextSymbolizer)
 */
public void visit(TextSymbolizer text) {
    TextSymbolizer copy = sf.createTextSymbolizer();
    copy.setFill(copy(text.getFill()));
    copy.fonts().clear();
    copy.fonts().addAll(copyFonts(text.fonts()));
    // Ignore geometry field so that symbol is rendered
    copy.setGeometry(copy(text.getGeometry()));
    copy.setUnitOfMeasure(text.getUnitOfMeasure());
    copy.setHalo(copy(text.getHalo()));
    copy.setLabel(copy(text.getLabel()));
    copy.setLabelPlacement(copy(text.getLabelPlacement()));
    copy.setPriority(copy(text.getPriority()));
    copy.getOptions().putAll(text.getOptions());
    if (text instanceof TextSymbolizer2) {
        TextSymbolizer2 text2 = (TextSymbolizer2) text;
        TextSymbolizer2 copy2 = (TextSymbolizer2) copy;
        copy2.setGraphic(copy(text2.getGraphic()));
        copy2.setSnippet(copy(text2.getSnippet()));
        copy2.setFeatureDescription(copy(text2.getFeatureDescription()));
        copy2.setOtherText(copy(text2.getOtherText()));
    }
    if (STRICT && !copy.equals(text)) {
        throw new IllegalStateException("Was unable to duplicate provided TextSymbolizer:" + text);
    }
    pages.push(copy);
}
Also used : TextSymbolizer2(org.geotools.styling.TextSymbolizer2) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 4 with TextSymbolizer

use of org.geotools.styling.TextSymbolizer 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 font = fontList.get(0);
        if (isFontNameUpdated()) {
            font.getFamily().clear();
            font.getFamily().addAll(this.font.getFamily());
        }
        if (isFontStyleUpdated()) {
            font.setStyle(ff.literal(this.font.getStyle()));
        }
        if (isFontWeightUpdated()) {
            font.setWeight(ff.literal(this.font.getWeight()));
        }
        if (isFontSizeUpdated()) {
            font.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 != null) {
                    if (currentSymbolizer instanceof TextSymbolizer) {
                        TextSymbolizer textSymbolizer = (TextSymbolizer) currentSymbolizer;
                        textSymbolizer.fonts().clear();
                        textSymbolizer.fonts().add(font);
                        refreshUI = true;
                    }
                }
            }
        }
        sldData.updateSLDContents(sldContents);
        setOriginalData(font);
    }
    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 5 with TextSymbolizer

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

the class BatchUpdateFontUtils method containsFonts.

/**
 * Contains font details.
 *
 * @param sldData the sld data
 * @return the scale sld data
 */
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
    List<BatchUpdateFontData> dataList = null;
    if (sldData != null) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        if (sld != null) {
            List<StyledLayer> styledLayerList = sld.layers();
            if (sld != null) {
                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>();
                                                }
                                                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)

Aggregations

TextSymbolizer (org.geotools.styling.TextSymbolizer)33 Test (org.junit.Test)19 Font (org.geotools.styling.Font)9 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 Rule (org.geotools.styling.Rule)9 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)8 LineSymbolizer (org.geotools.styling.LineSymbolizer)8 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)8 Style (org.geotools.styling.Style)8 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 NamedLayer (org.geotools.styling.NamedLayer)5 SLDTreeLeafText (com.sldeditor.common.tree.leaf.SLDTreeLeafText)4 SLDData (com.sldeditor.common.data.SLDData)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)3 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)3 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 BatchUpdateFontData (com.sldeditor.tool.batchupdatefont.BatchUpdateFontData)3 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)3 Symbolizer (org.geotools.styling.Symbolizer)3