Example usage for java.awt.geom AffineTransform getTranslateY

List of usage examples for java.awt.geom AffineTransform getTranslateY

Introduction

In this page you can find the example usage for java.awt.geom AffineTransform getTranslateY.

Prototype

public double getTranslateY() 

Source Link

Document

Returns the Y coordinate of the translation element (m12) of the 3x3 affine transformation matrix.

Usage

From source file:com.t_oster.visicut.misc.Helper.java

/**
* Compute the rotation angle of an affine transformation.
* Counter-clockwise rotation is considered positive.
*
* method taken from http://javagraphics.blogspot.com/
*
* @return rotation angle in radians (beween -pi and pi),
*  or NaN if the transformation is bogus.
*///from   ww  w  . ja va 2 s. c om
public static double getRotationAngle(AffineTransform transform) {
    transform = (AffineTransform) transform.clone();
    // Eliminate any post-translation
    transform.preConcatenate(
            AffineTransform.getTranslateInstance(-transform.getTranslateX(), -transform.getTranslateY()));
    Point2D p1 = new Point2D.Double(1, 0);
    p1 = transform.transform(p1, p1);
    return Math.atan2(p1.getY(), p1.getX());
}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToQuadrantRotation(2, 0.5, 0.5);

    System.out.println(at.getTranslateY());

    g2.setTransform(at);/*w  w  w . ja v  a 2 s  .c o m*/
    g2.draw(shape);

}

From source file:es.ucm.fdi.edd.ui.views.utils.SWTImageCanvas.java

private void scrollVertically(ScrollBar scrollBar) {
    if (sourceImage == null)
        return;/*from  ww w  .  ja v a 2s.co m*/

    AffineTransform af = transform;
    double ty = af.getTranslateY();
    double select = -scrollBar.getSelection();
    af.preConcatenate(AffineTransform.getTranslateInstance(0, select - ty));
    transform = af;
    syncScrollBars();
}

From source file:es.ucm.fdi.edd.ui.views.utils.SWTImageCanvas.java

/**
 * Synchronize the scrollbar with the image. If the transform is out of
 * range, it will correct it. This function considers only following factors
 * :<b> transform, image size, client area</b>.
 *//*w  ww  .j  av a2s .co m*/
public void syncScrollBars() {
    if (sourceImage == null) {
        redraw();
        return;
    }

    AffineTransform af = transform;
    double sx = af.getScaleX(), sy = af.getScaleY();
    double tx = af.getTranslateX(), ty = af.getTranslateY();
    if (tx > 0)
        tx = 0;
    if (ty > 0)
        ty = 0;

    ScrollBar horizontal = getHorizontalBar();
    horizontal.setIncrement((int) (getClientArea().width / 100));
    horizontal.setPageIncrement(getClientArea().width);
    Rectangle imageBound = sourceImage.getBounds();
    int cw = getClientArea().width, ch = getClientArea().height;
    if (imageBound.width * sx > cw) { /* image is wider than client area */
        horizontal.setMaximum((int) (imageBound.width * sx));
        horizontal.setEnabled(true);
        if (((int) -tx) > horizontal.getMaximum() - cw)
            tx = -horizontal.getMaximum() + cw;
    } else { /* image is narrower than client area */
        horizontal.setEnabled(false);
        tx = (cw - imageBound.width * sx) / 2; // center if too small.
    }
    horizontal.setSelection((int) (-tx));
    horizontal.setThumb((int) (getClientArea().width));

    ScrollBar vertical = getVerticalBar();
    vertical.setIncrement((int) (getClientArea().height / 100));
    vertical.setPageIncrement((int) (getClientArea().height));
    if (imageBound.height * sy > ch) { /* image is higher than client area */
        vertical.setMaximum((int) (imageBound.height * sy));
        vertical.setEnabled(true);
        if (((int) -ty) > vertical.getMaximum() - ch)
            ty = -vertical.getMaximum() + ch;
    } else { /* image is less higher than client area */
        vertical.setEnabled(false);
        ty = (ch - imageBound.height * sy) / 2; // center if too small.
    }
    vertical.setSelection((int) (-ty));
    vertical.setThumb((int) (getClientArea().height));

    /* update transform. */
    af = AffineTransform.getScaleInstance(sx, sy);
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
    transform = af;

    redraw();
}

