01: package gnu.kawa.models;
02:
03: import java.awt.*;
04: import java.awt.geom.*;
05:
06: public class WithTransform implements Paintable {
07: Paintable paintable;
08: AffineTransform transform;
09:
10: public WithTransform(Paintable paintable, AffineTransform transform) {
11: this .paintable = paintable;
12: this .transform = transform;
13: }
14:
15: public void paint(Graphics2D graphics) {
16: AffineTransform saved = graphics.getTransform();
17: try {
18: graphics.transform(transform);
19: paintable.paint(graphics);
20: } finally {
21: graphics.setTransform(saved);
22: }
23: }
24:
25: public Rectangle2D getBounds2D() {
26: return transform
27: .createTransformedShape(paintable.getBounds2D())
28: .getBounds2D();
29: }
30:
31: public Paintable transform(AffineTransform tr) {
32: AffineTransform combined = new AffineTransform(transform);
33: combined.concatenate(tr);
34: return new WithTransform(paintable, combined);
35: }
36: }
|