1 package gnu.kawa.models; 2 import java.awt.*; 3 import java.awt.geom.*; 4 5 public class WithTransform implements Paintable 6 { 7 Paintable paintable; 8 AffineTransform transform; 9 10 public WithTransform(Paintable paintable, AffineTransform transform) 11 { 12 this.paintable = paintable; 13 this.transform = transform; 14 } 15 16 public void paint (Graphics2D graphics) 17 { 18 AffineTransform saved = graphics.getTransform(); 19 try 20 { 21 graphics.transform(transform); 22 paintable.paint(graphics); 23 } 24 finally 25 { 26 graphics.setTransform(saved); 27 } 28 } 29 30 public Rectangle2D getBounds2D() 31 { 32 return transform.createTransformedShape(paintable.getBounds2D()) 33 .getBounds2D(); 34 } 35 36 public Paintable transform (AffineTransform tr) 37 { 38 AffineTransform combined = new AffineTransform(transform); 39 combined.concatenate(tr); 40 return new WithTransform(paintable, combined); 41 } 42 } 43 | Popular Tags |