@Override protected void done() { try { BufferedImage bufferedImage = get(); cachedImages.put(renderWidth + ":" + renderHeight, bufferedImage); fireAsyncCompleted(true); } catch (Exception exc) { fireAsyncCompleted(false); } } };
@Override public synchronized boolean isLoading() { BufferedImage image = this.cachedImages.get(this.getIconWidth() + ":" + this.getIconHeight()); return (image == null); } }
/** * Sets the preferred size for <code>this</code> icon. The rendering is * scheduled automatically. * * @param dim * Preferred size. */ public synchronized void setPreferredSize(Dimension dim) { if ((dim.width == this.width) && (dim.height == this.height)) return; this.width = dim.width; this.height = dim.height; this.renderImage(this.width, this.height); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { BufferedImage image = this.cachedImages.get(this.getIconWidth() + ":" + this.getIconHeight()); if (image != null) { int dx = (this.width - image.getWidth()) / 2; int dy = (this.height - image.getHeight()) / 2; g.drawImage(image, x + dx, y + dy, null); } }
String key = renderWidth + ":" + renderHeight; if (this.cachedImages.containsKey(key)) { fireAsyncCompleted(true); return;
/** * Create a new ICO icon. * * @param inputStream * The input stream to read the ICO bits from. * @param w * The width of the icon. * @param h * The height of the icon. */ public IcoWrapperIcon(InputStream inputStream, int w, int h) { this.icoInputStream = inputStream; this.width = w; this.height = h; this.listenerList = new EventListenerList(); this.cachedImages = new LinkedHashMap<String, BufferedImage>() { @Override protected boolean removeEldestEntry( Map.Entry<String, BufferedImage> eldest) { return size() > 5; } }; this.renderImage(this.width, this.height); }