use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class TextSymbolizerDetails method populate.
/**
* Populate.
*
* @param selectedSymbol the selected symbol
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
*/
@Override
public void populate(SelectedSymbol selectedSymbol) {
if (selectedSymbol != null) {
TextSymbolizer textSymbolizer = (TextSymbolizer) selectedSymbol.getSymbolizer();
if (textSymbolizer != null) {
populateStandardData(textSymbolizer);
//
// Geometry
//
fieldConfigVisitor.populateField(FieldIdEnum.GEOMETRY, textSymbolizer.getGeometry());
//
// Label
//
fieldConfigVisitor.populateField(FieldIdEnum.LABEL, textSymbolizer.getLabel());
// Font
Font font = textSymbolizer.getFont();
GroupConfigInterface group = getGroup(GroupIdEnum.FONT);
group.enable(font != null);
if (font != null) {
fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_FAMILY, font);
fieldConfigVisitor.populateField(FieldIdEnum.FONT_WEIGHT, font.getWeight());
fieldConfigVisitor.populateField(FieldIdEnum.FONT_STYLE, font.getStyle());
fieldConfigVisitor.populateField(FieldIdEnum.FONT_SIZE, font.getSize());
}
fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_PREVIEW, font);
// Fill
Fill fill = (FillImpl) textSymbolizer.getFill();
if (fill != null) {
fieldConfigVisitor.populateField(FieldIdEnum.FILL_COLOUR, fill.getColor());
fieldConfigVisitor.populateField(FieldIdEnum.TEXT_OPACITY, fill.getOpacity());
}
// Halo
Halo halo = textSymbolizer.getHalo();
group = getGroup(GroupIdEnum.HALO);
group.enable(halo != null);
if (halo != null) {
Fill haloFill = halo.getFill();
fieldConfigVisitor.populateField(FieldIdEnum.HALO_COLOUR, haloFill.getColor());
fieldConfigVisitor.populateField(FieldIdEnum.HALO_RADIUS, halo.getRadius());
} else {
fieldConfigVisitor.populateField(FieldIdEnum.HALO_COLOUR, (Expression) null);
fieldConfigVisitor.populateField(FieldIdEnum.HALO_RADIUS, (Expression) null);
}
group = getGroup(GroupIdEnum.PLACEMENT);
if (group != null) {
MultiOptionGroup labelPlacementGroup = (MultiOptionGroup) group;
LabelPlacement placement = textSymbolizer.getLabelPlacement();
if (placement instanceof PointPlacementImpl) {
PointPlacementImpl pointPlacement = (PointPlacementImpl) placement;
labelPlacementGroup.setOption(GroupIdEnum.POINTPLACEMENT);
Expression anchorPointX = null;
Expression anchorPointY = null;
AnchorPoint anchorPoint = pointPlacement.getAnchorPoint();
if (anchorPoint != null) {
anchorPointX = anchorPoint.getAnchorPointX();
anchorPointY = anchorPoint.getAnchorPointY();
} else {
// Use the defaults as non specified
anchorPointX = defaultPointPlacementAnchorPointX;
anchorPointY = defaultPointPlacementAnchorPointY;
}
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, anchorPointX);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, anchorPointY);
Displacement displacement = pointPlacement.getDisplacement();
if (displacement == null) {
displacement = DisplacementImpl.DEFAULT;
}
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, displacement.getDisplacementX());
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, displacement.getDisplacementY());
fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, pointPlacement.getRotation());
} else if (placement instanceof LinePlacementImpl) {
LinePlacementImpl linePlacement = (LinePlacementImpl) placement;
labelPlacementGroup.setOption(GroupIdEnum.LINEPLACEMENT);
fieldConfigVisitor.populateField(FieldIdEnum.GAP, linePlacement.getGap());
fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, linePlacement.getInitialGap());
fieldConfigVisitor.populateField(FieldIdEnum.PERPENDICULAR_OFFSET, linePlacement.getPerpendicularOffset());
fieldConfigVisitor.populateBooleanField(FieldIdEnum.GENERALISED_LINE, linePlacement.isGeneralizeLine());
fieldConfigVisitor.populateBooleanField(FieldIdEnum.ALIGN, linePlacement.isAligned());
fieldConfigVisitor.populateBooleanField(FieldIdEnum.REPEATED, linePlacement.isRepeated());
}
}
if (vendorOptionTextFactory != null) {
vendorOptionTextFactory.populate(textSymbolizer);
}
}
}
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class VOGeoServerTextSymbolizer2 method updateSymbol.
/**
* Update symbol.
*
* @param textSymbolizer the text symbolizer
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface#updateSymbol(org.geotools.styling.TextSymbolizer)
*/
@Override
public void updateSymbol(TextSymbolizer textSymbolizer) {
GroupConfigInterface fillGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_FILL);
GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_STROKE);
GroupConfigInterface group = null;
if (textSymbolizer instanceof TextSymbolizer2) {
TextSymbolizer2 textSymbol2 = (TextSymbolizer2) textSymbolizer;
Expression featureDescription = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_FEATURE_DESCRIPTION);
if (!featureDescription.toString().isEmpty()) {
textSymbol2.setFeatureDescription(featureDescription);
}
Expression snippet = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SNIPPET);
if (!snippet.toString().isEmpty()) {
textSymbol2.setSnippet(snippet);
}
// Extract OtherText
OtherText otherText = null;
group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT);
if (group != null) {
if (group.isPanelEnabled()) {
String target = fieldConfigVisitor.getText(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TARGET);
Expression text = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OTHERTEXT_TEXT);
if (!target.isEmpty() && !text.toString().isEmpty()) {
otherText = new OtherTextImpl();
otherText.setTarget(target);
otherText.setText(text);
}
}
}
textSymbol2.setOtherText(otherText);
// Graphic
Graphic graphic = null;
group = getGroup(GroupIdEnum.VO_TEXTSYMBOLIZER_2_GRAPHIC);
if (group.isPanelEnabled()) {
Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SYMBOL_TYPE);
boolean hasFill = (fillGroup == null) ? false : fillGroup.isPanelEnabled();
boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_SIZE);
Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_ANGLE);
List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
AnchorPoint anchor = null;
Displacement displacement = null;
graphic = getStyleFactory().graphic(symbols, null, size, rotation, anchor, displacement);
if (!symbols.isEmpty()) {
boolean overallOpacity = (symbols.get(0) instanceof ExternalGraphic);
if (overallOpacity) {
Expression opacity = fieldConfigVisitor.getExpression(FieldIdEnum.VO_TEXTSYMBOLIZER_2_OVERALL_OPACITY);
graphic.setOpacity(opacity);
}
}
}
textSymbol2.setGraphic(graphic);
}
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class LineFillSymbol method convertToFill.
/**
* Convert to fill.
*
* @param layerName the layer name
* @param element the element
* @param transparency the transparency
* @return the list
*/
/* (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 (layerName == null) {
return null;
}
if (element == null) {
return null;
}
List<Symbolizer> symbolizerList = new ArrayList<Symbolizer>();
JsonObject obj = element.getAsJsonObject();
Expression size = ff.literal(getDouble(obj, LineFillSymbolKeys.SEPARATION));
Expression opacity = null;
double lineAngle = normaliseAngle(getDouble(obj, CommonSymbolKeys.ANGLE));
Expression rotation = null;
AnchorPoint anchorPoint = null;
Displacement displacement = null;
Expression fillColour = getColour(obj.get(LineFillSymbolKeys.FILL_COLOUR));
Expression fillColourOpacity = null;
Expression join = null;
Expression cap = null;
float[] dashes = null;
Expression offset = null;
Expression width = ff.literal(1.0);
Stroke outlineStroke = null;
List<Stroke> strokeList = SymbolManager.getInstance().getStrokeList(obj.get(LineFillSymbolKeys.OUTLINE));
// TODO
if ((strokeList != null) && (strokeList.size() == 1)) {
outlineStroke = strokeList.get(0);
width = outlineStroke.getWidth();
}
Expression wellKnownName = null;
if (isDoubleEqual(lineAngle, 0.0) || isDoubleEqual(lineAngle, 180.0)) {
wellKnownName = ff.literal("shape://horline");
} else if (isDoubleEqual(lineAngle, 90.0) || isDoubleEqual(lineAngle, 270.0)) {
wellKnownName = ff.literal("shape://vertline");
} else if (isDoubleEqual(lineAngle, 45.0) || isDoubleEqual(lineAngle, 225.0)) {
wellKnownName = ff.literal("shape://slash");
} else if (isDoubleEqual(lineAngle, 135.0) || isDoubleEqual(lineAngle, 315.0)) {
wellKnownName = ff.literal("shape://backslash");
} else {
wellKnownName = ff.literal("shape://vertline");
rotation = ff.literal(lineAngle);
}
Fill fill = null;
Stroke markStroke = styleFactory.stroke(fillColour, fillColourOpacity, width, join, cap, dashes, offset);
Mark mark = styleFactory.createMark(wellKnownName, markStroke, fill, size, rotation);
List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
symbolList.add(mark);
GraphicFill graphicFill = styleFactory.graphicFill(symbolList, opacity, size, rotation, anchorPoint, displacement);
Fill completeFill = styleFactory.fill(graphicFill, null, null);
PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer();
polygonSymbolizer.setFill(completeFill);
polygonSymbolizer.setStroke(outlineStroke);
symbolizerList.add(polygonSymbolizer);
return symbolizerList;
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class PictureFillSymbol method getFill.
/**
* Gets the fill.
*
* @param layerName the layer name
* @param obj the obj
* @param transparency the transparency
* @return the fill
*/
@SuppressWarnings("unused")
private Fill getFill(String layerName, JsonObject obj, int transparency) {
double angle = getInt(obj, CommonSymbolKeys.ANGLE);
double xOffset = getInt(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getInt(obj, CommonSymbolKeys.Y_OFFSET);
double xScale = getInt(obj, PictureFillSymbolKeys.X_SCALE);
double yScale = getInt(obj, PictureFillSymbolKeys.Y_SCALE);
Graphic graphic = null;
JsonElement pictureElement = obj.get(PictureFillSymbolKeys.PICTURE);
if (pictureElement != null) {
JsonObject pictureObj = pictureElement.getAsJsonObject();
JsonElement imageElement = pictureObj.get(CommonPictureKeys.IMAGE);
if (imageElement != null) {
String imageString = imageElement.getAsString();
byte[] decodedBytes = DatatypeConverter.parseBase64Binary(imageString);
int height = getInt(pictureObj, CommonPictureKeys.HEIGHT);
int width = getInt(pictureObj, CommonPictureKeys.WIDTH);
String imageType = getString(pictureObj, CommonPictureKeys.TYPE);
ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
BufferedImage image = null;
try {
image = ImageIO.read(bis);
bis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
if (image != null) {
String filename = String.format("%s.%s", layerName, imageType);
File file = new File(filename);
BufferedOutputStream buffOutStream = null;
try {
buffOutStream = new BufferedOutputStream(new FileOutputStream(file));
Expression foregroundColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression backgroundColour = getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR));
if ((foregroundColour != null) && (backgroundColour != null)) {
setForegroundColour(foregroundColour, backgroundColour, image);
}
ImageIO.write(image, imageType, buffOutStream);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
} finally {
if (buffOutStream != null) {
try {
buffOutStream.close();
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
String fileExtension = ExternalFilenames.getFileExtension(filename);
String imageFormat = ExternalFilenames.getImageFormat(fileExtension);
ExternalGraphic externalGraphic = styleFactory.createExternalGraphic(file.toURI().toString(), imageFormat);
List<GraphicalSymbol> symbols = getSymbolList(externalGraphic);
Expression size = null;
Expression opacity = null;
Displacement displacement = styleFactory.createDisplacement(ff.literal(xOffset), ff.literal(yOffset));
AnchorPoint anchorPoint = null;
graphic = styleFactory.graphic(symbols, opacity, size, ff.literal(angle), anchorPoint, displacement);
}
}
}
Fill fill = styleFactory.createFill(getColour(obj.get(CommonSymbolKeys.COLOUR)), getColour(obj.get(PictureFillSymbolKeys.BACKGROUND_COLOUR)), getTransparency(transparency), graphic);
return fill;
}
use of org.geotools.styling.Displacement in project sldeditor by robward-scisys.
the class TextSymbol method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.symbols.EsriTextSymbolInterface#convert(org.geotools.styling.TextSymbolizer, com.google.gson.JsonElement, int)
*/
@SuppressWarnings("unused")
@Override
public void convert(TextSymbolizer textSymbolizer, JsonElement element, int transparency) {
if ((element != null) && (textSymbolizer != null)) {
JsonObject obj = element.getAsJsonObject();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
int breakCharacter = getInt(obj, TextSymbolKeys.BREAK_CHARACTER);
int textCase = getInt(obj, TextSymbolKeys.CASE);
double characterSpacing = getDouble(obj, TextSymbolKeys.CHARACTER_SPACING);
double characterWidth = getDouble(obj, TextSymbolKeys.CHARACTER_WIDTH);
double size = getDouble(obj, CommonSymbolKeys.SIZE);
size += MXDOptions.getInstance().getFontSizeFactor();
int direction = getInt(obj, TextSymbolKeys.DIRECTION);
double flipAngle = getDouble(obj, TextSymbolKeys.FLIP_ANGLE);
int horizontalAlignment = getInt(obj, TextSymbolKeys.HORIZONTAL_ALIGNMENT);
int verticalAlignment = getInt(obj, TextSymbolKeys.VERTICAL_ALIGNMENT);
double leading = getDouble(obj, TextSymbolKeys.LEADING);
double margin = getDouble(obj, TextSymbolKeys.MARGIN);
double maskSize = getDouble(obj, TextSymbolKeys.MASK_SIZE);
int maskStyle = getInt(obj, TextSymbolKeys.MASK_STYLE);
int position = getInt(obj, TextSymbolKeys.POSITION);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
double shadowXOffset = getDouble(obj, TextSymbolKeys.SHADOW_X_OFFSET);
double shadowYOffset = getDouble(obj, TextSymbolKeys.SHADOW_Y_OFFSET);
double wordSpacing = getDouble(obj, TextSymbolKeys.WORD_SPACING);
boolean CJKCharactersRotation = getBoolean(obj, TextSymbolKeys.CJK_CHARACTERS_ROTATION);
boolean clip = getBoolean(obj, TextSymbolKeys.CLIP);
boolean kerning = getBoolean(obj, TextSymbolKeys.KERNING);
boolean rightToLeft = getBoolean(obj, TextSymbolKeys.RIGHT_TO_LEFT);
boolean rotateWithTransform = getBoolean(obj, TextSymbolKeys.ROTATE_WITH_TRANSFORM);
boolean typeSetting = getBoolean(obj, TextSymbolKeys.TYPE_SETTING);
//
// Point placement
//
AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0), ff.literal(0));
Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
Expression rotationExpression = ff.literal(angle);
styleFactory.pointPlacement(anchorPoint, displacement, rotationExpression);
//
// Font
//
JsonElement fontElement = obj.get(TextSymbolKeys.FONT);
if (fontElement != null) {
JsonObject fontObj = fontElement.getAsJsonObject();
String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
boolean bold = getBoolean(fontObj, FontSymbolKeys.BOLD);
boolean italic = getBoolean(fontObj, FontSymbolKeys.ITALIC);
boolean strikeThrough = getBoolean(fontObj, FontSymbolKeys.STRIKE_THROUGH);
boolean underline = getBoolean(fontObj, FontSymbolKeys.UNDERLINE);
int weight = getInt(fontObj, FontSymbolKeys.FONT_WEIGHT);
int charset = getInt(fontObj, FontSymbolKeys.CHARSET);
int fontSize = getInt(obj, FontSymbolKeys.FONT_SIZE);
Expression fontFamilyExpression = ff.literal(fontName);
Expression fontSizeExpression = ff.literal(size);
String fontStyle = "normal";
if (italic) {
fontStyle = "italic";
}
Expression fontStyleExpression = ff.literal(fontStyle);
String fontWeight = "normal";
if (bold) {
fontWeight = "bold";
}
Expression fontWeightExpression = ff.literal(fontWeight);
Font font = styleFactory.createFont(fontFamilyExpression, fontStyleExpression, fontWeightExpression, fontSizeExpression);
textSymbolizer.setFont(font);
}
GraphicFill graphicFill = null;
Expression textColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression opacity = null;
if (transparency != 0) {
opacity = ff.literal(transparency / 255);
}
Fill fill = styleFactory.fill(graphicFill, textColour, opacity);
textSymbolizer.setFill(fill);
String geometryPropertyName = null;
textSymbolizer.setGeometryPropertyName(geometryPropertyName);
Expression shadowColour = getColour(obj.get(TextSymbolKeys.SHADOW_COLOUR));
}
}
Aggregations