Search in sources :

Example 6 with NamedLayerImpl

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

the class SelectedSymbol method addNewStyle.

/**
 * Adds the new style.
 *
 * @param style the style
 */
public void addNewStyle(Style style) {
    if (this.symbolData.getStyledLayer() == null) {
        ConsoleManager.getInstance().error(this, "styledLayer == null");
    } else {
        if (this.symbolData.getStyledLayer() instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) this.symbolData.getStyledLayer();
            List<Style> styleList = namedLayer.styles();
            styleList.add(style);
        } else if (this.symbolData.getStyledLayer() instanceof UserLayerImpl) {
            UserLayerImpl userLayer = (UserLayerImpl) this.symbolData.getStyledLayer();
            List<Style> styleList = userLayer.userStyles();
            styleList.add(style);
        }
    }
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with NamedLayerImpl

use of org.geotools.styling.NamedLayerImpl 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 8 with NamedLayerImpl

use of org.geotools.styling.NamedLayerImpl 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 9 with NamedLayerImpl

use of org.geotools.styling.NamedLayerImpl 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 10 with NamedLayerImpl

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

the class NamedLayerDetails method populate.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    if (selectedSymbol != null) {
        StyledLayer styledLayer = selectedSymbol.getStyledLayer();
        if (styledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            fieldConfigVisitor.populateTextField(FieldIdEnum.NAME, namedLayer.getName());
            // Feature layer constraint
            List<FeatureTypeConstraint> ftcList = namedLayer.layerFeatureConstraints();
            fieldConfigVisitor.populateFieldTypeConstraint(FieldIdEnum.LAYER_FEATURE_CONSTRAINTS, ftcList);
        }
    }
}
Also used : FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl)

Aggregations

NamedLayerImpl (org.geotools.styling.NamedLayerImpl)28 Style (org.geotools.styling.Style)24 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)22 StyledLayer (org.geotools.styling.StyledLayer)22 UserLayerImpl (org.geotools.styling.UserLayerImpl)18 Rule (org.geotools.styling.Rule)16 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 Symbolizer (org.geotools.styling.Symbolizer)8 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 PointSymbolizer (org.geotools.styling.PointSymbolizer)5 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)5 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 TextSymbolizer (org.geotools.styling.TextSymbolizer)3 Test (org.junit.Test)3 RenderSymbolInterface (com.sldeditor.datasource.RenderSymbolInterface)2 ArrayList (java.util.ArrayList)2 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)2 NamedLayer (org.geotools.styling.NamedLayer)2 TreeSelectionData (com.sldeditor.TreeSelectionData)1