KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > OverlayIconCache


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.team.internal.ui.*;
19
20 /**
21  * Maintains a cache of OverlayIcons.
22  */

23 public class OverlayIconCache {
24     private Map JavaDoc /*from OverlayIcon to Image*/ cache = new HashMap JavaDoc();
25     
26     /**
27      * Returns and caches an image corresponding to the specified icon.
28      * @param icon the icon
29      * @return the image
30      */

31     public Image getImageFor(OverlayIcon icon) {
32         Image image = (Image) cache.get(icon);
33         if (image == null) {
34             image = icon.createImage();
35             cache.put(icon, image);
36         }
37         return image;
38     }
39     
40     /**
41      * Disposes of all images in the cache.
42      */

43     public void disposeAll() {
44         for (Iterator JavaDoc it = cache.values().iterator(); it.hasNext();) {
45             Image image = (Image) it.next();
46             image.dispose();
47         }
48         cache.clear();
49     }
50 }
51
Popular Tags