Search in sources :

Example 46 with Rule

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

the class SLDTreeTools method addNewThing.

/**
 * Adds the new thing.
 *
 * @param hint the hint when the are multiple possibilities
 */
public void addNewThing(Class<?> hint) {
    if (symbolTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    DefaultMutableTreeNode newNode = null;
    Object obj = lastNode.getUserObject();
    // Store current state of the SLD before the add
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof String) {
        StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
        SelectedSymbol.getInstance().createNewSLD(sld);
        if (hint == NamedLayer.class) {
            NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
            newNode = sldTree.addObject(lastNode, namedLayer, true);
        } else if (hint == UserLayer.class) {
            UserLayer userLayer = DefaultSymbols.createNewUserLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
            newNode = sldTree.addObject(lastNode, userLayer, true);
        }
    } else if (obj instanceof StyledLayerDescriptor) {
        if (hint == NamedLayer.class) {
            NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
            newNode = sldTree.addObject(lastNode, namedLayer, true);
        } else if (hint == UserLayer.class) {
            UserLayer userLayer = DefaultSymbols.createNewUserLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
            newNode = sldTree.addObject(lastNode, userLayer, true);
        }
    } else if (obj instanceof NamedLayer) {
        Style style = DefaultSymbols.createNewStyle();
        SelectedSymbol.getInstance().addNewStyle(style);
        newNode = sldTree.addObject(lastNode, style, true);
    } else if (obj instanceof UserLayer) {
        Style style = DefaultSymbols.createNewStyle();
        SelectedSymbol.getInstance().addNewStyle(style);
        newNode = sldTree.addObject(lastNode, style, true);
    } else if (obj instanceof Style) {
        FeatureTypeStyle featureTypeStyle = DefaultSymbols.createNewFeatureTypeStyle();
        SelectedSymbol.getInstance().addNewFeatureTypeStyle(featureTypeStyle);
        newNode = sldTree.addObject(lastNode, featureTypeStyle, true);
    } else if (obj instanceof FeatureTypeStyle) {
        Rule rule = DefaultSymbols.createNewRule();
        SelectedSymbol.getInstance().addNewRule(rule);
        newNode = sldTree.addObject(lastNode, rule, true);
    }
    // Select the item just added
    if (newNode != null) {
        SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
        TreePath newPath = getPath(newNode);
        symbolTree.setSelectionPath(newPath);
        // Store current state of the SLD after the add
        Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
        UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
    }
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer)

Example 47 with Rule

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

the class SLDTreeTools method getRuleTreeNode.

/**
 * Gets the rule tree node.
 *
 * @return the rule tree node
 */
private DefaultMutableTreeNode getRuleTreeNode() {
    if (symbolTree != null) {
        TreePath path = symbolTree.getSelectionPath();
        DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object obj = lastNode.getUserObject();
        if (obj instanceof Symbolizer) {
            return (DefaultMutableTreeNode) lastNode.getParent();
        } else if (obj instanceof Rule) {
            return (DefaultMutableTreeNode) lastNode;
        }
    }
    return rootNode;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Rule(org.geotools.styling.Rule) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 48 with Rule

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

the class RuleTreeItem method getTreeString.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.item.SLDTreeItemInterface#getTreeString(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
     */
@Override
public String getTreeString(DefaultMutableTreeNode node, Object nodeObject) {
    Rule rule = (Rule) nodeObject;
    String name = "";
    if (rule != null) {
        if (rule.getName() != null) {
            name = rule.getName();
        }
    }
    return String.format("%s : %s", TITLE, name);
}
Also used : Rule(org.geotools.styling.Rule)

Example 49 with Rule

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

the class SLDTree method populateSLD.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.UpdateTreeStructureInterface#populateSLD()
     */
@Override
public void populateSLD() {
    reset();
    SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
    if (selectedSymbol != null) {
        StyledLayerDescriptor sld = selectedSymbol.getSld();
        rootNode.setUserObject(sld);
        treeModel.nodeChanged(rootNode);
        if (sld != null) {
            List<StyledLayer> styledLayerList = sld.layers();
            if (styledLayerList != null) {
                for (StyledLayer styledLayer : styledLayerList) {
                    DefaultMutableTreeNode styledLayerTreeNode = null;
                    List<Style> styleList = null;
                    if (styledLayer instanceof NamedLayerImpl) {
                        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                        styleList = namedLayerImpl.styles();
                        styledLayerTreeNode = addObject(rootNode, namedLayerImpl, true);
                    } else if (styledLayer instanceof UserLayerImpl) {
                        UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                        styleList = userLayerImpl.userStyles();
                        styledLayerTreeNode = addObject(rootNode, userLayerImpl, true);
                    }
                    if (styleList != null) {
                        for (Style style : styleList) {
                            DefaultMutableTreeNode styleTreeNode = addObject(styledLayerTreeNode, style, true);
                            for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                                DefaultMutableTreeNode ftsTreeNode = addObject(styleTreeNode, fts, true);
                                for (Rule rule : fts.rules()) {
                                    DefaultMutableTreeNode ruleTreeNode = addObject(ftsTreeNode, rule, true);
                                    for (Symbolizer symbolizer : rule.symbolizers()) {
                                        DefaultMutableTreeNode symbolizerTreeNode = addObject(ruleTreeNode, symbolizer, true);
                                        if ((symbolizer instanceof PointSymbolizer) || (symbolizer instanceof PolygonSymbolizer)) {
                                            addObject(symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getFill(symbolizer), true);
                                        }
                                        if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof LineSymbolizer)) {
                                            addObject(symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getStroke(symbolizer), true);
                                        }
                                        if (symbolizer instanceof RasterSymbolizer) {
                                            handleRasterSymbolizer(symbolizer, symbolizerTreeNode);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) PointSymbolizer(org.geotools.styling.PointSymbolizer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayerImpl(org.geotools.styling.UserLayerImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 50 with Rule

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

the class SLDExternalImagesTest method createTestPoint.

/**
 * Creates the test point.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPoint(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    PointSymbolizer point = styleFactory.createPointSymbolizer();
    rule.symbolizers().add(point);
    Graphic graphic = createGraphic(url, styleFactory);
    point.setGraphic(graphic);
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) StyleBuilder(org.geotools.styling.StyleBuilder) 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)

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