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 Andres Toussaint <an...@onemileup.com> on 2005/05/01 03:03:19 UTC

Re: Selecting elements (by position?)

Do you have "listener" elements in the SVG file that overlap each  
other? or are they going to be clearly separated? If they are  
separated, you may do a MouseEvent listening routine on the SVG  
elements while you are drawing the sketch in the overlay, and thus, you  
have nearest element.

But, if the situation is that you have multiple 'listener' elements  
that overlap each other and the sketch may be in some cases a path  
circling the element in question, with perhaps a glyph in the middle to  
indicate zoom into this one, etc. Then the MouseEvent approach may not  
work, because the element in question is inside the area indicated by  
the path but during the actual drawing of the path, the mouse was never  
on top of the element in question, and thus the MouseEvent for that  
element was never triggered. If this is the case, then the i see two  
options:
a. ) Traverse your DOM manually, and perform a check of each element's  
center, with the centroid you have found out.

b.) Programatically generate a DOM MouseEvent with your centroid  
coordinates, to trigger the MouseEvent on the desired Element. I have  
done no research on how to do this second approach, but it makes a lot  
of sense to me, to tell the DOM to trigger a mouse event with specific  
coordinates, so the underlying routines select the receiver target and  
trigger the event.
				Thomas: Can this be done?

Whatever the approach, you need to make sure the coordinates indicated  
in your centroid are in SVG coordinate space, as indicated in the Drag  
tutorial.

Regards,
Andres.


On Apr 30, 2005, at 3:34 PM, Archie Cobbs wrote:

> Brian Johnson wrote:
>> I'm new to Batik and naive in Java, though experienced in older  
>> languages and graphics environments. I have a student who is working  
>> to combine various technologies into a Java application--including  
>> SVG files and sketch recognition. The basic strategy is to load an  
>> externally generated SVG file which has associated style ID's with  
>> <g> elements, display this graphpic, allow the user to sketch marks  
>> on top of the SVG, categorize the sketch gesture, identify what was  
>> "under" the sketch, and then produce a folllow-up action. We're now  
>> at the point where we need to identify the element. We know where (in  
>> terms of the overlayed Java Graphics world) the centroid of the  
>> sketch was and want to query the SVG for the ID of the nearest  
>> element "under" this sketch.
>
> You can use the org.w3c.dom.events.EventTarget and
> org.w3c.dom.events.MouseEvent classes to detect mouse over,
> mouse click, etc. events by registering the appropriate
> listener(s). Pretty much any SVGElement in the DOM can be
> cast to an EventTarget.
>
> -Archie
>
> _______________________________________________________________________ 
> ___
> Archie Cobbs      *        CTO, Awarix        *       
> http://www.awarix.com
>
> ---------------------------------------------------------------------
> 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: saving svg as jpeg on tomcat server

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Arian,

Arian Hojat wrote:

> I guess some imaging/gui type code needs X support off? This is what
> headless means? This seems to be what i found out from googling.

    Yes, normally when the AWT toolkit is booted it contacts the
X Server so it can provide info about the 'graphics environment'
(color depth, fonts etc).  Headless means that there isn't a
display attached.

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


Re: saving svg as jpeg on tomcat server

Posted by Arian Hojat <ar...@gmail.com>.
I took off early from work to come back to college n try it out. i
cannot express the joy and satisfaction of finally getting some Batik
to work with Tomcat! hah.
I am gonna break out some inspirational 70's rock music: "Dont Stop
Beleivin' " heh.

I guess some imaging/gui type code needs X support off? This is what
headless means? This seems to be what i found out from googling.






On 5/2/05, Arian Hojat <ar...@gmail.com> wrote:
> hey thanx for the tip guys. I'll try it tonight... Also I am curious
> what exactly does this headless option for awt have to do with batik?
> Does everyone who uses tomcat and batik do this the 1st time or
> special cases (i just installed the server last month so it hasn't
> seen much action other than batik)?
> 
> thanks,
> Arian
> 
> On 5/2/05, Måns Rullgård <mr...@inprovide.com> wrote:
> > Thomas DeWeese <Th...@Kodak.com> writes:
> >
> > > Hi Arian,
> > >
> > > Arian Hojat wrote:
> > >
> > >> I was wondering am i doing something screwy here?
> > >
> > >     I don't think so, but it looks like the tomcat
> > > JVM might be a little confused/corrupt.  What version
> > > of java is it using?
> > >
> > > Are you running tomcat with '-Djava.awt.headless=true'?
> > >
> > >     Normally you get a can't start AWT message but since
> > > this is the first time AWT is accessed it might be
> > > related.  Or was someone using the headless AWT replacement
> > > at one time?  I think that set a property that was supposed
> > > to replace the Sun Graphics engine.  Perhaps those classes
> > > weren't copied over?
> >
> > I always get that exact error with fresh installs of Sun JDK and
> > Tomcat if -Djava.awt.headless=true is missing.  It took me a few
> > moments to figure it out the first time.
> >
> > >> here is a stack trace on tomcat if anyone wants a look:
> > >> java.lang.NoClassDefFoundError
> > >>      java.lang.Class.forName0(Native Method)
> > >>      java.lang.Class.forName(Class.java:141)
> > >>      java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
> > >>      java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
> > >>      org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
> > >>      org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)
> >
> > --
> > Måns Rullgård
> > mru@inprovide.com
> >
> >
> > ---------------------------------------------------------------------
> > 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: saving svg as jpeg on tomcat server