From source file:Matrix.java

/**
 * Set the values of the matrix from the AffineTransform.
 * //w w  w.j a  v  a2 s  .co m
 * @param af The transform to get the values from.
 */
public void setFromAffineTransform(AffineTransform af) {
    single[0] = (float) af.getScaleX();
    single[1] = (float) af.getShearY();
    single[3] = (float) af.getShearX();
    single[4] = (float) af.getScaleY();
    single[6] = (float) af.getTranslateX();
    single[7] = (float) af.getTranslateY();
}

From source file:org.apache.fop.afp.AFPGraphics2D.java

/** {@inheritDoc} */
@Override//from w  ww  .j  av  a  2s  .  c o  m
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
    int imgWidth = img.getWidth();
    int imgHeight = img.getHeight();

    AffineTransform gat = gc.getTransform();
    int graphicsObjectHeight = graphicsObj.getObjectEnvironmentGroup().getObjectAreaDescriptor().getHeight();

    double toMillipointFactor = UnitConv.IN2PT * 1000 / (double) paintingState.getResolution();
    double x = gat.getTranslateX();
    double y = -(gat.getTranslateY() - graphicsObjectHeight);
    x = toMillipointFactor * x;
    y = toMillipointFactor * y;
    double w = toMillipointFactor * imgWidth * gat.getScaleX();
    double h = toMillipointFactor * imgHeight * -gat.getScaleY();

    AFPImageHandlerRenderedImage handler = new AFPImageHandlerRenderedImage();
    ImageInfo imageInfo = new ImageInfo(null, null);
    imageInfo.setSize(new ImageSize(img.getWidth(), img.getHeight(), paintingState.getResolution()));
    imageInfo.getSize().calcSizeFromPixels();
    ImageRendered red = new ImageRendered(imageInfo, img, null);
    Rectangle targetPos = new Rectangle((int) Math.round(x), (int) Math.round(y), (int) Math.round(w),
            (int) Math.round(h));
    AFPRenderingContext context = new AFPRenderingContext(null, resourceManager, paintingState, fontInfo, null);
    try {
        handler.handleImage(context, red, targetPos);
    } catch (IOException ioe) {
        handleIOException(ioe);
    }
}

From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java

private void moveAnnotations(PDPage page, List pageAnnotations, AffineTransform at) {
    PDRectangle mediaBox = page.getMediaBox();
    PDRectangle cropBox = page.getCropBox();
    PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
    for (Object obj : pageAnnotations) {
        PDAnnotation annot = (PDAnnotation) obj;
        PDRectangle rect = annot.getRectangle();
        float translateX = (float) (at.getTranslateX() - viewBox.getLowerLeftX());
        float translateY = (float) (at.getTranslateY() - viewBox.getLowerLeftY());
        if (rect != null) {
            rect.setUpperRightX(rect.getUpperRightX() + translateX);
            rect.setLowerLeftX(rect.getLowerLeftX() + translateX);
            rect.setUpperRightY(rect.getUpperRightY() + translateY);
            rect.setLowerLeftY(rect.getLowerLeftY() + translateY);
            annot.setRectangle(rect);/*w w w . j  a  v a 2s.  c  o m*/
        }
        //            COSArray vertices = (COSArray) annot.getCOSObject().getDictionaryObject("Vertices");
        //            if (vertices != null) {
        //                Iterator iter = vertices.iterator();
        //                while (iter.hasNext()) {
        //                    COSFloat x = (COSFloat) iter.next();
        //                    COSFloat y = (COSFloat) iter.next();
        //                    x.setValue(x.floatValue() + translateX);
        //                    y.setValue(y.floatValue() + translateY);
        //                }
        //            }
    }
}

From source file:org.apache.pdfbox.pdmodel.graphics.shading.AxialShadingContext.java

