Search in sources :

Example 36 with FeatureTypeStyle

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

the class ExtractValidFieldTypes method fieldTypesUpdated.

/**
 * Evaluate fields types.
 *
 * @return true, field types updated
 */
public static boolean fieldTypesUpdated() {
    boolean fieldsUpdated = false;
    SLDStyleFactory styleFactory = new SLDStyleFactory();
    StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        for (StyledLayer styledLayer : styledLayerList) {
            List<org.geotools.styling.Style> styleList = null;
            if (styledLayer instanceof NamedLayerImpl) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                styleList = namedLayerImpl.styles();
            } else if (styledLayer instanceof UserLayerImpl) {
                UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                styleList = userLayerImpl.userStyles();
            }
            if (styleList != null) {
                for (Style style : styleList) {
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        for (Rule rule : fts.rules()) {
                            for (Symbolizer symbolizer : rule.symbolizers()) {
                                FeatureSource<SimpleFeatureType, SimpleFeature> featureList = DataSourceFactory.getDataSource().getFeatureSource();
                                if (featureList != null) {
                                    Object drawMe = null;
                                    try {
                                        drawMe = featureList.getFeatures().features().next();
                                    } catch (NoSuchElementException e) {
                                        e.printStackTrace();
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                    try {
                                        styleFactory.createStyle(drawMe, symbolizer);
                                    } catch (IllegalArgumentException e) {
                                        String message = e.getMessage();
                                        if (message.startsWith(UNABLE_TO_DECODE_PREFIX) && message.endsWith(UNABLE_TO_DECODE_SUFFIX)) {
                                            String fieldName = message.substring(UNABLE_TO_DECODE_PREFIX.length(), message.length() - UNABLE_TO_DECODE_SUFFIX.length());
                                            DataSourceFactory.getDataSource().updateFieldType(fieldName, Long.class);
                                            fieldsUpdated = true;
                                        } else {
                                            ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return fieldsUpdated;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) IOException(java.io.IOException) Symbolizer(org.geotools.styling.Symbolizer) SimpleFeature(org.opengis.feature.simple.SimpleFeature) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayerImpl(org.geotools.styling.UserLayerImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SLDStyleFactory(org.geotools.renderer.style.SLDStyleFactory) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NoSuchElementException(java.util.NoSuchElementException)

Example 37 with FeatureTypeStyle

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

the class RuleRenderVisitor method visit.

/**
 * Visit.
 *
 * @param fts the fts
 */
/*
     * (non-Javadoc)
     * 
     * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.
     * FeatureTypeStyle)
     */
@SuppressWarnings("deprecation")
@Override
public void visit(FeatureTypeStyle fts) {
    FeatureTypeStyle copy = new FeatureTypeStyleImpl((FeatureTypeStyleImpl) fts);
    if (!options.isTransformationApplied()) {
        copy.setTransformation(null);
    }
    Rule[] rules = fts.getRules();
    int length = rules.length;
    Rule[] rulesCopy = null;
    if (this.ruleToRender == null) {
        rulesCopy = new Rule[length];
        for (int i = 0; i < length; i++) {
            if (rules[i] != null) {
                rules[i].accept(this);
                rulesCopy[i] = (Rule) pages.pop();
            }
        }
    } else {
        rulesCopy = new Rule[1];
        for (int i = 0; i < length; i++) {
            if (rules[i] != null) {
                if (renderRule(rules[i])) {
                    rules[i].accept(this);
                    rulesCopy[0] = (Rule) pages.pop();
                }
            }
        }
    }
    copy.setRules(rulesCopy);
    if (STRICT && !copy.equals(fts)) {
        throw new IllegalStateException("Was unable to duplicate provided FeatureTypeStyle:" + fts);
    }
    pages.push(copy);
}
Also used : FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureTypeStyleImpl(org.geotools.styling.FeatureTypeStyleImpl)

Example 38 with FeatureTypeStyle

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

the class RuleRenderVisitor method visit.

/**
 * Visit.
 *
 * @param style the style
 */
// CHECKSTYLE:OFF
@SuppressWarnings("deprecation")
// CHECKSTYLE:ON
@Override
public void visit(Style style) {
    Style copy = null;
    FeatureTypeStyle[] fts = style.getFeatureTypeStyles();
    FeatureTypeStyle[] ftsCopy = null;
    if (this.ftsToRender != null) {
        ftsCopy = new FeatureTypeStyle[1];
        for (int i = 0; i < fts.length; i++) {
            if (fts[i] != null) {
                if (fts[i] == this.ftsToRender) {
                    fts[i].accept(this);
                    ftsCopy[0] = (FeatureTypeStyle) pages.pop();
                }
            }
        }
    } else {
        ftsCopy = new FeatureTypeStyle[fts.length];
        for (int i = 0; i < fts.length; i++) {
            if (fts[i] != null) {
                fts[i].accept(this);
                ftsCopy[i] = (FeatureTypeStyle) pages.pop();
            }
        }
    }
    copy = sf.createStyle();
    copy.setAbstract(style.getAbstract());
    copy.setName(style.getName());
    copy.setTitle(style.getTitle());
    copy.setFeatureTypeStyles(ftsCopy);
    if (STRICT && !copy.equals(style)) {
        throw new IllegalStateException("Was unable to duplicate provided Style:" + style);
    }
    pages.push(copy);
}
Also used : Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 39 with FeatureTypeStyle

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

Example 40 with FeatureTypeStyle

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

the class FeatureTypeStyleDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.
     * SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    if (selectedSymbol != null) {
        FeatureTypeStyle featureTypeStyle = selectedSymbol.getFeatureTypeStyle();
        populateStandardData(featureTypeStyle);
        if (featureTypeStyle != null) {
            fieldConfigVisitor.populateField(FieldIdEnum.TRANSFORMATION, featureTypeStyle.getTransformation());
        }
        if (vendorOptionFTSFactory != null) {
            vendorOptionFTSFactory.populate(featureTypeStyle);
        }
    }
}
Also used : FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Aggregations

FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)110 Style (org.geotools.styling.Style)81 Rule (org.geotools.styling.Rule)65 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)43 Test (org.junit.Test)42 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)24 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)21 LineSymbolizer (org.geotools.styling.LineSymbolizer)20 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)17 Symbolizer (org.geotools.styling.Symbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)14 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)12 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)12 UserLayerImpl (org.geotools.styling.UserLayerImpl)12 ArrayList (java.util.ArrayList)11 LineStyle (org.polymap.core.style.model.feature.LineStyle)11