Search in sources :

Example 6 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol 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 7 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testRemoveRasterImageOutline.

@Test
public void testRemoveRasterImageOutline() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    instance.removeRasterImageOutline(null);
    RasterSymbolizer rasterSymbol = DefaultSymbols.createDefaultRasterSymbolizer();
    rasterSymbol.setImageOutline(DefaultSymbols.createDefaultLineSymbolizer());
    instance.removeRasterImageOutline(rasterSymbol);
    assertNull(rasterSymbol.getImageOutline());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Test(org.junit.Test)

Example 8 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testRemove.

/**
 * Test method for
 * {@link com.sldeditor.common.data.SelectedSymbol#removeFeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)}.
 */
@Test
public void testRemove() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    Rule rule1 = DefaultSymbols.createNewRule();
    Rule rule2 = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts1 = DefaultSymbols.createNewFeatureTypeStyle();
    FeatureTypeStyle fts2 = DefaultSymbols.createNewFeatureTypeStyle();
    Style style1 = DefaultSymbols.createNewStyle();
    Style style2 = DefaultSymbols.createNewStyle();
    Style style3 = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer polygonSymbolizer1 = DefaultSymbols.createDefaultPolygonSymbolizer();
    PolygonSymbolizer polygonSymbolizer2 = DefaultSymbols.createDefaultPolygonSymbolizer();
    PolygonSymbolizer polygonSymbolizer3 = DefaultSymbols.createDefaultPolygonSymbolizer();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyledLayer(namedLayer);
    instance.addNewStyle(style1);
    instance.addNewStyle(style2);
    instance.addNewStyle(style3);
    instance.setStyle(style1);
    instance.addNewFeatureTypeStyle(fts1);
    instance.addNewFeatureTypeStyle(fts2);
    instance.setFeatureTypeStyle(fts1);
    instance.addNewRule(rule1);
    instance.setRule(rule1);
    instance.addSymbolizerToRule(polygonSymbolizer1);
    instance.addSymbolizerToRule(polygonSymbolizer2);
    instance.addSymbolizerToRule(polygonSymbolizer3);
    instance.addNewRule(rule2);
    Rule ruleToTest = instance.getRule();
    List<Symbolizer> symbolizerList = ruleToTest.symbolizers();
    assertEquals(3, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer3);
    assertEquals(2, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer3);
    assertEquals(2, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer2);
    assertEquals(1, symbolizerList.size());
    instance.removeSymbolizer(polygonSymbolizer1);
    assertEquals(0, symbolizerList.size());
    List<Rule> ruleList = instance.getFeatureTypeStyle().rules();
    assertEquals(2, ruleList.size());
    instance.removeRule(rule2);
    assertEquals(1, ruleList.size());
    instance.removeRule(rule1);
    assertEquals(0, ruleList.size());
    instance.removeRule(rule2);
    assertEquals(0, ruleList.size());
    List<FeatureTypeStyle> ftsList = instance.getStyle().featureTypeStyles();
    assertEquals(2, ftsList.size());
    instance.removeFeatureTypeStyle(fts2);
    assertEquals(1, ftsList.size());
    instance.removeFeatureTypeStyle(fts2);
    assertEquals(1, ftsList.size());
    instance.removeFeatureTypeStyle(fts1);
    assertEquals(0, ftsList.size());
    List<Style> styleList = ((NamedLayer) instance.getStyledLayer()).styles();
    assertEquals(3, styleList.size());
    instance.removeStyle(style3);
    assertEquals(2, styleList.size());
    instance.removeStyle(style2);
    assertEquals(1, styleList.size());
    instance.removeStyle(style2);
    assertEquals(1, styleList.size());
    instance.removeStyle(style1);
    assertEquals(0, styleList.size());
    instance.removeStyledLayerDescriptor(sld);
    assertEquals(sld, instance.getSld());
    instance.removeUserNamedLayer(namedLayer);
    assertEquals(1, instance.getSld().layers().size());
    instance.removeUserNamedLayer(namedLayer);
    assertEquals(0, instance.getSld().layers().size());
    instance.removeUserNamedLayer(namedLayer);
    assertEquals(0, instance.getSld().layers().size());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) 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) 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) Test(org.junit.Test)

Example 9 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testGetGraphic.

/**
 * Test method for {@link com.sldeditor.common.data.SelectedSymbol#getGraphic()}.
 */
