Search in sources :

Example 16 with NamedLayerImpl

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

the class SLDTreeTools method moveItem.

/**
 * Move item within a list. The direction parameter determines which way the item is moved.
 *
 * @param moveUp the move up flags (true), or down (false)
 */
public void moveItem(boolean moveUp) {
    if (symbolTree == null) {
        return;
    }
    if (treeModel == null) {
        return;
    }
    if (sldTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (lastNode == null) {
        return;
    }
    Object obj = lastNode.getUserObject();
    if (obj == null) {
        return;
    }
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) lastNode.getParent();
    if (parentNode == null) {
        return;
    }
    Object parentObj = parentNode.getUserObject();
    if (parentObj == null) {
        return;
    }
    // Calculate index offset value based on direction
    int direction = moveUp ? -1 : 1;
    // Store current state of the SLD before the move
    // CHECKSTYLE:OFF
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof StyledLayer) {
        StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
        // NamedLayerImpl.equals() doesn't work in the way I
        // want it to, so indexOf() does not work
        boolean found = false;
        int index = 0;
        for (StyledLayer styledLayer : sld.layers()) {
            if (styledLayer == obj) {
                found = true;
                break;
            } else {
                index++;
            }
        }
        if (found && ((index + direction) >= 0) && (index + direction) < sld.layers().size()) {
            StyledLayer styledLayer = sld.layers().remove(index);
            sld.layers().add(index + direction, styledLayer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Style) {
        if (parentObj instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
            int index = namedLayer.styles().indexOf(obj);
            if (((index + direction) >= 0) && (index + direction) < namedLayer.styles().size()) {
                Style style = namedLayer.styles().remove(index);
                namedLayer.styles().add(index + direction, style);
                treeModel.removeNodeFromParent(lastNode);
                treeModel.insertNodeInto(lastNode, parentNode, index + direction);
            } else {
                return;
            }
        }
    } else if (obj instanceof FeatureTypeStyle) {
        Style style = (Style) parentObj;
        int index = style.featureTypeStyles().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < style.featureTypeStyles().size()) {
            FeatureTypeStyle fts = style.featureTypeStyles().remove(index);
            style.featureTypeStyles().add(index + direction, fts);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Rule) {
        FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
        int index = fts.rules().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < fts.rules().size()) {
            Rule rule = fts.rules().remove(index);
            fts.rules().add(index + direction, rule);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Symbolizer) {
        Rule rule = (Rule) parentObj;
        int index = rule.symbolizers().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < rule.symbolizers().size()) {
            Symbolizer symbolizer = rule.symbolizers().remove(index);
            rule.symbolizers().add(index + direction, symbolizer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    }
    // Refresh the tree structure. Not very efficient but gets result wanted.
    // The node has been moved in the tree above. Now going to refresh model.
    treeModel.nodeStructureChanged(lastNode);
    // Get path for item moved
    TreePath newNodePath = getPath(lastNode);
    int[] selectedRows = new int[1];
    selectedRows[0] = symbolTree.getRowForPath(newNodePath);
    // Find the row of item moved
    // Now clear tree structure and re-populate, inefficient but it means
    // that all items are expanded as required.
    SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
    // Make item moved selected again
    symbolTree.setSelectionRows(selectedRows);
    // Re-render the symbol
    if (renderList != null) {
        for (RenderSymbolInterface render : renderList) {
            render.renderSymbol();
        }
    }
    // Store current state of the SLD after the move
    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) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) 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) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreePath(javax.swing.tree.TreePath) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 17 with NamedLayerImpl

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

the class SLDExternalImages method externalGraphicSymbolVisitor.

/**
 * Find the SLD graphical symbols.
 *
 * @param resourceLocator the resource locator
 * @param sld the sld
 * @param externalImageList the external image list
 * @param process the process
 */
private static void externalGraphicSymbolVisitor(URL resourceLocator, StyledLayerDescriptor sld, List<String> externalImageList, ProcessGraphicSymbolInterface process) {
    if (sld == null) {
        return;
    }
    if (process == null) {
        return;
    }
    for (StyledLayer styledLayer : sld.layers()) {
        List<Style> styles = null;
        if (styledLayer instanceof NamedLayer) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            styles = namedLayer.styles();
        } else if (styledLayer instanceof UserLayer) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
            styles = userLayer.userStyles();
        }
        if (styles != null) {
            for (Style style : styles) {
                for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                    for (Rule rule : fts.rules()) {
                        for (Symbolizer symbolizer : rule.symbolizers()) {
                            if (symbolizer instanceof PointSymbolizer) {
                                PointSymbolizer point = (PointSymbolizer) symbolizer;
                                if (point.getGraphic() != null) {
                                    process.processGraphicalSymbol(resourceLocator, point.getGraphic().graphicalSymbols(), externalImageList);
                                }
                            } else if (symbolizer instanceof LineSymbolizer) {
                                LineSymbolizer line = (LineSymbolizer) symbolizer;
                                updateStroke(resourceLocator, line.getStroke(), externalImageList, process);
                            } else if (symbolizer instanceof PolygonSymbolizer) {
                                PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer;
                                updateStroke(resourceLocator, polygon.getStroke(), externalImageList, process);
                                updateFill(resourceLocator, polygon.getFill(), externalImageList, process);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) 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) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer)

Example 18 with NamedLayerImpl

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

the class SLDUtils method findEquivalentSymbolizer.

/**
 * Find equivalent symbolizer in another SLD.
 *
 * @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
 * @param symbolizerIndex the symbolizer index
 * @return the symbolizer
 */
private static Symbolizer findEquivalentSymbolizer(StyledLayerDescriptor otherSLD, int styledLayerIndex, boolean isNamedLayer, int styleIndex, int ftsIndex, int ruleIndex, int symbolizerIndex) {
    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);
                    Rule rule = fts.rules().get(ruleIndex);
                    return rule.symbolizers().get(symbolizerIndex);
                }
            } 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) Rule(org.geotools.styling.Rule)

Example 19 with NamedLayerImpl

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

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

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