Posted by Arian Hojat <ar...@gmail.com>.
hey thanx for the tip guys. I'll try it tonight... Also I am curious
what exactly does this headless option for awt have to do with batik?
Does everyone who uses tomcat and batik do this the 1st time or
special cases (i just installed the server last month so it hasn't
seen much action other than batik)?

thanks,
Arian

On 5/2/05, Måns Rullgård <mr...@inprovide.com> wrote:
> Thomas DeWeese <Th...@Kodak.com> writes:
> 
> > Hi Arian,
> >
> > Arian Hojat wrote:
> >
> >> I was wondering am i doing something screwy here?
> >
> >     I don't think so, but it looks like the tomcat
> > JVM might be a little confused/corrupt.  What version
> > of java is it using?
> >
> > Are you running tomcat with '-Djava.awt.headless=true'?
> >
> >     Normally you get a can't start AWT message but since
> > this is the first time AWT is accessed it might be
> > related.  Or was someone using the headless AWT replacement
> > at one time?  I think that set a property that was supposed
> > to replace the Sun Graphics engine.  Perhaps those classes
> > weren't copied over?
> 
> I always get that exact error with fresh installs of Sun JDK and
> Tomcat if -Djava.awt.headless=true is missing.  It took me a few
> moments to figure it out the first time.
> 
> >> here is a stack trace on tomcat if anyone wants a look:
> >> java.lang.NoClassDefFoundError
> >>      java.lang.Class.forName0(Native Method)
> >>      java.lang.Class.forName(Class.java:141)
> >>      java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
> >>      java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
> >>      org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
> >>      org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)
> 
> --
> Måns Rullgård
> mru@inprovide.com
> 
> 
> ---------------------------------------------------------------------
> 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: saving svg as jpeg on tomcat server

Posted by Måns Rullgård <mr...@inprovide.com>.
Thomas DeWeese <Th...@Kodak.com> writes:

> Hi Arian,
>
> Arian Hojat wrote:
>
>> I was wondering am i doing something screwy here?
>
>     I don't think so, but it looks like the tomcat
> JVM might be a little confused/corrupt.  What version
> of java is it using?
>
> Are you running tomcat with '-Djava.awt.headless=true'?
>
>     Normally you get a can't start AWT message but since
> this is the first time AWT is accessed it might be
> related.  Or was someone using the headless AWT replacement
> at one time?  I think that set a property that was supposed
> to replace the Sun Graphics engine.  Perhaps those classes
> weren't copied over?

I always get that exact error with fresh installs of Sun JDK and
Tomcat if -Djava.awt.headless=true is missing.  It took me a few
moments to figure it out the first time.

>> here is a stack trace on tomcat if anyone wants a look:
>> java.lang.NoClassDefFoundError
>> 	java.lang.Class.forName0(Native Method)
>> 	java.lang.Class.forName(Class.java:141)
>> 	java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
>> 	java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
>> 	org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
>> 	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)

-- 
Måns Rullgård
mru@inprovide.com


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


Re: saving svg as jpeg on tomcat server

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Arian,

Arian Hojat wrote:

> I was wondering am i doing something screwy here?

    I don't think so, but it looks like the tomcat
JVM might be a little confused/corrupt.  What version
of java is it using?

Are you running tomcat with '-Djava.awt.headless=true'?

    Normally you get a can't start AWT message but since
this is the first time AWT is accessed it might be
related.  Or was someone using the headless AWT replacement
at one time?  I think that set a property that was supposed
to replace the Sun Graphics engine.  Perhaps those classes
weren't copied over?

> here is a stack trace on tomcat if anyone wants a look:
> 
> java.lang.NoClassDefFoundError
> 	java.lang.Class.forName0(Native Method)
> 	java.lang.Class.forName(Class.java:141)
> 	java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
> 	java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
> 	org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
> 	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)

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


saving svg as jpeg on tomcat server

Posted by Arian Hojat <ar...@gmail.com>.
whoops i might have sent this email be4 prematurely.... rewriting just
to make sure.....

