use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SimpleFillSymbol method convertToFill.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.symbols.EsriFillSymbolInterface#convertToFill(java.lang.String, com.google.gson.JsonElement, int)
*/
@Override
public List<Symbolizer> convertToFill(String layerName, JsonElement element, int transparency) {
if (element == null)
return null;
JsonObject obj = element.getAsJsonObject();
List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
Expression fillColour = getColour(obj.get(SimpleFillSymbolKeys.FILL_COLOUR));
Expression transparencyExpression = getTransparency(transparency);
Fill fill = null;
if (fillColour != null) {
fill = styleFactory.createFill(fillColour, transparencyExpression);
}
PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
polygon.setStroke(null);
polygon.setFill(fill);
symbolizerList.add(polygon);
return symbolizerList;
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class RuleRenderVisitor method visit.
/**
* Visit.
*
* @param rule the rule
*/
/*
* (non-Javadoc)
*
* @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.Rule)
*/
@SuppressWarnings("deprecation")
@Override
public void visit(Rule rule) {
Rule copy = null;
Symbolizer[] symsCopy = null;
if (!displayOverall && ((symbolizerIndex >= 0) && (symbolizerIndex < rule.getSymbolizers().length))) {
symsCopy = new Symbolizer[1];
symsCopy[0] = copy(rule.getSymbolizers()[symbolizerIndex]);
}
// As a catch all copy everything
if (symsCopy == null) {
symsCopy = rule.getSymbolizers();
for (int i = 0; i < symsCopy.length; i++) {
symsCopy[i] = copy(symsCopy[i]);
}
}
Graphic[] legendCopy = rule.getLegendGraphic();
for (int i = 0; i < legendCopy.length; i++) {
legendCopy[i] = copy(legendCopy[i]);
}
Description descCopy = rule.getDescription();
descCopy = copy(descCopy);
copy = sf.createRule();
copy.setSymbolizers(symsCopy);
copy.setDescription(descCopy);
copy.setLegendGraphic(legendCopy);
copy.setName(rule.getName());
Filter filterCopy = null;
copy.setFilter(filterCopy);
copy.setElseFilter(rule.isElseFilter());
if (STRICT && !copy.equals(rule)) {
throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule);
}
pages.push(copy);
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class BatchUpdateFontData method updateFont.
/**
* Update font.
*
* @param sldWriter the sld writer
* @return true, if successful
*/
public boolean updateFont(SLDWriterInterface sldWriter) {
boolean refreshUI = false;
if ((rule != null) && (sldWriter != null)) {
List<Font> fontList = symbolizer.fonts();
Font localFont = fontList.get(0);
if (isFontNameUpdated()) {
localFont.getFamily().clear();
localFont.getFamily().addAll(this.font.getFamily());
}
if (isFontStyleUpdated()) {
localFont.setStyle(ff.literal(this.font.getStyle()));
}
if (isFontWeightUpdated()) {
localFont.setWeight(ff.literal(this.font.getWeight()));
}
if (isFontSizeUpdated()) {
localFont.setSize(ff.literal(this.font.getSize()));
}
String sldContents = sldWriter.encodeSLD(null, this.sld);
SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();
if ((current != null) && (sldData != null)) {
if (((current.getSLDFile() == null) && (sldData.getSLDFile() == null)) || ((current.getSLDFile() != null) && current.getSLDFile().equals(sldData.getSLDFile())) || ((current.getSLDURL() != null) && current.getSLDURL().equals(sldData.getSLDURL()))) {
Symbolizer currentSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, SelectedSymbol.getInstance().getSld());
if (currentSymbolizer instanceof TextSymbolizer) {
TextSymbolizer textSymbolizer = (TextSymbolizer) currentSymbolizer;
textSymbolizer.fonts().clear();
textSymbolizer.fonts().add(localFont);
refreshUI = true;
}
}
}
if (sldData != null) {
sldData.updateSLDContents(sldContents);
}
setOriginalData(localFont);
}
return refreshUI;
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class BatchUpdateFontUtils method containsFonts.
/**
* Contains font details.
*
* @param sldData the sld data
* @return the scale sld data, returns null if invalid SLD string supplied.
*/
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
List<BatchUpdateFontData> dataList = null;
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
for (StyledLayer styledLayer : styledLayerList) {
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
for (Style style : namedLayerImpl.styles()) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
for (Symbolizer symbolizer : rule.symbolizers()) {
if (symbolizer instanceof TextSymbolizer) {
TextSymbolizer textSymbol = (TextSymbolizer) symbolizer;
Font font = textSymbol.getFont();
if (font != null) {
if (dataList == null) {
dataList = new ArrayList<>();
}
BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData);
fontSLDData.setNamedLayer(namedLayerImpl.getName());
fontSLDData.setFeatureTypeStyle(fts.getName());
fontSLDData.setStyle(style.getName());
fontSLDData.setRule(rule);
fontSLDData.setSymbolizer(textSymbol);
fontSLDData.setFont(font);
dataList.add(fontSLDData);
}
}
}
}
}
}
}
}
}
return dataList;
}
use of org.geotools.styling.Symbolizer 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());
}
Aggregations