1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.Graphics2D ; 22 import java.awt.Rectangle ; 23 import java.awt.RenderingHints ; 24 import java.awt.Shape ; 25 26 34 public class ATransform implements Painter { 35 public void paint(Graphics2D g) { 36 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 37 RenderingHints.VALUE_ANTIALIAS_ON); 38 39 g.setPaint(Color.black); 41 int legendX = 10, legendY = 12; 42 g.translate(0, 30); 43 44 java.awt.geom.AffineTransform defaultTransform = g.getTransform(); 45 46 Rectangle rect = new Rectangle (10, 20, 50, 30); 48 49 g.drawString("Default transform", legendX, legendY); 51 g.fill(rect); 52 53 g.translate(0, 90); 55 g.drawString("Translate applied", legendX, legendY); 56 g.fill(rect); 57 58 g.translate(0, 90); 60 g.rotate(Math.PI/2, 35, 35); 61 g.drawString("Rotate about center", legendX, legendY); 62 g.fill(rect); 63 64 g.setTransform(defaultTransform); 66 67 g.translate(150, 0); 69 g.drawString("Scale (sx=2, sy=1)", legendX, legendY); 70 g.scale(2, 1); 71 g.fill(rect); 72 73 g.setTransform(defaultTransform); 75 g.translate(150, 90); 76 g.drawString("Shear", legendX, legendY); 77 g.shear(.2, 1); 78 g.fill(rect); 79 80 java.awt.geom.AffineTransform txf = g.getTransform(); 81 g.setTransform(new java.awt.geom.AffineTransform ()); 82 Shape shearBounds = txf.createTransformedShape(rect).getBounds(); 83 g.setPaint(new Color (0, 0, 0, 128)); 84 g.fill(shearBounds); 85 } 86 } 87 | Popular Tags |