You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by mistercaste <mi...@gmail.com> on 2009/07/17 12:04:41 UTC

CompositeGraphicsNode to ShapeNode

Hi, I'm trying to change the GraphicsNode color of a relative DOM element via
the BridgeContext but I get as casting error "CompositeGraphicsNode cannot
be cast to ShapeNode". Here is my code:

BridgeContext bc = ((JSVGCanvas) c).getUpdateManager().getBridgeContext();
bc.setDynamic(true);
bc.setInteractive(true);

// This is a CompositeGraphicsNode (implements GraphicsNode)
GraphicsNode gn = (GraphicsNode) bc.getGraphicsNode(element);

ShapeNode sn = (ShapeNode)gn;  <---------- THIS CAST DOESN'T WORK
ShapePainter sp = sn.getShapePainter();
StrokeShapePainter painter = new StrokeShapePainter(sn.getShape());
painter.setPaint(Color.YELLOW);
painter.setStroke(new BasicStroke(10.0f));
sn.setShapePainter(painter);


On the ShapeNode casting I get the following error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
org.apache.batik.gvt.CompositeGraphicsNode cannot be cast to
org.apache.batik.gvt.ShapeNode

Any ideas or suggestion on what to do? Thanks



-- 
View this message in context: http://www.nabble.com/CompositeGraphicsNode-to-ShapeNode-tp24531759p24531759.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: CompositeGraphicsNode to ShapeNode

Posted by th...@kodak.com.
Hi  Mistercaste,

mistercaste <mi...@gmail.com> wrote on 07/17/2009 06:04:41 AM:

> Hi, I'm trying to change the GraphicsNode color of a relative DOM 
element via
> the BridgeContext but I get as casting error "CompositeGraphicsNode 
cannot
> be cast to ShapeNode". Here is my code:

   You can't change the color on a CompositeGraphicsNode.  You can set
the color of an SVG 'g' Element, which will then cascade to it's children
according to the rules of CSS.

> BridgeContext bc = ((JSVGCanvas) 
c).getUpdateManager().getBridgeContext();
> bc.setDynamic(true);
> bc.setInteractive(true);
> 
> // This is a CompositeGraphicsNode (implements GraphicsNode)
> GraphicsNode gn = (GraphicsNode) bc.getGraphicsNode(element);
> 
> ShapeNode sn = (ShapeNode)gn;  <---------- THIS CAST DOESN'T WORK
> ShapePainter sp = sn.getShapePainter();
> StrokeShapePainter painter = new StrokeShapePainter(sn.getShape());
> painter.setPaint(Color.YELLOW);
> painter.setStroke(new BasicStroke(10.0f));
> sn.setShapePainter(painter);

> Any ideas or suggestion on what to do? Thanks

    I would suggest code more like:

        element.setAttributeNS(null, "stroke", "yellow");
        element.setAttributeNS(null, "stroke-width", "10");