use of org.geotools.styling.Rule in project sldeditor by robward-scisys.
the class SLDTreeSymbolizerButtonStateTest method testPolygon.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#setGeometryType(com.sldeditor.datasource.impl.GeometryTypeEnum)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isMarkerVisible(java.lang.Object, java.lang.Object)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isLineVisible(java.lang.Object, java.lang.Object)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isPolygonVisible(java.lang.Object, java.lang.Object)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isRasterVisible(java.lang.Object, java.lang.Object)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isTextVisible(java.lang.Object, java.lang.Object)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isImageOutlineLineVisible(java.lang.Object, java.lang.Object)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isImageOutlinePolygonVisible(java.lang.Object, java.lang.Object)}.
*/
@Test
public void testPolygon() {
SLDTreeSymbolizerButtonState obj = new SLDTreeSymbolizerButtonState();
obj.setGeometryType(GeometryTypeEnum.POLYGON);
obj.showSymbolizerButtons();
assertFalse(obj.isLineVisible(null, null));
assertFalse(obj.isMarkerVisible(null, null));
assertFalse(obj.isPolygonVisible(null, null));
assertFalse(obj.isRasterVisible(null, null));
assertFalse(obj.isTextVisible(null, null));
assertFalse(obj.isImageOutlineLineVisible(null, null));
assertFalse(obj.isImageOutlinePolygonVisible(null, null));
Rule rule = DefaultSymbols.createNewRule();
assertTrue(obj.isPolygonVisible(null, rule));
assertTrue(obj.isTextVisible(null, rule));
}
use of org.geotools.styling.Rule 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.Rule 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.Rule in project sldeditor by robward-scisys.
the class LabelEngineLayerProperties method convert.
/* (non-Javadoc)
* @see com.sldeditor.extension.convert.esri.label.EsriLabelRendererInterface#convert(java.util.List, org.geotools.styling.Rule, com.google.gson.JsonElement, int)
*/
@Override
public void convert(List<Rule> labelRuleList, Rule rule, JsonElement json, int transparency) {
if ((json != null) && (rule != null) && (labelRuleList != null)) {
JsonObject jsonObj = json.getAsJsonObject();
TextSymbolizer textSymbolizer = styleFactory.createTextSymbolizer();
textSymbolizer.setUnitOfMeasure(NonSI.PIXEL);
textSymbolizer.setLabel(extractExpression(jsonObj));
JsonElement jsonElement = jsonObj.get(LabelEngineLayerPropertiesKey.SYMBOL);
SymbolManager.getInstance().convertTextSymbols(textSymbolizer, transparency, jsonElement);
// Yes, this really is round the wrong way
double maxScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MINIMUM_SCALE);
double minScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MAXIMUM_SCALE);
if ((minScale > 0.0) || (maxScale > 0.0)) {
Rule labelRule = styleFactory.createRule();
labelRule.setName(extractString(jsonObj, LabelEngineLayerPropertiesKey.CLASS));
if (minScale > 0.0) {
labelRule.setMinScaleDenominator(minScale);
}
if (maxScale > 0.0) {
labelRule.setMaxScaleDenominator(maxScale);
}
labelRule.symbolizers().add(textSymbolizer);
labelRuleList.add(labelRule);
} else {
rule.symbolizers().add(textSymbolizer);
}
}
}
use of org.geotools.styling.Rule 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);
}
Aggregations