use of org.geotools.styling.TextSymbolizer 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.TextSymbolizer in project sldeditor by robward-scisys.
the class TextSymbolizerDetailsTest method testTextSymbolizerDetails.
/**
* Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#TextSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
* Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
* Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
* Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#getFieldDataManager()}.
* Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#isDataPresent()}.
* Test method for {@link com.sldeditor.ui.detail.TextSymbolizerDetails#preLoadSymbol()}.
*/
@Test
public void testTextSymbolizerDetails() {
TextSymbolizerDetails panel = new TextSymbolizerDetails();
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 expectedRuleValue = "rule test value";
rule.setName(expectedRuleValue);
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
String expectedNameValue = "symbolizer test value";
symbolizer.setName(expectedNameValue);
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);
panel.dataChanged(null);
FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
assertNull(nameField);
assertTrue(panel.isDataPresent());
// Reset to default value
panel.preLoadSymbol();
}
use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class RuleRenderVisitor method visit.
/**
* (non-Javadoc)
*
* @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.TextSymbolizer)
*/
public void visit(TextSymbolizer text) {
TextSymbolizer copy = sf.createTextSymbolizer();
copy.setFill(copy(text.getFill()));
copy.fonts().clear();
copy.fonts().addAll(copyFonts(text.fonts()));
// Ignore geometry field so that symbol is rendered
copy.setGeometry(copy(text.getGeometry()));
copy.setUnitOfMeasure(text.getUnitOfMeasure());
copy.setHalo(copy(text.getHalo()));
copy.setLabel(copy(text.getLabel()));
copy.setLabelPlacement(copy(text.getLabelPlacement()));
copy.setPriority(copy(text.getPriority()));
copy.getOptions().putAll(text.getOptions());
if (text instanceof TextSymbolizer2) {
TextSymbolizer2 text2 = (TextSymbolizer2) text;
TextSymbolizer2 copy2 = (TextSymbolizer2) copy;
copy2.setGraphic(copy(text2.getGraphic()));
copy2.setSnippet(copy(text2.getSnippet()));
copy2.setFeatureDescription(copy(text2.getFeatureDescription()));
copy2.setOtherText(copy(text2.getOtherText()));
}
if (STRICT && !copy.equals(text)) {
throw new IllegalStateException("Was unable to duplicate provided TextSymbolizer:" + text);
}
pages.push(copy);
}
use of org.geotools.styling.TextSymbolizer 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 font = fontList.get(0);
if (isFontNameUpdated()) {
font.getFamily().clear();
font.getFamily().addAll(this.font.getFamily());
}
if (isFontStyleUpdated()) {
font.setStyle(ff.literal(this.font.getStyle()));
}
if (isFontWeightUpdated()) {
font.setWeight(ff.literal(this.font.getWeight()));
}
if (isFontSizeUpdated()) {
font.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 != null) {
if (currentSymbolizer instanceof TextSymbolizer) {
TextSymbolizer textSymbolizer = (TextSymbolizer) currentSymbolizer;
textSymbolizer.fonts().clear();
textSymbolizer.fonts().add(font);
refreshUI = true;
}
}
}
}
sldData.updateSLDContents(sldContents);
setOriginalData(font);
}
return refreshUI;
}
use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class BatchUpdateFontUtils method containsFonts.
/**
* Contains font details.
*
* @param sldData the sld data
* @return the scale sld data
*/
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
List<BatchUpdateFontData> dataList = null;
if (sldData != null) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
if (sld != null) {
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>();
}
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;
}
Aggregations