use of org.geotools.styling.FeatureTypeStyle 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;
}
use of org.geotools.styling.FeatureTypeStyle 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());
}
use of org.geotools.styling.FeatureTypeStyle 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());
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class SymbolDataTest method testSetFeatureTypeStyle.
@Test
public void testSetFeatureTypeStyle() {
SymbolData symbolData = new SymbolData();
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
symbolData.setFeatureTypeStyle(fts);
assertEquals(fts, symbolData.getFeatureTypeStyle());
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class VendorOptionManagerTest method testLoadSLDFile.
/**
* Test method for {@link com.sldeditor.common.vendoroption.VendorOptionManager#getVendorOptionVersion()}.
*/
@Test
public void testLoadSLDFile() {
VendorOptionManager.destroyInstance();
PrefData prefData = PrefManager.getInstance().getPrefData();
List<VersionData> vendorOptionList = new ArrayList<VersionData>();
VersionData actualPrefVO = VersionData.decode(GeoServerVendorOption.class, "2.4.2");
vendorOptionList.add(actualPrefVO);
prefData.setVendorOptionVersionList(vendorOptionList);
PrefManager.getInstance().setPrefData(prefData);
SLDData sldData = new SLDData(null, null);
StyledLayerDescriptor sld = null;
VendorOptionManager.getInstance().addVendorOptionListener(obj);
obj.vendorOptionVersionsList.clear();
// No SLD Editor file, SLD is empty so it should you PrefManager default set above
VendorOptionManager.getInstance().loadSLDFile(null, sld, sldData);
assertEquals(1, obj.vendorOptionVersionsList.size());
assertEquals(actualPrefVO, obj.vendorOptionVersionsList.get(0));
// No SLD Editor file, SLD contains PointSymboliser with vendor
// option so it should use the SLD vendor option
obj.vendorOptionVersionsList.clear();
sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedNameValue = "rule test value";
rule.setName(expectedNameValue);
PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
VersionData testVersionData = VersionData.decode(GeoServerVendorOption.class, "2.8.0");
VendorOptionManager.getInstance().loadSLDFile(new GetMinimumVersionInterface() {
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
VendorOptionInfo vendorOptionInfo = new VendorOptionInfo("qgis://", new VendorOptionVersion(testVersionData.getVendorOptionType(), testVersionData), "");
VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, vendorOptionInfo);
vendorOptionsPresentList.add(voPresent);
}
}, sld, sldData);
assertEquals(1, obj.vendorOptionVersionsList.size());
assertEquals(testVersionData, obj.vendorOptionVersionsList.get(0));
// Now set the SLD Editor file vendor option
obj.vendorOptionVersionsList.clear();
List<VersionData> sldEditorVendorOptionList = new ArrayList<VersionData>();
VersionData testVersionData2 = VersionData.decode(GeoServerVendorOption.class, "2.10.0");
sldEditorVendorOptionList.add(testVersionData2);
sldEditorVendorOptionList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
sldData.setVendorOptionList(sldEditorVendorOptionList);
sldData.setSldEditorFile(new File("."));
VendorOptionManager.getInstance().loadSLDFile(new GetMinimumVersionInterface() {
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
VendorOptionInfo vendorOptionInfo = new VendorOptionInfo("qgis://", new VendorOptionVersion(testVersionData.getVendorOptionType(), testVersionData), "");
VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, vendorOptionInfo);
vendorOptionsPresentList.add(voPresent);
}
}, sld, sldData);
Collections.sort(obj.vendorOptionVersionsList);
assertEquals(2, obj.vendorOptionVersionsList.size());
assertEquals(testVersionData2, obj.vendorOptionVersionsList.get(obj.vendorOptionVersionsList.size() - 1));
// Increase code coverage
VendorOptionManager.getInstance().loadSLDFile(null, null, null);
}
Aggregations