return get(uri, -1, -1);
}
public synchronized ImageResource get(final String uri, final int width, final int height) {
if (ImageUtil.isEmbeddedBase64Image(uri)) {
ImageResource resource = loadEmbeddedBase64ImageResource(uri);
resource.getImage().scale(width, height);
return resource;
} else {
CacheKey key = new CacheKey(uri, width, height);
ImageResource ir = (ImageResource) _imageCache.get(key);
if (ir == null) {
// not loaded, or not loaded at target size
// loaded a base size?
ir = (ImageResource) _imageCache.get(new CacheKey(uri, -1, -1));
// no: loaded
if (ir == null) {
if (isImmediateLoadUri(uri)) {
XRLog.load(Level.FINE, "Load immediate: " + uri);
ir = loadImageResourceFromUri(uri);
FSImage awtfsImage = ir.getImage();
BufferedImage newImg = ((AWTFSImage) awtfsImage).getImage();
loaded(ir, -1, -1);
if (width > -1 && height > -1) {
XRLog.load(Level.FINE, this + ", scaling " + uri + " to " + width + ", " + height);
newImg = ImageUtil.getScaledInstance(newImg, width, height);
ir = new ImageResource(ir.getImageUri(), AWTFSImage.createImage(newImg));
loaded(ir, width, height);
}
} else {
XRLog.load(Level.FINE, "Image cache miss, URI not yet loaded, queueing: " + uri);
MutableFSImage mfsi = new MutableFSImage(_repaintListener);
ir = new ImageResource(uri, mfsi);
_loadQueue.addToQueue(this, uri, mfsi, width, height);
}
_imageCache.put(key, ir);
} else {
// loaded at base size, need to scale
XRLog.load(Level.FINE, this + ", scaling " + uri + " to " + width + ", " + height);
FSImage awtfsImage = ir.getImage();
BufferedImage newImg = ((AWTFSImage) awtfsImage).getImage();
newImg = ImageUtil.getScaledInstance(newImg, width, height);
ir = new ImageResource(ir.getImageUri(), AWTFSImage.createImage(newImg));
loaded(ir, width, height);
}
}
return ir;
}