use of org.geotools.styling.Font in project sldeditor by robward-scisys.
the class FieldConfigPopulationTest method testFont.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateFontField(com.sldeditor.common.xml.ui.FieldIdEnum, org.geotools.styling.Font)}.
*/
@Test
public void testFont() {
FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
FieldConfigFont fontField = new FieldConfigFont(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
fontField.createUI();
fieldConfigManager.add(fieldId, fontField);
FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
StyleBuilder styleBuilder = new StyleBuilder();
Font expectedValue = styleBuilder.createFont(java.awt.Font.decode(null));
obj.populateFontField(fieldId, expectedValue);
// This shouldn't work as it does not know about the field
FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
obj.populateFontField(wrongFieldEnum, expectedValue);
}
use of org.geotools.styling.Font 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.Font 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;
}
use of org.geotools.styling.Font in project sldeditor by robward-scisys.
the class FontDetails method extractFont.
/**
* Extract font.
*
* @return the font
*/
private Font extractFont() {
Expression fontFamily = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_FAMILY);
List<Expression> fontFamilyList = new ArrayList<Expression>();
if (fontFamily != null) {
fontFamilyList.add(fontFamily);
}
Font font = getStyleFactory().getDefaultFont();
font.getFamily().clear();
font.getFamily().addAll(fontFamilyList);
Expression fontSize = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_SIZE);
Expression fontStyle = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_STYLE);
Expression fontWeight = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_WEIGHT);
font.setStyle(fontStyle);
font.setWeight(fontWeight);
font.setSize(fontSize);
return font;
}
use of org.geotools.styling.Font in project sldeditor by robward-scisys.
the class TextSymbolizerDetails method extractFont.
/**
* Extract font.
*
* @return the font
*/
private Font extractFont() {
Font font = null;
Expression fontFamily = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_FAMILY);
Expression fontSize = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_SIZE);
Expression fontStyle = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_STYLE);
Expression fontWeight = fieldConfigVisitor.getExpression(FieldIdEnum.FONT_WEIGHT);
List<Expression> fontFamilyList = new ArrayList<Expression>();
fontFamilyList.add(fontFamily);
if ((fontFamilyList == null) || (fontStyle == null) || (fontWeight == null) || (fontSize == null)) {
font = getStyleFactory().getDefaultFont();
} else {
font = (Font) getStyleFactory().font(fontFamilyList, fontStyle, fontWeight, fontSize);
}
return font;
}
Aggregations