use of org.geotools.styling.NamedLayer in project sldeditor by robward-scisys.
the class SymbolDataTest method testSetStyledLayer.
@Test
public void testSetStyledLayer() {
SymbolData symbolData = new SymbolData();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
symbolData.setStyledLayer(namedLayer);
assertEquals(namedLayer, symbolData.getStyledLayer());
}
use of org.geotools.styling.NamedLayer in project sldeditor by robward-scisys.
the class NewPolygonSLDTest method testNewPolygonSLD.
/**
* Test new polygon sld.
*/
@Test
public void testNewPolygonSLD() {
NewPolygonSLD newData = new NewPolygonSLD();
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 PolygonSymbolizer);
}
use of org.geotools.styling.NamedLayer 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);
}
use of org.geotools.styling.NamedLayer in project sldeditor by robward-scisys.
the class NewLineSLDTest method testNewLineSLD.
/**
* Test new line sld.
*/
@Test
public void testNewLineSLD() {
NewLineSLD newData = new NewLineSLD();
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 LineSymbolizer);
}
use of org.geotools.styling.NamedLayer in project sldeditor by robward-scisys.
the class BatchUpdateFontModelTest method testLoadData.
/**
* Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel#loadData(java.util.List)}.
*/
@Test
public void testLoadData() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
sld.layers().add(namedLayer);
String expectedNamedLayer = "namedLayer";
namedLayer.setName(expectedNamedLayer);
Style style = DefaultSymbols.createNewStyle();
String expectedStyleLayer = "style";
style.setName(expectedStyleLayer);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedFeatureTypeStyleLayer = "feature type style";
fts.setName(expectedFeatureTypeStyleLayer);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
fts.rules().add(rule);
String expectedRule = "rule";
rule.setName(expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
rule.symbolizers().add(symbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
symbolizer.setFont(font);
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
String sldContents = sldWriter.encodeSLD(null, sld);
String expectedWorkspace = "workspace";
String expectedStyle = "layer.sld";
StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
SLDData data = new SLDData(styleWrapper, sldContents);
File testFile = new File("test.sld");
data.setSLDFile(testFile);
SLDEditorFile.getInstance().setSldFile(testFile);
SLDEditorFile.getInstance().setSLDData(data);
BatchUpdateFontData testObj = new BatchUpdateFontData(sld, data);
SelectedSymbol.getInstance().setSld(sld);
testObj.setNamedLayer(expectedNamedLayer);
testObj.setStyle(expectedStyleLayer);
testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
testObj.setRule(rule);
testObj.setSymbolizer(symbolizer);
testObj.setFont(font);
List<BatchUpdateFontData> dataList = new ArrayList<BatchUpdateFontData>();
dataList.add(testObj);
BatchUpdateFontModel model = new BatchUpdateFontModel();
model.loadData(dataList);
for (int col = 0; col < model.getColumnCount(); col++) {
assertFalse(model.hasValueBeenUpdated(0, col));
}
assertFalse(model.anyChanges());
assertFalse(model.saveData(null));
List<Font> actualFontlist = model.getFontEntries(new int[] { 0 });
assertEquals(1, actualFontlist.size());
assertEquals(1, model.getRowCount());
// Update font
String originalFontname = "New Font";
String originalFontStyle = "italic";
String originalFontWeight = "bold";
int originalFontSize = 16;
font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
model.applyData(new int[] { 0 }, font);
assertTrue(model.hasValueBeenUpdated(0, 7));
assertTrue(model.hasValueBeenUpdated(0, 8));
assertTrue(model.hasValueBeenUpdated(0, 9));
assertTrue(model.hasValueBeenUpdated(0, 10));
assertTrue(model.anyChanges());
assertEquals(originalFontname, model.getValueAt(0, 7));
assertEquals(originalFontStyle, model.getValueAt(0, 8));
assertEquals(originalFontWeight, model.getValueAt(0, 9));
assertEquals(String.valueOf(originalFontSize), model.getValueAt(0, 10));
model.revertData();
assertFalse(model.anyChanges());
int expectedFontSize = 99;
model.applyData(new int[] { 0 }, expectedFontSize);
// Font size
assertTrue(model.hasValueBeenUpdated(0, 10));
assertEquals(expectedWorkspace, model.getValueAt(0, 0));
assertEquals(expectedStyle, model.getValueAt(0, 1));
assertEquals(expectedNamedLayer, model.getValueAt(0, 2));
assertEquals(expectedStyleLayer, model.getValueAt(0, 3));
assertEquals(expectedFeatureTypeStyleLayer, model.getValueAt(0, 4));
assertEquals(expectedRule, model.getValueAt(0, 5));
assertEquals(expectedSymbolizer, model.getValueAt(0, 6));
assertEquals("abc", model.getValueAt(0, 7));
assertEquals("normal", model.getValueAt(0, 8));
assertEquals("normal", model.getValueAt(0, 9));
assertEquals(String.valueOf(10 + expectedFontSize), model.getValueAt(0, 10));
assertNull(model.getValueAt(0, 42));
assertTrue(model.saveData(null));
SelectedSymbol.destroyInstance();
SLDEditorFile.destroyInstance();
model.setColumnRenderer(null);
JTable table = new JTable();
table.setModel(model);
model.setColumnRenderer(table.getColumnModel());
assertFalse(model.isCellEditable(0, 0));
assertEquals(Localisation.getString(BatchUpdateFontModel.class, "BatchUpdateFontModel.workspace"), model.getColumnName(0));
}
Aggregations