Search in sources :

Example 36 with Rule

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

the class MinimumVersion method findMinimumVersion.

/**
 * Find minimum version.
 *
 * @param sld the sld
 */
public void findMinimumVersion(StyledLayerDescriptor sld) {
    vendorOptionsPresentList.clear();
    Object parentObj = null;
    if ((sld != null) && (uiMgr != null)) {
        uiMgr.getMinimumVersion(parentObj, sld, vendorOptionsPresentList);
        List<StyledLayer> styledLayerList = sld.layers();
        if (styledLayerList != null) {
            parentObj = sld;
            for (StyledLayer styledLayer : styledLayerList) {
                uiMgr.getMinimumVersion(parentObj, styledLayer, vendorOptionsPresentList);
                List<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) {
                    parentObj = styledLayer;
                    for (Style style : styleList) {
                        uiMgr.getMinimumVersion(parentObj, style, vendorOptionsPresentList);
                        parentObj = style;
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            uiMgr.getMinimumVersion(parentObj, fts, vendorOptionsPresentList);
                            parentObj = fts;
                            for (Rule rule : fts.rules()) {
                                uiMgr.getMinimumVersion(parentObj, rule, vendorOptionsPresentList);
                                parentObj = rule;
                                for (Symbolizer symbolizer : rule.symbolizers()) {
                                    uiMgr.getMinimumVersion(parentObj, symbolizer, vendorOptionsPresentList);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    removeStrictSLD();
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer)

Example 37 with Rule

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

the class NewRasterSLD method create.

/**
 * Creates the symbol.
 *
 * @return the styled layer descriptor
 */
/* (non-Javadoc)
     * @see com.sldeditor.create.NewSLDInterface#create()
     */
@Override
public StyledLayerDescriptor create() {
    StyledLayerDescriptor sld = getStyleFactory().createStyledLayerDescriptor();
    NamedLayer namedLayer = getStyleFactory().createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = getStyleFactory().createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = getStyleFactory().createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = getStyleFactory().createRule();
    fts.rules().add(rule);
    RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
    rule.symbolizers().add(raster);
    return sld;
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) 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)

Example 38 with Rule

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

the class ExtractAttributes method visit.

/**
 * (non-Javadoc)
 *
 * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.
 * FeatureTypeStyle)
 */
public void visit(FeatureTypeStyle fts) {
    FeatureTypeStyle copy = new FeatureTypeStyleImpl(fts);
    Rule[] rules = fts.getRules();
    int length = rules.length;
    Rule[] rulesCopy = new Rule[length];
    for (int i = 0; i < length; i++) {
        if (rules[i] != null) {
            rules[i].accept(this);
            rulesCopy[i] = (Rule) pages.pop();
        }
    }
    copy.setRules(rulesCopy);
    if (fts.getTransformation() != null) {
        copy.setTransformation(copy(fts.getTransformation()));
    }
    if (fts.getOnlineResource() != null) {
        copy.setOnlineResource(fts.getOnlineResource());
    }
    copy.getOptions().clear();
    copy.getOptions().putAll(fts.getOptions());
    String sortbyGroup = fts.getOptions().get(FeatureTypeStyle.SORT_BY_GROUP);
    if (sortbyGroup != null) {
        List<String> foundList = new ArrayList<String>();
        extractAttribute(String.class, ff.property(sortbyGroup), foundList);
    }
    String sortby = fts.getOptions().get(FeatureTypeStyle.SORT_BY);
    if (sortby != null) {
        SortBy[] sortByArray = SLDStyleFactory.getSortBy(fts.getOptions());
        for (SortBy sortBy : sortByArray) {
            List<String> foundList = new ArrayList<String>();
            extractAttribute(String.class, ff.property(sortBy.getPropertyName().getPropertyName()), foundList);
        }
    }
    if (STRICT && !copy.equals(fts)) {
        throw new IllegalStateException("Was unable to duplicate provided FeatureTypeStyle:" + fts);
    }
    pages.push(copy);
}
Also used : SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) LineString(com.vividsolutions.jts.geom.LineString) FeatureTypeStyleImpl(org.geotools.styling.FeatureTypeStyleImpl) Point(com.vividsolutions.jts.geom.Point)

Example 39 with Rule

use of org.geotools.styling.Rule 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 40 with Rule

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

Aggregations

Rule (org.geotools.styling.Rule)110 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)65 Style (org.geotools.styling.Style)60 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)51 Test (org.junit.Test)48 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)26 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 Symbolizer (org.geotools.styling.Symbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)19 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)16 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)16 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)13 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)11 ArrayList (java.util.ArrayList)11 Filter (org.opengis.filter.Filter)11 UserLayerImpl (org.geotools.styling.UserLayerImpl)10 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)8