use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class DefaultSymbols method createDefaultTextSymbolizer.
/**
* Creates the default text symbolizer.
*
* @return the text symbolizer
*/
public static TextSymbolizer createDefaultTextSymbolizer() {
Expression fontFamily = ff.literal("Serif");
Expression fontSize = ff.literal(10.0);
Expression fontStyle = ff.literal("normal");
Expression fontWeight = ff.literal("normal");
Expression rotation = ff.literal(0.0);
Expression label = ff.literal("Test");
String geometryFieldName = null;
Expression geometryField = ff.property(geometryFieldName);
String name = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
AnchorPoint anchor = null;
Displacement displacement = null;
PointPlacement pointPlacement = (PointPlacement) styleFactory.pointPlacement(anchor, displacement, rotation);
Expression fillColour = ff.literal(DEFAULT_COLOUR);
Expression fillColourOpacity = ff.literal(1.0);
Fill fill = styleFactory.fill(null, fillColour, fillColourOpacity);
Halo halo = null;
List<Expression> fontFamilyList = new ArrayList<Expression>();
fontFamilyList.add(fontFamily);
Font font = (Font) styleFactory.font(fontFamilyList, fontStyle, fontWeight, fontSize);
Description description = null;
Unit<Length> unit = null;
TextSymbolizer newTextSymbolizer = (TextSymbolizer) styleFactory.textSymbolizer(name, geometryField, description, unit, label, font, pointPlacement, halo, fill);
return newTextSymbolizer;
}
use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class TextSymbolizerDetails method updateSymbol.
/**
* Update symbol.
*/
private void updateSymbol() {
if (!Controller.getInstance().isPopulating()) {
Expression haloRadius = fieldConfigVisitor.getExpression(FieldIdEnum.HALO_RADIUS);
// Label placement
LabelPlacement labelPlacement = null;
MultiOptionGroup labelPlacementPanel = (MultiOptionGroup) getGroup(GroupIdEnum.PLACEMENT);
OptionGroup labelPlacementOption = labelPlacementPanel.getSelectedOptionGroup();
if (labelPlacementOption.getId() == GroupIdEnum.POINTPLACEMENT) {
AnchorPoint anchor = null;
GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
if (anchorPointPanel == null) {
String errorMessage = String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.ANCHORPOINT);
ConsoleManager.getInstance().error(this, errorMessage);
} else if (anchorPointPanel.isPanelEnabled()) {
Expression anchorPointH = fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H);
Expression anchorPointV = fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V);
anchor = (AnchorPoint) getStyleFactory().anchorPoint(anchorPointH, anchorPointV);
}
//
// Displacement
//
Displacement displacement = null;
GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
if (displacementPanel == null) {
ConsoleManager.getInstance().error(this, String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.DISPLACEMENT));
} else if (displacementPanel.isPanelEnabled()) {
displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
}
//
// Rotation
//
Expression rotation = null;
GroupConfigInterface rotationPanel = getGroup(GroupIdEnum.ROTATION);
if (rotationPanel == null) {
ConsoleManager.getInstance().error(this, String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.ROTATION));
} else if (rotationPanel.isPanelEnabled()) {
rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
}
labelPlacement = getStyleFactory().pointPlacement(anchor, displacement, rotation);
} else if (labelPlacementOption.getId() == GroupIdEnum.LINEPLACEMENT) {
Expression offset = fieldConfigVisitor.getExpression(FieldIdEnum.PERPENDICULAR_OFFSET);
Expression initialGap = fieldConfigVisitor.getExpression(FieldIdEnum.INITIAL_GAP);
Expression gap = fieldConfigVisitor.getExpression(FieldIdEnum.GAP);
boolean repeated = fieldConfigVisitor.getBoolean(FieldIdEnum.REPEATED);
boolean aligned = fieldConfigVisitor.getBoolean(FieldIdEnum.ALIGN);
boolean generalizedLine = fieldConfigVisitor.getBoolean(FieldIdEnum.GENERALISED_LINE);
labelPlacement = getStyleFactory().linePlacement(offset, initialGap, gap, repeated, aligned, generalizedLine);
}
FieldConfigColour fdmFillColour = (FieldConfigColour) fieldConfigManager.get(FieldIdEnum.FILL_COLOUR);
Expression fillColour = fdmFillColour.getColourExpression();
Expression fillColourOpacity = fieldConfigVisitor.getExpression(FieldIdEnum.TEXT_OPACITY);
Fill fill = getStyleFactory().createFill(fillColour, fillColourOpacity);
FieldConfigColour fdmHaloColour = (FieldConfigColour) fieldConfigManager.get(FieldIdEnum.HALO_COLOUR);
Expression haloFillColour = fdmHaloColour.getColourExpression();
Expression haloFillColourOpacity = fdmHaloColour.getColourOpacityExpression();
Fill haloFill = getStyleFactory().fill(null, haloFillColour, haloFillColourOpacity);
//
// Halo
//
Halo halo = null;
GroupConfigInterface haloPanel = getGroup(GroupIdEnum.HALO);
if (haloPanel.isPanelEnabled()) {
halo = (Halo) getStyleFactory().halo(haloFill, haloRadius);
}
//
// Font
//
Font font = extractFont();
// Any changes made to the font details need to be reflected
// back to the FieldConfigFontPreview field
fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_PREVIEW, font);
StandardData standardData = getStandardData();
Expression label = fieldConfigVisitor.getExpression(FieldIdEnum.LABEL);
Expression geometryField = fieldConfigVisitor.getExpression(FieldIdEnum.GEOMETRY);
String geometryFieldName = null;
Expression defaultGeometryField = getFilterFactory().property(geometryFieldName);
TextSymbolizer textSymbolizer = (TextSymbolizer) getStyleFactory().textSymbolizer(standardData.name, defaultGeometryField, standardData.description, standardData.unit, label, font, labelPlacement, halo, fill);
if ((geometryField != null) && !geometryField.toString().isEmpty()) {
textSymbolizer.setGeometry(geometryField);
}
if (vendorOptionTextFactory != null) {
vendorOptionTextFactory.updateSymbol(textSymbolizer);
}
SelectedSymbol.getInstance().replaceSymbolizer(textSymbolizer);
this.fireUpdateSymbol();
}
}
use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class VOGeoServerLabelling method getMinimumVersion.
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.iface.PopulateDetailsInterface#getMinimumVersion(java.lang.Object, java.util.List)
*/
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
if (sldObj instanceof TextSymbolizer) {
TextSymbolizer textSymbolizer = (TextSymbolizer) sldObj;
Map<String, String> options = textSymbolizer.getOptions();
for (FieldIdEnum key : fieldMap.keySet()) {
String vendorOptionAttributeKey = fieldMap.get(key);
if (options.containsKey(vendorOptionAttributeKey)) {
VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, getVendorOptionInfo());
if (!vendorOptionsPresentList.contains(voPresent)) {
vendorOptionsPresentList.add(voPresent);
}
}
}
}
}
use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class SLDTreeItemWrapperTest method testSLDTreeItemWrapper.
/**
* Test method for
* {@link com.sldeditor.ui.tree.SLDTreeItemWrapper#SLDTreeItemWrapper(java.lang.Object)}.
*/
@Test
public void testSLDTreeItemWrapper() {
// Try with null objects first
String testObj1 = SLDTreeItemWrapper.generateKey(null);
String testObj2 = SLDTreeItemWrapper.generateKey(null);
assertTrue(testObj1.equals(testObj1));
assertTrue(testObj1.equals(testObj2));
// Try with 2 different text symbolizers instances but the same contents, hash codes should
// be different
String testObj3 = SLDTreeItemWrapper.generateKey(DefaultSymbols.createDefaultTextSymbolizer());
String testObj4 = SLDTreeItemWrapper.generateKey(DefaultSymbols.createDefaultTextSymbolizer());
assertTrue(testObj3.equals(testObj3));
assertFalse(testObj3.equals(testObj4));
// Try with one text symbolizer instances the same contents, hash codes should be the same
TextSymbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
textSymbolizer.setHalo(new HaloImpl());
String testObj5 = SLDTreeItemWrapper.generateKey(textSymbolizer);
String testObj6 = SLDTreeItemWrapper.generateKey(textSymbolizer);
assertTrue(testObj5.equals(testObj5));
assertTrue(testObj5.equals(testObj6));
}
use of org.geotools.styling.TextSymbolizer in project sldeditor by robward-scisys.
the class BatchUpdateFontDataTest method testBatchUpdateFontData.
/**
* Test method for
* {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontData#BatchUpdateFontData(org.geotools.styling.StyledLayerDescriptor, com.sldeditor.common.SLDDataInterface)}.
*/
@Test
public void testBatchUpdateFontData() {
BatchUpdateFontData testObj = new BatchUpdateFontData(null, null);
assertNull(testObj.getName());
assertNull(testObj.getWorkspace());
assertNull(testObj.getSldData());
String expectedWorkspace = "workspace";
String expectedStyle = "layer.sld";
StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
SLDData data = new SLDData(styleWrapper, null);
testObj = new BatchUpdateFontData(null, data);
assertEquals(testObj.getWorkspace(), expectedWorkspace);
assertEquals(testObj.getName(), expectedStyle);
assertEquals(testObj.getSldData(), data);
String expectedNamedLayer = "namedLayer";
testObj.setNamedLayer(expectedNamedLayer);
assertEquals(testObj.getNamedLayer(), expectedNamedLayer);
String expectedStyleLayer = "style";
testObj.setStyle(expectedStyleLayer);
assertEquals(testObj.getStyle(), expectedStyleLayer);
String expectedFeatureTypeStyleLayer = "feature type style";
testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
assertEquals(testObj.getFeatureTypeStyle(), expectedFeatureTypeStyleLayer);
assertNull(testObj.getRule());
assertEquals(testObj.getRuleName(), "");
assertEquals(testObj.getSymbolizer(), "");
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
String expectedRule = "rule";
Rule rule = styleFactory.createRule();
rule.setName(expectedRule);
testObj.setRule(rule);
assertEquals(testObj.getRule(), rule);
assertEquals(testObj.getRuleName(), expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = styleFactory.createTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
testObj.setSymbolizer(symbolizer);
testObj.setFont(symbolizer.getFont());
assertEquals(testObj.getSymbolizer(), expectedSymbolizer);
// Test with font == null
assertFalse(testObj.isFontNameSet());
assertFalse(testObj.isFontStyleSet());
assertFalse(testObj.isFontWeightSet());
assertFalse(testObj.isFontSizeSet());
assertEquals(testObj.getFontName(), "");
assertEquals(testObj.getFontStyle(), "");
assertEquals(testObj.getFontWeight(), "");
assertEquals(testObj.getFontSize(), "");
assertFalse(testObj.anyChanges());
testObj.revertToOriginal();
testObj.updateFont((Font) null);
assertFalse(testObj.updateFont((SLDWriterInterface) null));
testObj.setFont(null);
testObj.updateFontSize(45);
// Set font
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
String originalFontname = "Serif";
String originalFontStyle = "normal";
String originalFontWeight = "normal";
int originalFontSize = 24;
Font font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
testObj.setFont(font);
assertTrue(testObj.isFontNameSet());
assertTrue(testObj.isFontStyleSet());
assertTrue(testObj.isFontWeightSet());
assertTrue(testObj.isFontSizeSet());
assertFalse(testObj.isFontNameUpdated());
assertFalse(testObj.isFontStyleUpdated());
assertFalse(testObj.isFontWeightUpdated());
assertFalse(testObj.isFontSizeUpdated());
assertFalse(testObj.anyChanges());
// Update with a different copy of the same font - no changes
Font unchangedFont = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
testObj.updateFont(unchangedFont);
assertFalse(testObj.isFontNameUpdated());
assertFalse(testObj.isFontStyleUpdated());
assertFalse(testObj.isFontWeightUpdated());
assertFalse(testObj.isFontSizeUpdated());
// Update with a different copy of the same font - changes
String expectedFontName = "NewFont";
String expectedFontStyle = "italic";
String expectedFontWeight = "bold";
int expectedFontSize = 12;
Font changedFont = styleFactory.createFont(ff.literal(expectedFontName), ff.literal(expectedFontStyle), ff.literal(expectedFontWeight), ff.literal(expectedFontSize));
testObj.updateFont(changedFont);
assertTrue(testObj.isFontNameUpdated());
assertTrue(testObj.isFontStyleUpdated());
assertTrue(testObj.isFontWeightUpdated());
assertTrue(testObj.isFontSizeUpdated());
assertTrue(testObj.anyChanges());
assertEquals(testObj.getFontName(), expectedFontName);
assertEquals(testObj.getFontStyle(), expectedFontStyle);
assertEquals(testObj.getFontWeight(), expectedFontWeight);
assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize));
assertEquals(testObj.getFont(), changedFont);
// Increment font size
int expectedIncreaseFontSize = 5;
testObj.updateFontSize(expectedIncreaseFontSize);
assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize + expectedIncreaseFontSize));
// Decrease font size
expectedIncreaseFontSize *= -1;
testObj.updateFontSize(expectedIncreaseFontSize);
assertEquals(testObj.getFontSize(), String.valueOf(expectedFontSize));
// Try setting the font size less than zero
expectedIncreaseFontSize = -100;
testObj.updateFontSize(expectedIncreaseFontSize);
assertEquals(testObj.getFontSize(), String.valueOf(1));
// Update font size when font size is a function
String expectedFieldname = "fieldname";
changedFont.setSize(ff.property(expectedFieldname));
testObj.updateFont(changedFont);
expectedIncreaseFontSize = 5;
testObj.updateFontSize(expectedIncreaseFontSize);
String expectedResult = String.format("(%s+%d)", expectedFieldname, expectedIncreaseFontSize);
String actualResult = testObj.getFontSize();
assertEquals(actualResult, expectedResult);
// Revert to original
testObj.revertToOriginal();
assertFalse(testObj.isFontNameUpdated());
assertFalse(testObj.isFontStyleUpdated());
assertFalse(testObj.isFontWeightUpdated());
assertFalse(testObj.isFontSizeUpdated());
assertFalse(testObj.anyChanges());
assertEquals(testObj.getFontName(), originalFontname);
assertEquals(testObj.getFontStyle(), originalFontStyle);
assertEquals(testObj.getFontWeight(), originalFontWeight);
assertEquals(testObj.getFontSize(), String.valueOf(originalFontSize));
// Update with the changed font again
testObj.updateFont(changedFont);
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
symbolizer.fonts().add(changedFont);
assertFalse(testObj.updateFont(sldWriter));
}
Aggregations