Example usage for java.awt Graphics2D getTransform

List of usage examples for java.awt Graphics2D getTransform

Introduction

In this page you can find the example usage for java.awt Graphics2D getTransform.

Prototype

public abstract AffineTransform getTransform();

Source Link

Document

Returns a copy of the current Transform in the Graphics2D context.

Usage

From source file:view.BackgroundImageController.java

public void setGraphBackgroundImage(final VisualizationViewer vv, final ImageIcon background,
        final double xOffset, final double yOffset) {

    removeBackgroundImage(vv);//from   www  .ja  va 2 s .c  o m

    preRender = new VisualizationViewer.Paintable() {
        public void paint(Graphics g) {
            Graphics2D g2d = (Graphics2D) g;
            AffineTransform oldXform = g2d.getTransform();
            AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)
                    .getTransform();
            AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)
                    .getTransform();
            AffineTransform at = new AffineTransform();
            at.concatenate(g2d.getTransform());
            at.concatenate(vat);
            at.concatenate(lat);
            g2d.setTransform(at);
            g.drawImage(background.getImage(), (int) Math.round(-background.getIconWidth() / xOffset),
                    (int) Math.round(-background.getIconHeight() / yOffset), background.getIconWidth(),
                    background.getIconHeight(), vv);
            g2d.setTransform(oldXform);
        }

        public boolean useTransform() {
            return false;
        }
    };

    vv.addPreRenderPaintable(preRender);

    background.getImage().flush();
    Runtime.getRuntime().gc();
}