final int quintupleWidth = 5;
if (this.allowNullSymbolizer && allowNull && !styleJson.has(JSON_STROKE_COLOR)) {
return null;
}
Expression strokeColor = parseExpression(Color.black, styleJson, JSON_STROKE_COLOR, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return toColorExpression(input);
}
});
Expression strokeOpacity = parseExpression(1.0, styleJson, JSON_STROKE_OPACITY, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return Double.parseDouble(styleJson.getString(JSON_STROKE_OPACITY));
}
});
Expression widthExpression = parseExpression(1, styleJson, JSON_STROKE_WIDTH, new Function<String, Object>() {
@Nullable
@Override
public Object apply(final String input) {
return Double.parseDouble(styleJson.getString(JSON_STROKE_WIDTH));
}
});
float[] dashArray = null;
if (styleJson.has(JSON_STROKE_DASHSTYLE) && !STROKE_DASHSTYLE_SOLID.equals(styleJson.getString(JSON_STROKE_DASHSTYLE))) {
Double width = 1.0;
if (widthExpression instanceof Literal) {
Literal expression = (Literal) widthExpression;
width = ((Number) expression.getValue()).doubleValue();
}
String dashStyle = styleJson.getString(JSON_STROKE_DASHSTYLE);
if (dashStyle.equalsIgnoreCase(STROKE_DASHSTYLE_DOT)) {
dashArray = new float[]{defaultDashSpacing, (float) (doubleWidth * width)};
} else if (dashStyle.equalsIgnoreCase(STROKE_DASHSTYLE_DASH)) {
dashArray = new float[]{(float) (doubleWidth * width), (float) (doubleWidth * width)};
} else if (dashStyle.equalsIgnoreCase(STROKE_DASHSTYLE_DASHDOT)) {
dashArray = new float[]{
(float) (tripleWidth * width),
(float) (doubleWidth * width),
defaultDashSpacing,
(float) (doubleWidth * width)};
} else if (dashStyle.equalsIgnoreCase(STROKE_DASHSTYLE_LONGDASH)) {
dashArray = new float[]{
(float) (quadrupleWidth * width),
(float) (doubleWidth * width)};
} else if (dashStyle.equalsIgnoreCase(STROKE_DASHSTYLE_LONGDASHDOT)) {
dashArray = new float[]{
(float) (quintupleWidth * width),
(float) (doubleWidth * width),
defaultDashSpacing,
(float) (doubleWidth * width)};
} else if (dashStyle.contains(" ")) {
//check for pattern if empty array, throw.
try {
String[] x = dashStyle.split(" ");
if (x.length > 1) {
dashArray = new float[x.length];
for (int i = 0; i < x.length; i++) {
dashArray[i] = Float.parseFloat(x[i]);
}
}
} catch (NumberFormatException e) {
//assume solid!
}
} else {
throw new IllegalArgumentException("strokeDashstyle does not have a legal value: " + dashStyle);
}
}
Expression lineCap = parseExpression(null, styleJson, JSON_STROKE_LINECAP, Functions.<String>identity());
final Stroke stroke = this.styleBuilder.createStroke(strokeColor, widthExpression);
stroke.setLineCap(lineCap);
stroke.setOpacity(strokeOpacity);
stroke.setDashArray(dashArray);