Java Code Examples for java.awt.geom.AffineTransform#setToRotation()

The following examples show how to use java.awt.geom.AffineTransform#setToRotation() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 2
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 3
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 4
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 5
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 6
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 7
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 8
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 9
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 10
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 11
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 12
private AffineTransform getAffineTransform( int transform ) {
        /// ABP
        AffineTransform at = new AffineTransform();
        switch ( transform )
        {
        case SCALE:
          at.setToScale( 1.5f, 1.5f ); break;
        case ROTATE:
          at.setToRotation( Math.PI / 6 ); break;
        case SHEAR:
          at.setToShear( 0.4f, 0 ); break;
        case NONE:
          break;
        default:
          //System.err.println( "Illegal G2 Transform Arg: " + transform);
          break;
        }

        return at;
}
 
Example 13
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 14
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 15
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 16
public static void main(String[] args) {
    Object aahints[] = {RenderingHints.VALUE_TEXT_ANTIALIAS_OFF,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB};
    int i, j, k;
    AffineTransform a = new AffineTransform();

    for (i=0; i<aahints.length; i++) {
        for(j=0; j<8; j++) {
            System.out.println("Testing hint "+i+" angle="+j);
            a.setToRotation(j*Math.PI/4);
            testTransformedFont(a, aahints[i]);
        }
        testFontOfSize(0.0f, aahints[i]);
        testFontOfSize(-10.0f, aahints[i]);
    }
}
 
Example 17
/**
 * When calling setTransform() the caller passes in an AffineTransform 
 * instance.  If the caller retains a reference to the AffineTransform 
 * and subsequently modifies it, we don't want the Graphics2D object to
 * be affected...so it should be making an internal copy of the 
 * AffineTransform.
 */
@Test
public void checkSetTransformSafety() {
    AffineTransform t = AffineTransform.getTranslateInstance(1.0, 2.0);
    g2.setTransform(t);
    assertEquals(t, g2.getTransform());
    t.setToRotation(Math.PI);
    assertNotEquals(t, g2.getTransform());
}
 
Example 18
Source Project: Darcula   File: ArrowIcon.java    License: Apache License 2.0 5 votes vote down vote up
protected Image getArrowImage() {
    if (arrowImage == null) {
        arrowImage = Utilities.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*/ }                   
        }       
        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, Utilities.deriveColorHSB(base, 0f, 0f, .20f), xx, yy + 1);
    }
    return arrowImage;
}
 
