use of org.geotools.styling.NamedLayer 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());
}
use of org.geotools.styling.NamedLayer 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.NamedLayer 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.NamedLayer in project sldeditor by robward-scisys.
the class NewPointSLDTest method testNewPointSLD.
/**
* Test new point sld.
*/
@Test
public void testNewPointSLD() {
NewPointSLD newData = new NewPointSLD();
StyledLayerDescriptor sld = newData.create();
assertTrue(sld.layers().size() == 1);
StyledLayer styledLayer = sld.layers().get(0);
NamedLayer namedLayer = (NamedLayer) styledLayer;
Symbolizer symbolizer = namedLayer.styles().get(0).featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertTrue(symbolizer instanceof PointSymbolizer);
}
use of org.geotools.styling.NamedLayer in project sldeditor by robward-scisys.
the class NameLayerTreeItemTest method testGetTreeString.
/**
* Test method for
* {@link com.sldeditor.ui.tree.item.NameLayerTreeItem#getTreeString(java.lang.Object)}.
*/
@Test
public void testGetTreeString() {
NameLayerTreeItem item = new NameLayerTreeItem();
String actualValue = item.getTreeString(null, null);
String expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.namedlayer"), "");
assertTrue(actualValue.compareTo(expectedValue) == 0);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
actualValue = item.getTreeString(null, namedLayer);
assertTrue(actualValue.compareTo(expectedValue) == 0);
String expectedName = "test name";
namedLayer.setName(expectedName);
actualValue = item.getTreeString(null, namedLayer);
expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.namedlayer"), expectedName);
assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Aggregations