45 |
import java.awt.image.ImageObserver; |
import java.awt.image.ImageObserver; |
46 |
import java.io.Serializable; |
import java.io.Serializable; |
47 |
import java.net.URL; |
import java.net.URL; |
48 |
|
import java.util.Locale; |
49 |
|
|
50 |
|
import javax.accessibility.Accessible; |
51 |
|
import javax.accessibility.AccessibleContext; |
52 |
|
import javax.accessibility.AccessibleIcon; |
53 |
|
import javax.accessibility.AccessibleRole; |
54 |
|
import javax.accessibility.AccessibleStateSet; |
55 |
|
|
56 |
public class ImageIcon |
public class ImageIcon |
57 |
implements Icon, Serializable |
implements Icon, Serializable, Accessible |
58 |
{ |
{ |
59 |
|
/** |
60 |
|
* Accessibility support for ImageIcon. |
61 |
|
*/ |
62 |
|
protected class AccessibleImageIcon |
63 |
|
extends AccessibleContext |
64 |
|
implements AccessibleIcon, Serializable |
65 |
|
{ |
66 |
|
/** |
67 |
|
* Creates a new instance of AccessibleImageIcon. |
68 |
|
*/ |
69 |
|
protected AccessibleImageIcon() |
70 |
|
{ |
71 |
|
} |
72 |
|
|
73 |
|
/** |
74 |
|
* Returns the AccessibleRole of ImageIcon, which is |
75 |
|
* {@link AccessibleRole#ICON}. |
76 |
|
* |
77 |
|
* @return {@link AccessibleRole#ICON} |
78 |
|
*/ |
79 |
|
public AccessibleRole getAccessibleRole() |
80 |
|
{ |
81 |
|
return AccessibleRole.ICON; |
82 |
|
} |
83 |
|
|
84 |
|
/** |
85 |
|
* Returns the accessible state of this ImageIcon. |
86 |
|
* |
87 |
|
* @return the accessible state of this ImageIcon |
88 |
|
*/ |
89 |
|
public AccessibleStateSet getAccessibleStateSet() |
90 |
|
{ |
91 |
|
// TODO: which state information from ImageIcon is returned here?? |
92 |
|
return new AccessibleStateSet(); |
93 |
|
} |
94 |
|
|
95 |
|
/** |
96 |
|
* Returns the accessible parent of this object, which is <code>null</code> |
97 |
|
* in this case, because ImageIcons have no parent. |
98 |
|
* |
99 |
|
* @return <code>null</code>, because ImageIcons have no parent |
100 |
|
*/ |
101 |
|
public Accessible getAccessibleParent() |
102 |
|
{ |
103 |
|
// TODO: ImageIcons have no parent, have they ?? |
104 |
|
return null; |
105 |
|
} |
106 |
|
|
107 |
|
/** |
108 |
|
* Returns the index of this object in its accessible parent, which is |
109 |
|
* -1 here, because ImageIcons have no accessible parent. |
110 |
|
* |
111 |
|
* @return -1 because ImageIcons have no parent |
112 |
|
*/ |
113 |
|
public int getAccessibleIndexInParent() |
114 |
|
{ |
115 |
|
// TODO: do ImageIcons have parents?? |
116 |
|
return -1; |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
|
* Returns the number of accessible children of this component, |
121 |
|
* which is 0, because ImageIcons have no children. |
122 |
|
* |
123 |
|
* @return 0 because ImageIcons have no children |
124 |
|
*/ |
125 |
|
public int getAccessibleChildrenCount() |
126 |
|
{ |
127 |
|
return 0; |
128 |
|
} |
129 |
|
|
130 |
|
/** |
131 |
|
* Returns the accessible child at index <code>i</code>, which is |
132 |
|
* <code>null</code> in this case because ImageIcons have no children. |
133 |
|
* |
134 |
|
* @param i the index of the child to be fetched |
135 |
|
* |
136 |
|
* @return <code>null</code> because ImageIcons have no children |
137 |
|
*/ |
138 |
|
public Accessible getAccessibleChild(int i) |
139 |
|
{ |
140 |
|
return null; |
141 |
|
} |
142 |
|
|
143 |
|
/** |
144 |
|
* Returns the locale of this object. This returns the default locale |
145 |
|
* that is set for the current VM. |
146 |
|
* |
147 |
|
* @return the locale of this object |
148 |
|
*/ |
149 |
|
public Locale getLocale() |
150 |
|
{ |
151 |
|
return Locale.getDefault(); |
152 |
|
} |
153 |
|
|
154 |
|
/** |
155 |
|
* Returns the accessible Icon description. This returns the |
156 |
|
* actual 'description' property of the ImageIcon. |
157 |
|
* |
158 |
|
* @return the accessible Icon description |
159 |
|
*/ |
160 |
|
public String getAccessibleIconDescription() |
161 |
|
{ |
162 |
|
return getDescription(); |
163 |
|
} |
164 |
|
|
165 |
|
/** |
166 |
|
* Sets the accessible Icon description. This sets the |
167 |
|
* actual 'description' property of the ImageIcon. |
168 |
|
* |
169 |
|
* @param newDescr the description to be set |
170 |
|
*/ |
171 |
|
public void setAccessibleIconDescription(String newDescr) |
172 |
|
{ |
173 |
|
setDescription(newDescr); |
174 |
|
} |
175 |
|
|
176 |
|
/** |
177 |
|
* Returns the icon height. This returns the iconHeight property of |
178 |
|
* the underlying Icon. |
179 |
|
* |
180 |
|
* @return the icon height |
181 |
|
*/ |
182 |
|
public int getAccessibleIconHeight() |
183 |
|
{ |
184 |
|
return getIconHeight(); |
185 |
|
} |
186 |
|
|
187 |
|
/** |
188 |
|
* Returns the icon width. This returns the iconWidth property of |
189 |
|
* the underlying Icon. |
190 |
|
* |
191 |
|
* @return the icon width |
192 |
|
*/ |
193 |
|
public int getAccessibleIconWidth() |
194 |
|
{ |
195 |
|
return getIconWidth(); |
196 |
|
} |
197 |
|
} // AccessibleIcon |
198 |
|
|
199 |
private static final long serialVersionUID = 532615968316031794L; |
private static final long serialVersionUID = 532615968316031794L; |
200 |
|
|
201 |
/** A dummy Component that is used in the MediaTracker. */ |
/** A dummy Component that is used in the MediaTracker. */ |
214 |
/** The image loading status. */ |
/** The image loading status. */ |
215 |
private int loadStatus; |
private int loadStatus; |
216 |
|
|
217 |
|
/** The AccessibleContext of this ImageIcon. */ |
218 |
|
private AccessibleContext accessibleContext; |
219 |
|
|
220 |
public ImageIcon() |
public ImageIcon() |
221 |
{ |
{ |
222 |
} |
} |
344 |
{ |
{ |
345 |
return loadStatus; |
return loadStatus; |
346 |
} |
} |
347 |
|
|
348 |
|
/** |
349 |
|
* Returns the AccessibleContext for this ImageIcon. |
350 |
|
* |
351 |
|
* @return the AccessibleContext for this ImageIcon |
352 |
|
*/ |
353 |
|
public AccessibleContext getAccessibleContext() |
354 |
|
{ |
355 |
|
if (accessibleContext == null) |
356 |
|
accessibleContext = new AccessibleImageIcon(); |
357 |
|
return accessibleContext; |
358 |
|
} |
359 |
} |
} |