/**
 * Constructor creates an instance to be used for fill operations.
 * /*ww w.j a  va 2s.c  o  m*/
 * @param shadingType2 the shading type to be used
 * @param colorModelValue the color model to be used
 * @param xform transformation for user to device space
 * @param ctm current transformation matrix
 * @param pageHeight height of the current page
 * 
 */
public AxialShadingContext(PDShadingType2 shadingType2, ColorModel colorModelValue, AffineTransform xform,
        Matrix ctm, int pageHeight) {
    coords = shadingType2.getCoords().toFloatArray();
    if (ctm != null) {
        // the shading is used in combination with the sh-operator
        float[] coordsTemp = new float[coords.length];
        // transform the coords from shading to user space
        ctm.createAffineTransform().transform(coords, 0, coordsTemp, 0, 2);
        // move the 0,0-reference
        coordsTemp[1] = pageHeight - coordsTemp[1];
        coordsTemp[3] = pageHeight - coordsTemp[3];
        // transform the coords from user to device space
        xform.transform(coordsTemp, 0, coords, 0, 2);
    } else {
        // the shading is used as pattern colorspace in combination
        // with a fill-, stroke- or showText-operator
        float translateY = (float) xform.getTranslateY();
        // move the 0,0-reference including the y-translation from user to device space
        coords[1] = pageHeight + translateY - coords[1];
        coords[3] = pageHeight + translateY - coords[3];
    }
    // colorSpace 
    try {
        PDColorSpace cs = shadingType2.getColorSpace();
        if (!(cs instanceof PDDeviceRGB)) {
            // we have to create an instance of the shading colorspace if it isn't RGB
            shadingColorSpace = cs.getJavaColorSpace();
        }
    } catch (IOException exception) {
        LOG.error("error while creating colorSpace", exception);
    }
    // colorModel
    if (colorModelValue != null) {
        colorModel = colorModelValue;
    } else {
        try {
            // TODO bpc != 8 ??  
            colorModel = shadingType2.getColorSpace().createColorModel(8);
        } catch (IOException exception) {
            LOG.error("error while creating colorModel", exception);
        }
    }
    // shading function
    try {
        function = shadingType2.getFunction();
    } catch (IOException exception) {
        LOG.error("error while creating a function", exception);
    }
    // domain values
    if (shadingType2.getDomain() != null) {
        domain = shadingType2.getDomain().toFloatArray();
    } else {
        // set default values
        domain = new float[] { 0, 1 };
    }
    // extend values
    COSArray extendValues = shadingType2.getExtend();
    if (shadingType2.getExtend() != null) {
        extend = new boolean[2];
        extend[0] = ((COSBoolean) extendValues.get(0)).getValue();
        extend[1] = ((COSBoolean) extendValues.get(1)).getValue();
    } else {
        // set default values
        extend = new boolean[] { false, false };
    }
    // calculate some constants to be used in getRaster
    x1x0 = coords[2] - coords[0];
    y1y0 = coords[3] - coords[1];
    d1d0 = domain[1] - domain[0];
    denom = Math.pow(x1x0, 2) + Math.pow(y1y0, 2);
    // TODO take a possible Background value into account

}

From source file:org.apache.pdfbox.pdmodel.graphics.shading.RadialShadingContext.java

/**
 * Constructor creates an instance to be used for fill operations.
 * /*w w w .ja v a 2  s.com*/
 * @param shadingType3 the shading type to be used
 * @param colorModelValue the color model to be used
 * @param xform transformation for user to device space
 * @param ctm current transformation matrix
 * @param pageHeight height of the current page
 * 
 */
