You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Hervé Girod <he...@club-internet.fr> on 2005/04/27 02:44:53 UTC

Two questions about Batik

Hello !

I have two questions about Batik. They are about the current 1.6 version, but I think they also apply to the previous version :

I write an application using Batik at its core, to show and modify SVG images. I have sometimes an IllegalComponentStateException "component must be showing on the screen to determine its location" when loading a SVG file in a JSVGCanvas, where the class MouseMoveRunnable (used internally in JSVGComponent) perform the run() method (the code is : eventDispatcher.mouseMoved(event)). Is it due to Batik, or do I use wrongly the JSVGCanvas class ?

When a SVG document is generated (for example, with Java code, or a WMF file), one output SVG clippath is generated for each input path, even if the input path is not clipped. This leads to a lot of (unnecessary ?) clippings in the SVG output document. By subclassing the SVGGraphics2D class, I am able to generate only the few necessary output clippings (the output path is clipped only if the corresponding input path is clipped),  but may be generating one clippath for each input path is necessary for reasons I don't see yet ? 

Thanks,

Hervé

Re: Two questions about Batik

Posted by Hervé Girod <he...@club-internet.fr>.
Hello,

 Thomas DeWeese wrote:

>    I would think that it would be good to disable mouse event handling
> until the document is fully built.  The GVT/SVG components initialize
> this in the 'initializeEventHandling' method so you could subclass that
> and register your listeners in there.  Perhaps you are thinking that
> this isn't the problem anymore however...

Thank you for your advice ! After doing what you proposed, I have no more
exceptions during building of the document. I now only enable Mouse events
handling after the document has been fully built, and I explicitely disable
event handling in non-visible tabs (as I only remember to have mouse
problems during the building of the document).


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


Re: Two questions about Batik

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

Hervé Girod wrote:

> I think I understand the reason of my problem (at least the beginning). In
> my application, I use a tabbed pane to show the various SVG documents. When
> I load a new document, sometimes the canvas of some of the previously loaded
> tabs fire selection events. I never do anything to disallow not showing tabs
> to fire selection events, 

    I'm not entirely sure why any special action should be needed (why
would they get event's if they aren't showing)...

> do I need to do that (I think so), and how ? 
> (may be set eventsEnabled to false ?).

    Unfortunately, I think this only works at initialization time
(when the document is loaded).

> 
> Hervé Girod wrote:
> 
>>>>I have two questions about Batik. They are about the current 1.6
>>>>version, but I think they also apply to the previous version :
>>
>>Hi,
>>
>>
>>>>I write an application using Batik at its core, to show and modify
>>>>SVG images. I have sometimes an IllegalComponentStateException
>>>>"component must be showing on the screen to determine its location"
> 
> when
> 
>>>>loading a SVG file in a JSVGCanvas, where the class MouseMoveRunnable
>>>>(used internally in JSVGComponent) perform the run() method (the code
> 
> is
> 
>>>>: eventDispatcher.mouseMoved(event)). Is it due to Batik, or do I use
>>>>wrongly the JSVGCanvas class ?
>>>
>>>    I suspect that it is something in your code but I'm not sure how it
>>>would happen.  Are you artificially dispatching events to the canvas?
>>>There is even a check for the component being visible before we call
>>>getLocationOnScreen so I have a really hard time understanding where
>>>this one comes from.
>>
>>After looking at my code, here are some facts to help understanding my
>>problem (or so I think) :
>> *  I wanted to be able to select shapes (not only text), so I created a
>>ShapeSelectionManager class in the event handlng initialization, in the
>>pattern of Batik TextSelectionManager. This component dispatch events as
> 
> the
> 
>>TextSelectionManager do. To do this, I subclassed the JSVGCanvas class.
>>  * I looked at the code of AWTEventDispatcher,  to see if I could detect
>>what in my code could create that, and as you say, you check if the
>>component is showing before getting its location on the screen  !!
>>  * and I think the most important :  even if I register the listeners on
>>gvt build events provided by the canvas, I don't use the
> 
> "gvtBuildCompleted"
> 
>>event, so may be my problem is due to a sort of race condition (gvt not
>>finished sometimes when I check for mouse events on the canvas). Do I have
>>to disable mouse events before the build is completed or something like
> 
> that ?

   I would think that it would be good to disable mouse event handling
until the document is fully built.  The GVT/SVG components initialize
this in the 'initializeEventHandling' method so you could subclass that
and register your listeners in there.  Perhaps you are thinking that
this isn't the problem anymore however...



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


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


Re: Two questions about Batik

Posted by Hervé Girod <he...@club-internet.fr>.
Hello again,

I think I understand the reason of my problem (at least the beginning). In
my application, I use a tabbed pane to show the various SVG documents. When
I load a new document, sometimes the canvas of some of the previously loaded
tabs fire selection events. I never do anything to disallow not showing tabs
to fire selection events, do I need to do that (I think so), and how ? (may
be set eventsEnabled to false ?).

