public final void setImage(final URL imageURL) {
if (imageURL == null) {
throw new IllegalArgumentException("imageURL is null.");
}
Image imageLocal = (Image)ApplicationContext.getResourceCache().get(imageURL);
if (imageLocal == null) {
// Convert to URI because using a URL as a key causes performance problems
final java.net.URI imageURI;
try {
imageURI = imageURL.toURI();
} catch (URISyntaxException exception) {
throw new RuntimeException(exception);
}
if (asynchronous) {
if (loadMap.containsKey(imageURI)) {
// Add this to the list of image views that are interested in
// the image at this URL
loadMap.get(imageURI).add(this);
} else {
Image.load(imageURL, new TaskAdapter<Image>(new TaskListener<Image>() {
@Override
public void taskExecuted(Task<Image> task) {
Image imageLoadedLocal = task.getResult();
// Update the contents of all image views that requested this
// image
for (ImageView imageView : loadMap.get(imageURI)) {
imageView.setImage(imageLoadedLocal);