use of org.opengis.style.GraphicalSymbol 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.opengis.style.GraphicalSymbol 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.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class DefaultSymbols method createDefaultPointSymbolizer.
/**
* Creates the default point symbolizer.
*
* @return the point symbolizer
*/
public static PointSymbolizer createDefaultPointSymbolizer() {
String geometryFieldName = null;
Expression geometryField = ff.property(geometryFieldName);
List<GraphicalSymbol> symbolList = new ArrayList<GraphicalSymbol>();
Stroke stroke = null;
AnchorPoint anchorPoint = null;
Displacement displacement = null;
Fill fill = styleFactory.createFill(ff.literal(DEFAULT_MARKER_COLOUR));
GraphicalSymbol symbol = styleFactory.mark(ff.literal(DEFAULT_MARKER_SYMBOL), fill, stroke);
symbolList.add(symbol);
Graphic graphic = styleFactory.graphic(symbolList, ff.literal(DEFAULT_COLOUR_OPACITY), ff.literal(DEFAULT_MARKER_SYMBOL_SIZE), ff.literal(0.0), anchorPoint, displacement);
PointSymbolizer newPointSymbolizer = (PointSymbolizer) styleFactory.pointSymbolizer(Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker"), geometryField, null, null, graphic);
return newPointSymbolizer;
}
use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class StrokeDetails method populateStroke.
/**
* Populate stroke.
*
* @param symbolizerType the symbolizer type
* @param stroke the stroke
*/
private void populateStroke(Class<?> symbolizerType, Stroke stroke) {
Expression expColour = null;
Expression expStrokeColour = null;
Expression expOpacity = null;
Expression expStrokeWidth = null;
Expression expStrokeOffset = null;
Expression expStrokeLineCap = null;
Expression expStrokeLineJoin = null;
Expression expStrokeDashArray = null;
Expression expAnchorPointX = null;
Expression expAnchorPointY = null;
Expression expDisplacementX = null;
Expression expDisplacementY = null;
Expression expGap = null;
Expression expInitialGap = null;
Expression expSymbolSize = null;
Expression expSymbolRotation = null;
if (stroke == null) {
expColour = getFilterFactory().literal("#000000");
expOpacity = getFilterFactory().literal(1.0);
symbolTypeFactory.setSolidFill(fieldConfigManager, expColour, expOpacity);
expStrokeWidth = getFilterFactory().literal(1.0);
expStrokeOffset = getFilterFactory().literal(0.0);
expStrokeLineCap = getFilterFactory().literal("round");
expStrokeLineJoin = getFilterFactory().literal("round");
expStrokeDashArray = getFilterFactory().literal("");
} else {
Graphic graphicFill = stroke.getGraphicFill();
Graphic graphicStroke = stroke.getGraphicStroke();
if ((graphicFill == null) && (graphicStroke == null)) {
expOpacity = stroke.getOpacity();
symbolTypeFactory.setSolidFill(fieldConfigManager, stroke.getColor(), stroke.getOpacity());
}
expOpacity = stroke.getOpacity();
expStrokeWidth = stroke.getWidth();
expStrokeOffset = stroke.getDashOffset();
expStrokeLineCap = stroke.getLineCap();
expStrokeLineJoin = stroke.getLineJoin();
expColour = stroke.getColor();
List<Float> dashesArray = getStrokeDashArray(stroke);
expStrokeDashArray = getFilterFactory().literal(createDashArrayString(dashesArray));
if (graphicStroke != null) {
// Anchor points
AnchorPoint anchorPoint = graphicStroke.getAnchorPoint();
if (anchorPoint != null) {
expAnchorPointX = anchorPoint.getAnchorPointX();
expAnchorPointY = anchorPoint.getAnchorPointY();
} else {
expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
}
// Displacement
Displacement displacement = graphicStroke.getDisplacement();
if (displacement != null) {
expDisplacementX = displacement.getDisplacementX();
expDisplacementY = displacement.getDisplacementY();
} else {
expDisplacementX = defaultDisplacement.getDisplacementX();
expDisplacementY = defaultDisplacement.getDisplacementY();
}
expGap = graphicStroke.getGap();
expInitialGap = graphicStroke.getInitialGap();
expSymbolSize = graphicStroke.getSize();
expSymbolRotation = graphicStroke.getRotation();
List<GraphicalSymbol> graphicSymbolList = graphicStroke.graphicalSymbols();
for (GraphicalSymbol graphicSymbol : graphicSymbolList) {
if (graphicSymbol instanceof MarkImpl) {
MarkImpl mark = (MarkImpl) graphicSymbol;
Mark defaultMark = getStyleFactory().getDefaultMark();
Fill markFill = mark.getFill();
if (markFill != null) {
expColour = markFill.getColor();
}
expStrokeColour = defaultMark.getStroke().getColor();
Stroke markStroke = mark.getStroke();
if (markStroke != null) {
expStrokeColour = markStroke.getColor();
}
} else if (graphicSymbol instanceof ExternalGraphicImpl) {
@SuppressWarnings("unused") ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) graphicSymbol;
}
symbolTypeFactory.setValue(symbolizerType, this.fieldConfigManager, graphicStroke, graphicSymbol);
}
}
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_WIDTH, expStrokeWidth);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_OFFSET, expStrokeOffset);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_CAP, expStrokeLineCap);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_JOIN, expStrokeLineJoin);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_DASH_ARRAY, expStrokeDashArray);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_GAP, expGap);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP, expInitialGap);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_SIZE, expSymbolSize);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANGLE, expSymbolRotation);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H, expAnchorPointX);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V, expAnchorPointY);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X, expDisplacementX);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y, expDisplacementY);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_FILL_COLOUR, expColour);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_STROKE_COLOUR, expStrokeColour);
if ((graphicFill == null) && (graphicStroke == null)) {
GroupConfigInterface fillColourGroup = getGroup(GroupIdEnum.FILLCOLOUR);
if (fillColourGroup != null) {
fillColourGroup.enable(true);
}
}
//
// GroupConfigInterface strokeColourGroup = getGroup(GroupIdEnum.STROKECOLOUR);
// if (strokeColourGroup != null) {
// strokeColourGroup.enable(strokeColourEnabled);
// }
}
}
use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class StrokeDetails 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) {
Stroke stroke = null;
if (selectedSymbol != null) {
symbolizer = selectedSymbol.getSymbolizer();
if (symbolizer instanceof PointSymbolizer) {
PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
Graphic graphic = pointSymbolizer.getGraphic();
List<GraphicalSymbol> graphicalSymbols = graphic.graphicalSymbols();
if (graphicalSymbols.size() > 0) {
GraphicalSymbol symbol = graphicalSymbols.get(0);
if (symbol instanceof MarkImpl) {
MarkImpl markerSymbol = (MarkImpl) symbol;
stroke = markerSymbol.getStroke();
}
}
} else if (symbolizer instanceof LineSymbolizer) {
LineSymbolizer lineSymbol = (LineSymbolizer) symbolizer;
stroke = lineSymbol.getStroke();
} else if (symbolizer instanceof PolygonSymbolizer) {
PolygonSymbolizer polygonSymbol = (PolygonSymbolizer) symbolizer;
stroke = polygonSymbol.getStroke();
}
}
Class<?> symbolizerClass = null;
if (symbolizer != null) {
symbolizerClass = symbolizer.getClass();
}
populateStroke(symbolizerClass, stroke);
}
Aggregations