Hervé Girod wrote:
>
> > > I have two questions about Batik. They are about the current 1.6
> > > version, but I think they also apply to the previous version :
> Hi,
>
> > >
> > > I write an application using Batik at its core, to show and modify
> > > SVG images. I have sometimes an IllegalComponentStateException
> > > "component must be showing on the screen to determine its location"
when
> > > loading a SVG file in a JSVGCanvas, where the class MouseMoveRunnable
> > > (used internally in JSVGComponent) perform the run() method (the code
is
> > > : eventDispatcher.mouseMoved(event)). Is it due to Batik, or do I use
> > > wrongly the JSVGCanvas class ?
> >
> >     I suspect that it is something in your code but I'm not sure how it
> > would happen.  Are you artificially dispatching events to the canvas?
> > There is even a check for the component being visible before we call
> > getLocationOnScreen so I have a really hard time understanding where
> > this one comes from.
>
> After looking at my code, here are some facts to help understanding my
> problem (or so I think) :
>  *  I wanted to be able to select shapes (not only text), so I created a
> ShapeSelectionManager class in the event handlng initialization, in the
> pattern of Batik TextSelectionManager. This component dispatch events as
the
> TextSelectionManager do. To do this, I subclassed the JSVGCanvas class.
>   * I looked at the code of AWTEventDispatcher,  to see if I could detect
> what in my code could create that, and as you say, you check if the
> component is showing before getting its location on the screen  !!
>   * and I think the most important :  even if I register the listeners on
> gvt build events provided by the canvas, I don't use the
"gvtBuildCompleted"
> event, so may be my problem is due to a sort of race condition (gvt not
> finished sometimes when I check for mouse events on the canvas). Do I have
> to disable mouse events before the build is completed or something like
that ?


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


Re: Two questions about Batik

Posted by Hervé Girod <he...@club-internet.fr>.
Thomas DeWeesewrote:

> > I have two questions about Batik. They are about the current 1.6
> > version, but I think they also apply to the previous version :
Hi,

> >
> > I write an application using Batik at its core, to show and modify
> > SVG images. I have sometimes an IllegalComponentStateException
> > "component must be showing on the screen to determine its location" when
> > loading a SVG file in a JSVGCanvas, where the class MouseMoveRunnable
> > (used internally in JSVGComponent) perform the run() method (the code is
> > : eventDispatcher.mouseMoved(event)). Is it due to Batik, or do I use
> > wrongly the JSVGCanvas class ?
>
>     I suspect that it is something in your code but I'm not sure how it
> would happen.  Are you artificially dispatching events to the canvas?
> There is even a check for the component being visible before we call
> getLocationOnScreen so I have a really hard time understanding where
> this one comes from.

After looking at my code, here are some facts to help understanding my
problem (or so I think) :
 *  I wanted to be able to select shapes (not only text), so I created a
ShapeSelectionManager class in the event handlng initialization, in the
pattern of Batik TextSelectionManager. This component dispatch events as the
TextSelectionManager do. To do this, I subclassed the JSVGCanvas class.
  * I looked at the code of AWTEventDispatcher,  to see if I could detect
what in my code could create that, and as you say, you check if the
component is showing before getting its location on the screen  !!
  * and I think the most important :  even if I register the listeners on
gvt build events provided by the canvas, I don't use the "gvtBuildCompleted"
event, so may be my problem is due to a sort of race condition (gvt not
finished sometimes when I check for mouse events on the canvas). Do I have
to disable mouse events before the build is completed or something like that
?
>
> > When a SVG document is generated (for example, with Java code, or a WMF
> > file), one output SVG clippath is generated for each input path, even if
> > the input path is not clipped. This leads to a lot of (unnecessary ?)
> > clippings in the SVG output document. By subclassing the SVGGraphics2D
> > class, I am able to generate only the few necessary output clippings
> > (the output path is clipped only if the corresponding input path is
> > clipped)
>
>     How do you determine if the path being drawn needs to be clipped?
>
I use a very naive (and may be wrong) implementation : I clip the output
path only if the input is clipped (performed in a subclass of
GraphicContext). In fact, as I was not sure it was "valid", I allowed to
choose between the Batik clipping behavior and this new one.




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


Re: Two questions about Batik

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

Hervé Girod wrote:

> I have two questions about Batik. They are about the current 1.6 
> version, but I think they also apply to the previous version :
>  
> I write an application using Batik at its core, to show and modify 
> SVG images. I have sometimes an IllegalComponentStateException 
> "component must be showing on the screen to determine its location" when 
> loading a SVG file in a JSVGCanvas, where the class MouseMoveRunnable 
> (used internally in JSVGComponent) perform the run() method (the code is 
> : eventDispatcher.mouseMoved(event)). Is it due to Batik, or do I use 
> wrongly the JSVGCanvas class ?

    I suspect that it is something in your code but I'm not sure how it
would happen.  Are you artificially dispatching events to the canvas?
There is even a check for the component being visible before we call
getLocationOnScreen so I have a really hard time understanding where
this one comes from.

> When a SVG document is generated (for example, with Java code, or a WMF 
> file), one output SVG clippath is generated for each input path, even if 
> the input path is not clipped. This leads to a lot of (unnecessary ?) 
> clippings in the SVG output document. By subclassing the SVGGraphics2D 
> class, I am able to generate only the few necessary output clippings 
> (the output path is clipped only if the corresponding input path is 
> clipped)

    How do you determine if the path being drawn needs to be clipped?

>  but may be generating one clippath for each input path is 
> necessary for reasons I don't see yet ? 

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