Search in sources :

Example 1 with GraphicsSVG

use of org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG in project tdi-studio-se by Talend.

the class SVGImageExporter method export.

public static void export(GraphicalViewer viewer, OutputStream outputStream, List businessItems) {
    /*
         * 1. First get the figure whose visuals we want to save as image. So we would like to save the rooteditpart
         * which actually hosts all the printable layers.
         * 
         * NOTE: ScalableRootEditPart manages layers and is registered graphicalviewer's editpartregistry with the key
         * LayerManager.ID ... well that is because ScalableRootEditPart manages all layers that are hosted on a
         * FigureCanvas. Many layers exist for doing different things
         */
    SimpleRootEditPart rootEditPart = (SimpleRootEditPart) viewer.getEditPartRegistry().get(LayerManager.ID);
    // rootEditPart.
    IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
    // getFigure();
    Rectangle bounds = rootFigure.getBounds();
    GraphicsSVG graphics = GraphicsSVG.getInstance(bounds.getTranslated(bounds.getLocation().negate()));
    TalendSVGIDGenerator generator = new TalendSVGIDGenerator(businessItems);
    graphics.getSVGGraphics2D().getGeneratorContext().setIDGenerator(generator);
    graphics.translate(bounds.getLocation().negate());
    rootFigure.paint(graphics);
    try {
        graphics.getSVGGraphics2D().stream(new BufferedWriter(new OutputStreamWriter(outputStream)));
    } catch (SVGGraphics2DIOException e) {
        ExceptionHandler.process(e);
    }
}
Also used : SimpleRootEditPart(org.eclipse.gef.editparts.SimpleRootEditPart) SVGGraphics2DIOException(org.apache.batik.svggen.SVGGraphics2DIOException) Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicsSVG(org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG) OutputStreamWriter(java.io.OutputStreamWriter) LayerManager(org.eclipse.gef.editparts.LayerManager) IFigure(org.eclipse.draw2d.IFigure) BufferedWriter(java.io.BufferedWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 SVGGraphics2DIOException (org.apache.batik.svggen.SVGGraphics2DIOException)1 IFigure (org.eclipse.draw2d.IFigure)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 LayerManager (org.eclipse.gef.editparts.LayerManager)1 SimpleRootEditPart (org.eclipse.gef.editparts.SimpleRootEditPart)1 GraphicsSVG (org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.export.GraphicsSVG)1