Search in sources :

Example 31 with StyledLayer

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

the class SLDUtils method findEquivalentRule.

/**
 * Find equivalent rule.
 *
 * @param otherSLD the other SLD
 * @param styledLayerIndex the styled layer index
 * @param isNamedLayer the is named layer
 * @param styleIndex the style index
 * @param ftsIndex the fts index
 * @param ruleIndex the rule index
 * @return the rule
 */
private static Rule findEquivalentRule(StyledLayerDescriptor otherSLD, int styledLayerIndex, boolean isNamedLayer, int styleIndex, int ftsIndex, int ruleIndex) {
    if (otherSLD != null) {
        List<StyledLayer> styledLayerList = otherSLD.layers();
        if (styledLayerList != null) {
            try {
                StyledLayer styledLayer = styledLayerList.get(styledLayerIndex);
                List<Style> styleList = null;
                if (isNamedLayer) {
                    NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                    styleList = namedLayerImpl.styles();
                } else {
                    UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                    styleList = userLayerImpl.userStyles();
                }
                if (styleList != null) {
                    Style style = styleList.get(styleIndex);
                    FeatureTypeStyle fts = style.featureTypeStyles().get(ftsIndex);
                    return fts.rules().get(ruleIndex);
                }
            } catch (IndexOutOfBoundsException exception) {
            // Do nothing
            }
        }
    }
    return null;
}
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)

Example 32 with StyledLayer

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

the class SLDUtils method findSymbolizer.

/**
 * Find symbolizer.
 *
 * @param sld the sld
 * @param symbolizerToFind the symbolizer to find
 * @param otherSLD the other SLD
 * @return the symbolizer
 */
