Search in sources :

Example 11 with NamedLayerImpl

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

the class SLDTreeTools method setButtonState.

/**
 * Sets the buttons state.
 *
 * @param parentNode the parent node
 * @param selectedNode the new button state
 * @param currentGeometryType the current geometry type
 */
public void setButtonState(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode selectedNode, GeometryTypeEnum currentGeometryType) {
    boolean addButtonEnabled = true;
    boolean removeButtonEnabled = true;
    boolean addNamedLayerButtonEnabled = false;
    boolean addUserLayerButtonEnabled = false;
    boolean showMoveButtons = true;
    boolean hasMoreThan1Item = false;
    boolean isFirstSelected = false;
    boolean isLastSelected = false;
    boolean showLineArrowButtons = false;
    symbolizerButtonState.setGeometryType(currentGeometryType);
    Object obj = null;
    Object parentObj = null;
    if (selectedNode != null) {
        obj = selectedNode.getUserObject();
        if (parentNode != null) {
            parentObj = parentNode.getUserObject();
        }
        if (obj instanceof StyledLayerDescriptor) {
            addNamedLayerButtonEnabled = true;
            addUserLayerButtonEnabled = true;
            addButtonEnabled = false;
        } else if (obj instanceof StyledLayer) {
            if (parentObj != null) {
                StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
                hasMoreThan1Item = sld.layers().size() > 1;
                isFirstSelected = (obj == sld.layers().get(0));
                isLastSelected = (obj == sld.layers().get(sld.layers().size() - 1));
            }
        } else if (obj instanceof Style) {
            if (parentObj != null) {
                if (parentObj instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
                    hasMoreThan1Item = namedLayer.styles().size() > 1;
                    isFirstSelected = (obj == namedLayer.styles().get(0));
                    isLastSelected = (obj == namedLayer.styles().get(namedLayer.styles().size() - 1));
                }
            }
        } else if (obj instanceof FeatureTypeStyle) {
            if (parentObj != null) {
                Style style = (Style) parentObj;
                hasMoreThan1Item = style.featureTypeStyles().size() > 1;
                isFirstSelected = (obj == style.featureTypeStyles().get(0));
                isLastSelected = (obj == style.featureTypeStyles().get(style.featureTypeStyles().size() - 1));
            }
        } else if (obj instanceof Rule) {
            symbolizerButtonState.showSymbolizerButtons();
            addButtonEnabled = false;
            if (parentObj != null) {
                FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
                hasMoreThan1Item = fts.rules().size() > 1;
                isFirstSelected = (obj == fts.rules().get(0));
                isLastSelected = (obj == fts.rules().get(fts.rules().size() - 1));
            }
        } else if (obj instanceof Symbolizer) {
            symbolizerButtonState.showSymbolizerButtons();
            addButtonEnabled = false;
            if (parentObj != null) {
                if (parentObj instanceof Rule) {
                    Rule rule = (Rule) parentObj;
                    hasMoreThan1Item = rule.symbolizers().size() > 1;
                    isFirstSelected = (obj == rule.symbolizers().get(0));
                    isLastSelected = (obj == rule.symbolizers().get(rule.symbolizers().size() - 1));
                }
            }
            showLineArrowButtons = (obj instanceof LineSymbolizer);
        } else {
            addButtonEnabled = false;
            removeButtonEnabled = false;
            showMoveButtons = false;
        }
    }
    btnAddNamedLayerButton.setVisible(addNamedLayerButtonEnabled);
    btnAddUserLayerButton.setVisible(addUserLayerButtonEnabled);
    btnAddButton.setVisible(addButtonEnabled);
    // All symbolizer types are allowed be added to an SLD
    boolean allSymbolizer = symbolizerButtonState.isMarkerVisible(parentObj, obj) || symbolizerButtonState.isLineVisible(parentObj, obj) || symbolizerButtonState.isPolygonVisible(parentObj, obj) || symbolizerButtonState.isRasterVisible(parentObj, obj);
    btnNewMarker.setVisible(allSymbolizer);
    btnNewLine.setVisible(allSymbolizer);
    btnNewImageOutlineLine.setVisible(symbolizerButtonState.isImageOutlineLineVisible(parentObj, obj));
    btnNewPolygon.setVisible(allSymbolizer);
    btnNewImageOutlinePolygon.setVisible(symbolizerButtonState.isImageOutlinePolygonVisible(parentObj, obj));
    btnNewRaster.setVisible(allSymbolizer);
    btnNewText.setVisible(symbolizerButtonState.isTextVisible(parentObj, obj));
    btnRemoveMarker.setVisible(removeButtonEnabled);
    // Up / down buttons
    btnMoveUp.setVisible(showMoveButtons);
    btnMoveUp.setEnabled(hasMoreThan1Item && !isFirstSelected);
    btnMoveDown.setVisible(showMoveButtons);
    btnMoveDown.setEnabled(hasMoreThan1Item && !isLastSelected);
    btnSourceArrowButton.setVisible(showLineArrowButtons);
    btnDestArrowButton.setVisible(showLineArrowButtons);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) 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) 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 12 with NamedLayerImpl

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

