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 th...@kodak.com on 2007/04/01 02:46:57 UTC

Re: load 2 svg file into 1 svgCanvas

Hi Peppe,

Peppe <pe...@gmail.com> wrote on 03/31/2007 03:57:44 PM:

> sorry, but in this way the application show me a window that contain a 
slider
> and a button, and on center nothing (only gray)...

    I don't know what else you have tried but in what you have
shown you are missing the call to svgCanvas2.setOpaque(false).
This is why you are seeing the gray.  You should have still seen
the contents of canvas2 (if any) though.

> public SVGApplication(JFrame f) {
>         frame = f;
>         svgCanvas = new JSVGCanvas();
>         svgCanvas2 = new JSVGCanvas();
>         //svgCanvas.setOpaque(true);
>         //svgCanvas2.setOpaque(false);
>         //svgCanvas2.setBackground(new Color(0,0,0,0));
>     }
> 
>     public JComponent createComponents() {
>         // Create a panel and add the button, status label and the SVG
> canvas.
>         panel = new JPanel(new BorderLayout());
>         layer = new JLayeredPane();
>         svgCanvas2.setBackground(new Color(0,0,0,0));
>         layer.add(svgCanvas, new Integer(2));
>         layer.add(svgCanvas2, new Integer(1)); 
> 
>         JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
>         p.add(button);
>         p.add(getJSlider(), null);
>         p.add(label);
> 
>         panel.add("North", p);
> 
>         panel.add("Center", layer);
> 
> 
>         // 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 {
>                        if(svgCanvas.getURI() == null){
>                           svgCanvas.setDocumentState(JSVGCanvas.
> ALWAYS_DYNAMIC);
>                           svgCanvas.setURI(f.toURL().toString());
> 
>                        }else{
> 
> svgCanvas2.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>                           svgCanvas2.setURI(f.toURL().toString()); 
>                        }
>                     } catch (IOException ex) {
>                         ex.printStackTrace();
>                     }
>                 }
>             }
>         });
> 
>         return panel;
>     }
> }
> 
> -- 
> View this message in context: http://www.nabble.com/load-2-svg-file-
> into-1-svgCanvas-tf3492392.html#a9771659
> Sent from the Batik - Users mailing list archive at Nabble.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: load 2 svg file into 1 svgCanvas

Posted by Peppe <pe...@gmail.com>.
ok...finally i solved my problem....thanks

-- 
View this message in context: http://www.nabble.com/load-2-svg-file-into-1-svgCanvas-tf3492392.html#a9780681
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: load 2 svg file into 1 svgCanvas

Posted by Peppe <pe...@gmail.com>.
i changed my code completely...now i would merge 2 svg file into 1 svg file.
i wrote this code:
 public JComponent createComponents() {
        // Create a panel and add the button, status label and the SVG
canvas.
        final JPanel panel = new JPanel(new BorderLayout());

        JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
        p.add(button);
        p.add(label);
        p.add(getJSlider(), null);

        panel.add("North", p);
        panel.add("Center", svgCanvas);

        
        File file1 = new File("batik70.svg");
        File file2 = new File("asf-logo.svg");
        
        String parser = XMLResourceDescriptor.getXMLParserClassName ();
        SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);       
       
        SVGDocument document1 = null;
        SVGDocument document2 = null;

        try {
            document1 = (SVGDocument)
factory.createDocument(file1.toURL().toString());
            document2 = (SVGDocument)
factory.createDocument(file2.toURL().toString());
            document1.getDocumentElement().setAttributeNS(null, "id",
"doc1");
            document2.getDocumentElement().setAttributeNS(null, "id",
"doc2");
        } catch (MalformedURLException e1) {
            e1.printStackTrace ();
            System.exit(1);
        } catch (IOException e1) {
            e1.printStackTrace();
            System.exit(1);
        }

        //Copy the document2 inside document 1

        Node newDocument =
document1.importNode(document2.getDocumentElement(), true);
        
        //And append the result

        document1.getDocumentElement().appendChild(newDocument);
        svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        svgCanvas.setSVGDocument(document1);

in this way i include document 2 into document 1...but i need to create a
new document to contain both document, moreover i would labeled document 1
and document 2 with a "id" how then i can modify all document 1 or all
document 2...
-- 
View this message in context: http://www.nabble.com/load-2-svg-file-into-1-svgCanvas-tf3492392.html#a9776842
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: load 2 svg file into 1 svgCanvas

Posted by Peppe <pe...@gmail.com>.
so...my application is this:

JFrame f -> f.getContentPane().add(createComponents()) -> createComponents
contain -> JPanel called panel -> panel contain on North another panel
called p that contains a slider and a button load, on Center there is a
layeredPane where svgCanvas1 is in z-order 1 while svgCanvas2 is in z-order
0... 

-- 
View this message in context: http://www.nabble.com/load-2-svg-file-into-1-svgCanvas-tf3492392.html#a9775881
Sent from the Batik - Users mailing list archive at Nabble.com.


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