1 import java.awt.*;
2 import javax.swing.*;
3
4 /**
5
6 */
7 public class ImageProxy implements Icon
8 {
9 /**
10
11 @param name
12 */
13 public ImageProxy(String name)
14 {
15 this.name = name;
16 image = null;
17 }
18
19 public void paintIcon(Component c, Graphics g, int x, int y)
20 {
21 ensureImageLoaded();
22 image.paintIcon(c, g, x, y);
23 }
24
25 public int getIconWidth()
26 {
27 ensureImageLoaded();
28 return image.getIconWidth();
29 }
30
31 public int getIconHeight()
32 {
33 ensureImageLoaded();
34 return image.getIconHeight();
35 }
36
37 /**
38
39
40 */
41 private void ensureImageLoaded()
42 {
43 if (image == null)
44 {
45 System.out.println("Loading " + name);
46 image = new ImageIcon(name);
47 }
48 }
49
50 private String name;
51 private ImageIcon image;
52 }