use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class DefaultSymbols method createNewPolygon.
/**
* Creates a new polygon symbol.
*
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createNewPolygon() {
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 = createDefaultPolygonSymbolizer();
rule.symbolizers().add(polygon);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SLDExternalImagesTest method testGetExternalImagesPolygon.
/**
* Test method for {@link
* com.sldeditor.common.data.SLDExternalImages#getExternalImages(java.net.URL,
* org.geotools.styling.StyledLayerDescriptor)}.
*/
@Test
public void testGetExternalImagesPolygon() {
SLDWriterImpl writer = new SLDWriterImpl();
File f = new File("D:/temp/test.png");
URL url = null;
URL resourceLocator = null;
try {
url = f.toURI().toURL();
resourceLocator = new URL(f.getParentFile().toURI().toURL().toExternalForm() + "/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
StyledLayerDescriptor polygonSLD = createTestPolygon(url);
List<String> imageList = SLDExternalImages.getExternalImages(resourceLocator, polygonSLD);
String result = writer.encodeSLD(resourceLocator, polygonSLD);
assertTrue(checkResult(f, result, 3));
assertEquals(3, imageList.size());
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SelectedSymbolTest method testIsRasterSymbol.
@Test
public void testIsRasterSymbol() {
SelectedSymbol.destroyInstance();
SelectedSymbol instance = SelectedSymbol.getInstance();
// Create point symbolizer
StyledLayerDescriptor sld = DefaultSymbols.createNewPoint();
instance.createNewSLD(sld);
instance.setSld(sld);
// No selection made
assertFalse(instance.isRasterSymbol());
Style style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
instance.setStyle(style);
assertFalse(instance.isRasterSymbol());
// Create polygon symbolizer
SelectedSymbol.destroyInstance();
instance = SelectedSymbol.getInstance();
sld = DefaultSymbols.createNewPolygon();
instance.createNewSLD(sld);
instance.setSld(sld);
// No selection made
assertFalse(instance.isRasterSymbol());
style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
instance.setStyle(style);
assertFalse(instance.isRasterSymbol());
// Create line symbolizer
SelectedSymbol.destroyInstance();
instance = SelectedSymbol.getInstance();
sld = DefaultSymbols.createNewLine();
instance.createNewSLD(sld);
instance.setSld(sld);
// No selection made
assertFalse(instance.isRasterSymbol());
style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
instance.setStyle(style);
assertFalse(instance.isRasterSymbol());
// Create raster symbolizer
SelectedSymbol.destroyInstance();
instance = SelectedSymbol.getInstance();
sld = DefaultSymbols.createNewRaster();
instance.createNewSLD(sld);
instance.setSld(sld);
// No selection made
assertFalse(instance.isRasterSymbol());
style = ((NamedLayer) sld.layers().get(0)).styles().get(0);
instance.setStyle(style);
assertTrue(instance.isRasterSymbol());
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SelectedSymbolTest method testGetSLD.
@Test
public void testGetSLD() {
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);
assertEquals(namedLayer, instance.getStyledLayer());
assertNull(instance.getRule());
assertNull(instance.getStyle());
assertNull(instance.getFeatureTypeStyle());
assertNull(instance.getSymbolizer());
System.out.println("Select style");
instance.addNewStyle(style);
instance.setStyle(style);
assertEquals(namedLayer, instance.getStyledLayer());
assertEquals(style, instance.getStyle());
assertNull(instance.getFeatureTypeStyle());
assertNull(instance.getRule());
assertNull(instance.getSymbolizer());
System.out.println("Select feature type style");
instance.addNewFeatureTypeStyle(fts);
instance.setFeatureTypeStyle(fts);
assertEquals(namedLayer, instance.getStyledLayer());
assertEquals(style, instance.getStyle());
assertEquals(fts, instance.getFeatureTypeStyle());
assertNull(instance.getRule());
assertNull(instance.getSymbolizer());
System.out.println("Select rule");
instance.addNewRule(rule);
instance.setRule(rule);
assertEquals(namedLayer, instance.getStyledLayer());
assertEquals(style, instance.getStyle());
assertEquals(fts, instance.getFeatureTypeStyle());
assertEquals(rule, instance.getRule());
assertNull(instance.getSymbolizer());
assertTrue(instance.hasOnlyOneRule());
System.out.println("Select symbolizer");
instance.addSymbolizerToRule(symbolizer);
instance.addNewRule(DefaultSymbols.createNewRule());
assertFalse(instance.hasOnlyOneRule());
assertEquals(-1, instance.getSymbolIndex());
instance.setSymbolizer(symbolizer);
assertEquals(namedLayer, instance.getStyledLayer());
assertEquals(style, instance.getStyle());
assertEquals(fts, instance.getFeatureTypeStyle());
assertEquals(rule, instance.getRule());
assertEquals(symbolizer, instance.getSymbolizer());
assertEquals(0, instance.getSymbolIndex());
// Get SLD structure
StyledLayerDescriptor actualSLD = instance.getSld();
assertEquals(sld, actualSLD);
StyledLayer[] actualStyledLayers = actualSLD.getStyledLayers();
assertEquals(1, actualStyledLayers.length);
NamedLayer actualNamedLayer = (NamedLayer) actualStyledLayers[0];
assertEquals(namedLayer, actualNamedLayer);
Style[] actualStyle = actualNamedLayer.getStyles();
assertEquals(1, actualStyle.length);
assertEquals(style, actualStyle[0]);
assertEquals(1, style.featureTypeStyles().size());
FeatureTypeStyle actualFeatureTypeStyle = style.featureTypeStyles().get(0);
assertEquals(fts, actualFeatureTypeStyle);
List<Rule> actualRules = actualFeatureTypeStyle.rules();
assertEquals(2, actualRules.size());
Rule actualRule = actualRules.get(0);
assertEquals(rule, actualRule);
assertEquals(1, actualRule.symbolizers().size());
assertEquals(symbolizer, actualRule.symbolizers().get(0));
}
use of org.geotools.styling.StyledLayerDescriptor 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());
}
Aggregations