41 |
import java.awt.Graphics; |
import java.awt.Graphics; |
42 |
import java.awt.Image; |
import java.awt.Image; |
43 |
import java.awt.Toolkit; |
import java.awt.Toolkit; |
44 |
|
import java.awt.image.ImageObserver; |
45 |
import java.io.Serializable; |
import java.io.Serializable; |
46 |
import java.net.URL; |
import java.net.URL; |
47 |
|
|
51 |
{ |
{ |
52 |
private static final long serialVersionUID = 532615968316031794L; |
private static final long serialVersionUID = 532615968316031794L; |
53 |
Image image; |
Image image; |
54 |
String file; |
String description; |
55 |
String descr; |
ImageObserver observer; |
56 |
Component observer; |
|
57 |
|
public ImageIcon() |
58 |
public ImageIcon(String s) |
{ |
|
{ |
|
|
// if description is not specified, then file name becomes |
|
|
// desciption for this icon |
|
|
this(s, s); |
|
59 |
} |
} |
60 |
|
|
61 |
public ImageIcon(Image image) |
public ImageIcon(String file) |
62 |
|
{ |
63 |
|
this(file, file); |
64 |
|
} |
65 |
|
|
66 |
|
public ImageIcon(String file, String description) |
67 |
{ |
{ |
68 |
|
this(Toolkit.getDefaultToolkit().getImage(file), description); |
69 |
|
} |
70 |
|
|
71 |
|
public ImageIcon(byte[] imageData) |
72 |
|
{ |
73 |
|
this(imageData, null); |
74 |
|
} |
75 |
|
|
76 |
|
public ImageIcon(byte[] imageData, String description) |
77 |
|
{ |
78 |
|
this(Toolkit.getDefaultToolkit().createImage(imageData), description); |
79 |
} |
} |
80 |
|
|
81 |
public ImageIcon(URL url) |
public ImageIcon(URL url) |
82 |
{ |
{ |
83 |
image = Toolkit.getDefaultToolkit().getImage(url); |
this(url, null); |
84 |
} |
} |
85 |
|
|
86 |
public ImageIcon(String file, String descr) |
public ImageIcon(URL url, String description) |
87 |
{ |
{ |
88 |
this.file = file; |
this(Toolkit.getDefaultToolkit().getImage(url), description); |
89 |
this.descr = descr; |
} |
90 |
|
|
91 |
image = Toolkit.getDefaultToolkit().getImage(file); |
public ImageIcon(Image image) |
92 |
if (image == null) |
{ |
93 |
return; |
this(image, null); |
94 |
|
} |
95 |
|
|
96 |
//loadImage(image); |
public ImageIcon(Image image, String description) |
97 |
|
{ |
98 |
|
this.image = Toolkit.getDefaultToolkit().createImage(image.getSource()); |
99 |
|
this.description = description; |
100 |
|
} |
101 |
|
|
102 |
|
public ImageObserver getImageObserver() |
103 |
|
{ |
104 |
|
return observer; |
105 |
} |
} |
106 |
|
|
107 |
// not in SUN's spec !!! |
public void setImageObserver(ImageObserver newObserver) |
|
public void setParent(Component p) |
|
108 |
{ |
{ |
109 |
observer = p; |
observer = newObserver; |
110 |
} |
} |
111 |
|
|
112 |
public Image getImage() |
public Image getImage() |
116 |
|
|
117 |
public String getDescription() |
public String getDescription() |
118 |
{ |
{ |
119 |
return descr; |
return description; |
120 |
} |
} |
121 |
|
|
122 |
public void setDescription(String description) |
public void setDescription(String description) |
123 |
{ |
{ |
124 |
this.descr = description; |
this.description = description; |
125 |
} |
} |
126 |
|
|
127 |
public int getIconHeight() |
public int getIconHeight() |
136 |
|
|
137 |
public void paintIcon(Component c, Graphics g, int x, int y) |
public void paintIcon(Component c, Graphics g, int x, int y) |
138 |
{ |
{ |
139 |
g.drawImage(image, x, y, observer); |
g.drawImage(image, x, y, observer != null ? observer : c); |
140 |
} |
} |
141 |
} |
} |