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, double anchorx, double anchory) 

Source Link

Document

Sets this transform to a translated rotation transformation.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = new AffineTransform();
    at.setToRotation(-Math.PI / 2.0, getWidth() / 2.0, getHeight() / 2.0);
    g2d.setTransform(at);/*  ww w  .ja v a  2  s . c om*/
    g2d.drawString("Vertical text", 10, 10);
}

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.setToRotation(0.2, Math.PI / 6, Math.PI / 6);
    at.translate(100, 0);//from w w w .  j  a  v a 2 s  .  co m

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

}

From source file:ArrowIcon.java

protected Image getArrowImage() {
    if (arrowImage == null) {
        arrowImage = createTranslucentImage(size, size);
        AffineTransform atx = direction != SOUTH ? new AffineTransform() : null;
        switch (direction) {
        case NORTH:
            atx.setToRotation(Math.PI, size / 2, size / 2);
            break;
        case EAST:
            atx.setToRotation(-(Math.PI / 2), size / 2, size / 2);
            break;
        case WEST:
            atx.setToRotation(Math.PI / 2, size / 2, size / 2);
        case SOUTH:
        default: {
            /* no xform*/ }
        }/*from  w w w. j ava 2  s  .  c  om*/
        Graphics2D ig = (Graphics2D) arrowImage.getGraphics();
        if (atx != null) {
            ig.setTransform(atx);
        }
        int width = size;
        int height = size / 2 + 1;
        int xx = (size - width) / 2;
        int yy = (size - height + 1) / 2;

        Color base = color != null ? color : UIManager.getColor("controlDkShadow").darker();

        paintArrow(ig, base, xx, yy);
        paintArrowBevel(ig, base, xx, yy);
        paintArrowBevel(ig, deriveColorHSB(base, 0f, 0f, .20f), xx, yy + 1);
    }
    return arrowImage;
}

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java

public void createSignatureRectangle(PDSignatureField signatureField, PDFAsVisualSignatureDesigner properties,
        float degrees) throws IOException {

    PDRectangle rect = new PDRectangle();

    Point2D upSrc = new Point2D.Float();
    upSrc.setLocation(properties.getxAxis() + properties.getWidth(),
            properties.getPageHeight() - properties.getyAxis());

    Point2D llSrc = new Point2D.Float();
    llSrc.setLocation(properties.getxAxis(),
            properties.getPageHeight() - properties.getyAxis() - properties.getHeight());

    rect.setUpperRightX((float) upSrc.getX());
    rect.setUpperRightY((float) upSrc.getY());
    rect.setLowerLeftY((float) llSrc.getY());
    rect.setLowerLeftX((float) llSrc.getX());
    logger.debug("orig rectangle of signature has been created: {}", rect.toString());

    AffineTransform transform = new AffineTransform();
    transform.setToIdentity();//from   w w  w . j  a v a2s  .c o  m
    if (degrees % 360 != 0) {
        transform.setToRotation(Math.toRadians(degrees), llSrc.getX(), llSrc.getY());
    }

    Point2D upDst = new Point2D.Float();
    transform.transform(upSrc, upDst);

    Point2D llDst = new Point2D.Float();
    transform.transform(llSrc, llDst);

    float xPos = properties.getxAxis();
    float yPos = properties.getPageHeight() - properties.getyAxis();
    logger.debug("POS {} x {}", xPos, yPos);
    logger.debug("SIZE {} x {}", properties.getWidth(), properties.getHeight());
    // translate according to page! rotation
    int pageRotation = properties.getPageRotation();
    AffineTransform translate = new AffineTransform();
    switch (pageRotation) {
    case 90:
        translate.setToTranslation(
                properties.getPageHeight() - (properties.getPageHeight() - properties.getyAxis())
                        - properties.getxAxis() + properties.getHeight(),
                properties.getxAxis() + properties.getHeight()
                        - (properties.getPageHeight() - properties.getyAxis()));
        break;
    case 180:
        // translate.setToTranslation(properties.getPageWidth() -
        // properties.getxAxis() - properties.getxAxis(),
        // properties.getPageHeight() - properties.getyAxis() +
        // properties.getHeight());
        translate.setToTranslation(properties.getPageWidth() - 2 * xPos,
                properties.getPageHeight() - 2 * (yPos - properties.getHeight()));
        break;
    case 270:
        translate.setToTranslation(-properties.getHeight() + yPos - xPos,
                properties.getPageWidth() - (yPos - properties.getHeight()) - xPos);
        break;
    }

    translate.transform(upDst, upDst);
    translate.transform(llDst, llDst);

    rect.setUpperRightX((float) upDst.getX());
    rect.setUpperRightY((float) upDst.getY());
    rect.setLowerLeftY((float) llDst.getY());
    rect.setLowerLeftX((float) llDst.getX());
    logger.debug("rectangle of signature has been created: {}", rect.toString());
    signatureField.getWidget().setRectangle(rect);
    getStructure().setSignatureRectangle(rect);
    logger.debug("rectangle of signature has been created");
}