RE: Mix SVG and Swing components
I am trying to insert the Swing components in the painting chain. The swing component is scaled, but the area is not increased. The text and the cursor in the swing component become larger, but the area occupied by the swing component is not increased. Any suggestions. I am attaching the program too. See the CustTextField is used to introducte JTextField into the painting chain. Any help is really appreciated. package com.jvr.test; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import org.apache.batik.swing.*; import org.apache.batik.swing.gvt.*; import org.apache.batik.swing.svg.*; public class G2DFrame { class CustTextField extends JTextField { public CustTextField(int length) { super(length); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.scale(2,2); super.paint(g); } } JFrame frame; JButton button = new JButton(Load...); JLabel label = new JLabel(); JSVGCanvas svgCanvas = new JSVGCanvas(); //Swing objects to overlay the svg elements //JTextField aTxt = new JTextField(10); CustTextField aTxt = new CustTextField(10); public G2DFrame(JFrame f) { frame = f; aTxt.setLocation(10,10); aTxt.setSize(100,30); aTxt.setText(A TextBox); } public JComponent createComponents() { final JPanel panel = new JPanel(new BorderLayout()); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); p.add(button); p.add(label); panel.add(North, p); //panel.add(Center, testSVGCanvas); panel.add(Center, svgCanvas); // Set the button action. button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser fc = new JFileChooser(.); int choice = fc.showOpenDialog(panel); if (choice == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); try { svgCanvas.setURI(f.toURL().toString()); } catch (IOException ex) { ex.printStackTrace(); } } } }); // Set the JSVGCanvas listeners. svgCanvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() { public void documentLoadingStarted(SVGDocumentLoaderEvent e) { label.setText(Document Loading...); //Add the text field now svgCanvas.add(aTxt); } public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { label.setText(Document Loaded.); } }); svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() { public void gvtBuildStarted(GVTTreeBuilderEvent e) { label.setText(Build Started...); } public void gvtBuildCompleted(GVTTreeBuilderEvent e) { label.setText(Build Done.); frame.pack(); } }); svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() { public void gvtRenderingPrepare(GVTTreeRendererEvent e) { label.setText(Rendering Started...); } public void gvtRenderingCompleted(GVTTreeRendererEvent e) { label.setText(); //Sample scaling of the text field //Repaint the text field now aTxt.repaint(); } }); return panel; } public static void main(String[] args) { JFrame f = new JFrame(Batik Extension); G2DFrame app = new G2DFrame(f); f.getContentPane().add(app.createComponents()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 400); f.setVisible(true); } } -Original Message- From: Thomas DeWeese To: batik-dev@xml.apache.org Sent: 1/27/2005 6:35 PM Subject: Re: Mix SVG and Swing components
Re: Mix SVG and Swing components
Venkataramana_Jaladurgam wrote: Is there any way I can scale the swing components along the lines of SVG elements if I choose to add Swing components to JSVGCanvas directly. Only if you can insert yourself in the components repaint chain. So for example if you were to override the paintChildren method from JComponent you might be able to adjust the graphics object prior to drawing the children to scale/translate them as desired. -Original Message- From: Tonny Kohar [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 19, 2005 9:16 PM To: 'batik-dev@xml.apache.org' Subject: Re: Mix SVG and Swing components Hi, I am required to add Swing components to the SVG canvas. I want to use the batik extensions. The trouble I am facing is in the actual rendering class: The output I am getting in the JSVGCanvas is a static version of JTextField. I cannot enter characters or do anything with it. Any ideas? I believe if I can access JSVGCanvas or the related class where the components are being rendered, then I can directly add my swing component to it. But couldn't get how to get it. Batik developers pls. help. I do not know how to solve your problem, but as far as I know the batik GVT part is render the SVG stuff into Image that will be painted into the JSVGCanvas. The package org.apache.batik.gvt.renderer is where the rendering stuff. How about extending JSVGCanvas or its parent paintComponent method and adding your textField there. Or maybe wrap JSVGCanvas and your textfield into custom component and using Java JComponent layer or z-order capability. Regards Tonny Kohar - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mix SVG and Swing components
Is there any way I can scale the swing components along the lines of SVG elements if I choose to add Swing components to JSVGCanvas directly. -Original Message- From: Tonny Kohar [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 19, 2005 9:16 PM To: 'batik-dev@xml.apache.org' Subject: Re: Mix SVG and Swing components Hi, I am required to add Swing components to the SVG canvas. I want to use the batik extensions. The trouble I am facing is in the actual rendering class: The output I am getting in the JSVGCanvas is a static version of JTextField. I cannot enter characters or do anything with it. Any ideas? I believe if I can access JSVGCanvas or the related class where the components are being rendered, then I can directly add my swing component to it. But couldn't get how to get it. Batik developers pls. help. I do not know how to solve your problem, but as far as I know the batik GVT part is render the SVG stuff into Image that will be painted into the JSVGCanvas. The package org.apache.batik.gvt.renderer is where the rendering stuff. How about extending JSVGCanvas or its parent paintComponent method and adding your textField there. Or maybe wrap JSVGCanvas and your textfield into custom component and using Java JComponent layer or z-order capability. Regards Tonny Kohar -- Sketsa SVG Graphics Editor http://www.kiyut.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ** This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated. ** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mix SVG and Swing components
Thanks for the suggestion. The problem with this approach is the swing components will not be scalable. I have created a class that extends AbstractGraphicsNode to display the swing component. public class SwingGraphicsNode extends AbstractGraphicsNode implements GraphicsNodeMouseListener, GraphicsNodeKeyListener, GraphicsNodeChangeListener { JButton fButton = null; public SwingGraphicsNode() { //Test code fButton = new JButton(Button); setPointerEventType(ALL); } public void paint(Graphics2D g2d) { primitivePaint(g2d); } public void primitivePaint(Graphics2D g2d) { Rectangle2D bounds = getBounds(); g = g2d.create(); g.translate((int)bounds.getX(), (int)bounds.getY()); fButton.getModel().setPressed(true); fButton.paint(g); } //The mouse events are registered in Bridge Extension class //Think that mousePressed is called whenever mouse is pressed on the respective button public void mousePressed(GraphicsNodeMouseEvent evt) { // TODO Auto-generated method stub System.out.println([mouse pressed]); //fButton.getModel().setPressed(true); fButton.setForeground(Color.RED); fButton.setBackground(Color.GREEN); Rectangle2D bounds = getBounds(); fButton.repaint(); setVisible(false); setVisible(true); } } The button's foreground and background color are changed only when mouse button is released. I expected that the color of the button will change immediately when the mouse button is pressed. Any issues in the program? Any workarounds? Glad to know. -Original Message- From: Tonny Kohar [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 19, 2005 9:16 PM To: 'batik-dev@xml.apache.org' Subject: Re: Mix SVG and Swing components Hi, I am required to add Swing components to the SVG canvas. I want to use the batik extensions. The trouble I am facing is in the actual rendering class: The output I am getting in the JSVGCanvas is a static version of JTextField. I cannot enter characters or do anything with it. Any ideas? I believe if I can access JSVGCanvas or the related class where the components are being rendered, then I can directly add my swing component to it. But couldn't get how to get it. Batik developers pls. help. I do not know how to solve your problem, but as far as I know the batik GVT part is render the SVG stuff into Image that will be painted into the JSVGCanvas. The package org.apache.batik.gvt.renderer is where the rendering stuff. How about extending JSVGCanvas or its parent paintComponent method and adding your textField there. Or maybe wrap JSVGCanvas and your textfield into custom component and using Java JComponent layer or z-order capability. Regards Tonny Kohar -- Sketsa SVG Graphics Editor http://www.kiyut.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ** This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated. ** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Mix SVG and Swing components
Hi Venkataramana, You might want to talk with Lukasz as he appears to be working on this issue as well. Venkataramana_Jaladurgam wrote: Thanks for the suggestion. The problem with this approach is the swing components will not be scalable. I have created a class that extends AbstractGraphicsNode to display the swing component. [...] The button's foreground and background color are changed only when mouse button is released. I expected that the color of the button will change immediately when the mouse button is pressed. Any issues in the program? Any workarounds? Glad to know. What you need to do is figure out how to tie the Swing 'repaint' request system into the GVT 'update' system. Since I don't know the details of the Swing system I can't really help that much. See my response to Lukasz (mail archives) as it provides some hints. -Original Message- From: Tonny Kohar [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 19, 2005 9:16 PM To: 'batik-dev@xml.apache.org' Subject: Re: Mix SVG and Swing components Hi, I am required to add Swing components to the SVG canvas. I want to use the batik extensions. The trouble I am facing is in the actual rendering class: The output I am getting in the JSVGCanvas is a static version of JTextField. I cannot enter characters or do anything with it. Any ideas? I believe if I can access JSVGCanvas or the related class where the components are being rendered, then I can directly add my swing component to it. But couldn't get how to get it. Batik developers pls. help. I do not know how to solve your problem, but as far as I know the batik GVT part is render the SVG stuff into Image that will be painted into the JSVGCanvas. The package org.apache.batik.gvt.renderer is where the rendering stuff. How about extending JSVGCanvas or its parent paintComponent method and adding your textField there. Or maybe wrap JSVGCanvas and your textfield into custom component and using Java JComponent layer or z-order capability. Regards Tonny Kohar - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Mix SVG and Swing components
Hi, I am required to add Swing components to the SVG canvas. I want to use the batik extensions. The trouble I am facing is in the actual rendering class: The output I am getting in the JSVGCanvas is a static version of JTextField. I cannot enter characters or do anything with it. Any ideas? I believe if I can access JSVGCanvas or the related class where the components are being rendered, then I can directly add my swing component to it. But couldn't get how to get it. Batik developers pls. help. I do not know how to solve your problem, but as far as I know the batik GVT part is render the SVG stuff into Image that will be painted into the JSVGCanvas. The package org.apache.batik.gvt.renderer is where the rendering stuff. How about extending JSVGCanvas or its parent paintComponent method and adding your textField there. Or maybe wrap JSVGCanvas and your textfield into custom component and using Java JComponent layer or z-order capability. Regards Tonny Kohar -- Sketsa SVG Graphics Editor http://www.kiyut.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]