use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class DetailsUtilitiesTest method testIsSameDisplacementDisplacement.
/**
* Test method for {@link com.sldeditor.ui.detail.DetailsUtilities#isSame(org.geotools.styling.Displacement, org.geotools.styling.Displacement)}.
*/
@Test
public void testIsSameDisplacementDisplacement() {
assertFalse(DetailsUtilities.isSame((Displacement) null, (Displacement) null));
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
// Try values that are the same
Displacement displacement1 = new DisplacementImpl();
displacement1.setDisplacementX(ff.literal(42));
displacement1.setDisplacementY(ff.literal(-2));
Displacement displacement2 = new DisplacementImpl();
displacement2.setDisplacementX(ff.literal("42"));
displacement2.setDisplacementY(ff.literal(-2));
assertTrue(DetailsUtilities.isSame(displacement1, displacement2));
// Try values that are not the same
Displacement displacement3 = new DisplacementImpl();
displacement3.setDisplacementX(ff.literal(1));
displacement3.setDisplacementY(ff.literal(-2));
assertFalse(DetailsUtilities.isSame(displacement1, displacement3));
assertFalse(DetailsUtilities.isSame(displacement2, displacement3));
Displacement displacement4 = new DisplacementImpl();
displacement4.setDisplacementX(ff.literal((Long) 1L));
displacement4.setDisplacementY(ff.literal(-2));
assertFalse(DetailsUtilities.isSame(displacement1, displacement4));
assertFalse(DetailsUtilities.isSame(displacement2, displacement4));
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class CharacterMarkerSymbol method convert.
/**
* Convert.
*
* @param element the element
* @return the marker graphic
*/
@Override
public List<Graphic> convert(JsonElement element) {
if (element == null)
return null;
JsonObject obj = element.getAsJsonObject();
List<Graphic> markerList = new ArrayList<Graphic>();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT);
if (fontElement != null) {
JsonObject fontObj = fontElement.getAsJsonObject();
String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX);
Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code));
// Create colour
Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Fill fill = styleFactory.createFill(colour);
Stroke stroke = null;
Mark mark = styleFactory.mark(wellKnownName, fill, stroke);
ExternalGraphic[] externalGraphics = null;
Mark[] marks = new Mark[1];
marks[0] = mark;
Symbol[] symbols = null;
Expression opacity = null;
Expression rotation = ff.literal(angle);
Expression size = ff.literal(symbolSize);
Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation);
// Displacement (offsets)
if ((xOffset > 0.0) && (yOffset > 0.0)) {
Expression expressionX = ff.literal(xOffset);
Expression expressionY = ff.literal(yOffset);
Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY);
graphic.setDisplacement(displacement);
}
markerList.add(graphic);
}
return markerList;
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class SimpleMarkerSymbol method convert.
/**
* Convert.
*
* @param element the element
* @return the graphic marker list
*/
@Override
public List<Graphic> convert(JsonElement element) {
if (element == null)
return null;
JsonObject obj = element.getAsJsonObject();
List<Graphic> markList = new ArrayList<Graphic>();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE);
double size = getDouble(obj, CommonSymbolKeys.SIZE);
int style = getInt(obj, CommonSymbolKeys.STYLE);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR));
Expression wellKnownName = ff.literal(styleMap.get(style));
Stroke stroke = null;
if (outlineSize > 0.0) {
stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize));
}
Fill fill = styleFactory.createFill(markerColour);
Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle));
Expression expressionOpacity = null;
ExternalGraphic[] externalGraphics = null;
Symbol[] symbols = null;
Mark[] marks = new Mark[1];
marks[0] = mark;
Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle));
// Set offset
if ((xOffset > 0.0) && (yOffset > 0.0)) {
Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
graphic.setDisplacement(displacement);
}
markList.add(graphic);
return markList;
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class PolygonFillDetails method populate.
/**
* Populate.
*
* @param selectedSymbol the selected symbol
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
*/
@Override
public void populate(SelectedSymbol selectedSymbol) {
Expression expSize = null;
Expression expRotation = null;
Expression expAnchorPointX = null;
Expression expAnchorPointY = null;
Expression expDisplacementX = null;
Expression expDisplacementY = null;
Expression expFillColour = null;
Expression expGap = null;
Expression expInitialGap = null;
Fill fill = null;
Expression expOpacity = null;
symbolizer = null;
if (selectedSymbol != null) {
symbolizer = selectedSymbol.getSymbolizer();
Graphic graphic = null;
if (symbolizer instanceof PointSymbolizerImpl) {
PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
graphic = pointSymbolizer.getGraphic();
if (graphic != null) {
List<GraphicalSymbol> graphicSymbolList = graphic.graphicalSymbols();
if (!graphicSymbolList.isEmpty()) {
GraphicalSymbol graphicalSymbol = graphicSymbolList.get(0);
if (graphicalSymbol instanceof MarkImpl) {
MarkImpl mark = (MarkImpl) graphicalSymbol;
fill = mark.getFill();
if (fill != null) {
expOpacity = fill.getOpacity();
}
}
}
}
} else if (symbolizer instanceof PolygonSymbolizerImpl) {
PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
if (polygonSymbolizer != null) {
fill = polygonSymbolizer.getFill();
if (fill != null) {
expOpacity = fill.getOpacity();
graphic = fill.getGraphicFill();
}
}
}
if (graphic == null) {
if (fill != null) {
expFillColour = fill.getColor();
}
if (fill == null) {
symbolTypeFactory.setNoFill(this.fieldConfigManager);
} else {
symbolTypeFactory.setSolidFill(this.fieldConfigManager, expFillColour, expOpacity);
}
} else {
expSize = graphic.getSize();
expRotation = graphic.getRotation();
// Anchor point
AnchorPoint anchorPoint = graphic.getAnchorPoint();
if (anchorPoint != null) {
expAnchorPointX = anchorPoint.getAnchorPointX();
expAnchorPointY = anchorPoint.getAnchorPointY();
} else {
expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
}
// Offset
Displacement displacement = graphic.getDisplacement();
if (displacement != null) {
expDisplacementX = displacement.getDisplacementX();
expDisplacementY = displacement.getDisplacementY();
} else {
expDisplacementX = defaultDisplacement.getDisplacementX();
expDisplacementY = defaultDisplacement.getDisplacementY();
}
expGap = graphic.getGap();
expInitialGap = graphic.getInitialGap();
List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
if (!graphicalSymbolList.isEmpty()) {
GraphicalSymbol symbol = graphicalSymbolList.get(0);
symbolTypeFactory.setValue(PolygonSymbolizer.class, this.fieldConfigManager, graphic, symbol);
}
}
}
fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
fieldConfigVisitor.populateField(FieldIdEnum.OVERALL_OPACITY, expOpacity);
if (vendorOptionFillFactory != null) {
if (symbolizer instanceof PolygonSymbolizer) {
vendorOptionFillFactory.populate((PolygonSymbolizer) symbolizer);
}
}
updateSymbol();
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class PolygonFillDetails method getGraphicFill.
/**
* Gets the graphic fill.
*
* @return the graphic fill
*/
private GraphicFill getGraphicFill() {
GroupConfigInterface fillGroup = getGroup(GroupIdEnum.FILL);
boolean hasFill = fillGroup.isPanelEnabled();
GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.STROKE);
boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
Expression opacity = null;
Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.SIZE);
Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.SYMBOL_TYPE);
//
// Anchor point
//
AnchorPoint anchorPoint = null;
GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
if (anchorPointPanel.isPanelEnabled()) {
anchorPoint = (AnchorPoint) getStyleFactory().anchorPoint(fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H), fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V));
// default so it doesn't appear in the SLD
if (DetailsUtilities.isSame(defaultAnchorPoint, anchorPoint)) {
anchorPoint = null;
}
}
//
// Displacement
//
Displacement displacement = null;
GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
if (displacementPanel.isPanelEnabled()) {
displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
// it doesn't appear in the SLD
if (DetailsUtilities.isSame(defaultDisplacement, displacement)) {
displacement = null;
}
}
List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(this.fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
GraphicFill graphicFill = getStyleFactory().graphicFill(symbols, opacity, size, rotation, anchorPoint, displacement);
return graphicFill;
}
Aggregations