Search in sources :

Example 1 with NamedLayerImpl

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

the class SLDTreeToolsTest method testMoveItemNamedLayer.

/**
 * Check NamedLayers Test method for
 * {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
 */
@Test
public void testMoveItemNamedLayer() {
    TestRenderSymbolInterface renderSymbol = new TestRenderSymbolInterface();
    List<RenderSymbolInterface> renderList = new ArrayList<RenderSymbolInterface>();
    renderList.add(renderSymbol);
    SLDTreeTools treeTools = new SLDTreeTools();
    TestSLDTree sldTree = new TestSLDTree(renderList, treeTools);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    SelectedSymbol.getInstance().setSld(sld);
    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    DefaultMutableTreeNode namedLayer1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    NamedLayerImpl namedLayer1 = (NamedLayerImpl) namedLayer1Node.getUserObject();
    String expectedNamedLayer1 = "named layer 1";
    namedLayer1.setName(expectedNamedLayer1);
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    DefaultMutableTreeNode namedLayer2Node = (DefaultMutableTreeNode) rootNode.getChildAt(1);
    NamedLayerImpl namedLayer2 = (NamedLayerImpl) namedLayer2Node.getUserObject();
    String expectedNamedLayer2 = "named layer 2";
    namedLayer2.setName(expectedNamedLayer2);
    // Have 2 named layers
    TreeSelectionData data = new TreeSelectionData();
    data.setLayerIndex(1);
    sldTree.selectTreeItem(data);
    // Move named layer 2 so that they are reversed
    treeTools.moveItem(true);
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0);
    NamedLayerImpl testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Try and move 'named layer 2' up to index -1 which is invalid, result should be same as
    // last time
    data.setLayerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Move it back
    data.setLayerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(1);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Move it beyond the end of the list, should be the same answer as before
    data.setLayerIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(1);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Undo the last valid move
    UndoManager.getInstance().undo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Redo the last valid move
    UndoManager.getInstance().redo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(1);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) TreeSelectionData(com.sldeditor.TreeSelectionData) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) ArrayList(java.util.ArrayList) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Example 2 with NamedLayerImpl

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

the class SLDUtils method findRule.

/**
 * Find rule.
 *
 * @param sld the sld
 * @param ruleToFind the rule to find
 * @param otherSLD the other SLD
 * @return the rule
 */
public static Rule findRule(StyledLayerDescriptor sld, Rule ruleToFind, StyledLayerDescriptor otherSLD) {
    if (sld != null) {
        List<StyledLayer> styledLayerList = sld.layers();
        if (styledLayerList != null) {
            int styledLayerIndex = 0;
            int styleIndex = 0;
            int ftsIndex = 0;
            int ruleIndex = 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()) {
                                if (rule == ruleToFind) {
                                    return findEquivalentRule(otherSLD, styledLayerIndex, isNamedLayer, styleIndex, ftsIndex, ruleIndex);
                                }
                                ruleIndex++;
                            }
                            ftsIndex++;
                        }
                        styleIndex++;
                    }
                }
                styledLayerIndex++;
            }
        }
    }
    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 3 with NamedLayerImpl

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

the class SelectedSymbol method replaceStyle.

/**
 * Replace style.
 *
 * @param newStyle the new style
 */
