use of com.sldeditor.common.data.SelectedSymbol 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 com.sldeditor.common.data.SelectedSymbol 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 com.sldeditor.common.data.SelectedSymbol in project sldeditor by robward-scisys.
the class SLDEditor method populate.
/**
* Populate the application with the SLD.
*
* @param sldData the sld data
*/
protected void populate(SLDDataInterface sldData) {
String layerName = sldData.getLayerName();
File sldEditorFile = sldData.getSldEditorFile();
if (sldEditorFile != null) {
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDEditorFile"), sldEditorFile.getAbsolutePath()));
}
ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDFile"), layerName));
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
SelectedSymbol selectedSymbolInstance = SelectedSymbol.getInstance();
selectedSymbolInstance.setSld(sld);
selectedSymbolInstance.setFilename(layerName);
selectedSymbolInstance.setName(layerName);
SLDEditorFile.getInstance().setSLDData(sldData);
// Reload data source if sticky flag is set
boolean isDataSourceSticky = SLDEditorFile.getInstance().isStickyDataSource();
DataSourcePropertiesInterface previousDataSource = dataSource.getDataConnectorProperties();
dataSource.reset();
if (isDataSourceSticky) {
SLDEditorFile.getInstance().setDataSource(previousDataSource);
}
dataSource.connect(ExternalFilenames.removeSuffix(layerName), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
VendorOptionManager.getInstance().loadSLDFile(uiMgr, sld, sldData);
LegendManager.getInstance().SLDLoaded(sldData.getLegendOptions());
SLDEditorFile.getInstance().fileOpenedSaved();
}
Aggregations