Search in sources :

Example 21 with NamedLayer

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

the class SLDExternalImagesTest method createTestPolygon.

/**
 * Creates the test polygon.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPolygon(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);
    PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
    rule.symbolizers().add(polygon);
    Graphic graphicFill1 = createGraphic(url, styleFactory);
    Graphic graphicFill2 = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);
    Fill fill = styleFactory.createFill(null, null, null, graphicFill1);
    polygon.setFill(fill);
    Stroke stroke = styleFactory.createStroke(null, null, null, null, null, null, null, graphicFill2, graphicStroke);
    polygon.setStroke(stroke);
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) 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)

Example 22 with NamedLayer

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

the class SLDExternalImagesTest method createTestLine.

/**
 * Creates the test line.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestLine(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);
    LineSymbolizer line = styleFactory.createLineSymbolizer();
    rule.symbolizers().add(line);
    Graphic graphicFill = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);
    Stroke stroke = styleFactory.createStroke(null, null, null, null, null, null, null, graphicFill, graphicStroke);
    line.setStroke(stroke);
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Stroke(org.geotools.styling.Stroke) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) LineSymbolizer(org.geotools.styling.LineSymbolizer) 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)

Example 23 with NamedLayer

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

the class SLDUtilsTest method testCreateSLDFromStringFile.

@Test
public void testCreateSLDFromStringFile() {
    StyleWrapper wrapper = new StyleWrapper();
    SLDData sldData = new SLDData(wrapper, expectedSld);
    String filename = "D:/tmp/test.sld";
    File file = new File(filename);
    sldData.setSLDFile(file);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(null);
    assertNull(sld);
    sld = SLDUtils.createSLDFromString(sldData);
    StyledLayer[] styledLayers = sld.getStyledLayers();
    NamedLayer namedLayer = (NamedLayer) styledLayers[0];
    Style[] actualStyles = namedLayer.getStyles();
    PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
    assertEquals("circle", mark.getWellKnownName().toString());
    // Check resource locator
    try {
        URL url = file.getParentFile().toURI().toURL();
        String actualResourceLocator = sldData.getResourceLocator().toExternalForm();
        String expectedResourcelocator = url.toExternalForm();
        assertTrue(expectedResourcelocator.compareTo(actualResourceLocator) == 0);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) MalformedURLException(java.net.MalformedURLException) StyledLayer(org.geotools.styling.StyledLayer) MarkImpl(org.geotools.styling.MarkImpl) URL(java.net.URL) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) File(java.io.File) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Example 24 with NamedLayer

use of org.geotools.styling.NamedLayer 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 25 with NamedLayer

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

Aggregations

NamedLayer (org.geotools.styling.NamedLayer)51 Style (org.geotools.styling.Style)44 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)44 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)42 Rule (org.geotools.styling.Rule)38 Test (org.junit.Test)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)13 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 LineSymbolizer (org.geotools.styling.LineSymbolizer)11 StyledLayer (org.geotools.styling.StyledLayer)10 Symbolizer (org.geotools.styling.Symbolizer)8 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)7 SLDData (com.sldeditor.common.data.SLDData)6 TextSymbolizer (org.geotools.styling.TextSymbolizer)6 FilterFactory (org.opengis.filter.FilterFactory)6 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)5 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)5