Hello all,
I have a function to save my svg document as a jpeg. i fixed my code
from be4 so unix or windows filepaths shouldnt make a difference. it
works fine in windows. but on unix, it saves a 0 kb jpg and throws an
exception somewhere as my code does not go completely through and get
the standard 'The page cannot be displayed' page.
I was wondering am i doing something screwy here?



 public static void saveJPEG(Document svgDoc, String fullPath,
PrintWriter out) {
        //printwriter used for debugging in servlet
        JPEGTranscoder t = new JPEGTranscoder();

        FileInputStream blah = null;
        TranscoderInput input = null;
        FileOutputStream ostream = null;
        TranscoderOutput output = null;
        
        File f = null;
        
        input = new TranscoderInput( svgDoc );
        
        f = new File(fullPath+     "yyyy.jpg");

        
        try {
            ostream = new FileOutputStream(f);
        } catch(FileNotFoundException e) {
            e.getMessage();
        }
        output = new TranscoderOutput(ostream);

        try {
>stack trace says there is a problem here....           
t.transcode(input, output);
        } catch( TranscoderException e) {
            e.getMessage();
        }
        
        try{
            ostream.flush();
            ostream.close();
        } catch(IOException e) {
            e.getMessage();
        }
        
        
    }


here is a stack trace on tomcat if anyone wants a look:

java.lang.NoClassDefFoundError
	java.lang.Class.forName0(Native Method)
	java.lang.Class.forName(Class.java:141)
	java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
	java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
	org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)
	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.copyData(Unknown Source)
	org.apache.batik.ext.awt.image.rendered.TileCacheRed.genRect(Unknown Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.drawBlockInPlace(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.drawBlock(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.copyToRasterByBlocks(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.copyData(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.TranslateRed.copyData(Unknown Source)
	org.apache.batik.ext.awt.image.rendered.PadRed.copyData(Unknown Source)
	org.apache.batik.gvt.renderer.StaticRenderer.repaint(Unknown Source)
	org.apache.batik.gvt.renderer.StaticRenderer.repaint(Unknown Source)
	org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
	org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
	org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
	w6.saveJPEG(w6.java:254)
	w6.imageTest(w6.java:413)
	w6.doGet(w6.java:199)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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


Re: Selecting elements (by position?)

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi all,

    The easiest way to do this is with
'SVGSVGElement.getIntersectionList'.  Which lets you provide
a rectangle and it will return all the elements that intersect
that rect.

Andres Toussaint wrote:
> b.) Programatically generate a DOM MouseEvent with your centroid  
> coordinates, to trigger the MouseEvent on the desired Element. I have  
> done no research on how to do this second approach, but it makes a lot  
> of sense to me, to tell the DOM to trigger a mouse event with specific  
> coordinates, so the underlying routines select the receiver target and  
> trigger the event.
>                 Thomas: Can this be done?

     Yes it can... Sort of.  You use 
dom.events.DocumentEvent.createEvent (on the Document object) to create 
an event instance.  Then you can
dispatch it with dispatchEvent the problem is that you already have to
know what element you want to dispatch it to (i.e. what element is under
the point).  So you really want to use getIntersectionList.

> Whatever the approach, you need to make sure the coordinates indicated  
> in your centroid are in SVG coordinate space, as indicated in the Drag  
> tutorial.

    Yes, you must have a clear idea what coordinate system you are
working in.  getIntersectionList can also be nice in this regard as
it takes care of much of the coordinate system work you just have
to get it to the root SVG element's coordinate system.

> On Apr 30, 2005, at 3:34 PM, Archie Cobbs wrote:
> 
>> Brian Johnson wrote:
>>
>>> I'm new to Batik and naive in Java, though experienced in older  
>>> languages and graphics environments. I have a student who is working  
>>> to combine various technologies into a Java application--including  
>>> SVG files and sketch recognition. The basic strategy is to load an  
>>> externally generated SVG file which has associated style ID's with  
>>> <g> elements, display this graphpic, allow the user to sketch marks  
>>> on top of the SVG, categorize the sketch gesture, identify what was  
>>> "under" the sketch, and then produce a folllow-up action. We're now  
>>> at the point where we need to identify the element. We know where 
>>> (in  terms of the overlayed Java Graphics world) the centroid of the  
>>> sketch was and want to query the SVG for the ID of the nearest  
>>> element "under" this sketch.
>>
>>
>> You can use the org.w3c.dom.events.EventTarget and
>> org.w3c.dom.events.MouseEvent classes to detect mouse over,
>> mouse click, etc. events by registering the appropriate
>> listener(s). Pretty much any SVGElement in the DOM can be
>> cast to an EventTarget.
>>
>> -Archie
>>
>> _______________________________________________________________________ 
>> ___
>> Archie Cobbs      *        CTO, Awarix        *       
>> http://www.awarix.com
>>
>> ---------------------------------------------------------------------
>> 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