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 "Warren W. Thompson" <wt...@altaira.com> on 2002/01/07 21:06:34 UTC

Re: Embed a Swing Component in an JSVGCanvas

Thank you pointing me in the right direction Thierry! :)

I would like something a little more generic than creating a different
SVG element for every Swing component. I think it might be possible to
make something like...

<batikSwing:awtComponent style="class:javax.swing.JButton;foreground:red" .../>

...so that all of the existing Swing components would be available,
as well as any custom components that a developer may have created.

Does this sort of approach sound feasible?

Are any plans to integrate the ability to embed Swing components into
the Batik source code?

Are there any concrete examples of embedding a Swing, or AWT, component
in a Batik canvas? (I must admit to having a little difficulty creating
my own custom SVG element to support this functionality.)

Thanks again for all of your help!

Warren

Beer is proof that God loves us and wants us to be happy.
                                            --Benjamin Franklin


Thierry Kormann wrote:
> 
> On Thursday 20 December 2001 16:03, Warren W. Thompson wrote:
> > Is it possible to embed Swing components, like a JTextField, inside of
> > an SVG file being shown in a JSVGCanvas? The closest thing that I found
> > on the Batik Web site was the section that deals with 'Extensions' to the
> > SVG XML. Has anyone successfully done something like this?
> 
> I manage to include swing component inside SVG using extensions. What have
> done is:
> 
> - a custom SwingGraphicsNode that extends AbstractGaphicsNode and delegates
> to an enclosed swing component the primitive paint (basically, the GVT's
> primitivePaint calls the paintComponent methods).
> 
> - a custom bridge that builds this SwingGraphicsNode (through elements such
> as: <batikSwing:jbutton ...>
> 
> Then, you have swing inside JSVGCanvas through SVG syntax. The problem now
> (much more difficult) is to handle events properly and repaint the widget if
> necessary.
> 
> repaint could be done when batik will be dynamique, events are trickier.
> 
> Good luck.
> Thierry.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org

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


Re: Embed a Swing Component in an JSVGCanvas

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "WT" == Warren W Thompson <wt...@altaira.com> writes:

WT> [...] I have read about the SVG foreignObject element and I am
WT> wondering if it is proper to integrate that with the proposed
WT> embedded Swing tag. [...]

WT> Is this the correct approach to solving this sort of problem?

    It looked pretty good to me but I'll let Thierry answer that one.

WT> If so, how do I proceed to tell Batik about the extension with the
WT> URI http://mydomain.com/SVGExtenstions/BatikSwing ?

Read: 
   http://xml.apache.org/batik/extendingBatik.html
   xml-batik/sources/org/apache/batik/extension/svg/BatikBridgeExtension.java.

    When you add your tag to the bridge (see BridgeExtension).  by
implementing the BridgeExtension interface one of the methods is
'getImplementedExtensions'.  The returned iterator should have your
extension URI in it.

    Good luck.

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


Re: Embed a Swing Component in an JSVGCanvas

Posted by "Warren W. Thompson" <wt...@altaira.com>.
Sorry to ask so many questions, but I am relatively new to SVG development.

I have read about the SVG foreignObject element and I am wondering if
it is proper to integrate that with the proposed embedded Swing tag. I
am not exactly sure how the foreignObject element is intended to be
used. There is an example in the SVG specification, but it is relatively
simplistic. So, if I were to use the foreignObject element, in
combination with the switch element as described in the specification,
would it look something like this?

<switch>
  <!-- Draw the JButton here is the extension to Batik is available. -->
  <foreignObject width="100" height="50"
      requiredExtensions="http://mydomain.com/SVGExtenstions/BatikSwing">
    <batikSwing:javaAWTComponent
        style="class:javax.swing.JButton;foreground:red;text:Click Here"/>
  </foreignObject>

  <!-- Draw a red rectangle with an error message to indicate -->
  <!-- the the JButton could not be rendered.                 -->
  <g>
    <rect width="100" height="50" style="fill:red"/>
    <text>JButton Goes Here.</text>
  </g>
</switch>

Is this the correct approach to solving this sort of problem?

If so, how do I proceed to tell Batik about the extension with the URI
http://mydomain.com/SVGExtenstions/BatikSwing ?

Thanks again,

Warren

Beer is proof that God loves us and wants us to be happy.
                                            --Benjamin Franklin

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


Re: Embed a Swing Component in an JSVGCanvas

Posted by Thierry Kormann <tk...@ilog.fr>.
On Monday 07 January 2002 21:06, Warren W. Thompson wrote:
> Thank you pointing me in the right direction Thierry! :)
>
> I would like something a little more generic than creating a different
> SVG element for every Swing component. I think it might be possible to
> make something like...
>
> <batikSwing:awtComponent style="class:javax.swing.JButton;foreground:red"
> .../>
>
> ...so that all of the existing Swing components would be available,
> as well as any custom components that a developer may have created.
>
> Does this sort of approach sound feasible?

absolutely.

Swing components are JavaBeans so introspection is easy to do to set 
properties and instantiate your class.

Thierry.


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