Example usage for java.awt.geom AffineTransform setToRotation

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

Introduction

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

Prototype

public void setToRotation(double theta) 

Source Link

Document

Sets this transform to a rotation transformation.

Usage

From source file:BasicDraw.java

public void paint(Graphics g) {

    Graphics2D g2d = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 4.0);
    g2d.setTransform(at);//from   w  w w .  j ava 2s. c  o  m
    g2d.drawString("aString", 200, 100);

}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    g2d.drawString("aString", 100, 100);
    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 4.0);
    g2d.setTransform(at);//ww  w.ja  v  a 2s . c  o  m
    g2d.drawString("aString", 100, 100);

}

From source file:MainClass.java

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

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 6);
    at.translate(100, 0);//w ww.j  av a 2s  . co  m

    g2.setTransform(at);
    g2.draw(shape);

}

From source file:TransformersRotationTranslation.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from ww w. j ava2 s  . c  o m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform rat = new AffineTransform();
    rat.setToRotation(Math.PI / 6);
    rat.translate(100, 100);

    g2.transform(rat);

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:at.gv.egiz.pdfas.lib.impl.pdfbox.placeholder.SignaturePlaceholderExtractor.java

@Override
protected void processOperator(PDFOperator operator, List<COSBase> arguments) throws IOException {
    String operation = operator.getOperation();
    if (operation.equals("Do")) {
        COSName objectName = (COSName) arguments.get(0);
        Map<?, ?> xobjects = getResources().getXObjects();
        PDXObject xobject = (PDXObject) xobjects.get(objectName.getName());
        if (xobject instanceof PDXObjectImage) {
            try {
                PDXObjectImage image = (PDXObjectImage) xobject;
                SignaturePlaceholderData data = checkImage(image);
                if (data != null) {
                    PDPage page = getCurrentPage();
                    Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
                    int pageRotation = page.findRotation();
                    pageRotation = pageRotation % 360;
                    double rotationInRadians = Math.toRadians(pageRotation);//(page.findRotation() * Math.PI) / 180;

                    AffineTransform rotation = new AffineTransform();
                    rotation.setToRotation(rotationInRadians);
                    AffineTransform rotationInverse = rotation.createInverse();
                    Matrix rotationInverseMatrix = new Matrix();
                    rotationInverseMatrix.setFromAffineTransform(rotationInverse);
                    Matrix rotationMatrix = new Matrix();
                    rotationMatrix.setFromAffineTransform(rotation);

                    Matrix unrotatedCTM = ctm.multiply(rotationInverseMatrix);

                    float x = unrotatedCTM.getXPosition();
                    float yPos = unrotatedCTM.getYPosition();
                    float yScale = unrotatedCTM.getYScale();
                    float y = yPos + yScale;
                    float w = unrotatedCTM.getXScale();

                    logger.debug("Page height: {}", page.findCropBox().getHeight());
                    logger.debug("Page width: {}", page.findCropBox().getWidth());

                    if (pageRotation == 90) {
                        y = page.findCropBox().getWidth() - (y * (-1));
                    } else if (pageRotation == 180) {
                        x = page.findCropBox().getWidth() + x;
                        y = page.findCropBox().getHeight() - (y * (-1));
                    } else if (pageRotation == 270) {
                        x = page.findCropBox().getHeight() + x;
                    }//from   w  w  w  .  j a v a2  s  .  com

                    String posString = "p:" + currentPage + ";x:" + x + ";y:" + y + ";w:" + w;

                    logger.debug("Found Placeholder at: {}", posString);
                    try {
                        data.setTablePos(new TablePos(posString));
                        data.setPlaceholderName(objectName.getName());
                        placeholders.add(data);
                    } catch (PdfAsException e) {
                        throw new WrappedIOException(e);
                    }
                }
            } catch (NoninvertibleTransformException e) {
                throw new WrappedIOException(e);
            }
        }
    } else {
        super.processOperator(operator, arguments);
    }
}