public static Symbolizer findSymbolizer(StyledLayerDescriptor sld, Symbolizer symbolizerToFind, StyledLayerDescriptor otherSLD) {
    List<StyledLayer> styledLayerList = sld.layers();
    if (styledLayerList != null) {
        int styledLayerIndex = 0;
        int styleIndex = 0;
        int ftsIndex = 0;
        int ruleIndex = 0;
        int symbolizerIndex = 0;
        boolean isNamedLayer = true;
        for (StyledLayer styledLayer : styledLayerList) {
            List<Style> styleList = null;
            if (styledLayer instanceof NamedLayerImpl) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                styleList = namedLayerImpl.styles();
                isNamedLayer = true;
            } else if (styledLayer instanceof UserLayerImpl) {
                UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                styleList = userLayerImpl.userStyles();
                isNamedLayer = false;
            }
            if (styleList != null) {
                styleIndex = 0;
                for (Style style : styleList) {
                    ftsIndex = 0;
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        ruleIndex = 0;
                        for (Rule rule : fts.rules()) {
                            symbolizerIndex = 0;
                            for (org.opengis.style.Symbolizer symbolizer : rule.symbolizers()) {
                                if (symbolizer == symbolizerToFind) {
                                    return findEquivalentSymbolizer(otherSLD, styledLayerIndex, isNamedLayer, styleIndex, ftsIndex, ruleIndex, symbolizerIndex);
                                }
                                symbolizerIndex++;
                            }
                            ruleIndex++;
                        }
                        ftsIndex++;
                    }
                    styleIndex++;
                }
            }
            styledLayerIndex++;
        }
    }
    return null;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) UserLayerImpl(org.geotools.styling.UserLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 33 with StyledLayer

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

the class SelectedSymbol method removeUserNamedLayer.

/**
 * Removes the named/user layer.
 *
 * @param layerToDelete the named/user layer to delete
 */
public void removeUserNamedLayer(StyledLayer layerToDelete) {
    List<StyledLayer> styledLayerList = this.sld.layers();
    int indexFound = -1;
    int index = 0;
    for (StyledLayer styledLayer : styledLayerList) {
        if (styledLayer == layerToDelete) {
            indexFound = index;
            break;
        } else {
            index++;
        }
    }
    if (indexFound > -1) {
        styledLayerList.remove(indexFound);
    }
}
Also used : StyledLayer(org.geotools.styling.StyledLayer)

Example 34 with StyledLayer

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

the class SymbolizerDetailsPanel method getMinimumVersion.

/**
 * Gets the minimum version vendor option present in the SLD.
 *
 * @param parentObj the parent obj
 * @param sldObj the sld obj
 * @param vendorOptionsPresentList the vendor options present list
 */
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
    Class<?> parentClass = null;
    Class<?> classSelected = sldObj.getClass();
    if (sldObj instanceof StyledLayerDescriptor) {
    // No parent
    } else if (sldObj instanceof StyledLayer) {
        parentClass = StyledLayerDescriptor.class;
    } else if (sldObj instanceof Style) {
        parentClass = StyledLayer.class;
    } else if (sldObj instanceof FeatureTypeStyle) {
        parentClass = Style.class;
    } else if (sldObj instanceof Rule) {
        parentClass = FeatureTypeStyle.class;
    } else if (sldObj instanceof Symbolizer) {
        parentClass = Rule.class;
    }
    internal_getMinimumVersion(parentObj, sldObj, vendorOptionsPresentList, parentClass, classSelected);
    if (sldObj instanceof PointSymbolizerImpl) {
        PointSymbolizerImpl pointSymbolizer = (PointSymbolizerImpl) sldObj;
        parentClass = PointSymbolizerImpl.class;
        classSelected = FillImpl.class;
        internal_getMinimumVersion(pointSymbolizer, pointSymbolizer.getGraphic(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof LineSymbolizerImpl) {
        LineSymbolizerImpl lineSymbolizer = (LineSymbolizerImpl) sldObj;
        parentClass = LineSymbolizerImpl.class;
        classSelected = StrokeImpl.class;
        internal_getMinimumVersion(lineSymbolizer, lineSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof PolygonSymbolizerImpl) {
        PolygonSymbolizerImpl polygonSymbolizer = (PolygonSymbolizerImpl) sldObj;
        parentClass = PolygonSymbolizerImpl.class;
        classSelected = FillImpl.class;
        internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getFill(), vendorOptionsPresentList, parentClass, classSelected);
        classSelected = StrokeImpl.class;
        internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof TextSymbolizerImpl) {
        TextSymbolizerImpl textSymbolizer = (TextSymbolizerImpl) sldObj;
        parentClass = Rule.class;
        classSelected = TextSymbolizerImpl.class;
        internal_getMinimumVersion(parentObj, textSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
    } else if (sldObj instanceof RasterSymbolizerImpl) {
        RasterSymbolizerImpl rasterSymbolizer = (RasterSymbolizerImpl) sldObj;
        parentClass = Rule.class;
        classSelected = RasterSymbolizerImpl.class;
        internal_getMinimumVersion(parentObj, rasterSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
    }
}
Also used : TextSymbolizerImpl(org.geotools.styling.TextSymbolizerImpl) StyledLayer(org.geotools.styling.StyledLayer) LineSymbolizerImpl(org.geotools.styling.LineSymbolizerImpl) StrokeImpl(org.geotools.styling.StrokeImpl) Symbolizer(org.geotools.styling.Symbolizer) RasterSymbolizerImpl(org.geotools.styling.RasterSymbolizerImpl) PolygonSymbolizerImpl(org.geotools.styling.PolygonSymbolizerImpl) 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) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl)

Example 35 with StyledLayer

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

the class UserLayerDetails method updateSymbol.

/**
 * Update symbol.
 *
 * @param changedField the changed field
 */
private void updateSymbol(FieldIdEnum changedField) {
    if (!Controller.getInstance().isPopulating()) {
        UserLayer userLayer = getStyleFactory().createUserLayer();
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        userLayer.setName(name);
        // Feature type constraints
        List<FeatureTypeConstraint> ftcList = fieldConfigVisitor.getFeatureTypeConstraint(FieldIdEnum.LAYER_FEATURE_CONSTRAINTS);
        if ((ftcList != null) && !ftcList.isEmpty()) {
            FeatureTypeConstraint[] ftcArray = new FeatureTypeConstraint[ftcList.size()];
            userLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }
        // Source
        GroupConfigInterface group = getGroup(GroupIdEnum.USER_LAYER_SOURCE);
        if (group != null) {
            MultiOptionGroup userLayerSourceGroup = (MultiOptionGroup) group;
            OptionGroup selectedOption = userLayerSourceGroup.getSelectedOptionGroup();
            switch(selectedOption.getId()) {
                case REMOTE_OWS_OPTION:
                    {
                        RemoteOWS remoteOWS = new RemoteOWSImpl();
                        String service = fieldConfigVisitor.getText(FieldIdEnum.REMOTE_OWS_SERVICE);
                        remoteOWS.setService(service);
                        String onlineResource = fieldConfigVisitor.getText(FieldIdEnum.REMOTE_OWS_ONLINERESOURCE);
                        remoteOWS.setOnlineResource(onlineResource);
                        userLayer.setRemoteOWS(remoteOWS);
                    }
                    break;
                case INLINE_FEATURE_OPTION:
                    {
                        String inlineFeatures = fieldConfigVisitor.getText(FieldIdEnum.INLINE_FEATURE);
                        if ((inlineFeatures != null) && (!inlineFeatures.isEmpty())) {
                            InlineFeatureUtils.setInlineFeatures(userLayer, inlineFeatures);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof UserLayerImpl) {
            UserLayerImpl existingUserLayer = (UserLayerImpl) existingStyledLayer;
            for (Style style : existingUserLayer.userStyles()) {
                userLayer.addUserStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(userLayer);
        // reduces creation of datasources
        if (changedField != null) {
            if (changedField == FieldIdEnum.INLINE_FEATURE) {
                DataSourceInterface dataSource = DataSourceFactory.getDataSource();
                if (dataSource != null) {
                    dataSource.updateUserLayers();
                }
            }
        }
        this.fireUpdateSymbol();
    }
}
Also used : RemoteOWS(org.geotools.styling.RemoteOWS) StyledLayer(org.geotools.styling.StyledLayer) RemoteOWSImpl(org.geotools.styling.RemoteOWSImpl) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) UserLayerImpl(org.geotools.styling.UserLayerImpl) Style(org.geotools.styling.Style) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) UserLayer(org.geotools.styling.UserLayer) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup)

Aggregations

StyledLayer (org.geotools.styling.StyledLayer)43 Style (org.geotools.styling.Style)28 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)25 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)22 Rule (org.geotools.styling.Rule)19 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)19 UserLayerImpl (org.geotools.styling.UserLayerImpl)16 Symbolizer (org.geotools.styling.Symbolizer)12 NamedLayer (org.geotools.styling.NamedLayer)10 Test (org.junit.Test)10 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)7 LineSymbolizer (org.geotools.styling.LineSymbolizer)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)5 IOException (java.io.IOException)4 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)4 SLDData (com.sldeditor.common.data.SLDData)3 ArrayList (java.util.ArrayList)3 UserLayer (org.geotools.styling.UserLayer)3 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)2