public RadialShadingContext(PDShadingType3 shadingType3, ColorModel colorModelValue, AffineTransform xform,
        Matrix ctm, int pageHeight) {
    coords = shadingType3.getCoords().toFloatArray();
    if (ctm != null) {
        // the shading is used in combination with the sh-operator
        float[] coordsTemp = new float[coords.length];
        // transform the coords from shading to user space
        ctm.createAffineTransform().transform(coords, 0, coordsTemp, 0, 1);
        ctm.createAffineTransform().transform(coords, 3, coordsTemp, 3, 1);
        // move the 0,0-reference
        coordsTemp[1] = pageHeight - coordsTemp[1];
        coordsTemp[4] = pageHeight - coordsTemp[4];
        // transform the coords from user to device space
        xform.transform(coordsTemp, 0, coords, 0, 1);
        xform.transform(coordsTemp, 3, coords, 3, 1);
    } else {
        // the shading is used as pattern colorspace in combination
        // with a fill-, stroke- or showText-operator
        float translateY = (float) xform.getTranslateY();
        // move the 0,0-reference including the y-translation from user to device space
        coords[1] = pageHeight + translateY - coords[1];
        coords[4] = pageHeight + translateY - coords[4];
    }
    // colorSpace 
    try {
        PDColorSpace cs = shadingType3.getColorSpace();
        if (!(cs instanceof PDDeviceRGB)) {
            // we have to create an instance of the shading colorspace if it isn't RGB
            shadingColorSpace = cs.getJavaColorSpace();
        }
    } catch (IOException exception) {
        LOG.error("error while creating colorSpace", exception);
    }
    // colorModel
    if (colorModelValue != null) {
        colorModel = colorModelValue;
    } else {
        try {
            // TODO bpc != 8 ??  
            colorModel = shadingType3.getColorSpace().createColorModel(8);
        } catch (IOException exception) {
            LOG.error("error while creating colorModel", exception);
        }
    }
    // shading function
    try {
        function = shadingType3.getFunction();
    } catch (IOException exception) {
        LOG.error("error while creating a function", exception);
    }
    // domain values
    if (shadingType3.getDomain() != null) {
        domain = shadingType3.getDomain().toFloatArray();
    } else {
        // set default values
        domain = new float[] { 0, 1 };
    }
    // extend values
    COSArray extendValues = shadingType3.getExtend();
    if (shadingType3.getExtend() != null) {
        extend = new boolean[2];
        extend[0] = ((COSBoolean) extendValues.get(0)).getValue();
        extend[1] = ((COSBoolean) extendValues.get(1)).getValue();
    } else {
        // set default values
        extend = new boolean[] { false, false };
    }
    // calculate some constants to be used in getRaster
    x1x0 = coords[3] - coords[0];
    y1y0 = coords[4] - coords[1];
    r1r0 = coords[5] - coords[2];
    x1x0pow2 = Math.pow(x1x0, 2);
    y1y0pow2 = Math.pow(y1y0, 2);
    r0pow2 = Math.pow(coords[2], 2);
    denom = x1x0pow2 + y1y0pow2 - Math.pow(r1r0, 2);
    d1d0 = domain[1] - domain[0];
    // TODO take a possible Background value into account

}

From source file:org.apache.pdfbox.rendering.PageDrawer.java

private void drawBufferedImage(BufferedImage image, AffineTransform at) throws IOException {
    graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    setClip();/*from  w  w  w .j a  v a  2 s  . c  om*/
    PDSoftMask softMask = getGraphicsState().getSoftMask();
    if (softMask != null) {
        AffineTransform imageTransform = new AffineTransform(at);
        imageTransform.scale(1, -1);
        imageTransform.translate(0, -1);
        Paint awtPaint = new TexturePaint(image, new Rectangle2D.Double(imageTransform.getTranslateX(),
                imageTransform.getTranslateY(), imageTransform.getScaleX(), imageTransform.getScaleY()));
        awtPaint = applySoftMaskToPaint(awtPaint, softMask);
        graphics.setPaint(awtPaint);
        Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1);
        graphics.fill(at.createTransformedShape(unitRect));
    } else {
        int width = image.getWidth(null);
        int height = image.getHeight(null);
        AffineTransform imageTransform = new AffineTransform(at);
        imageTransform.scale(1.0 / width, -1.0 / height);
        imageTransform.translate(0, -height);
        graphics.drawImage(image, imageTransform, null);
    }
}