use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SimpleRenderer method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
*/
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
String label = json.get(CommonRendererKeys.LABEL).getAsString();
namedLayer.setName(label);
sld.addStyledLayer(namedLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
// style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
Rule rule = styleFactory.createRule();
if (minScale > 0.0) {
rule.setMinScaleDenominator(minScale);
}
if (maxScale > 0.0) {
rule.setMaxScaleDenominator(maxScale);
}
JsonElement jsonElement = json.get(CommonRendererKeys.SYMBOL);
rule.setName(label);
SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonElement);
fts.rules().add(rule);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class UniqueValueRenderer method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
*/
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
boolean useDefaultSymbol = false;
JsonElement useDefaultSymbolElement = json.get(UniqueValueRendererKeys.USE_DEFAULTSYMBOL);
if (useDefaultSymbolElement != null) {
useDefaultSymbol = useDefaultSymbolElement.getAsBoolean();
}
JsonElement jsonElement = json.get(CommonRendererKeys.LABEL);
if (jsonElement != null) {
namedLayer.setName(jsonElement.getAsString());
}
sld.addStyledLayer(namedLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
// style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
JsonElement element = json.get(UniqueValueRendererKeys.VALUES);
if (element != null) {
JsonArray valueList = element.getAsJsonArray();
for (int index = 0; index < valueList.size(); index++) {
JsonElement valueElement = valueList.get(index);
if (valueElement != null) {
Rule rule = styleFactory.createRule();
JsonObject valueObj = valueElement.getAsJsonObject();
String value = getString(valueObj, UniqueValueRendererKeys.VALUES_VALUE);
String label = getString(valueObj, UniqueValueRendererKeys.VALUES_LABEL);
rule.setName(label);
createFilter(rule, json.get(UniqueValueRendererKeys.FIELDS), json.get(UniqueValueRendererKeys.FIELD_DELIMETER), value);
// Heading /description
String heading = getString(valueObj, UniqueValueRendererKeys.VALUES_HEADING);
@SuppressWarnings("unused") String description = getString(valueObj, UniqueValueRendererKeys.VALUES_DESCRIPTION);
if ((heading != null) && !heading.isEmpty() || (label != null) && !label.isEmpty()) {
if (label == null) {
label = "";
}
InternationalString titleString = Text.text(label);
if (heading == null) {
heading = "";
}
InternationalString descriptionString = Text.text(heading);
Description descriptionObj = styleFactory.description(titleString, descriptionString);
rule.setDescription(descriptionObj);
}
if (minScale > 0.0) {
rule.setMinScaleDenominator(minScale);
}
if (maxScale > 0.0) {
rule.setMaxScaleDenominator(maxScale);
}
JsonElement jsonSymbolElement = valueObj.get(UniqueValueRendererKeys.VALUES_SYMBOL);
SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonSymbolElement);
if (useDefaultSymbol && value == null) {
rule.setIsElseFilter(true);
}
fts.rules().add(rule);
}
}
}
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class StrokeDetailsTest method testStrokeDetailsPolygon.
/**
* Test method for
* {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testStrokeDetailsPolygon() {
StrokeDetails panel = new StrokeDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor 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);
PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
SelectedSymbol.getInstance().setRule(rule);
SelectedSymbol.getInstance().setSymbolizer(symbolizer);
panel.populate(SelectedSymbol.getInstance());
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
FieldConfigSymbolType symbolTypeField = (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
symbolTypeField.populateField("circle");
double expectedAngle = 14.5;
FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
angleField.populateField(expectedAngle);
FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
double opacity = 0.15;
opacityField.populateField(opacity);
FieldConfigString dashField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
String dashArray = "1 2";
dashField.populateField(dashArray);
panel.dataChanged(null);
double actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
assertTrue(panel.isDataPresent());
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - opacity) < 0.01);
// Reset to default value
panel.preLoadSymbol();
actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.01);
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class StrokeDetailsTest method testStrokeDetailsCircle.
/**
* Test method for
* {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testStrokeDetailsCircle() {
StrokeDetails panel = new StrokeDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor 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);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
SelectedSymbol.getInstance().setRule(rule);
SelectedSymbol.getInstance().setSymbolizer(symbolizer);
panel.populate(SelectedSymbol.getInstance());
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
FieldConfigSymbolType symbolTypeField = (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
symbolTypeField.populateField("circle");
double expectedAngle = 14.5;
FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
angleField.populateField(expectedAngle);
FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
double opacity = 0.15;
opacityField.populateField(opacity);
FieldConfigString dashField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
String dashArray = "1 2";
dashField.populateField(dashArray);
panel.dataChanged(null);
double actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
assertFalse(panel.isDataPresent());
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - opacity) < 0.01);
// Reset to default value
panel.preLoadSymbol();
actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.01);
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class StyleDetailsTest method testStyleDetails.
/**
* Test method for {@link com.sldeditor.ui.detail.StyleDetails#StyleDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
* Test method for {@link com.sldeditor.ui.detail.StyleDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
* Test method for {@link com.sldeditor.ui.detail.StyleDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
* Test method for {@link com.sldeditor.ui.detail.StyleDetails#getFieldDataManager()}.
* Test method for {@link com.sldeditor.ui.detail.StyleDetails#isDataPresent()}.
* Test method for {@link com.sldeditor.ui.detail.StyleDetails#preLoadSymbol()}.
*/
@Test
public void testStyleDetails() {
StyleDetails panel = new StyleDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor 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 expectedNameValue = "style test value";
style.setName(expectedNameValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
style.featureTypeStyles().add(fts);
sld.layers().add(namedLayer);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
panel.populate(SelectedSymbol.getInstance());
panel.dataChanged(null);
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
assertTrue(expectedNameValue.compareTo(nameField.getStringValue()) == 0);
assertTrue(panel.isDataPresent());
// Reset to default value
panel.preLoadSymbol();
assertTrue("".compareTo(nameField.getStringValue()) == 0);
}
Aggregations