use of org.geotools.styling.MarkImpl in project sldeditor by robward-scisys.
the class SLDUtilsTest method testReadSLDFile.
@Test
public void testReadSLDFile() {
try {
File tmpFile = File.createTempFile(getClass().getSimpleName(), ".sld");
FileWriter fileWriter = new FileWriter(tmpFile);
fileWriter.write(expectedSld);
fileWriter.flush();
fileWriter.close();
StyledLayerDescriptor sld = SLDUtils.readSLDFile(null);
assertNull(sld);
sld = SLDUtils.readSLDFile(tmpFile);
StyledLayer[] styledLayers = sld.getStyledLayers();
NamedLayer namedLayer = (NamedLayer) styledLayers[0];
Style[] actualStyles = namedLayer.getStyles();
PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
assertEquals("circle", mark.getWellKnownName().toString());
tmpFile.delete();
} catch (IOException e) {
e.printStackTrace();
fail("Failed to create test file");
}
}
use of org.geotools.styling.MarkImpl in project sldeditor by robward-scisys.
the class SLDTreeLeafPointTest method testGetFill.
/**
* Test method for
* {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPoint#getFill(org.opengis.style.Symbolizer)}.
*/
@Test
public void testGetFill() {
SLDTreeLeafPoint leaf = new SLDTreeLeafPoint();
assertNull(leaf.getFill(null));
assertNull(leaf.getFill(DefaultSymbols.createDefaultPolygonSymbolizer()));
PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
Fill expectedFill = null;
Graphic graphic = pointSymbolizer.getGraphic();
if (graphic != null) {
List<GraphicalSymbol> symbolList = graphic.graphicalSymbols();
if ((symbolList != null) && !symbolList.isEmpty()) {
GraphicalSymbol obj = symbolList.get(0);
if (obj != null) {
if (obj instanceof MarkImpl) {
MarkImpl mark = (MarkImpl) obj;
expectedFill = mark.getFill();
}
}
}
}
assertEquals(expectedFill, leaf.getFill(pointSymbolizer));
}
use of org.geotools.styling.MarkImpl 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.geotools.styling.MarkImpl 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);
}
use of org.geotools.styling.MarkImpl in project sldeditor by robward-scisys.
the class StrokeDetails method updateSymbol.
/**
* Update symbol.
*/
private void updateSymbol() {
if (!Controller.getInstance().isPopulating()) {
Stroke stroke = getStroke();
if (symbolizer instanceof PointSymbolizer) {
PointSymbolizer pointSymbol = (PointSymbolizer) symbolizer;
Graphic graphic = pointSymbol.getGraphic();
GraphicalSymbol symbol = graphic.graphicalSymbols().get(0);
if (symbol instanceof MarkImpl) {
MarkImpl markerSymbol = (MarkImpl) symbol;
markerSymbol.setStroke(stroke);
SelectedSymbol.getInstance().replaceSymbolizer(pointSymbol);
this.fireUpdateSymbol();
}
} else if (symbolizer instanceof LineSymbolizer) {
LineSymbolizer lineSymbol = (LineSymbolizer) symbolizer;
lineSymbol.setStroke(stroke);
SelectedSymbol.getInstance().replaceSymbolizer(lineSymbol);
this.fireUpdateSymbol();
} else if (symbolizer instanceof PolygonSymbolizer) {
PolygonSymbolizer polygonSymbol = (PolygonSymbolizer) symbolizer;
polygonSymbol.setStroke(stroke);
SelectedSymbol.getInstance().replaceSymbolizer(polygonSymbol);
this.fireUpdateSymbol();
}
}
}
Aggregations