the class NameLayerTreeItem 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) {
    NamedLayerImpl namedLayer = (NamedLayerImpl) nodeObject;
    String name = "";
    if (namedLayer != null) {
        if (namedLayer.getName() != null) {
            name = namedLayer.getName();
        }
    }
    return String.format("%s : %s", TITLE, name);
}
Also used : NamedLayerImpl(org.geotools.styling.NamedLayerImpl)

Example 13 with NamedLayerImpl

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

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

the class RenderSymbolTest method testRenderSymbol.

/**
 * Test method for {@link com.sldeditor.render.RenderSymbol#RenderSymbol()}.
 */
@Test
public void testRenderSymbol() {
    RenderSymbol symbol = new RenderSymbol();
    StyledLayerDescriptor sld = createSLD();
    StyledLayer styledLayer = sld.layers().get(0);
    if (styledLayer instanceof NamedLayerImpl) {
        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
        Style expectedStyle = namedLayerImpl.styles().get(0);
        SelectedSymbol.getInstance().setSld(sld);
        Style actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
        assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
        assertEquals(expectedStyle.getName(), actualStyle.getName());
        Rule expectedRule = expectedStyle.featureTypeStyles().get(0).rules().get(1);
        SelectedSymbol.getInstance().setFeatureTypeStyle(expectedStyle.featureTypeStyles().get(0));
        SelectedSymbol.getInstance().setRule(expectedRule);
        actualStyle = symbol.getRenderStyle(SelectedSymbol.getInstance());
        assertNull(actualStyle.featureTypeStyles().get(0).rules().get(0).getFilter());
        assertEquals(expectedRule.getName(), actualStyle.featureTypeStyles().get(0).rules().get(0).getName());
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) RenderSymbol(com.sldeditor.render.RenderSymbol) Style(org.geotools.styling.Style) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 15 with NamedLayerImpl

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

the class RuleRenderVisitorTest method testRuleRenderVisitor.

/**
 * Test rule render visitor.
 */
@Test
public void testRuleRenderVisitor() {
    StyledLayerDescriptor sld = createSLD();
    StyledLayer styledLayer = sld.layers().get(0);
    if (styledLayer instanceof NamedLayerImpl) {
        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
        Style style = namedLayerImpl.styles().get(0);
        FeatureTypeStyle ftsToRender = style.featureTypeStyles().get(0);
        // Just find matching feature type style
        int symbolIndex = 0;
        RuleRenderVisitor visitor = new RuleRenderVisitor(ftsToRender, null, symbolIndex, new RuleRenderOptions());
        style.accept(visitor);
        Style copy = (Style) visitor.getCopy();
        Rule ruleToRender = ftsToRender.rules().get(0);
        Rule actualRule = copy.featureTypeStyles().get(0).rules().get(0);
        // Filters should be null
        assertNull(actualRule.getFilter());
        assertEquals(ruleToRender.symbolizers(), actualRule.symbolizers());
        // Now try and find 2nd rule, 2nd symbolizer
        ruleToRender = ftsToRender.rules().get(1);
        symbolIndex = 1;
        visitor = new RuleRenderVisitor(ftsToRender, ruleToRender, symbolIndex, new RuleRenderOptions());
        style.accept(visitor);
        copy = (Style) visitor.getCopy();
        assertEquals(1, copy.featureTypeStyles().get(0).rules().size());
        actualRule = copy.featureTypeStyles().get(0).rules().get(0);
        assertNull(actualRule.getFilter());
        assertEquals(1, actualRule.symbolizers().size());
        assertEquals(ruleToRender.symbolizers().get(1), actualRule.symbolizers().get(0));
    }
}
Also used : RuleRenderOptions(com.sldeditor.ui.render.RuleRenderOptions) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) RuleRenderVisitor(com.sldeditor.render.RuleRenderVisitor) 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) Test(org.junit.Test)

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