public void replaceStyle(Style newStyle) {
    List<Style> styleList = null;
    if (this.symbolData.getStyledLayer() instanceof NamedLayerImpl) {
        NamedLayerImpl namedLayer = (NamedLayerImpl) this.symbolData.getStyledLayer();
        styleList = namedLayer.styles();
    } else if (this.symbolData.getStyledLayer() instanceof UserLayerImpl) {
        UserLayerImpl userLayer = (UserLayerImpl) this.symbolData.getStyledLayer();
        styleList = userLayer.userStyles();
    }
    if (styleList != null) {
        Style oldStyle = null;
        int indexFound = -1;
        int index = 0;
        for (Style style : styleList) {
            if (style == this.symbolData.getStyle()) {
                oldStyle = style;
                indexFound = index;
                break;
            } else {
                index++;
            }
        }
        if (indexFound > -1) {
            styleList.remove(indexFound);
            styleList.add(indexFound, newStyle);
            setStyle(newStyle);
        }
        for (SLDTreeUpdatedInterface listener : treeUpdateListenerList) {
            listener.updateNode(oldStyle, newStyle);
        }
    }
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 4 with NamedLayerImpl

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

the class SelectedSymbol method hasOnlyOneRule.

/**
 * Checks for only one rule.
 *
 * @return true, if successful
 */
public boolean hasOnlyOneRule() {
    boolean oneRule = false;
    StyledLayer[] styledLayers = sld.getStyledLayers();
    int noOfRules = 0;
    if (styledLayers != null) {
        for (StyledLayer styledLayer : styledLayers) {
            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) {
                for (Style style : styleList) {
                    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                        noOfRules += fts.rules().size();
                    }
                }
            }
        }
    }
    oneRule = (noOfRules == 1);
    logger.debug(String.format("Number of rules : %d", noOfRules));
    return oneRule;
}
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 5 with NamedLayerImpl

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

the class SelectedSymbol method updateInternalData.

/**
 * Update internal data based on the supplied mask.
 *
 * @param maskValue the mask value
 */
private void updateInternalData(SelectedSymbolMask.SymbolMaskEnum maskValue) {
    SymbolData localSymbolData = new SymbolData();
    SelectedSymbolMask mask = new SelectedSymbolMask(maskValue);
    if (sld == null) {
        return;
    }
    StyledLayer[] styledLayers = sld.getStyledLayers();
    if (styledLayers != null) {
        localSymbolData.initialiseSelectedStyledLayerIndex();
        for (StyledLayer styledLayer : styledLayers) {
            localSymbolData.setStyledLayer(styledLayer);
            if (styledLayer == symbolData.getStyledLayer()) {
                this.symbolData.update(localSymbolData);
                return;
            }
            List<Style> styleList = null;
            if ((styledLayer instanceof NamedLayerImpl) && mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLED_LAYER)) {
                NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                styleList = namedLayerImpl.styles();
            } else if ((styledLayer instanceof UserLayerImpl) && mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLED_LAYER)) {
                UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                styleList = userLayerImpl.userStyles();
            }
            if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLE) && (styleList != null)) {
                localSymbolData.initialiseSelectedStyleIndex();
                for (Style style : styleList) {
                    localSymbolData.setStyle(style);
                    if (style == symbolData.getStyle()) {
                        this.symbolData.update(localSymbolData);
                        return;
                    }
                    if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_FEATURE_TYPE_STYLE)) {
                        localSymbolData.initialiseSelectedFTSIndex();
                        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                            localSymbolData.setFeatureTypeStyle(fts);
                            if (fts == symbolData.getFeatureTypeStyle()) {
                                this.symbolData.update(localSymbolData);
                                return;
                            }
                            if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_RULE)) {
                                localSymbolData.initialiseSelectedRuleIndex();
                                for (Rule rule : fts.rules()) {
                                    localSymbolData.setRule(rule);
                                    if (rule == symbolData.getRule()) {
                                        this.symbolData.update(localSymbolData);
                                        return;
                                    }
                                    if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_SYMBOLIZER)) {
                                        localSymbolData.initialiseSelectedSymbolizerIndex();
                                        for (Symbolizer symbol : rule.symbolizers()) {
                                            localSymbolData.setSymbolizer(symbol);
                                            if (symbol == this.symbolData.getSymbolizer()) {
                                                this.symbolData.update(localSymbolData);
                                                return;
                                            } else {
                                                localSymbolData.incrementSelectedSymbolizerIndex();
                                            }
                                        }
                                    }
                                    localSymbolData.incrementSelectedRuleIndex();
                                }
                            }
                            localSymbolData.incrementSelectedFTSIndex();
                        }
                    }
                    localSymbolData.incrementSelectedStyleIndex();
                }
            }
            localSymbolData.incrementSelectedStyledLayerIndex();
        }
    }
}
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) RasterSymbolizer(org.geotools.styling.RasterSymbolizer)

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