use of org.geotools.styling.AnchorPoint 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.AnchorPoint 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.AnchorPoint 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.AnchorPoint 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));
}
}
use of org.geotools.styling.AnchorPoint 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;
}
Aggregations