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 "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2006/03/08 20:09:45 UTC

RE: Seemingly simple question...

OK, long time getting to it, but I'm finally messing with this
SVGStylable interface.  When I take an SVG element and try to cast it to
an SVGStylable, everything works.  It seems that calling getStyle()
results in an NPE if no style attribute currently exists.  In some
cases, it breaks even if it does exist!

I try to create a "layer" in my document and default it to being
visible:

element = svgDocument.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
SVGConstants.SVG_G_TAG);
element.setAttribute(Constants.PNTR_EVTS_ATTR,
SVGConstants.SVG_NONE_VALUE);
SVGStylable stylable = (SVGStylable) element;

// This causes an NPE!
stylable.getStyle().setProperty("visibility", "visible", "");

// So I try this instead...
element.setAttribute(Constants.STYLE_ATTR,Constants.VISIBILITY_ATTR + ":
" + Constants.VISIBLE_VALUE);

// Which works until I try to check its visibility elsewhere:
public static boolean isVisible(Element element) {
        SVGStylable stylable = (SVGStylable) element;

	  // NPE here again.
        String visible = 
	
stylable.getStyle().getPropertyValue(Constants.VISIBILITY_ATTR);

        return visible.equalsIgnoreCase(Constants.VISIBLE_VALUE);
}

Any help?

Michael Bishop

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: Thursday, December 22, 2005 7:47 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Seemingly simple question...

Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on

12/22/2005 04:13:34 PM:

> OK, well in that case, working with CSS won't be so bad.  Now on the
SAC
> page, they have their own implementation, and they also say that Batik
> has an implementation.  What kind of object is "e" where you can call
> getStyle() on it?  Do you use the Batik 1.2 SAC or the standalone SAC
> 1.3?

   'e' is any 'graphics' SVG Element from the DOM.

        e = document.getElementById("myG");

   You will want to cast it to a 'org.w3c.dom.svg.SVGStylable'
interface.

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

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


RE: Seemingly simple question...

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

   I think the element has to be 'part of the document' for styling to 
work properly (otherwise the cascade is wonky).
So you will need to append it to the Document (preferably where it will be 
rendered) before querying style info
otherwise it could inherit values other than the CSS 'defaults'.

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
03/08/2006 02:09:45 PM:

> OK, long time getting to it, but I'm finally messing with this
> SVGStylable interface.  When I take an SVG element and try to cast it to
> an SVGStylable, everything works.  It seems that calling getStyle()
> results in an NPE if no style attribute currently exists.  In some
> cases, it breaks even if it does exist!
> 
> I try to create a "layer" in my document and default it to being
> visible:
> 
> element = svgDocument.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
> SVGConstants.SVG_G_TAG);
> element.setAttribute(Constants.PNTR_EVTS_ATTR,
> SVGConstants.SVG_NONE_VALUE);
> SVGStylable stylable = (SVGStylable) element;
> 
> // This causes an NPE!
> stylable.getStyle().setProperty("visibility", "visible", "");
> 
> // So I try this instead...
> element.setAttribute(Constants.STYLE_ATTR,Constants.VISIBILITY_ATTR + ":
> " + Constants.VISIBLE_VALUE);
> 
> // Which works until I try to check its visibility elsewhere:
> public static boolean isVisible(Element element) {
>         SVGStylable stylable = (SVGStylable) element;
> 
>      // NPE here again.
>         String visible = 
> 
> stylable.getStyle().getPropertyValue(Constants.VISIBILITY_ATTR);
> 
>         return visible.equalsIgnoreCase(Constants.VISIBLE_VALUE);
> }
> 
> Any help?
> 
> Michael Bishop
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
> Sent: Thursday, December 22, 2005 7:47 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: Seemingly simple question...
> 
> Hi Michael,
> 
> "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on
> 
> 12/22/2005 04:13:34 PM:
> 
> > OK, well in that case, working with CSS won't be so bad.  Now on the
> SAC
> > page, they have their own implementation, and they also say that Batik
> > has an implementation.  What kind of object is "e" where you can call
> > getStyle() on it?  Do you use the Batik 1.2 SAC or the standalone SAC
> > 1.3?
> 
>    'e' is any 'graphics' SVG Element from the DOM.
> 
>         e = document.getElementById("myG");
> 
>    You will want to cast it to a 'org.w3c.dom.svg.SVGStylable'
> interface.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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