01: package gnu.kawa.models;
02:
03: import java.awt.*;
04: import java.awt.geom.*;
05: import java.awt.image.*;
06: import gnu.mapping.WrappedException;
07: import java.net.URL;
08: import gnu.text.*;
09:
10: public class DrawImage extends Model implements Paintable,
11: java.io.Serializable {
12: BufferedImage image;
13: Path src;
14: String description;
15:
16: public DrawImage() {
17: }
18:
19: public void makeView(Display display, Object where) {
20: display.addImage(this , where);
21: }
22:
23: void loadImage() {
24: if (image == null) {
25: try {
26: image = javax.imageio.ImageIO.read(src
27: .openInputStream());
28: } catch (Throwable ex) {
29: throw WrappedException.wrapIfNeeded(ex);
30: }
31: }
32: }
33:
34: public DrawImage(BufferedImage image) {
35: this .image = image;
36: }
37:
38: public void paint(Graphics2D graphics) {
39: loadImage();
40: graphics.drawImage(image, null, null);
41: }
42:
43: public Rectangle2D getBounds2D() {
44: loadImage();
45: int w = image.getWidth();
46: int h = image.getHeight();
47: return new Rectangle2D.Float(0, 0, w, h);
48: }
49:
50: public Paintable transform(AffineTransform tr) {
51: return new WithTransform(this , tr);
52: }
53:
54: public Image getImage() {
55: loadImage();
56: return image;
57: }
58:
59: public Path getSrc() {
60: return src;
61: }
62:
63: public void setSrc(Path src) {
64: this.src = src;
65: }
66: }
|