01: // ImageCache.java
02: // $Id: ImageCache.java,v 1.4 2000/08/16 21:37:56 ylafon Exp $
03: // Author: Jean-Michel.Leon@sophia.inria.fr
04: // (c) COPYRIGHT MIT and INRIA, 1997.
05: // Please first read the full copyright statement in file COPYRIGHT.html
06:
07: package org.w3c.tools.widgets;
08:
09: import java.awt.Component;
10: import java.awt.Image;
11:
12: import java.util.Hashtable;
13:
14: /**
15: * A Basic Image Cache class.
16: */
17: public class ImageCache {
18: private static Hashtable images = new Hashtable();
19:
20: /**
21: * Gets an Image of the requested size.
22: *
23: * Checks if an Image already exists in the cache for the current Thread and
24: * if this image is large enough. Else, creates a new Image and store it in
25: * the cache.
26: */
27: static public Image getImage(Component c, int w, int h) {
28: Image img = (Image) images.get(Thread.currentThread());
29: if ((img == null) || (img.getWidth(c) < w)
30: || (img.getHeight(c) < h)) {
31: img = c.createImage(w, h);
32: images.put(Thread.currentThread(), img);
33: }
34: return img;
35: }
36: }
|