Example 19
Source Project: pumpernickel   File: MirageTransition2D.java    License: MIT License 4 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
		Dimension size) {
	float ySize = (size.height) * .1f;
	float xSize = (size.width) * .1f;
	List<Rectangle2D> v = new ArrayList<Rectangle2D>();
	for (float y = 0; y < size.height; y += ySize) {
		for (float x = 0; x < size.width; x += xSize) {
			v.add(new Rectangle2D.Float(x, y, xSize, ySize));
		}
	}
	Transition2DInstruction[] instr = new Transition2DInstruction[2 * v
			.size()];
	Random random = new Random();
	Point2D center = new Point2D.Double(size.width / 2, size.height / 2);
	double max = Math.sqrt(size.width * size.width / 4 + size.height
			* size.height / 4);
	Point2D p1, p2;
	try {
		for (int a = 0; a < v.size(); a++) {
			float progress2 = (float) Math.pow(progress,
					.9 + .2 * random.nextFloat());
			Rectangle2D r = v.get(a);
			AffineTransform transform = new AffineTransform();
			Shape shape;

			transform.setToRotation(-Math.PI + Math.PI * (1 - progress2),
					size.width / 2, size.height / 2);
			p1 = new Point2D.Double(r.getCenterX(), r.getCenterY());
			p2 = new Point2D.Double();
			transform.transform(p1, p2);
			// transform.setToTranslation(p1.getX()-p2.getX(),p1.getY()-p2.getY());
			transform.setToTranslation(p2.getX() - p1.getX(), p2.getY()
					- p1.getY());
			shape = transform.createInverse().createTransformedShape(r);
			if (a == 0) {
				instr[a] = new ImageInstruction(true);
			} else {
				instr[2 * a + 0] = new ImageInstruction(true, 0, transform,
						shape);
			}
			transform.setToRotation(-1 * Math.PI * (1 - progress),
					size.width / 2, size.height / 2);
			transform.translate(size.width / 2, size.height / 2);
			transform.scale(1 / progress2, 1 / progress2);
			transform.translate(-size.width / 2, -size.height / 2);

			p1 = new Point2D.Double(r.getCenterX(), r.getCenterY());
			p2 = new Point2D.Double();
			transform.transform(p1, p2);
			// transform.setToTranslation(p1.getX()-p2.getX(),p1.getY()-p2.getY());
			transform.setToTranslation(p2.getX() - p1.getX(), p2.getY()
					- p1.getY());
			shape = r; // transform.createInverse().createTransformedShape(r);
			float progress3 = (float) ((1 - progress2) * (1 - p1
					.distance(center) / max));
			/**
			 * This doesn't look terrible if you don't use opacity... but it
			 * looks better with it...
			 * 
			 */
			// instr[2*a+1] = new
			// ImageInstruction(false,transform.createInverse(),shape);
			instr[2 * a + 1] = new ImageInstruction(false, 1 - progress3,
					transform.createInverse(), shape);
		}
	} catch (Exception e) {

	}
	return instr;
}
 
Example 20
Source Project: pumpernickel   File: KaleidoscopeTransition2D.java    License: MIT License 4 votes vote down vote up
@Override
public Transition2DInstruction[] getInstructions(float progress,
		Dimension size) {
	List<Rectangle2D> v1 = new ArrayList<Rectangle2D>();
	List<Transition2DInstruction> v2 = new ArrayList<Transition2DInstruction>();

	float factor = .2f;

	float ySize = (size.height) * factor;
	float xSize = (size.width) * factor;
	for (float y = 0; y < size.height; y += ySize) {
		for (float x = 0; x < size.width; x += xSize) {
			v1.add(new Rectangle2D.Float(x, y, xSize, ySize));
		}
	}

	progress = 1 - progress;

	Point2D p1, p2;
	v2.add(new ImageInstruction(false));
	float dx = 10; // (float)(0*Math.cos(2*(1-progress)*Math.PI));
	float dy = 10; // (float)(0*Math.sin(2*(1-progress)*Math.PI));
	for (int a = 0; a < v1.size(); a++) {
		try {
			Rectangle2D r = v1.get(a);
			p1 = new Point2D.Double(r.getCenterX(), r.getCenterY());
			AffineTransform transform = new AffineTransform();

			transform.setToRotation(-2 * Math.PI
					* (1 - Math.sqrt(progress)), size.width / 2 + dx,
					size.height / 2 + dy);
			transform.translate(size.width / 2, size.height / 2);
			transform.scale(progress * progress, progress * progress);
			transform.translate(-size.width / 2, -size.height / 2);

			p2 = new Point2D.Double();
			transform.transform(p1, p2);
			transform.setToTranslation(p2.getX() - p1.getX(), p2.getY()
					- p1.getY());
			v2.add(new ImageInstruction(false, progress, transform
					.createInverse(), r));

			transform.setToRotation(-2 * Math.PI
					* (1 - Math.sqrt(progress)), size.width / 2 + dx,
					size.height / 2 + dy);

			p2 = new Point2D.Double();
			transform.transform(p1, p2);
			transform.setToTranslation(p2.getX() - p1.getX(), p2.getY()
					- p1.getY());
			v2.add(new ImageInstruction(true, progress * progress,
					transform.createInverse(), r));
		} catch (Exception e) {

		}
	}
	return v2.toArray(new Transition2DInstruction[v2.size()]);
}