@Test
public void testGetGraphic() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    // CHECKSTYLE:OFF
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    // CHECKSTYLE:ON
    instance.createNewSLD(sld);
    instance.setSld(sld);
    System.out.println("Select named layer");
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyle(style);
    instance.setStyle(style);
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    instance.addNewRule(rule);
    instance.setRule(rule);
    instance.addSymbolizerToRule(symbolizer);
    instance.setSymbolizer(symbolizer);
    Graphic graphic = getGraphic(symbolizer);
    assertNull(graphic);
    Fill graphicFill = DefaultSymbols.createDefaultGraphicFill();
    PolygonSymbolizer newSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    newSymbolizer.setFill(graphicFill);
    instance.addSymbolizerToRule(newSymbolizer);
    instance.setSymbolizer(newSymbolizer);
    graphic = getGraphic(newSymbolizer);
    assertNotNull(graphic);
    assertTrue(instance.hasFill());
    assertTrue(instance.hasStroke());
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    instance.addSymbolizerToRule(lineSymbolizer);
    instance.setSymbolizer(lineSymbolizer);
    graphic = getGraphic(lineSymbolizer);
    assertNull(graphic);
    assertFalse(instance.hasFill());
    assertTrue(instance.hasStroke());
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    instance.addSymbolizerToRule(pointSymbolizer);
    instance.setSymbolizer(pointSymbolizer);
    graphic = getGraphic(pointSymbolizer);
    assertNotNull(graphic);
    assertTrue(instance.hasFill());
    assertFalse(instance.hasStroke());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) 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) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 10 with SelectedSymbol

use of com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.

the class SelectedSymbolTest method testReplacment.

/**
 * Test method for
 * {@link com.sldeditor.common.data.SelectedSymbol#removeRule(org.geotools.styling.Rule)}.
 */
@Test
public void testReplacment() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    instance.createNewSLD(sld);
    instance.setSld(sld);
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyle(style);
    instance.setStyle(style);
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    instance.addNewRule(rule);
    instance.setRule(rule);
    instance.addSymbolizerToRule(polygonSymbolizer);
    instance.addNewRule(DefaultSymbols.createNewRule());
    instance.setSymbolizer(polygonSymbolizer);
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    DummySLDTreeUpdated dummyTreeUpdated = new DummySLDTreeUpdated();
    instance.setTreeUpdateListener(dummyTreeUpdated);
    instance.replaceSymbolizer(lineSymbolizer);
    assertEquals(lineSymbolizer, instance.getSymbolizer());
    assertEquals(dummyTreeUpdated.objectOld, polygonSymbolizer);
    assertEquals(dummyTreeUpdated.objectNew, lineSymbolizer);
    Rule newRule = DefaultSymbols.createNewRule();
    newRule.setTitle("Replacement rule");
    instance.replaceRule(newRule);
    assertEquals(newRule, instance.getRule());
    assertNull(instance.getSymbolizer());
    FeatureTypeStyle newFts = DefaultSymbols.createNewFeatureTypeStyle();
    newFts.setName("Replacement fts");
    instance.replaceFeatureTypeStyle(newFts);
    assertEquals(newFts, instance.getFeatureTypeStyle());
    assertNull(instance.getRule());
    Style newStyle = DefaultSymbols.createNewStyle();
    newStyle.setName("Replacement style");
    instance.replaceStyle(newStyle);
    assertEquals(newStyle, instance.getStyle());
    assertNull(instance.getRule());
    NamedLayer newNamedLayer = DefaultSymbols.createNewNamedLayer();
    newNamedLayer.setName("Replacement named layer");
    instance.replaceStyledLayer(newNamedLayer);
    assertEquals(newNamedLayer, instance.getStyledLayer());
    assertNull(instance.getStyle());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) 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) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Aggregations

SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)7 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)6 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)6 Style (org.geotools.styling.Style)6 Test (org.junit.Test)6 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 NamedLayer (org.geotools.styling.NamedLayer)5 Rule (org.geotools.styling.Rule)5 Symbolizer (org.geotools.styling.Symbolizer)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 PointSymbolizer (org.geotools.styling.PointSymbolizer)4 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)4 PopulateDetailsInterface (com.sldeditor.ui.iface.PopulateDetailsInterface)2 StyledLayer (org.geotools.styling.StyledLayer)2 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)1 CardLayout (java.awt.CardLayout)1 File (java.io.File)1 Fill (org.geotools.styling.Fill)1