Search in sources :

Example 1 with RenderInfo

use of org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo in project tmdmaker by tmdmaker.

the class GraphicsToGraphics2DAdaptor method drawRenderedImage.

/* (non-Javadoc)
	 * @see org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.DrawableRenderedImage#drawRenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage, org.eclipse.draw2d.geometry.Rectangle, org.eclipse.gmf.runtime.draw2d.ui.render.RenderingListener)
	 */
public RenderedImage drawRenderedImage(RenderedImage srcImage, Rectangle rect, RenderingListener listener) {
    RenderInfo info = srcImage.getRenderInfo();
    info.setValues(rect.width, rect.height, info.shouldMaintainAspectRatio(), info.shouldAntiAlias(), info.getBackgroundColor(), info.getForegroundColor());
    RenderedImage img = srcImage.getNewRenderedImage(info);
    BufferedImage bufImg = (BufferedImage) img.getAdapter(BufferedImage.class);
    if (bufImg == null) {
        bufImg = ImageConverter.convert(img.getSWTImage());
    }
    // Translate the Coordinates
    int x = rect.x + transX;
    int y = rect.y + transY + rect.height - bufImg.getHeight();
    checkState();
    getGraphics2D().drawImage(bufImg, new AffineTransform(1f, 0f, 0f, 1f, x, y), null);
    return img;
}
Also used : AffineTransform(java.awt.geom.AffineTransform) RenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage) DrawableRenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.internal.DrawableRenderedImage) RenderInfo(org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo) BufferedImage(java.awt.image.BufferedImage) Point(org.eclipse.draw2d.geometry.Point) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 2 with RenderInfo

use of org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo in project tmdmaker by tmdmaker.

the class GraphicsSVG method drawRenderedImage.

/* (non-Javadoc)
	 * @see org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor#drawRenderedImage(org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage, org.eclipse.draw2d.geometry.Rectangle, org.eclipse.gmf.runtime.draw2d.ui.render.RenderingListener)
	 */
public RenderedImage drawRenderedImage(RenderedImage srcImage, Rectangle rect, RenderingListener listener) {
    // Check for a change in the state
    checkState();
    // Get the Tree Manager
    DOMTreeManager treeManager = getSVGGraphics2D().getDOMTreeManager();
    Point trans = getTranslationOffset();
    // Get the Root element of the SVG document to export
    if (srcImage instanceof SVGImage) {
        Document document = ((SVGImage) srcImage).getDocument();
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        document = DOMUtilities.deepCloneDocument(document, impl);
        if (document instanceof SVGOMDocument) {
            RenderInfo info = srcImage.getRenderInfo();
            if (info != null && info.getBackgroundColor() != null && info.getForegroundColor() != null) {
                SVGColorConverter.getInstance().replaceDocumentColors((SVGOMDocument) document, new Color(info.getBackgroundColor().red, info.getBackgroundColor().green, info.getBackgroundColor().blue), new Color(info.getForegroundColor().red, info.getForegroundColor().green, info.getForegroundColor().blue));
            }
        }
        Element root = document.getDocumentElement();
        // Create a "deep" copy of the document
        Element toAppend = (Element) doc.importNode(root, true);
        // Modify the X Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_X_ATTRIBUTE, String.valueOf(rect.x + trans.x));
        // Modify the Y Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_Y_ATTRIBUTE, String.valueOf(rect.y + trans.y));
        // Modify the Width Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE, String.valueOf(rect.width));
        // Modify the Height Attribute
        toAppend.setAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE, String.valueOf(rect.height));
        treeManager.appendGroup(toAppend, null);
        return srcImage;
    } else {
        return super.drawRenderedImage(srcImage, rect, listener);
    }
}
Also used : SVGOMDocument(org.apache.batik.dom.svg.SVGOMDocument) DOMTreeManager(org.apache.batik.svggen.DOMTreeManager) Color(java.awt.Color) Element(org.w3c.dom.Element) SVGDOMImplementation(org.apache.batik.dom.svg.SVGDOMImplementation) DOMImplementation(org.w3c.dom.DOMImplementation) Point(org.eclipse.draw2d.geometry.Point) SVGOMDocument(org.apache.batik.dom.svg.SVGOMDocument) Document(org.w3c.dom.Document) RenderInfo(org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo) SVGImage(org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 RenderInfo (org.eclipse.gmf.runtime.draw2d.ui.render.RenderInfo)2 Color (java.awt.Color)1 GradientPaint (java.awt.GradientPaint)1 Paint (java.awt.Paint)1 AffineTransform (java.awt.geom.AffineTransform)1 BufferedImage (java.awt.image.BufferedImage)1 SVGDOMImplementation (org.apache.batik.dom.svg.SVGDOMImplementation)1 SVGOMDocument (org.apache.batik.dom.svg.SVGOMDocument)1 DOMTreeManager (org.apache.batik.svggen.DOMTreeManager)1 RenderedImage (org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage)1 SVGImage (org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.SVGImage)1 DrawableRenderedImage (org.eclipse.gmf.runtime.draw2d.ui.render.internal.DrawableRenderedImage)1 DOMImplementation (org.w3c.dom.DOMImplementation)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1