Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Eclipse RCP and Apache Batik together

Is it possible to use all the Batik components in an application developed in Eclipse RCP? Can you please point me to relevant documentation.

like image 998
Sameer Patil Avatar asked Jun 03 '26 13:06

Sameer Patil


2 Answers

Have a look at the following link:

  1. http://sourceforge.net/projects/svgplugin/
  2. Also you can use the SWT/AWT Bridge. See the SWT Snippet Page.

>> SWT/AWT & Batik Sample Code

import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;

import javax.swing.JComponent;
import javax.swing.JPanel;

import org.apache.batik.swing.JSVGCanvas;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BatikTest 
{

    public static void main(String[] args) 
    {
        // Uncomment the below lines and set proper values if you are behind a proxy server
        ///System.setProperty("http.proxyHost", "");
        ///System.setProperty("http.proxyPort", ""); 

        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setSize(200, 120);
        shell.setText("SWT Batik Example");
        shell.setLayout(new GridLayout());
        shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));


        Composite composite = new Composite(shell, SWT.EMBEDDED);
        composite.setLayout(new GridLayout());
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        java.awt.Frame locationFrame = SWT_AWT.new_Frame(composite);
        locationFrame.add(createComponents(new File("batik3D.svg")));

        locationFrame.pack();
        //shell.pack();


        shell.open();
        while(!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }

    private static JComponent createComponents(File f) 
    {
        // Create a panel and add the button, status label and the SVG canvas.
        final JPanel panel = new JPanel(new BorderLayout());
        JSVGCanvas svgCanvas = new JSVGCanvas();

        panel.add("Center", svgCanvas);


        try {
            svgCanvas.setURI(f.toURI().toURL().toString());
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }   

        return panel;
    }
}

>>Output

enter image description here

like image 159
Favonius Avatar answered Jun 07 '26 23:06

Favonius


It is possible to use batik in eclipse RCP apps, as e4 uses the CSS engine. See http://www.eclipse.org/orbit for the latest stable build that includes a number of the batik bundles. Ex, in our RCP app we use the following + some supporting w3c bundles:

org.apache.batik.css_1.6.0.v201011041432.jar
org.apache.batik.util_1.6.0.v201011041432.jar
org.apache.batik.util.gui_1.6.0.v201011041432.jar
org.apache.batik.xml_1.6.0.v201011041432.jar
like image 25
Paul Webster Avatar answered Jun 07 '26 22:06

Paul Webster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!