Hi Emily and Johann
Here is an example of how to update a LineSymbolizer with a new color ..
using a visitor to duplicate the immutable parts rather than just a set
method.
Based on the experience Emily and I just had writing this I would like
to suggest that Johann's StyleVisitor to be similar to the
ExpressionVisitor and allow the implementor to return an object. It will
also be important that the factory interface used not perform any logic
(such as magically adding in default styles).
For code already making use of the SLD utility class this transition
should be smooth; for code making use of the set methods directly some
pain may ensue.
Here is that example:
> /**
> * Updates the color for line symbolizers in the current style.
> * <p>
> * This method will update the Style in place; some of the symbolizers
> * will be replaced with modified copies.
> * </p>
> *
> * @param style Will update the style in place
> * @param colour Color to to use
> */
> public static void setLineColour(Style style, final Color colour) {
> if (style == null) {
> return;
> }
> for( FeatureTypeStyle featureTypeStyle :
> style.getFeatureTypeStyles() ){
> for( int i =0; i<featureTypeStyle.rules().size(); i++){
> Rule rule = featureTypeStyle.rules().get( i );
> DuplicatingStyleVisitor update = new
> DuplicatingStyleVisitor(){
> public void visit(LineSymbolizer line) {
> String name = line.getGeometryPropertyName();
> Stroke stroke = update( line.getStroke());
> LineSymbolizer copy = sf.createLineSymbolizer(
> stroke, name );
> pages.push(copy);
> }
> Stroke update( Stroke stroke ){
> Expression color = ff.literal( colour );
> Expression width = copy(stroke.getWidth());
> Expression opacity = copy( stroke.getOpacity() );
> Expression lineJoin = copy(
> stroke.getLineJoin() );
> Expression lineCap = copy( stroke.getLineCap() );
> float[] dashArray = copy( stroke.getDashArray() );
> Expression dashOffset = copy(
> stroke.getDashOffset() );
> Graphic graphicStroke = copy(
> stroke.getGraphicStroke() );
> Graphic graphicFill = copy(
> stroke.getGraphicFill() );
> return sf.createStroke(color, width, opacity,
> lineJoin, lineCap, dashArray, dashOffset, graphicFill,
> graphicStroke);
> }
> };
> rule.accept( update );
> Rule updatedRule = (Rule) update.getCopy();
> featureTypeStyle.rules().set(i, updatedRule);
> }
> }
> }
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel